Class: ListsApi

Inherits:
Object show all
Defined in:
lib/lists_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ ListsApi

apiInvoker = APIInvoker



7
8
9
10
11
12
13
14
15
# File 'lib/lists_api.rb', line 7

def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
  @sms_api = SmsApi

  @api_key_secret = create_api_key_secret()

  config_swagger()
end

Instance Method Details

#add_list(name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts = {}) ⇒ Object

Create a new list including the ability to add custom fields.

Parameters:

  • name (defaults to: nil)

    A unique name for the list

  • field_1 (defaults to: nil)

    Custom field value 1

  • field_2 (defaults to: nil)

    Custom field value 2

  • field_3 (defaults to: nil)

    Custom field value 3

  • field_4 (defaults to: nil)

    Custom field value 4

  • field_5 (defaults to: nil)

    Custom field value 5

  • field_6 (defaults to: nil)

    Custom field value 6

  • field_7 (defaults to: nil)

    Custom field value 7

  • field_8 (defaults to: nil)

    Custom field value 8

  • field_9 (defaults to: nil)

    Custom field value 9

  • field_10 (defaults to: nil)

    Custom field value 10

Returns:

  • void



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/lists_api.rb', line 46

def add_list (name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts={})
  query_param_keys = [:name,:field_1,:field_2,:field_3,:field_4,:field_5,:field_6,:field_7,:field_8,:field_9,:field_10]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'name' => name,
    :'field_1' => field_1,
    :'field_2' => field_2,
    :'field_3' => field_3,
    :'field_4' => field_4,
    :'field_5' => field_5,
    :'field_6' => field_6,
    :'field_7' => field_7,
    :'field_8' => field_8,
    :'field_9' => field_9,
    :'field_10' => field_10
    
  }.merge(opts)

  #resource path
  path = "/add-list.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#add_to_list(list_id = nil, msisdn = nil, first_name = nil, last_name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts = {}) ⇒ Object

Add a member to a list.

Parameters:

  • list_id (defaults to: nil)

    ID of the list to add to

  • msisdn (defaults to: nil)

    Mobile number of the member

  • first_name (defaults to: nil)

    First name of the member

  • last_name (defaults to: nil)

    Last name of the member

  • field_1 (defaults to: nil)

    Custom field value 1

  • field_2 (defaults to: nil)

    Custom field value 2

  • field_3 (defaults to: nil)

    Custom field value 3

  • field_4 (defaults to: nil)

    Custom field value 4

  • field_5 (defaults to: nil)

    Custom field value 5

  • field_6 (defaults to: nil)

    Custom field value 6

  • field_7 (defaults to: nil)

    Custom field value 7

  • field_8 (defaults to: nil)

    Custom field value 8

  • field_9 (defaults to: nil)

    Custom field value 9

  • field_10 (defaults to: nil)

    Custom field value 10

Returns:

  • void



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/lists_api.rb', line 120

def add_to_list (list_id = nil, msisdn = nil, first_name = nil, last_name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts={})
  query_param_keys = [:list_id,:msisdn,:first_name,:last_name,:field_1,:field_2,:field_3,:field_4,:field_5,:field_6,:field_7,:field_8,:field_9,:field_10]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id,
    :'msisdn' => msisdn,
    :'first_name' => first_name,
    :'last_name' => last_name,
    :'field_1' => field_1,
    :'field_2' => field_2,
    :'field_3' => field_3,
    :'field_4' => field_4,
    :'field_5' => field_5,
    :'field_6' => field_6,
    :'field_7' => field_7,
    :'field_8' => field_8,
    :'field_9' => field_9,
    :'field_10' => field_10
    
  }.merge(opts)

  #resource path
  path = "/add-to-list.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#config_swaggerObject



22
23
24
25
26
27
28
29
# File 'lib/lists_api.rb', line 22

def config_swagger()
  Swagger.configure do |config|
    config.host = "https://api.transmitsms.com/".gsub("http://", "").gsub("https://", "").gsub("/", "")
    config.base_path = "/"
    config.format = "x-www-form-urlencoded"
    config.camelize_params = false
  end
end

#create_api_key_secretObject



17
18
19
20
# File 'lib/lists_api.rb', line 17

def create_api_key_secret()
  api_key_secret = Base64.strict_encode64("#{@api_key}:#{@api_secret}")
  "Basic #{api_key_secret}"
end

#delete_from_list(list_id = nil, msisdn = nil, opts = {}) ⇒ Object

Remove a member from one list or all lists.

Parameters:

  • list_id (defaults to: nil)

    ID of the list to remove from. If set to 0 (zero) the member will be removed from all lists.

  • msisdn (defaults to: nil)

    Mobile number of the member

Returns:

  • void



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/lists_api.rb', line 185

