Class: Bitpagos::Client
- Inherits:
-
Object
- Object
- Bitpagos::Client
- Defined in:
- lib/bitpagos/client.rb
Constant Summary collapse
- PENDING =
"PE".freeze
- WAITING =
"WA".freeze
- COMPLETED =
"CO".freeze
- PARTIALLY_PAID =
"PP".freeze
- API_BASE =
"https://www.bitpagos.com/api/v1".freeze
Instance Attribute Summary collapse
-
#api_base ⇒ Object
Returns the value of attribute api_base.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
- #completed_transactions ⇒ Object
- #get_transaction(transaction_id) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #partially_paid_transactions ⇒ Object
- #pending_transactions ⇒ Object
-
#transaction_count ⇒ Integer
Returns the total count of transactions in all states.
-
#transactions(params = {}) ⇒ Hash
Retrieve all transactions, or specify them with parameters, to retrieve allow retrieving paginated transactions.
- #waiting_transactions ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 |
# File 'lib/bitpagos/client.rb', line 11 def initialize(api_key) if api_key.to_s.empty? raise Bitpagos::Errors::InvalidApiKey.new("No API key provided") end @api_key = "ApiKey #{api_key}".freeze @headers = { authorization: @api_key, content_type: :json, accept: :json } @api_base = API_BASE end |
Instance Attribute Details
#api_base ⇒ Object
Returns the value of attribute api_base.
9 10 11 |
# File 'lib/bitpagos/client.rb', line 9 def api_base @api_base end |
#headers ⇒ Object
Returns the value of attribute headers.
9 10 11 |
# File 'lib/bitpagos/client.rb', line 9 def headers @headers end |
Instance Method Details
#completed_transactions ⇒ Object
40 41 42 |
# File 'lib/bitpagos/client.rb', line 40 def completed_transactions retrieve_transactions(status: COMPLETED) end |
#get_transaction(transaction_id) ⇒ Object
21 22 23 |
# File 'lib/bitpagos/client.rb', line 21 def get_transaction(transaction_id) retrieve_transactions(nil, transaction_id) end |
#partially_paid_transactions ⇒ Object
52 53 54 |
# File 'lib/bitpagos/client.rb', line 52 def partially_paid_transactions retrieve_transactions(status: PARTIALLY_PAID) end |
#pending_transactions ⇒ Object
48 49 50 |
# File 'lib/bitpagos/client.rb', line 48 def pending_transactions retrieve_transactions(status: PENDING) end |
#transaction_count ⇒ Integer
Returns the total count of transactions in all states.
59 60 61 |
# File 'lib/bitpagos/client.rb', line 59 def transaction_count transactions["meta"]["total_count"] end |
#transactions(params = {}) ⇒ Hash
Retrieve all transactions, or specify them with parameters, to retrieve allow retrieving paginated transactions.
33 34 35 36 37 38 |
# File 'lib/bitpagos/client.rb', line 33 def transactions(params = {}) if status = params[:status] params[:status] = get_transaction_type_from_symbol(status) end retrieve_transactions(params) end |
#waiting_transactions ⇒ Object
44 45 46 |
# File 'lib/bitpagos/client.rb', line 44 def waiting_transactions retrieve_transactions(status: WAITING) end |