Everlastly 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/example.rb +13 -0
- data/lib/everlastly.rb +100 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 867f9229196ee588e91329147f7e8738c9342882
|
4
|
+
data.tar.gz: 8a2ad098a5e31ff92c21bc92c13eea5d11c15d13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddc485e17c25f07241912f89de1d9f1db2d02234a32f517eec42446212de7946271644a034e765e0364616ec643d855677893845636de1d8099763fb89741141
|
7
|
+
data.tar.gz: 7fa9fa19cf213da2ca6bc7c4b0101376c966906bc41708d5581eb17497a63931b8a7c918a7dd0e7f5a1e21a2a9715c2ed8ce13e33f1e6e4f814c1a81436fadd3
|
data/example.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'everlastly'
|
2
|
+
|
3
|
+
Everlastly.setup do | config |
|
4
|
+
config.public_key = 'pub key'
|
5
|
+
config.private_key = 'priv key'
|
6
|
+
end
|
7
|
+
|
8
|
+
example_hash="3e79ffa0e95c435ec8ee50ebb6959259968b4c66852d4fba4fc0876e83b4a0e1"
|
9
|
+
|
10
|
+
anchor_result = Everlastly.anchor example_hash, metadata: {"additional info":"隨機詞"}
|
11
|
+
|
12
|
+
p Everlastly.get_receipts([ anchor_result[:receiptID], ]) if anchor_result[:success]
|
13
|
+
|
data/lib/everlastly.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# everlastly.py: Everlastly API implementation
|
2
|
+
#
|
3
|
+
# Copyright © 2016 Emelyanenko Kirill
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
6
|
+
# copy of this software and associated documentation files (the "Software"),
|
7
|
+
# to deal in the Software without restriction, including without limitation
|
8
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
10
|
+
# Software is furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
18
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
21
|
+
# DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'rest-client'
|
24
|
+
require 'openssl'
|
25
|
+
require 'open-uri'
|
26
|
+
require 'json'
|
27
|
+
require 'addressable/uri'
|
28
|
+
|
29
|
+
module Everlastly
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :configuration
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.setup
|
36
|
+
@configuration ||= Configuration.new
|
37
|
+
yield( configuration )
|
38
|
+
end
|
39
|
+
|
40
|
+
class Configuration
|
41
|
+
attr_accessor :public_key, :private_key
|
42
|
+
|
43
|
+
def intialize
|
44
|
+
@public_key = ''
|
45
|
+
@private_key = ''
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_receipts(receipts, params={})
|
50
|
+
payload = { uuids: JSON.dump(receipts)}
|
51
|
+
payload[:nonce] = (Time.now.to_f * 10000000).to_i unless params[:no_nonce]
|
52
|
+
begin
|
53
|
+
response = JSON.parse(post('get_receipts', payload))
|
54
|
+
{ success: true, receipts: response["receipts"] }
|
55
|
+
rescue JSON::ParserError
|
56
|
+
{ success: false, error_message: "Strange answer from server" }
|
57
|
+
rescue RestClient::Exception
|
58
|
+
{ success: false, error_message: "Network error" }
|
59
|
+
rescue SocketError
|
60
|
+
{ success: false, error_message: "Network error" }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.anchor(dochash, params={})
|
65
|
+
payload = { hash: dochash }
|
66
|
+
if params[:no_nonce] then
|
67
|
+
payload[:no_nonce]='True'
|
68
|
+
else
|
69
|
+
payload[:nonce] = (Time.now.to_f * 10000000).to_i
|
70
|
+
end
|
71
|
+
payload[:metadata] = JSON.dump(params[:metadata]) if params[:metadata]
|
72
|
+
payload[:no_salt] = 'True' if params[:no_salt]
|
73
|
+
payload[:save_dochash_in_receipt] = 'True' if params[:save_dochash_in_receipt]
|
74
|
+
begin
|
75
|
+
response = JSON.parse(post('anchor', payload))
|
76
|
+
{ success: (response["status"]=="Accepted"), error_message: response["error"], receiptID: response["receiptID"] }
|
77
|
+
rescue JSON::ParserError
|
78
|
+
{ success: false, error_message: "Strange answer from server" }
|
79
|
+
rescue RestClient::Exception
|
80
|
+
{ success: false, error_message: "Network error" }
|
81
|
+
rescue SocketError
|
82
|
+
{ success: false, error_message: "Network error" }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
def self.resource
|
89
|
+
@@resouce ||= RestClient::Resource.new( 'https://everlastly.com/api/v1/' )
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def self.post( command, payload )
|
94
|
+
encoded_payload = Addressable::URI.form_encode(payload)
|
95
|
+
sign = OpenSSL::HMAC.hexdigest( 'sha512', configuration.private_key , encoded_payload )
|
96
|
+
resource[ command ].post encoded_payload, { "pub-key" => configuration.public_key , sign: sign, 'content-type' => 'application/x-www-form-urlencoded' }
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Everlastly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emelyanenko Kirill
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Everlastly.com API wrapper for Ruby. Notarize all your data using the
|
14
|
+
blockchain!
|
15
|
+
email: emelyanenko.kirill@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- example.rb
|
21
|
+
- lib/everlastly.rb
|
22
|
+
homepage: https://everlastly.com
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Everlastly.com API wrapper
|
46
|
+
test_files: []
|