Class: Airtime
- Inherits:
-
Object
- Object
- Airtime
- Includes:
- AfricasTalking
- Defined in:
- lib/AfricasTalking/Airtime.rb
Constant Summary collapse
- HTTP_CREATED =
201- HTTP_OK =
200
Constants included from AfricasTalking
AfricasTalking::DEBUG, AfricasTalking::VERSION
Instance Method Summary collapse
-
#initialize(username, apikey) ⇒ Airtime
constructor
Set debug flag to to true to view response body.
- #send(options) ⇒ Object
Constructor Details
#initialize(username, apikey) ⇒ Airtime
Set debug flag to to true to view response body
7 8 9 10 |
# File 'lib/AfricasTalking/Airtime.rb', line 7 def initialize username, apikey @username = username @apikey = apikey end |
Instance Method Details
#send(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/AfricasTalking/Airtime.rb', line 12 def send url = getAirtimeUrl() + "/send" recipients = .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 |