class SMSGateway::Callback
Constants
- API_ENDPOINT
Attributes
action[RW]
device_id[RW]
event[RW]
filter[RW]
filter_type[RW]
method[RW]
name[RW]
secret[RW]
Public Class Methods
all()
click to toggle source
# File lib/smsgateway.rb, line 330 def self.all result = nil params = { filters: [] }.to_json response = API.post(API_ENDPOINT + 'search', params) if response.code == '200' res = JSON.parse(response.body)['results'] converted_objects = [] res.each do |obj| converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id']) end result = converted_objects end result end
find(id)
click to toggle source
# File lib/smsgateway.rb, line 319 def self.find(id) result = nil response = API.get(API_ENDPOINT, id) if response.code == '200' res = JSON.parse(response.body) result = Callback.new(res['name'], res['event'], res['device_id'], res['filter_type'], res['filter'], res['method'], res['action'], res['secret'], res['id']) end result end
new(name=nil, event=nil, device_id=nil, filter_type=nil, filter=nil, method=nil, action=nil, secret=nil, id=nil)
click to toggle source
# File lib/smsgateway.rb, line 286 def initialize(name=nil, event=nil, device_id=nil, filter_type=nil, filter=nil, method=nil, action=nil, secret=nil, id=nil) @name = name @event = event @device_id = device_id @filter_type = filter_type @filter = filter @method = method @action = action @secret = secret @id = id end
where(params)
click to toggle source
# File lib/smsgateway.rb, line 346 def self.where(params) result = nil search_params = [] tokens = params.split('AND') tokens.each do |tkn| tkn = tkn.split('=') params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!} search_params << params end params = { filters: [ search_params ], order_by: [ { field: 'created_at', direction: 'desc'}, limit: 5, offset: 5] }.to_json response = API.post(API_ENDPOINT + 'search', params) if response.code == '200' res = JSON.parse(response.body)['results'] converted_objects = [] res.each do |obj| converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id']) end result = converted_objects end result end
Public Instance Methods
save()
click to toggle source
# File lib/smsgateway.rb, line 298 def save result = nil params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json response = API.post(API_ENDPOINT.chomp('/'), params) if response.code == '200' res = JSON.parse(response.body) @name = res['name'] @device_id = res['device_id'] @event = res['event'] @filter_type = res['filter_type'] @filter = res['filter'] @method = res['method'] @action = res['action'] @secret = res['secret'] result = self end result end
update()
click to toggle source
# File lib/smsgateway.rb, line 370 def update result = nil params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json response = API.put(API_ENDPOINT + "#{@id}", params) if response.code == '200' res = JSON.parse(response.body) @name = res['name'] @device_id = res['device_id'] @event = res['event'] @filter_type = res['filter_type'] @filter = res['filter'] @method = res['method'] @action = res['action'] @secret = res['secret'] result = self end result end