trolley / ruby-sdk Goto Github PK
View Code? Open in Web Editor NEWTrolley SDK for Ruby
Home Page: https://trolley.com
License: MIT License
Trolley SDK for Ruby
Home Page: https://trolley.com
License: MIT License
This is an accepted default on pretty much every repo on Github, unsure why this one needs to break that precedence
My argument was [{:recipient=>{:referenceId=>"SOME_REFERENCE_ID"}, :amount=>"SOME_AMOUNT", :memo=>"SOME_MEMO"}]
. Batch was created, payout was not
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:
MAX_RETRIES
constant is defined to specify the maximum number of retry attempts.begin
/ rescue
block to catch errors that occur during the request.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.MAX_RETRIES
and sleep
values to suit your specific needs.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):
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
The Recipient.findLogs
API returns paginated information but the SDK doesn't seem to build a list with this API's response.
Ideally this should also return paginated object, unless I am missing something.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.