Class: App42::AppTab::BillService

Inherits:
Object
  • Object
show all
Defined in:
lib/appTab/BillService.rb

Overview

AppTab - Billing service. This service is used along with the Usage service. It generates Bill for a particular based on Usage Scheme. For e.g. if user sid’s bill has to be seen for May and 2012. This service will list all the charging transactions and calculate the bill for May and tell the total usage and price. The calculation is done based on the Price which is given during scheme creation, the unit of charging and corresponding usage. AppTab currently just maintains the data and does calculation. How the Bill is rendered and the interface with Payment Gateway is left with the App developer.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ BillService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


32
33
34
35
36
37
38
39
# File 'lib/appTab/BillService.rb', line 32

def initialize(api_key, secret_key, base_url)
  puts "BillService->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "bill"
  @version = "1.0"
end

Instance Method Details

#usage_bandwidth_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

    fetched
    
  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


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
216
# File 'lib/appTab/BillService.rb', line 181

def usage_bandwidth_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageBandwidthByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/bandwidth/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_feature_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

      fetched
      
  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/appTab/BillService.rb', line 358

def usage_feature_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageFeatureByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/feature/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_level_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

@throws App42Exception

Parameters:

  • userName
    • The user for which the charging information has to be fetched

  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011



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
269
270
271
272
273
274
275
# File 'lib/appTab/BillService.rb', line 240

def usage_level_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageLevelByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/level/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_license_by_month_and_year(userName, licenseName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

      fetched
      
  • licenseName
    • The name of the License

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


418
419
420
421
422
423
424
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
# File 'lib/appTab/BillService.rb', line 418

def usage_license_by_month_and_year(userName, licenseName, billMonth, year)
  puts "usageLicenseByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(licenseName, "LicenseName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("licenseName", licenseName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/license/#{licenseName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_one_time_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

    fetched
    
  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/appTab/BillService.rb', line 299

def usage_one_time_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageOneTimeByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/oneTime/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_storage_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

      fetched
      
  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

    BillMonth.JANUARY, BillMonth.DECEMBER
    
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


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
# File 'lib/appTab/BillService.rb', line 122

def usage_storage_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageStorageByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/storage/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end

#usage_time_by_month_and_year(userName, usageName, billMonth, year) ⇒ Object

Get usage for Scheme based on Month and Year. This is useful to show the user the charging details of the User for the Scheme

price for that month

Parameters:

  • userName
    • The user for which the charging information has to be

      fetched
      
  • usageName
    • The name of the Scheme

  • billMonth
    • The month name for which the usage has to be fetched e.g.

      BillMonth.JANUARY, BillMonth.DECEMBER
      
  • year
    • The year for which the usage has to be fetched e.g. 2012,

    2011
    


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
# File 'lib/appTab/BillService.rb', line 63

def usage_time_by_month_and_year(userName, usageName, billMonth, year)
  puts "usageTimeByMonthAndYear Called "
  puts "Base url #{@base_url}"
  response = nil;
  billObj = nil;
  billObj = Bill.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "UserName");
  util.throwExceptionIfNullOrBlank(usageName, "UsageName");
  util.throwExceptionIfNullOrBlank(billMonth, "billMonth");
  util.throwExceptionIfNullOrBlank(year, "Year");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    bm = BillMonth.new()
    params.store("usageName", usageName);
    params.store("year", "" + (year.to_i).to_s);
    params.store("month", bm.enum(billMonth));
    params.store("userName", userName);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/time/#{usageName}/#{(year.to_i).to_s}/#{billMonth}/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    billObj = BillResponseBuilder.new().buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return billObj
end