smsgateway 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smsgateway.rb +316 -329
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 530cebff2b9dd33dc014c50b1b9078e69666f7adb8fe076a12f10f0de89a062d
4
- data.tar.gz: 41787fc5cb6525e4576b16834947d5310f005f0542e35760d1aacdac5a2b4fbe
3
+ metadata.gz: e20178396d124cef3cbba4af579526ee97663ddb08fba142d82ecad5b9812399
4
+ data.tar.gz: e3bbd072ee4fd090a43b7ba7a6c0058f7477c35d3277dc865b1299459fa7b721
5
5
  SHA512:
6
- metadata.gz: '097b80fcf075331938cc95059bbca6d96979f8d4cc606d2abdb48d21ad3ce98404dd9cf72d2a647af5a6e4b15a3e7166cb2e7f10ecfb9b23600e77e1c90b6b27'
7
- data.tar.gz: 7e726d0369babf1fc995f2b8cc126ab6d94817ab9037b1eaf94be814508f2ceed0f68cab3d84ecd3540cb75a8503526c814d9e875d5d5c0fe8d28593a047cde8
6
+ metadata.gz: 4aa4575bd3fb17a23a21989531164fbb42875e30fddde8a1c6c94d34e23d16f7ea390ab32e59767bd7777cf82ab29a26a009b7331e31106e31df0884369008b1
7
+ data.tar.gz: f438bf77b90cce53980f2ad6b06f1708f8b3aa67ad0f01c85f45ff83b4fe90457e602066d370ff5dcaac43977e6ae5bab57011587424ab7077447028547e4831
data/lib/smsgateway.rb CHANGED
@@ -1,404 +1,391 @@
1
1
  require 'json'
2
2
  require 'api'
3
+ require 'gem_config'
3
4
 
4
5
  module SMSGateway
5
- class << self
6
- attr_accessor :configuration
7
- end
6
+ include GemConfig::Base
8
7
 
9
- def self.configuration
10
- @configuration ||= Configuration.new
11
- end
12
-
13
- def self.configure
14
- yield(configuration) if block_given?
15
- end
8
+ with_configuration do
9
+ has :authorization_token, classes: String
10
+ end
16
11
 
17
- class Configuration
18
- attr_accessor :authorization_token
12
+ class Message
13
+
14
+ API_ENDPOINT = 'message/'
15
+
16
+ attr_accessor :device_id, :phone_number, :message, :id, :status, :created_at, :updated_at, :log
17
+
18
+ def initialize(device_id, phone_number, message, id = nil, status = nil, created_at = nil, updated_at = nil, log = nil)
19
+ @id = id
20
+ @device_id = device_id
21
+ @phone_number = phone_number
22
+ @message = message
23
+ @status = status
24
+ @updated_at = updated_at
25
+ @created_at = created_at
26
+ @log = log
27
+ end
28
+
29
+ def send
30
+ result = nil
31
+ params = { device_id: @device_id, phone_number: @phone_number, message: @message }.to_json
32
+
33
+ response = API.post(API_ENDPOINT + 'send', params)
34
+ if response.code == '200'
35
+ res = JSON.parse(response.body)
36
+ @id = res[0]['id']
37
+ @device_id = res[0]['device_id']
38
+ @phone_number = res[0]['phone_number']
39
+ @message = res[0]['message']
40
+ @status = res[0]['status']
41
+ @updated_at = res[0]['updated_at']
42
+ @created_at = res[0]['created_at']
43
+ @log = res[0]['log']
44
+ result = self
45
+ end
19
46
 
