lib/razorpay/request.rb in razorpay-1.0.3 vs lib/razorpay/request.rb in razorpay-1.1.0

- old
+ new

@@ -6,13 +6,22 @@ # objects, which make requests to the server # using HTTParty class Request include HTTParty + ssl_ca_file File.dirname(__FILE__) + '/../ca-bundle.crt' + def initialize(entity_name) self.class.base_uri(Razorpay::BASE_URI) @entity_name = entity_name + @options = { + basic_auth: Razorpay.auth, + timeout: 30, + headers: { + 'User-Agent' => "Razorpay-Ruby/#{Razorpay::VERSION}" + } + } end def fetch(id) request :get, "/#{@entity_name}/#{id}" end @@ -23,19 +32,29 @@ def post(url, data = {}) request :post, "/#{@entity_name}/#{url}", data end + def create(data) + request :post, "/#{@entity_name}", data + end + def request(method, url, data = {}) case method when :get - create_instance self.class.send(method, url, query: data, basic_auth: Razorpay.auth) + @options[:query] = data when :post - create_instance self.class.send(method, url, body: data, basic_auth: Razorpay.auth) + @options[:body] = data end + create_instance self.class.send(method, url, @options) end + # Since we need to change the base route + def make_test_request + self.class.get Razorpay::TEST_URL, @options + end + # Recursively builds entity instances # out of all hashes in the response object def create_instance(res) response = res.parsed_response @@ -65,9 +84,9 @@ Razorpay.const_get(class_name) # We got an unknown error, cast it to Error for now rescue NameError Razorpay::Error end - fail klass.new(*args), error['description'] + raise klass.new(*args), error['description'] end end end