class MailchainApi

Public Class Methods

new(config) click to toggle source

Initialize the config

# File lib/api/mailchain.rb, line 10
def initialize(config)
  @config = config
end

Public Instance Methods

addresses(protocol, network) click to toggle source

Get addresses endpoint `protocol` = the protocol `network` = the network

# File lib/api/mailchain.rb, line 25
def addresses(protocol, network)
  res = self.class.get("#{base_uri}/addresses?protocol=#{protocol}&network=#{network}")
  { body: JSON.parse(res.body), status_code: res.code }
end
base_uri() click to toggle source

Return the base_uri as specified in the config

# File lib/api/mailchain.rb, line 15
def base_uri
  ssl = @config['ssl'] ? 'https' : 'http'
  uri = @config['hostname']
  port = @config['port']
  "#{ssl}://#{uri}:#{port}/api"
end
messages(address, protocol, network) click to toggle source

Get messages from api `address`: the address (string e.g. '0x123…') `protocol`: the protocol (string e.g. 'ethereum) `network`: the network (string e.g. 'ropsten')

# File lib/api/mailchain.rb, line 34
def messages(address, protocol, network)
  res = self.class.get("#{base_uri}/messages?address=#{address}&protocol=#{protocol}&network=#{network}")
  { body: JSON.parse(res.body), status_code: res.code }
end
protocols() click to toggle source

Get protocols endpoint

# File lib/api/mailchain.rb, line 40
def protocols
  res = self.class.get("#{base_uri}/protocols")
  { body: JSON.parse(res.body), status_code: res.code }
end
version() click to toggle source

Calls the version endpoint, returns version

# File lib/api/mailchain.rb, line 46
def version
  res = self.class.get("#{base_uri}/version")
  { body: JSON.parse(res.body), status_code: res.code }
end