Giter VIP home page Giter VIP logo

ruby-sdk's People

Contributors

aman-aalam avatar barnett avatar bassochette avatar fronugget avatar jhadeepakkumar14 avatar jideengdev avatar jsilber94 avatar koblas avatar maschwenk avatar phil-monroe avatar snkashis avatar suitedjimster avatar zero-bites avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-sdk's Issues

Add retry logic around Client#send_request

Currently, we don't have any retry logic present if API request fails with some network related exceptions in this line,

response = http.request(request)

we are using Net::HTTP library to make API request and recently it has been seen many request getting end of file reached exception which may be due to this issue.

If we have some retry logic around Client#send_request then it will help to handle these exceptions till some extent.

To add retry logic, we need to define a maximum number of retries, and then wrap the HTTP request in a loop that attempts to resend the request until either it succeeds or it hits the maximum number of retries. We may also want to add a sleep call between retries to prevent quickly exhausting your retry limit in the case of temporary network issues or server-side problems.

module Trolley
  class Client
    #...

    MAX_RETRIES = 3 # Maximum number of retries

    #...
    private

    def send_request(endPoint, method, body = '')
      # your original send_request logic here
      uri = URI.parse(@config.api_base + endPoint)
      #...

      begin
        retries = 0
        response = http.request(request)
      rescue StandardError => e
        if retries < MAX_RETRIES
          retries += 1
          sleep(2**retries) # Exponential back-off
          retry
        else
          raise "Request failed after #{MAX_RETRIES} attempts: #{e.message}"
        end
      end

      if response.code != '200' && response.code != '204'
        throw_status_code_exception(response.message + ' ' + response.body , response.code)
      end
      response.body
    end

    #...
  end
end

Please note that:

  1. The MAX_RETRIES constant is defined to specify the maximum number of retry attempts.
  2. I've added a begin / rescue block to catch errors that occur during the request.
  3. Inside the rescue block, we check if we've hit our maximum number of retries. If not, we increment the retry count, wait for a period of time (sleep(2**retries) provides an exponential back-off), and then retry the request. If we have hit our maximum number of retries, we raise an exception to alert the user that the request has ultimately failed.
  4. We can adjust the MAX_RETRIES and sleep values to suit your specific needs.

TypeError (no implicit conversion of nil into String):

SDK Version 0.20
payload = {
:referenceId => "34",
:type => "business",
:name => "Adams Company",
:firstName => "fish",
:lastName => "frako",
:email => "[email protected]",
:address => {
:street1 => "123 Main Street",
:street2 => "",
:postalCode => "53719",
:city => "Madison",
:country => "US",
:region => "Wisconsin",
:phone => "123-123-1234"
},
:payout => {
"accountNum" => "123",
"branchId" => "123",
"type" => "bank-transfer",
"currency" => "USD",
"country" => "US",
"accountHolderName" => "fish frako"
}
}

result = client.recipient.update(payment_rails_id, payload)

Error message TypeError (no implicit conversion of nil into String):

Adopt to changed Ruby 3 behavior of keyword arguments

Ruby 3 changed how it handles keyword arguments, resulting in following errors when initializing the sdk:

paymentrails-0.2.10/lib/paymentrails/Configuration.rb:5:in `initialize': wrong number of arguments (given 4, expected 2..3) (ArgumentError)

The SDK should handle this change and continue working smoothly

Top level constant conflicts

I believe this current implementation, which uses Gateway and Configuration, as top level constants, is flawed, because any apps which currently have these classes defined... Will fail out...

I think the init of this api client should be as simple as this
client = PaymentRails.new('YOUR-API-KEY', 'YOUR-SECRET-KEY')
Only one top level constant exposed, PaymentRails

I believe a gem structure like https://github.com/hvssle/onfido would be better suited for something like this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.