lib/AfricasTalking.rb in africastalking-ruby-2.0.0 vs lib/AfricasTalking.rb in africastalking-ruby-2.1.0
- old
+ new
@@ -58,14 +58,10 @@
def sendNormalRequest url_, data_ = nil
uri = URI.parse(url_)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
- headers = {
- "apikey" => @apikey,
- "Accept" => "application/json"
- }
if(data_ != nil)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(data_)
else
request = Net::HTTP::Get.new(uri.request_uri)
@@ -80,23 +76,25 @@
@response_code = response.code.to_i
return response.body
end
- def sendJSONRequest (url_, data_)
+ def sendJSONRequest url_, data_, get_request = false
uri = URI.parse(url_)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
- req = Net::HTTP::Post.new(uri.request_uri, 'Content-Type'=>"application/json")
+ if get_request === true
+ uri.query = URI.encode_www_form(data_)
+ req = Net::HTTP::Get.new(uri.request_uri, 'Content-Type'=>"application/json")
+ else
+ req = Net::HTTP::Post.new(uri.request_uri, 'Content-Type'=>"application/json")
+ req.body = data_.to_json
+ end
req["apikey"] = @apikey
req["Accept"] = "application/json"
-
- req.body = data_.to_json
-
response = http.request(req)
-
if (DEBUG)
puts "Full response #{response.body}"
end
@response_code = response.code.to_i
@@ -110,9 +108,7 @@
elsif v.empty?
raise AfricasTalkingException, "Please make sure your key #{v} is not empty"
end
}
return true
-
end
-
end