20
- def initialize
21
- @authorization_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhZG1pbiIsImlhdCI6MTUyODgwOTkzNSwiZXhwIjo0MTAyNDQ0ODAwLCJ1aWQiOjUxOTAzLCJyb2xlcyI6WyJST0xFX1VTRVIiXX0.2gZqY9ElCB8d1WxcLgrRmEp7q53dlTiHNrdNEXFDX9s'
22
- end
23
- end
24
-
25
- class Message
26
-
27
- API_ENDPOINT = 'message/'
28
-
29
- attr_accessor :device_id, :phone_number, :message, :id, :status, :created_at, :updated_at, :log
30
-
31
- def initialize(device_id, phone_number, message, id = nil, status = nil, created_at = nil, updated_at = nil, log = nil)
32
- @id = id
33
- @device_id = device_id
34
- @phone_number = phone_number
35
- @message = message
36
- @status = status
37
- @updated_at = updated_at
38
- @created_at = created_at
39
- @log = log
40
- end
41
-
42
- def send
43
- result = nil
44
- params = { device_id: @device_id, phone_number: @phone_number, message: @message }.to_json
45
-
46
- response = API.post(API_ENDPOINT + 'send', params)
47
- if response.code == '200'
48
- res = JSON.parse(response.body)
49
- @id = res[0]['id']
50
- @device_id = res[0]['device_id']
51
- @phone_number = res[0]['phone_number']
52
- @message = res[0]['message']
53
- @status = res[0]['status']
54
- @updated_at = res[0]['updated_at']
55
- @created_at = res[0]['created_at']
56
- @log = res[0]['log']
57
- result = self
47
+ result
58
48
  end
59
49
 
60
- result
61
- end
50
+ def cancel
51
+ result = nil
52
+ params = { id: @id }.to_json
53
+
54
+ response = API.post(API_ENDPOINT + 'cancel', params)
55
+ if response.code == '200'
56
+ res = JSON.parse(response.body)
57
+ @id = res[0]['id']
58
+ @device_id = res[0]['device_id']
59
+ @phone_number = res[0]['phone_number']
60
+ @message = res[0]['message']
61
+ @status = res[0]['status']
62
+ @updated_at = res[0]['updated_at']
63
+ @created_at = res[0]['created_at']
64
+ @log = res[0]['log']
65
+ result = self
66
+ end
62
67
 
63
- def cancel
64
- result = nil
65
- params = { id: @id }.to_json
66
-
67
- response = API.post(API_ENDPOINT + 'cancel', params)
68
- if response.code == '200'
69
- res = JSON.parse(response.body)
70
- @id = res[0]['id']
71
- @device_id = res[0]['device_id']
72
- @phone_number = res[0]['phone_number']
73
- @message = res[0]['message']
74
- @status = res[0]['status']
75
- @updated_at = res[0]['updated_at']
76
- @created_at = res[0]['created_at']
77
- @log = res[0]['log']
78
- result = self
68
+ result
79
69
  end
80
70
 
81
- result
82
- end
71
+ def self.where(params)
72
+ result = nil
73
+ search_params = []
74
+ tokens = params.split('AND')
75
+ tokens.each do |tkn|
76
+ tkn = tkn.split('=')
77
+ params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
78
+ search_params << params
79
+ end
80
+
81
+ params = { filters: [ search_params ], order_by: [ { field: 'created_at', direction: 'desc'}, limit: 5, offset: 5] }.to_json
82
+ response = API.post(API_ENDPOINT + 'search', params)
83
+ if response.code == '200'
84
+ res = JSON.parse(response.body)['results']
85
+ converted_objects = []
86
+ res.each do |obj|
87
+ converted_objects << Message.new(obj['device_id'], obj['phone_number'], obj['message'], obj['id'], obj['status'], obj['created_at'], obj['updated_at'], obj['log'])
88
+ end
89
+ result = converted_objects
90
+ end
83
91
 
84
- def self.where(params)
85
- result = nil
86
- search_params = []
87
- tokens = params.split('AND')
88
- tokens.each do |tkn|
89
- tkn = tkn.split('=')
90
- params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
91
- search_params << params
92
+ result
92
93
  end
93
94
 
