Class: Bcoin::Client::Base

Inherits:
Object
  • Object
show all
Includes:
HttpMethods
Defined in:
lib/bcoin/client/base.rb

Direct Known Subclasses

Account, Balance, Master, Wallet

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HttpMethods

#delete, #get, #post, #put

Constructor Details

#initialize(client, attr = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/bcoin/client/base.rb', line 9

def initialize client, attr = {}
  @client = client
  self.attributes = attr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



59
60
61
62
63
64
65
# File 'lib/bcoin/client/base.rb', line 59

def method_missing method, *args
  if @attributes[method].nil?
    raise NoMethodError
  else
    @attributes[method]
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/bcoin/client/base.rb', line 7

def attributes
  @attributes
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/bcoin/client/base.rb', line 7

def client
  @client
end

Instance Method Details

#base_pathObject

Override this in sub class



24
25
26
# File 'lib/bcoin/client/base.rb', line 24

def base_path
  '/base'
end

#error=(_error) ⇒ Object



45
46
47
# File 'lib/bcoin/client/base.rb', line 45

def error= _error
  @attributes[:error] = _error
end

#idObject

Override this in sub class



19
20
21
# File 'lib/bcoin/client/base.rb', line 19

def id
  'base'
end

#inspectObject



14
15
16
# File 'lib/bcoin/client/base.rb', line 14

def inspect
  printf "#<%s @attributes=%p>", self.class.name, @attributes
end

#refresh!Object



28
29
30
31
# File 'lib/bcoin/client/base.rb', line 28

def refresh!
  self.attributes = get '/'
  self
end

#token=(_token) ⇒ Object



37
38
39
# File 'lib/bcoin/client/base.rb', line 37

def token= _token
  @attributes[:token] = _token
end

#wallet_tokenObject



33
34
35
# File 'lib/bcoin/client/base.rb', line 33

def wallet_token
  @attributes[:token] if @attributes
end