lib/gameball/utils/request.rb in gameball-1.0.1 vs lib/gameball/utils/request.rb in gameball-2.0.0

- old
+ new

@@ -1,40 +1,42 @@ module Gameball module Utils extend self - def request(verb, path, body = {},lang="") + def request(verb, path, body = {},params:{}) # check for api_version and key and throw error if not included if !Gameball.api_key raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'") end uri = URI(Gameball.api_base + "/api" + "/" + Gameball.api_version + path) - + if params != {} + uri.query=URI.encode_www_form(params) + end + puts uri https = Net::HTTP.new(uri.host, uri.port) https.max_retries = Gameball.max_retries https.read_timeout = Gameball.read_timeout https.keep_alive_timeout = Gameball.keep_alive_timeout https.use_ssl = true - + case verb.downcase when "post" - req = Net::HTTP::Post.new(uri.path, initheader = { "Content-Type" => "application/json" }) + req = Net::HTTP::Post.new(uri, initheader = { "Content-Type" => "application/json" }) when "get" - req = Net::HTTP::Get.new(uri.path, initheader = { "Content-Type" => "application/json" }) + req = Net::HTTP::Get.new(uri, initheader = { "Content-Type" => "application/json" }) when "put" - req = Net::HTTP::Put.new(uri.path, initheader = { "Content-Type" => "application/json" }) + req = Net::HTTP::Put.new(uri, initheader = { "Content-Type" => "application/json" }) when "delete" - req = Net::HTTP::Delete.new(uri.path, initheader = { "Content-Type" => "application/json" }) + req = Net::HTTP::Delete.new(uri, initheader = { "Content-Type" => "application/json" }) else raise Gameball::GameballException.new("Please provide a valid HTTP Verb") # will later throw an exception end if body != {} req.body = body.to_json end - if lang!="" - req["lang"]=lang - end + req["APIKey"] = Gameball.api_key + req["secretKey"]=Gameball.transaction_key res = https.request(req) return res end def request_async(verb, path, body = {})