94
- params = { filters: [ search_params ], order_by: [ { field: 'created_at', direction: 'desc'}, limit: 5, offset: 5] }.to_json
95
- response = API.post(API_ENDPOINT + 'search', params)
96
- if response.code == '200'
97
- res = JSON.parse(response.body)['results']
98
- converted_objects = []
99
- res.each do |obj|
100
- converted_objects << Message.new(obj['device_id'], obj['phone_number'], obj['message'], obj['id'], obj['status'], obj['created_at'], obj['updated_at'], obj['log'])
95
+ def self.all
96
+ result = nil
97
+ params = { filters: [] }.to_json
98
+ response = API.post(API_ENDPOINT + 'search', params)
99
+ if response.code == '200'
100
+ res = JSON.parse(response.body)['results']
101
+ converted_objects = []
102
+ res.each do |obj|
103
+ converted_objects << Message.new(obj['device_id'], obj['phone_number'], obj['message'], obj['id'], obj['status'], obj['created_at'], obj['updated_at'], obj['log'])
104
+ end
105
+ result = converted_objects
101
106
  end
102
- result = converted_objects
107
+
108
+ result
103
109
  end
104
110
 
105
- result
106
- end
111
+ def self.find(id)
112
+ result = nil
113
+ response = API.get(API_ENDPOINT, id)
107
114
 
108
- def self.all
109
- result = nil
110
- params = { filters: [] }.to_json
111
- response = API.post(API_ENDPOINT + 'search', params)
112
- if response.code == '200'
113
- res = JSON.parse(response.body)['results']
114
- converted_objects = []
115
- res.each do |obj|
116
- converted_objects << Message.new(obj['device_id'], obj['phone_number'], obj['message'], obj['id'], obj['status'], obj['created_at'], obj['updated_at'], obj['log'])
115
+ if response.code == '200'
116
+ res = JSON.parse(response.body)
117
+ result = Message.new(res['device_id'], res['phone_number'], res['message'], res['id'], res['status'], res['created_at'], res['updated_at'], res['log'])
117
118
  end
118
- result = converted_objects
119
- end
120
119
 
121
- result
120
+ result
121
+ end
122
122
  end
123
123
 
124
- def self.find(id)
125
- result = nil
126
- response = API.get(API_ENDPOINT, id)
124
+ class Device
127
125
 
128
- if response.code == '200'
129
- res = JSON.parse(response.body)
130
- result = Message.new(res['device_id'], res['phone_number'], res['message'], res['id'], res['status'], res['created_at'], res['updated_at'], res['log'])
131
- end
126
+ API_ENDPOINT = 'device/'
132
127
 
133
- result
134
- end
135
- end
128
+ attr_accessor :id, :name, :attributes
136
129
 
137
- class Device
130
+ def initialize(id, name, attributes)
131
+ @id = id
132
+ @name = name
133
+ @attributes = attributes
134
+ end
138
135
 
139
- API_ENDPOINT = 'device/'
136
+ def self.find(id)
137
+ result = nil
138
+ response = API.get(API_ENDPOINT, id)
139
+ if response.code == '200'
140
+ res = JSON.parse(response.body)
141
+ result = Device.new(res['id'], res['name'], res['attributes'])
142
+ end
140
143
 
141
- attr_accessor :id, :name, :attributes
144
+ result
145
+ end
142
146
 
143
- def initialize(id, name, attributes)
144
- @id = id
145
- @name = name
146
- @attributes = attributes
147
- end
147
+ def self.all
148
+ result = nil
149
+ params = { filters: [] }.to_json
150
+ response = API.post(API_ENDPOINT + 'search', params)
151
+ if response.code == '200'
152
+ res = JSON.parse(response.body)['results']
153
+ converted_objects = []
154
+ res.each do |obj|
155
+ converted_objects << Device.new(obj['id'], obj['name'], obj['attributes'])
156
+ end
157
+ result = converted_objects
158
+ end
148
159
 
