Class: Token

Inherits:
Object
  • Object
show all
Includes:
AfricasTalking
Defined in:
lib/AfricasTalking/Token.rb

Constant Summary collapse

HTTP_CREATED =
201
HTTP_OK =
200

Constants included from AfricasTalking

AfricasTalking::DEBUG, AfricasTalking::VERSION

Instance Method Summary collapse

Constructor Details

#initialize(username, apikey) ⇒ Token

Set debug flag to to true to view response body



7
8
9
10
# File 'lib/AfricasTalking/Token.rb', line 7

def initialize username, apikey
	@username    = username
	@apikey      = apikey
end

Instance Method Details

#createCheckoutToken(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/AfricasTalking/Token.rb', line 27

def createCheckoutToken options
	post_body = {
		'phoneNumber' => options['phoneNumber']
	}
	url = getApiHost() + "/checkout/token/create"
	response = sendNormalRequest(url, post_body)
	# 
	if(@response_code == HTTP_CREATED)
		r= JSON.parse(response, :quirky_mode => true)
		return CheckoutTokenResponse.new r['token'], r['description']
	else
		raise AfricasTalkingException, response
	end
end

#generateAuthTokenObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/AfricasTalking/Token.rb', line 12

def generateAuthToken
	post_body = {
		'username' => @username
	}
	url = getApiHost() + "/auth-token/generate"
	response = sendJSONRequest(url, post_body)
	# 
	if(@response_code == HTTP_CREATED)
		r=JSON.parse(response, :quirky_mode => true)
		return AuthTokenResponse.new r["token"], r["lifetimeInSeconds"]
	else
		raise AfricasTalkingException, response
	end
end