lib/openpay/open_pay_resource.rb in openpay-2.0.0 vs lib/openpay/open_pay_resource.rb in openpay-2.0.1

- old
+ new

@@ -60,15 +60,18 @@ if is_filter_string?(args) terminated = false end + strUrl = url(args, terminated) + strUrlAux = delete_ending_slash(strUrl) + LOG.debug("#{resource_name}:") LOG.debug(" GET Resource URL:#{url(args, terminated)}") res=RestClient::Request.new( :method => :get, - :url => url(args, terminated), + :url => strUrlAux, :user => @private_key, :timeout => @timeout, :ssl_version => :TLSv1_2, :headers => {:accept => :json, :content_type => :json, @@ -91,17 +94,21 @@ def delete(args) @errors=false + + strUrl = url(args) + strUrlAux = delete_ending_slash(strUrl) + LOG.debug("#{self.class.name.downcase}:") - LOG.debug(" DELETE URL:#{url(args)}") + LOG.debug(" DELETE URL:#{strUrlAux}") res='' req=RestClient::Request.new( :method => :delete, - :url => url(args), + :url => strUrlAux, :user => @private_key, :timeout => @timeout, :ssl_version => :TLSv1_2, :headers => {:accept => :json, :content_type => :json, @@ -131,20 +138,23 @@ else json=message return_hash=false end + + strUrl = url(args) + strUrlAux = delete_ending_slash(strUrl) + # LOG.debug("#{self.class.name.downcase}:") - LOG.debug " POST URL:#{url(args)}" + LOG.debug " POST URL:#{strUrlAux}" LOG.debug " json: #{json}" begin - #request res= RestClient::Request.new( :method => :post, - :url => url(args), + :url => strUrlAux, :user => @private_key, :timeout => @timeout, :ssl_version => :TLSv1_2, :payload => json, :headers => {:accept => :json, @@ -179,17 +189,20 @@ else json=message return_hash=false end - LOG.info "PUT URL:#{url}" + strUrl = url(args) + strUrlAux = delete_ending_slash(strUrl) + + LOG.info "PUT URL:#{strUrlAux}" #LOG.info " json: #{json}" - begin + begin res= RestClient::Request.new( :method => :put, - :url => url(args), + :url => strUrlAux, :user => @private_key, :timeout => @timeout, :ssl_version => :TLSv1_2, :payload => json, :headers => {:accept => :json, @@ -225,15 +238,29 @@ end private def url(args = '', terminated = true) + if args.nil? || args.empty? + terminated = false + end termination = terminated ? '/' : '' @base_url + "#{@merchant_id}/" + resource_name + termination + args end def resource_name self.class.name.to_s.downcase + end + + def delete_ending_slash(url) + slash = '/' + strUrl = url + strUrlAux = url + ending = strUrl.to_s[-1,1] + if ending == slash + strUrlAux = strUrl.to_s[0,strUrl.length - 1] + end + strUrlAux end def is_filter_string?(args) is_filter = false if args =~ /^\?/