Class: Etherscanio::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/etherscanio/call.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, action) ⇒ Call

Returns a new instance of Call.



18
19
20
21
22
23
# File 'lib/etherscanio/call.rb', line 18

def initialize(mod, action)
  @base = 'http://api.etherscan.io/api?'
  @mod = mod
  @action = action
  @api_key = false
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def action
  @action
end

#addressObject

Returns the value of attribute address.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def address
  @address
end

#api_keyObject

Returns the value of attribute api_key.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def api_key
  @api_key
end

#blocknoObject

Returns the value of attribute blockno.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def blockno
  @blockno
end

#blocktypeObject

Returns the value of attribute blocktype.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def blocktype
  @blocktype
end

#endblockObject

Returns the value of attribute endblock.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def endblock
  @endblock
end

#modObject

Returns the value of attribute mod.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def mod
  @mod
end

#offsetObject

Returns the value of attribute offset.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def offset
  @offset
end

#pageObject

Returns the value of attribute page.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def page
  @page
end

#sortObject

Returns the value of attribute sort.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def sort
  @sort
end

#startblockObject

Returns the value of attribute startblock.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def startblock
  @startblock
end

#tagObject

Returns the value of attribute tag.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def tag
  @tag
end

#txhashObject

Returns the value of attribute txhash.



4
5
6
# File 'lib/etherscanio/call.rb', line 4

def txhash
  @txhash
end

Instance Method Details

#fetchObject



25
26
27
28
29
# File 'lib/etherscanio/call.rb', line 25

def fetch
  res = RestClient.get(to_s, {}).body
  parsed = JSON.parse(res)
  JSON.generate(parsed)
end

#to_sObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/etherscanio/call.rb', line 31

def to_s
  uri = 'module=' + mod + '&action=' + action
  uri += '&apikey=' + api_key if api_key
  uri += address_fragment
  uri += '&startblock=' + startblock.to_s if startblock
  uri += '&endblock=' + endblock.to_s if endblock
  uri += '&blocktype=' + blocktype if blocktype
  uri += '&txhash=' + txhash if txhash
  uri += '&blockno=' + blockno.to_s if blockno
  uri += '&offset=' + offset.to_s if offset
  uri += '&sort=' + sort if sort
  uri += '&page=' + page.to_s if page
  uri += '&tag=' + tag if tag
  @base + uri
end