Class: Vodacom::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vodacom/client.rb

Constant Summary collapse

LOGIN_PATH =

include HTTParty_with_cookies

'https://www.vodacom.co.za/cloud/login/v3/login'
BALANCE_PATH =
'https://www.vodacom.co.za/cloud/rest/balances/v3/bundle/balances/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, base_path: 'https://www.vodacom.co.za/cloud', port: 80) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
# File 'lib/vodacom/client.rb', line 16

def initialize(username:, password:, base_path: 'https://www.vodacom.co.za/cloud', port: 80)
  @username = username
  @password = password
  @base_path = base_path
  @port = port
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def base_path
  @base_path
end

#expiryObject (readonly)

Returns the value of attribute expiry.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def expiry
  @expiry
end

#login_responseObject (readonly)

Returns the value of attribute login_response.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def 
  @login_response
end

#passwordObject (readonly)

Returns the value of attribute password.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def port
  @port
end

Returns the value of attribute raw_cookie.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def raw_cookie
  @raw_cookie
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/vodacom/client.rb', line 8

def username
  @username
end

Class Method Details

.api_versionObject

This is the version of the API docs this client was built off-of



28
29
30
# File 'lib/vodacom/client.rb', line 28

def self.api_version
  'v3 2021-03-13'
end

.compatible_api_versionObject



23
24
25
# File 'lib/vodacom/client.rb', line 23

def self.compatible_api_version
  'v3'
end

Instance Method Details

#balance(phone_number) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vodacom/client.rb', line 32

def balance(phone_number)
  start_time = get_micro_second_time

   unless (raw_cookie && (expiry.to_i > Time.now.to_i))
  response = HTTParty.send(
    :get,
    "#{BALANCE_PATH}#{phone_number}",
    headers: {
      'Content-Type': 'application/json',
      'Accept': '*/*',
      'Cookie': process_cookies
    },
    port: port
  )

  end_time = get_micro_second_time
  construct_response_object(response, BALANCE_PATH, start_time, end_time)
end