Module: Factom::APIv1

Defined in:
lib/factom-ruby/client.rb

Constant Summary collapse

GetBalanceFailed =
"Failed to get balance!"
VERSION =
'00'.freeze
DENOMINATION_FACTOID =
100000000
DENOMINATION_ENTRY_CREDIT =
1

Instance Method Summary collapse

Instance Method Details

#block(keymr) ⇒ Object



27
28
29
# File 'lib/factom-ruby/client.rb', line 27

def block(keymr)
  get "/v1/directory-block-by-keymr/#{keymr}"
end

#chain_head(id) ⇒ Object



31
32
33
34
# File 'lib/factom-ruby/client.rb', line 31

def chain_head(id)
  json = get "/v1/chain-head/#{id}"
  json['ChainHead']
end

#commit_chain(chain_names, content) ⇒ Object

Params: chain_names - chain name combination, must be unique globally. It’s

first entry's external ids actually.

content - content of first entry



81
82
83
84
# File 'lib/factom-ruby/client.rb', line 81

def commit_chain(chain_names, content)
  params = { 'CommitChainMsg' => get_chain_commit(chain_names, content) }
  raw_post "/v1/commit-chain/", params.to_json, content_type: :json
end

#commit_entry(chain_id, ext_ids, content) ⇒ Object



94
95
96
97
98
# File 'lib/factom-ruby/client.rb', line 94

def commit_entry(chain_id, ext_ids, content)
  params = { 'CommitEntryMsg' => get_entry_commit(chain_id, ext_ids, content) }
  # TODO: will factom make response return json, for a better world?
  raw_post "/v1/commit-entry/", params.to_json, content_type: :json
end

#ec_balance(pubkey = ec_public_key) ⇒ Object

Raises:



67
68
69
70
71
# File 'lib/factom-ruby/client.rb', line 67

def ec_balance(pubkey=ec_public_key)
  json = get "/v1/entry-credit-balance/#{pubkey}"
  raise GetBalanceFailed unless json['Success']
  json['Response']
end

#ec_balance_in_decimal(pubkey = ec_public_key) ⇒ Object



73
74
75
# File 'lib/factom-ruby/client.rb', line 73

def ec_balance_in_decimal(pubkey=ec_public_key)
  BigDecimal.new(ec_balance(pubkey)) / DENOMINATION_ENTRY_CREDIT
end

#entry(hash) ⇒ Object



44
45
46
# File 'lib/factom-ruby/client.rb', line 44

def entry(hash)
  decode_entry get "/v1/entry-by-hash/#{hash}"
end

#entry_block(keymr) ⇒ Object



36
37
38
# File 'lib/factom-ruby/client.rb', line 36

def entry_block(keymr)
  get "/v1/entry-block-by-keymr/#{keymr}"
end

#fa_balance(pubkey) ⇒ Object

Raises:



57
58
59
60
61
# File 'lib/factom-ruby/client.rb', line 57

def fa_balance(pubkey)
  json = get "/v1/factoid-balance/#{pubkey}"
  raise GetBalanceFailed unless json['Success']
  json['Response']
end

#fa_balance_in_decimal(pubkey) ⇒ Object



63
64
65
# File 'lib/factom-ruby/client.rb', line 63

def fa_balance_in_decimal(pubkey)
  BigDecimal.new(fa_balance(pubkey)) / DENOMINATION_FACTOID
end

#feeObject



48
49
50
51
# File 'lib/factom-ruby/client.rb', line 48

def fee
  json = get "/v1/factoid-get-fee/"
  json['Fee']
end

#headObject



22
23
24
25
# File 'lib/factom-ruby/client.rb', line 22

def head
  json = get "/v1/directory-block-head/"
  json['KeyMR']
end

#heightObject



17
18
19
20
# File 'lib/factom-ruby/client.rb', line 17

def height
  json = get "/v1/directory-block-height/"
  json['Height']
end

#propertiesObject



53
54
55
# File 'lib/factom-ruby/client.rb', line 53

def properties
  get "/v1/properties/"
end

#raw_data(hash) ⇒ Object



40
41
42
# File 'lib/factom-ruby/client.rb', line 40

def raw_data(hash)
  get "/v1/get-raw-data/#{hash}"
end

#reveal_chain(chain_names, content) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/factom-ruby/client.rb', line 86

def reveal_chain(chain_names, content)
  chain_id = get_chain_id chain_names
  ext_ids  = chain_names

  params = { 'Entry' => build_entry(chain_id, ext_ids, content) }
  raw_post "/v1/reveal-chain/", params.to_json, content_type: :json
end

#reveal_entry(chain_id, ext_ids, content) ⇒ Object



100
101
102
103
104
# File 'lib/factom-ruby/client.rb', line 100

def reveal_entry(chain_id, ext_ids, content)
  params = { 'Entry' => build_entry(chain_id, ext_ids, content) }
  # TODO: the same, replace raw_post with post
  raw_post "/v1/reveal-entry/", params.to_json, content_type: :json
end