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.



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

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

#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



37
38
39
# File 'lib/vodacom/client.rb', line 37

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

.compatible_api_versionObject



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

def self.compatible_api_version
  'v3'
end

Instance Method Details

#balance(phone_number) ⇒ Object



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

def balance(phone_number)
  start_time = get_micro_second_time

   unless raw_cookie
  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