Class: ResellersApi

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ ResellersApi

apiInvoker = APIInvoker



7
8
9
10
11
12
13
14
15
# File 'lib/resellers_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_client(name = nil, contact = nil, email = nil, password = nil, msisdn = nil, timezone = nil, client_pays = nil, sms_margin = nil, number_margin = nil, opts = {}) ⇒ Object

Add a new client.

Parameters:

  • name (defaults to: nil)

    Client company name

  • contact (defaults to: nil)

    Contact name

  • email (defaults to: nil)

    Client email address

  • password (defaults to: nil)

    Client password

  • msisdn (defaults to: nil)

    Client phone number

  • timezone (defaults to: nil)

    A valid timezone, Australia/Sydney. Defaults to your own

  • client_pays (defaults to: nil)

    Set to true if the client will pay (the default) or false if you will pay

  • sms_margin (defaults to: nil)

    The number of cents to add to the base SMS price. A decimal value

  • number_margin (defaults to: nil)

    The number of cents to add to the base Number price. A decimal value

Returns:

  • void



44
45
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
# File 'lib/resellers_api.rb', line 44

def add_client (name = nil, contact = nil, email = nil, password = nil, msisdn = nil, timezone = nil, client_pays = nil, sms_margin = nil, number_margin = nil, opts={})
  query_param_keys = [:name,:contact,:email,:password,:msisdn,:timezone,:client_pays,:sms_margin,:number_margin]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'name' => name,
    :'contact' => contact,
    :'email' => email,
    :'password' => password,
    :'msisdn' => msisdn,
    :'timezone' => timezone,
    :'client_pays' => client_pays,
    :'sms_margin' => sms_margin,
    :'number_margin' => number_margin
    
  }.merge(opts)

  #resource path
  path = "/add-client.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/resellers_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/resellers_api.rb', line 17

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

#edit_client(client_id = nil, name = nil, contact = nil, email = nil, password = nil, msisdn = nil, timezone = nil, client_pays = nil, sms_margin = nil, opts = {}) ⇒ Object

Edit an existing client

Parameters:

  • client_id (defaults to: nil)

    The ID of the client

  • name (defaults to: nil)

    Client company name

  • contact (defaults to: nil)

    Contact name

  • email (defaults to: nil)

    Client email address

  • password (defaults to: nil)

    Client password

  • msisdn (defaults to: nil)

    Client phone number

  • timezone (defaults to: nil)

    A valid timezone, Australia/Sydney. Defaults to your own

  • client_pays (defaults to: nil)

    Set to true if the client will pay (the default) or false if you will pay

  • sms_margin (defaults to: nil)

    The number of cents to add to the base SMS price. A decimal value

Returns:

  • void



111
112
113
114
115
116
117
118
119
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
# File 'lib/resellers_api.rb', line 111

def edit_client (client_id = nil, name = nil, contact = nil, email = nil, password = nil, msisdn = nil, timezone = nil, client_pays = nil, sms_margin = nil, opts={})
  query_param_keys = [:client_id,:name,:contact,:email,:password,:msisdn,:timezone,:client_pays,:sms_margin]
  headerParams = {}

  
  
  # set default values and merge with input
  options = {
    :'client_id' => client_id,
    :'name' => name,
    :'contact' => contact,
    :'email' => email,
    :'password' => password,
    :'msisdn' => msisdn,
    :'timezone' => timezone,
    :'client_pays' => client_pays,
    :'sms_margin' => sms_margin
    
  }.merge(opts)

  #resource path
  path = "/edit-client.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(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_client(client_id = nil, opts = {}) ⇒ Object

Get detailed information about a client.

Parameters:

  • client_id (defaults to: nil)

    The ID of the client

Returns:

  • void



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
# File 'lib/resellers_api.rb', line 170

def get_client (client_id = nil, opts={})
  query_param_keys = [:client_id]
  headerParams = {}

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

  #resource path
  path = "/get-client.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(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

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

Get a list of all clients.

Parameters:

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/resellers_api.rb', line 222

def get_clients (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-clients.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(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_transaction(id = nil, opts = {}) ⇒ Object

Get a list of transactions for an account.

Parameters:

  • id (defaults to: nil)

    Transaction ID

Returns:

  • void



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
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/resellers_api.rb', line 274

def get_transaction (id = nil, opts={})
  query_param_keys = [:id]
  headerParams = {}

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

  #resource path
  path = "/get-transaction.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(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end

#get_transactions(client_id = nil, start = nil, _end = nil, page = nil, max = nil, opts = {}) ⇒ Object

Get a list of transactions for an account.

Parameters:

  • client_id (defaults to: nil)

    Only retrieve records for a particular client

  • start (defaults to: nil)

    A timestamp to start the report from

  • _end (defaults to: nil)

    A timestamp to end the report at

  • page (defaults to: nil)

    Page number, for pagination

  • max (defaults to: nil)

    Maximum results returned per page

Returns:

  • void



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
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/resellers_api.rb', line 329

def get_transactions (client_id = nil, start = nil, _end = nil, page = nil, max = nil, opts={})
  query_param_keys = [:client_id,:start,:_end,:page,:max]
  headerParams = {}

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

  #resource path
  path = "/get-transactions.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(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
  

end