Class: Billingrails::Client
- Inherits:
-
Object
- Object
- Billingrails::Client
- Defined in:
- lib/billingrails/client.rb
Overview
Main client for interacting with the Billingrails API
Constant Summary collapse
- DEFAULT_BASE_URL =
'https://api.billingrails.com/v1'- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#biller ⇒ Object
readonly
Returns the value of attribute biller.
-
#credit_grants ⇒ Object
readonly
Returns the value of attribute credit_grants.
-
#discounts ⇒ Object
readonly
Returns the value of attribute discounts.
-
#fees ⇒ Object
readonly
Returns the value of attribute fees.
-
#invoices ⇒ Object
readonly
Returns the value of attribute invoices.
-
#payment_pages ⇒ Object
readonly
Returns the value of attribute payment_pages.
-
#payments ⇒ Object
readonly
Returns the value of attribute payments.
-
#seller ⇒ Object
readonly
Returns the value of attribute seller.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT) ⇒ Client
constructor
Initialize a new client.
-
#request(method, path, body: nil, params: nil) ⇒ Hash
Make an HTTP request.
Constructor Details
#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT) ⇒ Client
Initialize a new client
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/billingrails/client.rb', line 44 def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT) @api_key = api_key @base_url = base_url.chomp('/') @timeout = timeout validate_config! # Initialize top-level resources @accounts = Resources::Accounts.new(self) @credit_grants = Resources::CreditGrants.new(self) @discounts = Resources::Discounts.new(self) @fees = Resources::Fees.new(self) @invoices = Resources::Invoices.new(self) @payments = Resources::Payments.new(self) @payment_pages = Resources::PaymentPages.new(self) # Initialize nested namespaces @biller = BillerNamespace.new(self) @seller = SellerNamespace.new(self) end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def accounts @accounts end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
35 36 37 |
# File 'lib/billingrails/client.rb', line 35 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
35 36 37 |
# File 'lib/billingrails/client.rb', line 35 def base_url @base_url end |
#biller ⇒ Object (readonly)
Returns the value of attribute biller.
37 38 39 |
# File 'lib/billingrails/client.rb', line 37 def biller @biller end |
#credit_grants ⇒ Object (readonly)
Returns the value of attribute credit_grants.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def credit_grants @credit_grants end |
#discounts ⇒ Object (readonly)
Returns the value of attribute discounts.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def discounts @discounts end |
#fees ⇒ Object (readonly)
Returns the value of attribute fees.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def fees @fees end |
#invoices ⇒ Object (readonly)
Returns the value of attribute invoices.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def invoices @invoices end |
#payment_pages ⇒ Object (readonly)
Returns the value of attribute payment_pages.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def payment_pages @payment_pages end |
#payments ⇒ Object (readonly)
Returns the value of attribute payments.
36 37 38 |
# File 'lib/billingrails/client.rb', line 36 def payments @payments end |
#seller ⇒ Object (readonly)
Returns the value of attribute seller.
37 38 39 |
# File 'lib/billingrails/client.rb', line 37 def seller @seller end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
35 36 37 |
# File 'lib/billingrails/client.rb', line 35 def timeout @timeout end |
Instance Method Details
#request(method, path, body: nil, params: nil) ⇒ Hash
Make an HTTP request
71 72 73 74 75 76 77 |
# File 'lib/billingrails/client.rb', line 71 def request(method, path, body: nil, params: nil) uri = build_uri(path, params) request = build_request(method, uri, body) response = execute_request(uri, request) handle_response(response) end |