class SMSGateway::Device
Constants
- API_ENDPOINT
Attributes
attributes[RW]
id[RW]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/smsgateway.rb, line 147 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 << Device.new(obj['id'], obj['name'], obj['attributes']) end result = converted_objects end result end
find(id)
click to toggle source
# File lib/smsgateway.rb, line 136 def self.find(id) result = nil response = API.get(API_ENDPOINT, id) if response.code == '200' res = JSON.parse(response.body) result = Device.new(res['id'], res['name'], res['attributes']) end result end
new(id, name, attributes)
click to toggle source
# File lib/smsgateway.rb, line 130 def initialize(id, name, attributes) @id = id @name = name @attributes = attributes end
where(params)
click to toggle source
# File lib/smsgateway.rb, line 163 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: 'type', 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 << Device.new(obj['id'], obj['name'], obj['attributes']) end result = converted_objects end result end