149
- def self.find(id)
150
- result = nil
151
- response = API.get(API_ENDPOINT, id)
152
- if response.code == '200'
153
- res = JSON.parse(response.body)
154
- result = Device.new(res['id'], res['name'], res['attributes'])
160
+ result
155
161
  end
156
162
 
157
- result
158
- end
163
+ def self.where(params)
164
+ result = nil
165
+ search_params = []
166
+ tokens = params.split('AND')
167
+ tokens.each do |tkn|
168
+ tkn = tkn.split('=')
169
+ params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
170
+ search_params << params
171
+ end
159
172
 
160
- def self.all
161
- result = nil
162
- params = { filters: [] }.to_json
163
- response = API.post(API_ENDPOINT + 'search', params)
164
- if response.code == '200'
165
- res = JSON.parse(response.body)['results']
166
- converted_objects = []
167
- res.each do |obj|
168
- converted_objects << Device.new(obj['id'], obj['name'], obj['attributes'])
173
+ params = { filters: [ search_params ], order_by: [ { field: 'type', direction: 'desc'}, limit: 5, offset: 5] }.to_json
174
+ response = API.post(API_ENDPOINT + 'search', params)
175
+ if response.code == '200'
176
+ res = JSON.parse(response.body)['results']
177
+ converted_objects = []
178
+ res.each do |obj|
179
+ converted_objects << Device.new(obj['id'], obj['name'], obj['attributes'])
180
+ end
181
+ result = converted_objects
169
182
  end
170
- result = converted_objects
171
- end
172
183
 
173
- result
184
+ result
185
+ end
174
186
  end
175
187
 
176
- def self.where(params)
177
- result = nil
178
- search_params = []
179
- tokens = params.split('AND')
180
- tokens.each do |tkn|
181
- tkn = tkn.split('=')
182
- params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
183
- search_params << params
184
- end
188
+ class Contact
185
189
 
186
- params = { filters: [ search_params ], order_by: [ { field: 'type', direction: 'desc'}, limit: 5, offset: 5] }.to_json
187
- response = API.post(API_ENDPOINT + 'search', params)
188
- if response.code == '200'
189
- res = JSON.parse(response.body)['results']
190
- converted_objects = []
191
- res.each do |obj|
192
- converted_objects << Device.new(obj['id'], obj['name'], obj['attributes'])
193
- end
194
- result = converted_objects
195
- end
190
+ API_ENDPOINT = 'contact'
196
191
 
197
- result
198
- end
199
- end
192
+ attr_accessor :id, :name, :phone_numbers
200
193
 
201
- class Contact
194
+ def initialize(name, phone_numbers, id = nil)
195
+ @id = id
196
+ @name = name
197
+ @phone_numbers = phone_numbers
198
+ end
202
199
 
203
- API_ENDPOINT = 'contact'
200
+ def save
201
+ params = { name: @name, phone_numbers: @phone_numbers }.to_json
202
+ response = API.post(API_ENDPOINT, params)
203
+ if response.code == '200'
204
+ res = JSON.parse(response.body)
205
+ @id = res[0]['id']
206
+ @name = res[0]['name']
207
+ @phone_numbers = res[0]['phone_numbers']
208
+ result = self
209
+ end
204
210
 
205
- attr_accessor :id, :name, :phone_numbers
211
+ result
212
+ end
206
213
 
207
- def initialize(name, phone_numbers, id = nil)
208
- @id = id
209
- @name = name
210
- @phone_numbers = phone_numbers
211
- end
214
+ def self.find(id)
215
+ result = nil
216
+ response = API.get(API_ENDPOINT + '/', id)
217
+ if response.code == '200'
218
+ res = JSON.parse(response.body)
219
+ result = Contact.new(res['name'], res['phone_numbers'], res['id'])
220
+ end
212
221
 
