Class: Handcash::API
- Inherits:
-
Object
- Object
- Handcash::API
- Defined in:
- lib/handcash/api.rb,
lib/handcash/api/version.rb
Overview
API is the main class for all Handcash gem functions. For now this is limited to ‘receive`.
Constant Summary collapse
- TESTNET_URL =
'https://test-api.handcash.io/api/'.freeze
- MAINNET_URL =
'https://api.handcash.io/api/'.freeze
- VERSION =
'0.2.0'.freeze
Instance Attribute Summary collapse
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ API
constructor
A new instance of API.
- #receive(user) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ API
Returns a new instance of API.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/handcash/api.rb', line 14 def initialize(opts = {}) # Default to mainnet. @network = opts[:network] || :mainnet case @network when :testnet @url = TESTNET_URL when :mainnet @url = MAINNET_URL else raise "Unsupported network - #{@network}" end end |
Instance Attribute Details
#network ⇒ Object (readonly)
Returns the value of attribute network.
9 10 11 |
# File 'lib/handcash/api.rb', line 9 def network @network end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/handcash/api.rb', line 9 def url @url end |
Instance Method Details
#receive(user) ⇒ Object
27 28 29 30 31 |
# File 'lib/handcash/api.rb', line 27 def receive(user) uri = URI("#{url}receivingAddress/#{user}") data = Net::HTTP.get(uri) data == '' ? {} : JSON.parse(data) end |