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

#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