Class: Life::API
- Inherits:
-
Object
- Object
- Life::API
- Defined in:
- lib/life-api.rb,
lib/life-api/methods.rb,
lib/life-api/version.rb
Constant Summary collapse
- VERSION =
"0.1.5"
Class Attribute Summary collapse
-
.log ⇒ Object
Default logger for all Life::API instances.
Instance Attribute Summary collapse
-
#sub_id ⇒ Object
Returns the value of attribute sub_id.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #call_me_back(msisdn_b) ⇒ Object
- #change_language(new_language_id) ⇒ Object
- #change_super_password(old_password, new_password) ⇒ Object
- #get_available_tariffs ⇒ Object
- #get_balances ⇒ Object
-
#get_expenses_summary(month_period) ⇒ Object
Summary expenses report for calendar month
month_period
. - #get_languages ⇒ Object
-
#get_payments_history(month_period) ⇒ Object
Payments history for calendar month
month_period
. - #get_services ⇒ Object
- #get_summary_data ⇒ Object
- #get_token ⇒ Object
-
#get_ui_properties(language_id, last_date_update) ⇒ Object
last_date_update
is DateTime object. -
#initialize(params = {}) ⇒ API
constructor
Create a new API object using the given parameters.
-
#log ⇒ Object
The current logger.
-
#log=(logger) ⇒ Object
Sets the
logger
used by this instance of Life::API. - #refill_balance_by_scratch_card(secret_code) ⇒ Object
- #request(method, params = {}) ⇒ Object
- #request_balance_transfer(msisdn_b) ⇒ Object
- #sign_in ⇒ Object
- #sign_out ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ API
Create a new API object using the given parameters.
Required parameters
-
:msisdn
- telephone number in format ‘38063*******’ -
:password
- life:) super password -
:lang
- ‘uk’, ‘ru’ or ‘en’
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/life-api.rb', line 77 def initialize(params = {}) @msisdn = params.delete(:msisdn) @password = params.delete(:password) @lang = params.delete(:lang) || 'uk' @log = nil @os_type = 'ANDROID' @api_url = 'https://api.life.com.ua/mobile/' @access_key_code = '7' @application_key = 'E6j_$4UnR_)0b' end |
Class Attribute Details
Instance Attribute Details
#sub_id ⇒ Object
Returns the value of attribute sub_id.
59 60 61 |
# File 'lib/life-api.rb', line 59 def sub_id @sub_id end |
#token ⇒ Object
Returns the value of attribute token.
59 60 61 |
# File 'lib/life-api.rb', line 59 def token @token end |
Instance Method Details
#call_me_back(msisdn_b) ⇒ Object
85 86 87 |
# File 'lib/life-api/methods.rb', line 85 def call_me_back(msisdn_b) request('callMeBack', base_api_parameters.merge({ msisdnB: msisdn_b })) end |
#change_language(new_language_id) ⇒ Object
81 82 83 |
# File 'lib/life-api/methods.rb', line 81 def change_language(new_language_id) request('changeLanguage', base_api_parameters.merge({ newLanguageId: new_language_id})) end |
#change_super_password(old_password, new_password) ⇒ Object
42 43 44 |
# File 'lib/life-api/methods.rb', line 42 def change_super_password(old_password, new_password) request('changeSuperPassword', base_api_parameters.merge({ oldPassword: old_password, newPassword: new_password })) end |
#get_available_tariffs ⇒ Object
69 70 71 |
# File 'lib/life-api/methods.rb', line 69 def get_available_tariffs request('getAvailableTariffs', base_api_parameters) end |
#get_balances ⇒ Object
73 74 75 |
# File 'lib/life-api/methods.rb', line 73 def get_balances request('getBalances', base_api_parameters) end |
#get_expenses_summary(month_period) ⇒ Object
Summary expenses report for calendar month month_period
month_period
- A string like ‘yyyy-MM’ that represent month of year
105 106 107 |
# File 'lib/life-api/methods.rb', line 105 def get_expenses_summary(month_period) request('getExpensesSummary', base_api_parameters.merge({ monthPeriod: month_period })) end |
#get_languages ⇒ Object
77 78 79 |
# File 'lib/life-api/methods.rb', line 77 def get_languages request('getLanguages', base_api_parameters) end |
#get_payments_history(month_period) ⇒ Object
Payments history for calendar month month_period
month_period
- A string like ‘yyyy-MM’ that represent month of year
97 98 99 |
# File 'lib/life-api/methods.rb', line 97 def get_payments_history(month_period) request('getPaymentsHistory', base_api_parameters.merge({ monthPeriod: month_period })) end |
#get_services ⇒ Object
65 66 67 |
# File 'lib/life-api/methods.rb', line 65 def get_services request('getServices', base_api_parameters) end |
#get_summary_data ⇒ Object
61 62 63 |
# File 'lib/life-api/methods.rb', line 61 def get_summary_data request('getSummaryData', base_api_parameters) end |
#get_token ⇒ Object
46 47 48 |
# File 'lib/life-api/methods.rb', line 46 def get_token request('getToken', { msisdn: @msisdn, subId: @sub_id }) end |
#get_ui_properties(language_id, last_date_update) ⇒ Object
last_date_update
is DateTime object
52 53 54 55 56 57 58 59 |
# File 'lib/life-api/methods.rb', line 52 def get_ui_properties(language_id, last_date_update) request('getUIProperties', { accessKeyCode: @access_key_code, languageId: language_id, osType: @os_type, lastDateUpdate: last_date_update, }) end |
#log ⇒ Object
The current logger. If no logger has been set Life::API.log is used.
93 94 95 |
# File 'lib/life-api.rb', line 93 def log @log || Life::API.log end |
#log=(logger) ⇒ Object
Sets the logger
used by this instance of Life::API
99 100 101 |
# File 'lib/life-api.rb', line 99 def log= logger @log = logger end |
#refill_balance_by_scratch_card(secret_code) ⇒ Object
109 110 111 |
# File 'lib/life-api/methods.rb', line 109 def refill_balance_by_scratch_card(secret_code) request('refillBalanceByScratchCard', base_api_parameters.merge({ secretCode: secret_code})) end |
#request(method, params = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/life-api.rb', line 103 def request(method, params = {}) params = { accessKeyCode: @access_key_code }.merge(params) url = create_signed_url(method, params) log.debug("[#{method}] request: #{url}") if log uri = URI(url) request = Net::HTTP::Get.new(uri.request_uri) response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) } log.debug("[#{method}] response: #{response.body}") if log xml = parse_xml(response.body) if xml['responseCode'] if xml['responseCode'] == '0' return xml else = Life::RESPONSE_CODES[xml['responseCode']] ||= "Unknown error code #{xml['responseCode']}" raise MethodError, end else raise MethodError, "Unknown error: #{xml}" end end |
#request_balance_transfer(msisdn_b) ⇒ Object
89 90 91 |
# File 'lib/life-api/methods.rb', line 89 def request_balance_transfer(msisdn_b) request('requestBalanceTransfer', base_api_parameters.merge({ msisdnB: msisdn_b })) end |
#sign_in ⇒ Object
31 32 33 34 35 36 |
# File 'lib/life-api/methods.rb', line 31 def sign_in xml = request('signIn', { msisdn: @msisdn, superPassword: @password }) @token = xml['token'] @sub_id = xml['subId'] return xml end |
#sign_out ⇒ Object
38 39 40 |
# File 'lib/life-api/methods.rb', line 38 def sign_out request('signOut', { msisdn: @msisdn, subId: @sub_id }) end |