Class: Zapper::Client
- Inherits:
-
Object
- Object
- Zapper::Client
- Defined in:
- lib/zapper.rb
Overview
The main entry point for the client. You can instantiated a ‘Zapper::Client` instance.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
API key for Zapper.fi.
-
#conn ⇒ Object
readonly
The Faraday::Connection.
Instance Method Summary collapse
-
#apps(id = nil) ⇒ Faraday::Response
Returns all apps Zapper knows about.
-
#balances(address) ⇒ Faraday::Response
Returns all apps Zapper knows about.
-
#initialize(api_key = "") ⇒ Client
constructor
A new instance of Client.
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
API key for Zapper.fi
19 20 21 |
# File 'lib/zapper.rb', line 19 def api_key @api_key end |
#conn ⇒ Object (readonly)
The Faraday::Connection
21 22 23 |
# File 'lib/zapper.rb', line 21 def conn @conn end |
Instance Method Details
#apps(id = nil) ⇒ Faraday::Response
Returns all apps Zapper knows about. If an ‘id` is provided, it will return information on just that app.
36 37 38 |
# File 'lib/zapper.rb', line 36 def apps(id = nil) id ? conn.get("/v2/apps/#{id}") : conn.get("/v2/apps") end |
#balances(address) ⇒ Faraday::Response
Returns all apps Zapper knows about. If an ‘id` is provided, it will return information on just that app.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zapper.rb', line 45 def balances(address) response = conn.get("/v2/balances") do |req| req.params["addresses[]"] = address end response.env.response_body = response .body .split("event: ") .map { |x| x.split("balance\ndata: ")[1] } .compact.map { |x| JSON.parse(x) } response end |