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/'
BALANCE_V4_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, use_v4: false) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
# File 'lib/vodacom/client.rb', line 18

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

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



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

def base_path
  @base_path
end

#expiryObject (readonly)

Returns the value of attribute expiry.



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

def expiry
  @expiry
end

#login_responseObject (readonly)

Returns the value of attribute login_response.



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

def 
  @login_response
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Returns the value of attribute raw_cookie.



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

def raw_cookie
  @raw_cookie
end

#use_v4Object (readonly)

Returns the value of attribute use_v4.



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

def use_v4
  @use_v4
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.api_versionObject

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



31
32
33
# File 'lib/vodacom/client.rb', line 31

def self.api_version
  'v4 2024-03-26'
end

.compatible_api_versionObject



26
27
28
# File 'lib/vodacom/client.rb', line 26

def self.compatible_api_version
  'v4'
end

Instance Method Details

#balance(phone_number) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vodacom/client.rb', line 35

def balance(phone_number)
  start_time = get_micro_second_time

  if use_v4
    balance_path = "#{BALANCE_V4_PATH}#{phone_number}"
  else
    balance_path = "#{BALANCE_PATH}#{phone_number}"
  end

   unless (raw_cookie && (expiry.to_i > Time.now.to_i))
  response = HTTParty.send(
    :get,
    balance_path,
    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