ecm-blockchain-api 1.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/.gitignore +12 -0
- data/.gitlab-ci.yml +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +127 -0
- data/README.md +144 -0
- data/Rakefile +12 -0
- data/bin/console +18 -0
- data/bin/setup +8 -0
- data/ecm-blockchain-api.gemspec +38 -0
- data/lib/ecm-blockchain-api/asset.rb +51 -0
- data/lib/ecm-blockchain-api/ca.rb +31 -0
- data/lib/ecm-blockchain-api/client.rb +7 -0
- data/lib/ecm-blockchain-api/errors.rb +64 -0
- data/lib/ecm-blockchain-api/models/asset_model.rb +51 -0
- data/lib/ecm-blockchain-api/models/custom_attribute.rb +17 -0
- data/lib/ecm-blockchain-api/models/data_content_file.rb +9 -0
- data/lib/ecm-blockchain-api/models/data_content_model.rb +31 -0
- data/lib/ecm-blockchain-api/models/data_file_model.rb +24 -0
- data/lib/ecm-blockchain-api/models/digital_signature_model.rb +25 -0
- data/lib/ecm-blockchain-api/models/member.rb +21 -0
- data/lib/ecm-blockchain-api/models/token_collection.rb +17 -0
- data/lib/ecm-blockchain-api/models/token_model.rb +19 -0
- data/lib/ecm-blockchain-api/request.rb +42 -0
- data/lib/ecm-blockchain-api/routes.rb +8 -0
- data/lib/ecm-blockchain-api/token.rb +36 -0
- data/lib/ecm-blockchain-api/version.rb +5 -0
- data/lib/ecm-blockchain-api.rb +41 -0
- data/tags +76018 -0
- metadata +140 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class DataContent
|
|
3
|
+
include ActiveModel::Validations
|
|
4
|
+
attr_accessor :data
|
|
5
|
+
|
|
6
|
+
validate :empty_data
|
|
7
|
+
|
|
8
|
+
def initialize(data={})
|
|
9
|
+
data ||= {}
|
|
10
|
+
@data = data.deep_symbolize_keys
|
|
11
|
+
create_data_attr_accessors
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def added?
|
|
15
|
+
@data.any?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def create_data_attr_accessors
|
|
21
|
+
@data.each do |name, value|
|
|
22
|
+
self.class.class_eval { attr_accessor name }
|
|
23
|
+
self.instance_variable_set("@#{name}", value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def empty_data
|
|
28
|
+
errors.add(:base, "Please supply at least one key value pair") unless data.any?
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class DataFile
|
|
3
|
+
include ActiveModel::Validations
|
|
4
|
+
|
|
5
|
+
attr_accessor :identifier, :base64, :storage, :digitalSignature
|
|
6
|
+
attr_reader :fileHash, :href
|
|
7
|
+
|
|
8
|
+
validates :identifier, :base64, presence: true
|
|
9
|
+
|
|
10
|
+
def initialize(data={})
|
|
11
|
+
data ||= {}
|
|
12
|
+
@identifier = data[:identifier]
|
|
13
|
+
@base64 = data[:base64]
|
|
14
|
+
@storage = data[:storage]
|
|
15
|
+
@fileHash = data[:fileHash]
|
|
16
|
+
@href = data[:href]
|
|
17
|
+
@digitalSignature = ECMBlockchain::DigitalSignature.new(data.fetch(:digitalSignature) {})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def added?
|
|
21
|
+
self.valid?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class DigitalSignature
|
|
3
|
+
include ActiveModel::Validations
|
|
4
|
+
|
|
5
|
+
attr_accessor :standard, :signatureType
|
|
6
|
+
attr_reader :cms, :timestamp, :validated
|
|
7
|
+
|
|
8
|
+
validates :standard, :signatureType, presence: true
|
|
9
|
+
validates :signatureType, inclusion: { in: %w(certification approval)}
|
|
10
|
+
validates :standard, inclusion: { in: %w(simple PAdES XAdES CAdES)}
|
|
11
|
+
|
|
12
|
+
def initialize(data={})
|
|
13
|
+
data ||= {}
|
|
14
|
+
@standard = data[:standard]
|
|
15
|
+
@signatureType = data[:signatureType]
|
|
16
|
+
@cms = data[:cms]
|
|
17
|
+
@validated = data[:validated]
|
|
18
|
+
@timestamp = data[:timestamp]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def added?
|
|
22
|
+
self.valid?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
|
|
3
|
+
module ECMBlockchain
|
|
4
|
+
class Member
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
|
|
7
|
+
attr_accessor :uuid, :organisation, :custom_attributes, :certificate
|
|
8
|
+
|
|
9
|
+
validates :uuid, presence: true
|
|
10
|
+
validates :organisation, :certificate, presence: true
|
|
11
|
+
|
|
12
|
+
def initialize(data={})
|
|
13
|
+
@uuid = data.fetch(:uuid)
|
|
14
|
+
@organisation = data.fetch(:organisation)
|
|
15
|
+
@certificate = data.fetch(:certificate)
|
|
16
|
+
@custom_attributes = data[:customAttributes].map do |attr|
|
|
17
|
+
ECMBlockchain::CustomAttribute.new(attr)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class TokensCollection
|
|
3
|
+
|
|
4
|
+
include Enumerable
|
|
5
|
+
attr_accessor :tokens
|
|
6
|
+
|
|
7
|
+
def initialize(tokens=[])
|
|
8
|
+
self.tokens = tokens.map do |token|
|
|
9
|
+
ECMBlockchain::TokenModel.new(token)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def each(&block)
|
|
14
|
+
self.tokens.each(&block)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
|
|
3
|
+
module ECMBlockchain
|
|
4
|
+
class TokenModel
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
|
|
7
|
+
attr_accessor :kind, :quantity, :owner, :transferee
|
|
8
|
+
|
|
9
|
+
validates :kind, :quantity, presence: true
|
|
10
|
+
|
|
11
|
+
def initialize(data={})
|
|
12
|
+
@kind = data.fetch(:kind)
|
|
13
|
+
@quantity = data.fetch(:quantity)
|
|
14
|
+
@owner = data.fetch(:owner, nil)
|
|
15
|
+
@transferee = data.fetch(:transferee, nil)
|
|
16
|
+
raise error unless valid?
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module ECMBlockchain
|
|
4
|
+
module Request
|
|
5
|
+
def self.extended(base)
|
|
6
|
+
base.include HTTParty
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
HTTP_VERBS = %i(post get delete patch)
|
|
10
|
+
|
|
11
|
+
def request(method, url, data=nil)
|
|
12
|
+
ECMBlockchain.has_api_key?
|
|
13
|
+
check_http_verb(method)
|
|
14
|
+
response = api_client_call(method, url, data)
|
|
15
|
+
raise ECMBlockchain::Error.raise_error(response) unless response.success?
|
|
16
|
+
JSON.parse(response.body, symbolize_names: true) if response.body
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def api_client_call(verb, url, data)
|
|
22
|
+
args = [ verb, ECMBlockchain.base_url + url ]
|
|
23
|
+
headers = {}
|
|
24
|
+
headers[:body] = data.to_json if data
|
|
25
|
+
headers.merge! request_headers
|
|
26
|
+
args.push(headers)
|
|
27
|
+
self.send *args
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def check_http_verb(verb)
|
|
31
|
+
unless HTTP_VERBS.include?(verb)
|
|
32
|
+
raise BadRequest.new(
|
|
33
|
+
message: "HTTP Verb needs to be one of the following: #{ HTTP_VERBS }",
|
|
34
|
+
code: 400)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def request_headers
|
|
39
|
+
{ :headers => {"Content-Type" => "application/json", "Authorization" => "Bearer #{ECMBlockchain.access_token}"} }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class Tokens
|
|
3
|
+
extend ECMBlockchain::Routes
|
|
4
|
+
extend ECMBlockchain::Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def create(identity, data)
|
|
8
|
+
token(request( :post, "/#{identity}#{TOKENS_URL}/mint", data ))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def retrieve(identity, kind='all')
|
|
12
|
+
token(request( :get, "/#{identity}#{TOKENS_URL}/#{kind}" ))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def total_supply()
|
|
16
|
+
token(request( :get, "/#{TOKENS_URL}"))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def burn(identity, data)
|
|
20
|
+
response = request( :delete, "/#{identity}#{TOKENS_URL}/burn", data)
|
|
21
|
+
OpenStruct.new(success: true, details: "Tokens successfully burnt")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def transfer(from, to, data)
|
|
25
|
+
data[:transferee] = request( :get, "/#{to}#{TOKENS_URL}/wallet")[:address]
|
|
26
|
+
token(request( :patch, "/#{from}#{TOKENS_URL}/transfer", data ))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def token(params)
|
|
32
|
+
ECMBlockchain::TokensCollection.new(params)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "ecm-blockchain-api/version"
|
|
4
|
+
require_relative "ecm-blockchain-api/client"
|
|
5
|
+
require_relative "ecm-blockchain-api/routes"
|
|
6
|
+
require_relative "ecm-blockchain-api/request"
|
|
7
|
+
require_relative "ecm-blockchain-api/errors"
|
|
8
|
+
require_relative "ecm-blockchain-api/models/member"
|
|
9
|
+
require_relative "ecm-blockchain-api/models/asset_model"
|
|
10
|
+
require_relative "ecm-blockchain-api/models/token_model"
|
|
11
|
+
require_relative "ecm-blockchain-api/models/token_collection"
|
|
12
|
+
require_relative "ecm-blockchain-api/models/data_file_model"
|
|
13
|
+
require_relative "ecm-blockchain-api/models/data_content_model"
|
|
14
|
+
require_relative "ecm-blockchain-api/models/custom_attribute"
|
|
15
|
+
require_relative "ecm-blockchain-api/models/digital_signature_model"
|
|
16
|
+
require "httparty"
|
|
17
|
+
require "logger"
|
|
18
|
+
require "active_model"
|
|
19
|
+
|
|
20
|
+
require "ecm-blockchain-api/ca"
|
|
21
|
+
require "ecm-blockchain-api/asset"
|
|
22
|
+
require "ecm-blockchain-api/token"
|
|
23
|
+
|
|
24
|
+
module ECMBlockchain
|
|
25
|
+
require "pry"
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
attr_accessor :access_token, :logger, :base_url
|
|
29
|
+
|
|
30
|
+
def has_api_key?
|
|
31
|
+
return unless ECMBlockchain.access_token.to_s.empty?
|
|
32
|
+
raise Unauthorized.new(
|
|
33
|
+
message: "You need to set your access_token",
|
|
34
|
+
code: 401,
|
|
35
|
+
name: Unauthorized)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@logger = Logger.new(STDOUT)
|
|
40
|
+
@base_url = "https://api.ecmsecure.com/v1"
|
|
41
|
+
end
|