class Simpal::Client
Provides an API
client for performing requests under an account within a particular environment.
PayPal API
credentials can be obtained from the following URL:
=> https://developer.paypal.com/developer/applications
Attributes
@return [String] The 'Client ID' from your PayPal account dashboard.
@return [String] The 'Client Secret' from your PayPal account dashboard.
Public Class Methods
Create a new API
client.
@parameter client_id
[String] The 'Client ID' from your PayPal account dashboard. @parameter client_secret
[String] The 'Client Secret' from your PayPal account dashboard. @parameter sandbox [Boolean] `true` when using the sandbox API
, `false` when using the live API
.
# File lib/simpal/client.rb, line 28 def initialize(client_id:, client_secret:, sandbox: false) @client_id = client_id @client_secret = client_secret @sandbox = sandbox end
Public Instance Methods
@return [Faraday::Connection] The connection to use when executing an API
request.
# File lib/simpal/client.rb, line 52 def connection @connection ||= Faraday.new(service_url, headers: headers) do |connection| connection.use Faraday::Response::RaiseError connection.use Simpal::Middleware::Headers connection.use FaradayMiddleware::EncodeJson connection.use FaradayMiddleware::ParseJson connection.use Simpal::Middleware::Authorization, self connection.adapter Faraday.default_adapter end end
@return [Hash] The default headers, which should be merged into every API
request.
# File lib/simpal/client.rb, line 46 def headers { 'User-Agent' => "Simpal/#{Simpal::VERSION}" } end
@return [String] The URL for the PayPal API
service.
# File lib/simpal/client.rb, line 36 def service_url if sandbox 'https://api-m.sandbox.paypal.com' else 'https://api-m.paypal.com' end end