213
- def save
214
- params = { name: @name, phone_numbers: @phone_numbers }.to_json
215
- response = API.post(API_ENDPOINT, params)
216
- if response.code == '200'
217
- res = JSON.parse(response.body)
218
- @id = res[0]['id']
219
- @name = res[0]['name']
220
- @phone_numbers = res[0]['phone_numbers']
221
- result = self
222
+ result
222
223
  end
223
224
 
224
- result
225
- end
225
+ def self.where(params)
226
+ result = nil
227
+ search_params = []
228
+ tokens = params.split('AND')
229
+ tokens.each do |tkn|
230
+ tkn = tkn.split('=')
231
+ params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
232
+ search_params << params
233
+ end
226
234
 
227
- def self.find(id)
228
- result = nil
229
- response = API.get(API_ENDPOINT + '/', id)
230
- if response.code == '200'
231
- res = JSON.parse(response.body)
232
- result = Contact.new(res['name'], res['phone_numbers'], res['id'])
235
+ params = { filters: [ search_params ], order_by: [ { field: 'name', direction: 'desc'}, limit: 5, offset: 5] }.to_json
236
+ response = API.post(API_ENDPOINT + '/search', params)
237
+ if response.code == '200'
238
+ res = JSON.parse(response.body)['results']
239
+ converted_objects = []
240
+ res.each do |obj|
241
+ converted_objects << Contact.new(obj['name'], obj['phone_numbers'], obj['id'])
242
+ end
243
+ result = converted_objects
244
+ end
245
+
246
+ result
233
247
  end
234
248
 
235
- result
236
- end
249
+ def self.all
250
+ result = nil
251
+ params = { filters: [] }.to_json
252
+ response = API.post(API_ENDPOINT + '/search', params)
253
+ if response.code == '200'
254
+ res = JSON.parse(response.body)['results']
255
+ converted_objects = []
256
+ res.each do |obj|
257
+ converted_objects << Contact.new(obj['name'], obj['phone_numbers'], obj['id'])
258
+ end
259
+ result = converted_objects
260
+ end
237
261
 
238
- def self.where(params)
239
- result = nil
240
- search_params = []
241
- tokens = params.split('AND')
242
- tokens.each do |tkn|
243
- tkn = tkn.split('=')
244
- params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
245
- search_params << params
262
+ result
246
263
  end
247
264
 
248
- params = { filters: [ search_params ], order_by: [ { field: 'name', direction: 'desc'}, limit: 5, offset: 5] }.to_json
249
- response = API.post(API_ENDPOINT + '/search', params)
250
- if response.code == '200'
251
- res = JSON.parse(response.body)['results']
252
- converted_objects = []
253
- res.each do |obj|
254
- converted_objects << Contact.new(obj['name'], obj['phone_numbers'], obj['id'])
265
+ def update
266
+ params = { name: @name, phone_numbers: @phone_numbers }.to_json
267
+ response = API.put(API_ENDPOINT + "/#{@id}", params)
268
+ if response.code == '200'
269
+ res = JSON.parse(response.body)
270
+ @id = res['id']
271
+ @name = res['name']
272
+ @phone_numbers = res['phone_numbers']
273
+ result = self
255
274
  end
256
- result = converted_objects
257
- end
258
275
 
259
- result
276
+ result
277
+ end
260
278
  end
261
279
 
