Sha256: 92f3d5b6de6465f40287f654693d53301c92d3ab135eeb0b9696a2d5f405ea81

Contents?: true

Size: 803 Bytes

Versions: 1

Compression:

Stored size: 803 Bytes

Contents

require 'handcash/api/version'
require 'net/http'
require 'json'

module Handcash
  # API is the main class for all Handcash gem functions.
  # For now this is limited to `receive`.
  class API
    attr_reader :network, :url

    TESTNET_URL = 'https://test-api.handcash.io/api/'.freeze
    MAINNET_URL = 'https://api.handcash.io/api/'.freeze

    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

    def receive(user)
      uri = URI("#{url}receivingAddress/#{user}")
      data = Net::HTTP.get(uri)
      data == '' ? {} : JSON.parse(data)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
handcash-0.2.0 lib/handcash/api.rb