Sha256: 29092b984ff92631a0f6b42e41f24fedae570b8cc909023de8d09dae199b0d52

Contents?: true

Size: 968 Bytes

Versions: 5

Compression:

Stored size: 968 Bytes

Contents

class Token
	include AfricasTalking
	HTTP_CREATED     = 201
	HTTP_OK          = 200

	#Set debug flag to to true to view response body
	def initialize username, apikey
		@username    = username
		@apikey      = apikey
	end

	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

	private

		def getApiHost()
			if(@username == "sandbox")
				return "https://api.sandbox.africastalking.com"
			else
				return "https://api.africastalking.com"
			end
		end
end

class AuthTokenResponse
	attr_accessor :token, :lifetimeInSeconds
	def initialize token_, lifetimeInSeconds_
		@token      = token_
		@lifetimeInSeconds = lifetimeInSeconds_
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
africastalking-ruby-2.2.1 lib/AfricasTalking/Token.rb
africastalking-ruby-2.2.0 lib/AfricasTalking/Token.rb
africastalking-ruby-2.1.9 lib/AfricasTalking/Token.rb
africastalking-ruby-2.1.8 lib/AfricasTalking/Token.rb
africastalking-ruby-2.1.7 lib/AfricasTalking/Token.rb