lib/AfricasTalking/Airtime.rb in africastalking-ruby-2.0.0 vs lib/AfricasTalking/Airtime.rb in africastalking-ruby-2.1.0

- old
+ new

@@ -8,18 +8,22 @@ @username = username @apikey = apikey end def send options - recipients = options.collect{ |r| r } - post_body = { - 'username' => @username, - 'recipients' => recipients.to_json - } url = getAirtimeUrl() + "/send" - response = sendNormalRequest(url, post_body) - # + + 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| @@ -29,10 +33,9 @@ # return SendAirtimeResult.new responses["errorMessage"], responses["numSent"], responses["totalAmount"], responses["totalDiscount"], results else raise AfricasTalkingException, responses['errorMessage'] end - else raise AfricasTalkingException, response end end private \ No newline at end of file