Class: WaffleAPI::Client

Inherits:
Object
  • Object
show all
Includes:
AddressValidator, Helpers
Defined in:
lib/waffle_api/client.rb

Overview

A Ruby class to call the Waffle stat API. You might use this if you want to retrieve your waffle pool stats from within a Ruby program.

Example:

require 'waffle_api'
stats = WaffleAPI::Client.new address: '<BTC_ADDRESS_HERE>'
stats.create()

Constant Summary

Constants included from Helpers

Helpers::INVALIDATION_TIME, Helpers::NOT_FOUND_ERROR, Helpers::WAFFLE_POOL_HOST

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#call_uri, #data_recent!, #data_recent?, #request_json, #stats

Constructor Details

#initialize(address: nil, https_only: false, ignore_bad_address: false) ⇒ Client



20
21
22
23
24
25
26
# File 'lib/waffle_api/client.rb', line 20

def initialize(address: nil, https_only: false, ignore_bad_address: false)
  @address   = address || ENV['BTC_ADDRESS']
  @https_only = https_only

  fail Error::EmptyAddress if @address.nil? || @address.empty?
  fail Error::BadAddress, @address unless valid_address? || ignore_bad_address
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



32
33
34
35
36
# File 'lib/waffle_api/client.rb', line 32

def method_missing(method, *args, &block)
  stats method.to_s
rescue Error::UnknownKey
  super method, *args, &block
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



18
19
20
# File 'lib/waffle_api/client.rb', line 18

def address
  @address
end

#https_onlyObject

Returns the value of attribute https_only.



18
19
20
# File 'lib/waffle_api/client.rb', line 18

def https_only
  @https_only
end

Instance Method Details

#hashrateObject



28
29
30
# File 'lib/waffle_api/client.rb', line 28

def hashrate
  stats 'hash_rate'
end