Class: BiilabsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/biilabs-client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBiilabsClient

Returns a new instance of BiilabsClient.



7
8
9
10
11
12
13
14
# File 'lib/biilabs-client.rb', line 7

def initialize
  config_path = 'config/biilabs-client.yml'
  env = ENV['RAILS_ENV'] || 'development'
  string = File.open(config_path, 'rb') { |f| f.read }
  fail "#{config_path} not existed nor not readable" if string.nil?
  @config = YAML.load(string)[env]
  fail "#{config_path} incorrect or environment not exist" if @config.nil?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/biilabs-client.rb', line 5

def config
  @config
end

Instance Method Details

#get_tangle(tangle_id) ⇒ Object



30
31
32
33
34
# File 'lib/biilabs-client.rb', line 30

def get_tangle(tangle_id)
  path = "/transaction/#{tangle_id}"
  resp = connection.get(path)
  response_handler(resp)
end

#get_tangle_by_tag(tag) ⇒ Object



36
37
38
39
40
41
# File 'lib/biilabs-client.rb', line 36

def get_tangle_by_tag(tag)
  tag_id = (tag.to_trytes.value + "9" * 27)[0..26]
  path = "/tag/#{tag_id}"
  resp = connection.get(path)
  response_handler(resp)
end

#post_tangle(tag, message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/biilabs-client.rb', line 16

def post_tangle(tag, message)
  path = '/transaction'
  body = {
    tag: tag.to_trytes.value,
    message: message
  }
  resp = connection.post do |req|
    req.url path
    req.headers['Content-Type'] = 'application/json'
    req.body = body.to_json
  end
  response_handler(resp)
end