class Airtime
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/Airtime.rb, line 7 def initialize username, apikey @username = username @apikey = apikey end
Public Instance Methods
send(options)
click to toggle source
# File lib/AfricasTalking/Airtime.rb, line 12 def send options url = getAirtimeUrl() + "/send" recipients = options.each{|item| validateParamsPresence? item, %w(phoneNumber currencyCode amount) item['amount'].to_s.prepend(item['currencyCode'].to_s + " ") item.delete('currencyCode') } post_body = { 'username' => @username, 'recipients' => recipients.to_json, } response = sendNormalRequest(url, post_body) if (@response_code == HTTP_CREATED) responses = JSON.parse(response, :quirky_mode =>true) if (responses['responses'].length > 0) # results = responses['responses'].collect{ |result| # AirtimeResponse.new result['status'], result['phoneNumber'],result['amount'],result['requestId'], result['errorMessage'], result['discount'] } # return SendAirtimeResult.new responses["errorMessage"], responses["numSent"], responses["totalAmount"], responses["totalDiscount"], results else raise AfricasTalkingException, responses['errorMessage'] end raise AfricasTalkingException, response end end
Private Instance Methods
getAirtimeUrl()
click to toggle source
# File lib/AfricasTalking/Airtime.rb, line 43 def getAirtimeUrl() return getApiHost() + "/version1/airtime" end
getApiHost()
click to toggle source
# File lib/AfricasTalking/Airtime.rb, line 47 def getApiHost() if(@username == "sandbox") return "https://api.sandbox.africastalking.com" else return "https://api.africastalking.com" end end