262
- def self.all
263
- result = nil
264
- params = { filters: [] }.to_json
265
- response = API.post(API_ENDPOINT + '/search', params)
266
- if response.code == '200'
267
- res = JSON.parse(response.body)['results']
268
- converted_objects = []
269
- res.each do |obj|
270
- converted_objects << Contact.new(obj['name'], obj['phone_numbers'], obj['id'])
280
+ class Callback
281
+
282
+ API_ENDPOINT = 'callback/'
283
+
284
+ attr_accessor :name, :event, :device_id, :filter_type, :filter, :method, :action, :secret
285
+
286
+ def initialize(name=nil, event=nil, device_id=nil, filter_type=nil, filter=nil, method=nil, action=nil, secret=nil, id=nil)
287
+ @name = name
288
+ @event = event
289
+ @device_id = device_id
290
+ @filter_type = filter_type
291
+ @filter = filter
292
+ @method = method
293
+ @action = action
294
+ @secret = secret
295
+ @id = id
296
+ end
297
+
298
+ def save
299
+ result = nil
300
+ params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json
301
+
302
+ response = API.post(API_ENDPOINT.chomp('/'), params)
303
+ if response.code == '200'
304
+ res = JSON.parse(response.body)
305
+ @name = res['name']
306
+ @device_id = res['device_id']
307
+ @event = res['event']
308
+ @filter_type = res['filter_type']
309
+ @filter = res['filter']
310
+ @method = res['method']
311
+ @action = res['action']
312
+ @secret = res['secret']
313
+ result = self
271
314
  end
272
- result = converted_objects
273
- end
274
315
 
275
- result
276
- end
277
-
278
- def update
279
- params = { name: @name, phone_numbers: @phone_numbers }.to_json
280
- response = API.put(API_ENDPOINT + "/#{@id}", params)
281
- if response.code == '200'
282
- res = JSON.parse(response.body)
283
- @id = res['id']
284
- @name = res['name']
285
- @phone_numbers = res['phone_numbers']
286
- result = self
316
+ result
287
317
  end
288
318
 
289
- result
290
- end
291
- end
292
-
293
- class Callback
294
-
295
- API_ENDPOINT = 'callback/'
296
-
297
- attr_accessor :name, :event, :device_id, :filter_type, :filter, :method, :action, :secret
298
-
299
- def initialize(name=nil, event=nil, device_id=nil, filter_type=nil, filter=nil, method=nil, action=nil, secret=nil, id=nil)
300
- @name = name
301
- @event = event
302
- @device_id = device_id
303
- @filter_type = filter_type
304
- @filter = filter
305
- @method = method
306
- @action = action
307
- @secret = secret
308
- @id = id
309
- end
310
-
311
- def save
312
- result = nil
313
- params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json
314
-
315
- response = API.post(API_ENDPOINT.chomp('/'), params)
316
- if response.code == '200'
317
- res = JSON.parse(response.body)
318
- @name = res['name']
319
- @device_id = res['device_id']
320
- @event = res['event']
321
- @filter_type = res['filter_type']
322
- @filter = res['filter']
323
- @method = res['method']
324
- @action = res['action']
325
- @secret = res['secret']
326
- result = self
319
+ def self.find(id)
320
+ result = nil
321
+ response = API.get(API_ENDPOINT, id)
322
+ if response.code == '200'
323
+ res = JSON.parse(response.body)
324
+ result = Callback.new(res['name'], res['event'], res['device_id'], res['filter_type'], res['filter'], res['method'], res['action'], res['secret'], res['id'])
325
+ end
326
+
327
+ result
327
328
  end
328
329
 
329
- result
330
- end
330
+ def self.all
331
+ result = nil
332
+ params = { filters: [] }.to_json
333
+ response = API.post(API_ENDPOINT + 'search', params)
334
+ if response.code == '200'
335
+ res = JSON.parse(response.body)['results']
336
+ converted_objects = []
337
+ res.each do |obj|
338
+ converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id'])
339
+ end
340
+ result = converted_objects
341
+ end
331
342
 
332
- def self.find(id)
333
- result = nil
334
- response = API.get(API_ENDPOINT, id)
335
- if response.code == '200'
336
- res = JSON.parse(response.body)
337
- result = Callback.new(res['name'], res['event'], res['device_id'], res['filter_type'], res['filter'], res['method'], res['action'], res['secret'], res['id'])
343
+ result
338
344
  end
339
345
 
