Class: Handcash::API

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#networkObject (readonly)

Returns the value of attribute network.



9
10
11
# File 'lib/handcash/api.rb', line 9

def network
  @network
end

#urlObject (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