Class: Lifecell::API
- Inherits:
-
Object
- Object
- Lifecell::API
- Defined in:
- lib/lifecell_api.rb,
lib/lifecell_api/methods.rb,
lib/lifecell_api/version.rb
Overview
:nodoc:
Constant Summary collapse
- BASE_URL =
'https://api.lifecell.com.ua/mobile/'
- ACCESS_KEY_CODE =
'7'
- APPLICATION_KEY =
'E6j_$4UnR_)0b'
- OS_TYPE =
'ANDROID'
- VERSION =
'0.7.0'
Class Attribute Summary collapse
-
.log ⇒ Object
Default logger for all Lifecell::API instances.
Instance Attribute Summary collapse
-
#log ⇒ Object
The current logger.
-
#sub_id ⇒ Object
Returns the value of attribute sub_id.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #available_tariffs ⇒ Object
- #balances ⇒ Object
- #call_me_back(msisdn_b) ⇒ Object
- #change_language(new_language_id) ⇒ Object
- #change_super_password(old_password, new_password) ⇒ Object
-
#expenses_summary(month_period) ⇒ Object
Summary expenses report for calendar month
month_period
. -
#initialize(msisdn:, password:, lang: 'uk') ⇒ API
constructor
Create a new API object using the given parameters.
- #languages ⇒ Object
-
#payments_history(month_period) ⇒ Object
Payments history for calendar month
month_period
. - #refill_balance_by_scratch_card(secret_code) ⇒ Object
- #request(method, params = {}) ⇒ Object
- #request_balance_transfer(msisdn_b) ⇒ Object
- #services ⇒ Object
- #sign_in ⇒ Object
- #sign_out ⇒ Object
- #summary_data ⇒ Object
-
#ui_properties(language_id, last_date_update) ⇒ Object
last_date_update
is DateTime object.
Constructor Details
#initialize(msisdn:, password:, lang: 'uk') ⇒ API
Create a new API object using the given parameters.
Required parameters
-
:msisdn
- telephone number in format ‘38063*******’ -
:password
- super password -
:lang
- ‘uk’, ‘ru’ or ‘en’
84 85 86 87 88 89 90 |
# File 'lib/lifecell_api.rb', line 84 def initialize(msisdn:, password:, lang: 'uk') @msisdn = msisdn @password = password @lang = lang @log = nil end |
Class Attribute Details
Instance Attribute Details
#log ⇒ Object
The current logger. If no logger has been set Lifecell::API.log is used.
94 95 96 |
# File 'lib/lifecell_api.rb', line 94 def log @log ||= Lifecell::API.log end |
#sub_id ⇒ Object
Returns the value of attribute sub_id.
61 62 63 |
# File 'lib/lifecell_api.rb', line 61 def sub_id @sub_id end |
#token ⇒ Object
Returns the value of attribute token.
61 62 63 |
# File 'lib/lifecell_api.rb', line 61 def token @token end |
Instance Method Details
#available_tariffs ⇒ Object
88 89 90 91 92 93 |
# File 'lib/lifecell_api/methods.rb', line 88 def available_tariffs request( 'getAvailableTariffs', base_api_parameters ) end |
#balances ⇒ Object
95 96 97 98 99 100 |
# File 'lib/lifecell_api/methods.rb', line 95 def balances request( 'getBalances', base_api_parameters ) end |
#call_me_back(msisdn_b) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/lifecell_api/methods.rb', line 116 def call_me_back(msisdn_b) request( 'callMeBack', base_api_parameters.merge(msisdnB: msisdn_b) ) end |
#change_language(new_language_id) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/lifecell_api/methods.rb', line 109 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/lifecell_api/methods.rb', line 48 def change_super_password(old_password, new_password) request( 'changeSuperPassword', base_api_parameters.merge( oldPassword: old_password, newPassword: new_password ) ) end |
#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
145 146 147 148 149 150 |
# File 'lib/lifecell_api/methods.rb', line 145 def expenses_summary(month_period) request( 'getExpensesSummary', base_api_parameters.merge(monthPeriod: month_period) ) end |
#languages ⇒ Object
102 103 104 105 106 107 |
# File 'lib/lifecell_api/methods.rb', line 102 def languages request( 'getLanguages', base_api_parameters ) end |
#payments_history(month_period) ⇒ Object
Payments history for calendar month month_period
month_period
- A string like ‘yyyy-MM’ that represent month of year
134 135 136 137 138 139 |
# File 'lib/lifecell_api/methods.rb', line 134 def payments_history(month_period) request( 'getPaymentsHistory', base_api_parameters.merge(monthPeriod: month_period) ) end |
#refill_balance_by_scratch_card(secret_code) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/lifecell_api/methods.rb', line 152 def refill_balance_by_scratch_card(secret_code) request( 'refillBalanceByScratchCard', base_api_parameters.merge(secretCode: secret_code) ) end |
#request(method, params = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/lifecell_api.rb', line 102 def request(method, params = {}) params = { accessKeyCode: ACCESS_KEY_CODE }.merge(params) url = create_signed_url(method, params) log&.debug("[#{method}] request: #{url}") response = response(url) raise StatusError, "Received status code #{response.code} from server" unless response.code == '200' log&.debug("[#{method}] response: #{response.body}") xml = parse_xml(response.body) return xml if xml['responseCode'] == '0' raise_error!(xml) end |
#request_balance_transfer(msisdn_b) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/lifecell_api/methods.rb', line 123 def request_balance_transfer(msisdn_b) request( 'requestBalanceTransfer', base_api_parameters.merge(msisdnB: msisdn_b) ) end |
#services ⇒ Object
84 85 86 |
# File 'lib/lifecell_api/methods.rb', line 84 def services request('getServices', base_api_parameters) end |
#sign_in ⇒ Object
33 34 35 36 37 38 |
# File 'lib/lifecell_api/methods.rb', line 33 def sign_in xml = request('signIn', msisdn: @msisdn, superPassword: @password) @token = xml['token'] @sub_id = xml['subId'] xml end |
#sign_out ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/lifecell_api/methods.rb', line 40 def sign_out request( 'signOut', msisdn: @msisdn, subId: @sub_id ) end |
#summary_data ⇒ Object
77 78 79 80 81 82 |
# File 'lib/lifecell_api/methods.rb', line 77 def summary_data request( 'getSummaryData', base_api_parameters ) end |
#ui_properties(language_id, last_date_update) ⇒ Object
last_date_update
is DateTime object
67 68 69 70 71 72 73 74 75 |
# File 'lib/lifecell_api/methods.rb', line 67 def ui_properties(language_id, last_date_update) request( 'getUIProperties', accessKeyCode: ACCESS_KEY_CODE, languageId: language_id, osType: OS_TYPE, lastDateUpdate: last_date_update ) end |