340
- result
341
- end
342
-
343
- def self.all
344
- result = nil
345
- params = { filters: [] }.to_json
346
- response = API.post(API_ENDPOINT + 'search', params)
347
- if response.code == '200'
348
- res = JSON.parse(response.body)['results']
349
- converted_objects = []
350
- res.each do |obj|
351
- converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id'])
346
+ def self.where(params)
347
+ result = nil
348
+ search_params = []
349
+ tokens = params.split('AND')
350
+ tokens.each do |tkn|
351
+ tkn = tkn.split('=')
352
+ params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
353
+ search_params << params
352
354
  end
353
- result = converted_objects
354
- end
355
355
 
356
- result
357
- end
356
+ params = { filters: [ search_params ], order_by: [ { field: 'created_at', direction: 'desc'}, limit: 5, offset: 5] }.to_json
357
+ response = API.post(API_ENDPOINT + 'search', params)
358
+ if response.code == '200'
359
+ res = JSON.parse(response.body)['results']
360
+ converted_objects = []
361
+ res.each do |obj|
362
+ converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id'])
363
+ end
364
+ result = converted_objects
365
+ end
358
366
 
359
- def self.where(params)
360
- result = nil
361
- search_params = []
362
- tokens = params.split('AND')
363
- tokens.each do |tkn|
364
- tkn = tkn.split('=')
365
- params = { field: tkn[0].strip!, operator: '=', value: tkn[1].delete("'").strip!}
366
- search_params << params
367
+ result
367
368
  end
368
369
 
369
- params = { filters: [ search_params ], order_by: [ { field: 'created_at', direction: 'desc'}, limit: 5, offset: 5] }.to_json
370
- response = API.post(API_ENDPOINT + 'search', params)
371
- if response.code == '200'
372
- res = JSON.parse(response.body)['results']
373
- converted_objects = []
374
- res.each do |obj|
375
- converted_objects << Callback.new(obj['name'], obj['event'], obj['device_id'], obj['filter_type'], obj['filter'], obj['method'], obj['action'], obj['secret'], obj['id'])
370
+ def update
371
+ result = nil
372
+ params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json
373
+
374
+ response = API.put(API_ENDPOINT + "#{@id}", params)
375
+ if response.code == '200'
376
+ res = JSON.parse(response.body)
377
+ @name = res['name']
378
+ @device_id = res['device_id']
379
+ @event = res['event']
380
+ @filter_type = res['filter_type']
381
+ @filter = res['filter']
382
+ @method = res['method']
383
+ @action = res['action']
384
+ @secret = res['secret']
385
+ result = self
376
386
  end
377
- result = converted_objects
378
- end
379
387
 
380
- result
381
- end
382
-
383
- def update
384
- result = nil
385
- params = { name: @name, event: @event, device_id: @device_id, filter_type: @filter_type, filter: @filter, method: @method, action: @action, secret: @secret }.to_json
386
-
387
- response = API.put(API_ENDPOINT + "#{@id}", params)
388
- if response.code == '200'
389
- res = JSON.parse(response.body)
390
- @name = res['name']
391
- @device_id = res['device_id']
392
- @event = res['event']
393
- @filter_type = res['filter_type']
394
- @filter = res['filter']
395
- @method = res['method']
396
- @action = res['action']
397
- @secret = res['secret']
398
- result = self
388
+ result
399
389
  end
400
-
401
- result
402
390
  end
403
- end
404
391
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsgateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashhad Sheikh
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-06-10 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A ruby gem to interact with smsgateway.me API
14
28
  email: ashhadsheikh@hotmail.com
15
29
  executables: []
@@ -18,7 +32,7 @@ extra_rdoc_files: []
18
32
  files:
19
33
  - lib/api.rb
20
34
  - lib/smsgateway.rb
21
- homepage:
35
+ homepage: https://github.com/ashhadsheikh/smsgateway
22
36
  licenses:
23
37
  - MIT
24
38
  metadata: {}