class Token

Constants

HTTP_CREATED
HTTP_OK

Public Class Methods

new(username, apikey) click to toggle source

Set debug flag to to true to view response body

# File lib/AfricasTalking/Token.rb, line 7
def initialize username, apikey
        @username    = username
        @apikey      = apikey
end

Public Instance Methods

generateAuthToken() click to toggle source
# 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

Private Instance Methods

getApiHost() click to toggle source
# File lib/AfricasTalking/Token.rb, line 29
def getApiHost()
        if(@username == "sandbox")
                return "https://api.sandbox.africastalking.com"
        else
                return "https://api.africastalking.com"
        end
end