def delete_from_list (list_id = nil, msisdn = nil, opts={})
  query_param_keys = [:list_id,:msisdn]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id,
    :'msisdn' => msisdn
    
  }.merge(opts)

  #resource path
  path = "/delete-from-list.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#edit_list_member(list_id = nil, msisdn = nil, first_name = nil, last_name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts = {}) ⇒ Object

Edit a member of a list.

Parameters:

  • list_id (defaults to: nil)

    ID of the list the member belongs to

  • msisdn (defaults to: nil)

    Mobile number of the member to edit

  • first_name (defaults to: nil)

    First name of the member

  • last_name (defaults to: nil)

    Last name of the member

  • field_1 (defaults to: nil)

    Custom field value 1

  • field_2 (defaults to: nil)

    Custom field value 2

  • field_3 (defaults to: nil)

    Custom field value 3

  • field_4 (defaults to: nil)

    Custom field value 4

  • field_5 (defaults to: nil)

    Custom field value 5

  • field_6 (defaults to: nil)

    Custom field value 6

  • field_7 (defaults to: nil)

    Custom field value 7

  • field_8 (defaults to: nil)

    Custom field value 8

  • field_9 (defaults to: nil)

    Custom field value 9

  • field_10 (defaults to: nil)

    Custom field value 10

Returns:

  • void



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/lists_api.rb', line 250

def edit_list_member (list_id = nil, msisdn = nil, first_name = nil, last_name = nil, field_1 = nil, field_2 = nil, field_3 = nil, field_4 = nil, field_5 = nil, field_6 = nil, field_7 = nil, field_8 = nil, field_9 = nil, field_10 = nil, opts={})
  query_param_keys = [:list_id,:msisdn,:first_name,:last_name,:field_1,:field_2,:field_3,:field_4,:field_5,:field_6,:field_7,:field_8,:field_9,:field_10]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id,
    :'msisdn' => msisdn,
    :'first_name' => first_name,
    :'last_name' => last_name,
    :'field_1' => field_1,
    :'field_2' => field_2,
    :'field_3' => field_3,
    :'field_4' => field_4,
    :'field_5' => field_5,
    :'field_6' => field_6,
    :'field_7' => field_7,
    :'field_8' => field_8,
    :'field_9' => field_9,
    :'field_10' => field_10
    
  }.merge(opts)

  #resource path
  path = "/edit-list-member.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_list(list_id = nil, members = nil, page = nil, max = nil, opts = {}) ⇒ Object

Get information about a list and its members.

Parameters:

  • list_id (defaults to: nil)

    List ID

  • members (defaults to: nil)

    Types of members to return. (active, inactive, all, none)

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/lists_api.rb', line 317

def get_list (list_id = nil, members = nil, page = nil, max = nil, opts={})
  query_param_keys = [:list_id,:members,:page,:max]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id,
    :'members' => members,
    :'page' => page,
    :'max' => max
    
  }.merge(opts)

  #resource path
  path = "/get-list.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_lists(page = nil, max = nil, opts = {}) ⇒ Object

Get the metadata of all your lists.

Parameters:

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/lists_api.rb', line 372

def get_lists (page = nil, max = nil, opts={})
  query_param_keys = [:page,:max]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'page' => page,
    :'max' => max
    
  }.merge(opts)

  #resource path
  path = "/get-lists.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#optout_list_member(list_id = nil, msisdn = nil, opts = {}) ⇒ Object

Opt a user out of one list or all lists.

Parameters:

  • list_id (defaults to: nil)

    ID of the list to opt the user out of. Set this to 0 (zero) to opt out of all of your lists.

  • msisdn (defaults to: nil)

    Mobile number of the member to opt out

Returns:

  • void



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/lists_api.rb', line 425

def optout_list_member (list_id = nil, msisdn = nil, opts={})
  query_param_keys = [:list_id,:msisdn]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id,
    :'msisdn' => msisdn
    
  }.merge(opts)

  #resource path
  path = "/optout-list-member.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#remove_list(list_id = nil, opts = {}) ⇒ Object

Delete a list and its members.

Parameters:

  • list_id (defaults to: nil)

    ID of the list to remove.

Returns:

  • void



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/lists_api.rb', line 477

def remove_list (list_id = nil, opts={})
  query_param_keys = [:list_id]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'list_id' => list_id
    
  }.merge(opts)

  #resource path
  path = "/remove-list.json".sub('{format}','json')
  
  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  # header parameters
  headers = {}

  _header_accept = 'application/json'
  if _header_accept != ''
    headerParams['Accept'] = _header_accept
  end 
  _header_content_type = ['application/x-www-form-urlencoded']
  headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'

  
  
  headers[:'Authorization'] = @api_key_secret

  # http body (model)
  post_body = nil
  
  # form parameters
  form_parameter_hash = {}
  
  
  
  Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end