Class: Life::API

Inherits:
Object
  • Object
show all
Defined in:
lib/life-api.rb,
lib/life-api/methods.rb,
lib/life-api/version.rb

Overview

:nodoc:

Constant Summary collapse

VERSION =
'0.2.1'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ 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’



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

.logObject

Default logger for all Life::API instances

Life::API.log = Logger.new($stderr)


66
67
68
# File 'lib/life-api.rb', line 66

def log
  @log
end

Instance Attribute Details

#logObject

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

#sub_idObject

Returns the value of attribute sub_id.



59
60
61
# File 'lib/life-api.rb', line 59

def sub_id
  @sub_id
end

#tokenObject

Returns the value of attribute token.



59
60
61
# File 'lib/life-api.rb', line 59

def token
  @token
end

Instance Method Details

#available_tariffsObject



88
89
90
91
92
93
# File 'lib/life-api/methods.rb', line 88

def available_tariffs
  request(
    'getAvailableTariffs',
    base_api_parameters
  )
end

#balancesObject



95
96
97
98
99
100
# File 'lib/life-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/life-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/life-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/life-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/life-api/methods.rb', line 145

def expenses_summary(month_period)
  request(
    'getExpensesSummary',
    base_api_parameters.merge(monthPeriod: month_period)
  )
end

#languagesObject



102
103
104
105
106
107
# File 'lib/life-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/life-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/life-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



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/life-api.rb', line 101

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)

  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/life-api/methods.rb', line 123

def request_balance_transfer(msisdn_b)
  request(
    'requestBalanceTransfer',
    base_api_parameters.merge(msisdnB: msisdn_b)
  )
end

#servicesObject



84
85
86
# File 'lib/life-api/methods.rb', line 84

def services
  request('getServices', base_api_parameters)
end

#sign_inObject



33
34
35
36
37
38
# File 'lib/life-api/methods.rb', line 33

def 
  xml = request('signIn', msisdn: @msisdn, superPassword: @password)
  @token  = xml['token']
  @sub_id = xml['subId']
  xml
end

#sign_outObject



40
41
42
43
44
45
46
# File 'lib/life-api/methods.rb', line 40

def sign_out
  request(
    'signOut',
    msisdn: @msisdn,
    subId: @sub_id
  )
end

#summary_dataObject



77
78
79
80
81
82
# File 'lib/life-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/life-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