Class: Xapo::API
- Inherits:
-
Object
- Object
- Xapo::API
- Defined in:
- lib/xapo_api.rb
Overview
Xapo’s API.
This class allows the interaction with bitcoins APIs provided with Xapo.
Params:
+service_url+ (str): The endpoint URL that returns the payment widget.
+app_id+ (str): The id of the TPA doing the credit.
+app_secret+ (str): The TPA secret used to encrypt payload.
Instance Method Summary collapse
-
#credit(to, amount, request_id, currency: Xapo::Currency::BTC, comments: "", subject: "") ⇒ Object
Transfer a given amount from the main wallet of the TPA to a given sub account.
-
#initialize(service_url, app_id, app_secret) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(service_url, app_id, app_secret) ⇒ API
Returns a new instance of API.
26 27 28 29 30 31 |
# File 'lib/xapo_api.rb', line 26 def initialize(service_url, app_id, app_secret) @service_url = service_url @app_id = app_id @app_secret = app_secret @credit_resource = '/credit/' end |
Instance Method Details
#credit(to, amount, request_id, currency: Xapo::Currency::BTC, comments: "", subject: "") ⇒ Object
Transfer a given amount from the main wallet of the TPA to a given sub account.
Params:
+to+ (str): the destination of the credit.
+amount+ (decimal): the amount to be credited.
+currency+ (Xapo::Currency): the currency of the operation (SAT|BTC).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xapo_api.rb', line 39 def credit(to, amount, request_id, currency: Xapo::Currency::BTC, comments: "", subject: "") = XapoUtils. payload = { :to => to, :currency => currency, :amount => amount, :comments => comments, :subject => subject, :timestamp => , :unique_request_id => request_id } json_payload = JSON.generate(payload) encrypted_payload = XapoUtils.encrypt(json_payload, @app_secret, false) uri = URI(@service_url + @credit_resource) query = URI.encode_www_form(:appID => @app_id, :hash => encrypted_payload) uri.query = query res = Net::HTTP.get_response(uri) return JSON.parse(res.body) end |