module Everlastly
Attributes
configuration[RW]
Public Class Methods
anchor(dochash, params={})
click to toggle source
# File lib/everlastly.rb, line 64 def self.anchor(dochash, params={}) payload = { hash: dochash } if params[:no_nonce] then payload[:no_nonce]='True' else payload[:nonce] = (Time.now.to_f * 10000000).to_i end payload[:metadata] = JSON.dump(params[:metadata]) if params[:metadata] payload[:no_salt] = 'True' if params[:no_salt] payload[:save_dochash_in_receipt] = 'True' if params[:save_dochash_in_receipt] begin response = JSON.parse(post('anchor', payload)) { success: (response["status"]=="Accepted"), error_message: response["error"], receiptID: response["receiptID"] } rescue JSON::ParserError { success: false, error_message: "Strange answer from server" } rescue RestClient::Exception { success: false, error_message: "Network error" } rescue SocketError { success: false, error_message: "Network error" } end end
get_receipts(receipts, params={})
click to toggle source
# File lib/everlastly.rb, line 49 def self.get_receipts(receipts, params={}) payload = { uuids: JSON.dump(receipts)} payload[:nonce] = (Time.now.to_f * 10000000).to_i unless params[:no_nonce] begin response = JSON.parse(post('get_receipts', payload)) { success: true, receipts: response["receipts"] } rescue JSON::ParserError { success: false, error_message: "Strange answer from server" } rescue RestClient::Exception { success: false, error_message: "Network error" } rescue SocketError { success: false, error_message: "Network error" } end end
setup() { |configuration| ... }
click to toggle source
# File lib/everlastly.rb, line 35 def self.setup @configuration ||= Configuration.new yield( configuration ) end
Protected Class Methods
post( command, payload )
click to toggle source
# File lib/everlastly.rb, line 93 def self.post( command, payload ) encoded_payload = Addressable::URI.form_encode(payload) sign = OpenSSL::HMAC.hexdigest( 'sha512', configuration.private_key , encoded_payload ) resource[ command ].post encoded_payload, { "pub-key" => configuration.public_key , sign: sign, 'content-type' => 'application/x-www-form-urlencoded' } end
resource()
click to toggle source
# File lib/everlastly.rb, line 88 def self.resource @@resouce ||= RestClient::Resource.new( 'https://everlastly.com/api/v1/' ) end