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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3c29f674d6983fe3dcf4b95893a2303be793d7a5076376522f095be9fc49c11c
|
|
4
|
+
data.tar.gz: cc8b4f888bc347214ad4594ab2326c4c26772f77d0181708d80a04b2dc3128eb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c944def2149adf904e7e44b33772d42b12253124f8c3578d841be171ba0a8faf5004805fd95f105623ff2bcb9acc0ed70f8d378a181b5764cfe57a58251d99ab
|
|
7
|
+
data.tar.gz: 8b2ede233cc6bdd1f0da48568fcf69808a8ebc820a449d43bb16601226586fe32eebcb609277a34126d2c6d22c67c087d41dcefe3b4ed20ff8492815618fd79f
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby 3.0.5
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2023-02-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial Release
|
|
12
|
+
- Ability to transact with certificate authority
|
|
13
|
+
- Ability to transact with your ECM blockchain network
|
data/Gemfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in ecm_blockchain_api.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem "rake", "~> 13.0"
|
|
9
|
+
gem 'activesupport', '~> 7.0', '>= 7.0.4.3'
|
|
10
|
+
gem 'activemodel', '~> 7.0', '>= 7.0.4.3'
|
|
11
|
+
gem "rspec", "~> 3.0"
|
|
12
|
+
gem 'pry'
|
|
13
|
+
|
|
14
|
+
gem "rubocop", "~> 1.7"
|
|
15
|
+
gem 'schemacop', '>= 3.0.0'
|
|
16
|
+
|
|
17
|
+
group :development, :test do
|
|
18
|
+
gem 'factory_bot'
|
|
19
|
+
gem 'faker'
|
|
20
|
+
gem 'shoulda-matchers', '~> 5.0'
|
|
21
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
ecm_blockchain_api (1.0.1)
|
|
5
|
+
activemodel (~> 7.0, >= 7.0.4.3)
|
|
6
|
+
httparty (~> 0.22.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activemodel (7.1.4.2)
|
|
12
|
+
activesupport (= 7.1.4.2)
|
|
13
|
+
activesupport (7.1.4.2)
|
|
14
|
+
base64
|
|
15
|
+
bigdecimal
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
|
+
connection_pool (>= 2.2.5)
|
|
18
|
+
drb
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
minitest (>= 5.1)
|
|
21
|
+
mutex_m
|
|
22
|
+
tzinfo (~> 2.0)
|
|
23
|
+
addressable (2.8.7)
|
|
24
|
+
public_suffix (>= 2.0.2, < 7.0)
|
|
25
|
+
ast (2.4.2)
|
|
26
|
+
base64 (0.2.0)
|
|
27
|
+
bigdecimal (3.1.8)
|
|
28
|
+
coderay (1.1.3)
|
|
29
|
+
concurrent-ruby (1.3.4)
|
|
30
|
+
connection_pool (2.4.1)
|
|
31
|
+
crack (1.0.0)
|
|
32
|
+
bigdecimal
|
|
33
|
+
rexml
|
|
34
|
+
csv (3.3.0)
|
|
35
|
+
diff-lcs (1.5.1)
|
|
36
|
+
drb (2.2.1)
|
|
37
|
+
factory_bot (6.5.0)
|
|
38
|
+
activesupport (>= 5.0.0)
|
|
39
|
+
faker (3.5.1)
|
|
40
|
+
i18n (>= 1.8.11, < 2)
|
|
41
|
+
hashdiff (1.1.1)
|
|
42
|
+
httparty (0.22.0)
|
|
43
|
+
csv
|
|
44
|
+
mini_mime (>= 1.0.0)
|
|
45
|
+
multi_xml (>= 0.5.2)
|
|
46
|
+
i18n (1.14.6)
|
|
47
|
+
concurrent-ruby (~> 1.0)
|
|
48
|
+
json (2.7.4)
|
|
49
|
+
language_server-protocol (3.17.0.3)
|
|
50
|
+
method_source (1.1.0)
|
|
51
|
+
mini_mime (1.1.5)
|
|
52
|
+
minitest (5.25.1)
|
|
53
|
+
multi_xml (0.6.0)
|
|
54
|
+
mutex_m (0.2.0)
|
|
55
|
+
parallel (1.26.3)
|
|
56
|
+
parser (3.3.5.0)
|
|
57
|
+
ast (~> 2.4.1)
|
|
58
|
+
racc
|
|
59
|
+
pry (0.14.2)
|
|
60
|
+
coderay (~> 1.1)
|
|
61
|
+
method_source (~> 1.0)
|
|
62
|
+
public_suffix (6.0.1)
|
|
63
|
+
racc (1.8.1)
|
|
64
|
+
rainbow (3.1.1)
|
|
65
|
+
rake (13.2.1)
|
|
66
|
+
regexp_parser (2.9.2)
|
|
67
|
+
rexml (3.3.9)
|
|
68
|
+
rspec (3.13.0)
|
|
69
|
+
rspec-core (~> 3.13.0)
|
|
70
|
+
rspec-expectations (~> 3.13.0)
|
|
71
|
+
rspec-mocks (~> 3.13.0)
|
|
72
|
+
rspec-core (3.13.2)
|
|
73
|
+
rspec-support (~> 3.13.0)
|
|
74
|
+
rspec-expectations (3.13.3)
|
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
+
rspec-support (~> 3.13.0)
|
|
77
|
+
rspec-mocks (3.13.2)
|
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
79
|
+
rspec-support (~> 3.13.0)
|
|
80
|
+
rspec-support (3.13.1)
|
|
81
|
+
rubocop (1.67.0)
|
|
82
|
+
json (~> 2.3)
|
|
83
|
+
language_server-protocol (>= 3.17.0)
|
|
84
|
+
parallel (~> 1.10)
|
|
85
|
+
parser (>= 3.3.0.2)
|
|
86
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
87
|
+
regexp_parser (>= 2.4, < 3.0)
|
|
88
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
|
89
|
+
ruby-progressbar (~> 1.7)
|
|
90
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
91
|
+
rubocop-ast (1.32.3)
|
|
92
|
+
parser (>= 3.3.1.0)
|
|
93
|
+
ruby-progressbar (1.13.0)
|
|
94
|
+
ruby2_keywords (0.0.5)
|
|
95
|
+
schemacop (3.0.29)
|
|
96
|
+
activesupport (>= 4.0)
|
|
97
|
+
ruby2_keywords (>= 0.0.4)
|
|
98
|
+
shoulda-matchers (5.3.0)
|
|
99
|
+
activesupport (>= 5.2.0)
|
|
100
|
+
tzinfo (2.0.6)
|
|
101
|
+
concurrent-ruby (~> 1.0)
|
|
102
|
+
unicode-display_width (2.6.0)
|
|
103
|
+
webmock (3.24.0)
|
|
104
|
+
addressable (>= 2.8.0)
|
|
105
|
+
crack (>= 0.3.2)
|
|
106
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
107
|
+
|
|
108
|
+
PLATFORMS
|
|
109
|
+
arm64-darwin-23
|
|
110
|
+
x86_64-darwin-19
|
|
111
|
+
|
|
112
|
+
DEPENDENCIES
|
|
113
|
+
activemodel (~> 7.0, >= 7.0.4.3)
|
|
114
|
+
activesupport (~> 7.0, >= 7.0.4.3)
|
|
115
|
+
ecm_blockchain_api!
|
|
116
|
+
factory_bot
|
|
117
|
+
faker
|
|
118
|
+
pry
|
|
119
|
+
rake (~> 13.0)
|
|
120
|
+
rspec (~> 3.0)
|
|
121
|
+
rubocop (~> 1.7)
|
|
122
|
+
schemacop (>= 3.0.0)
|
|
123
|
+
shoulda-matchers (~> 5.0)
|
|
124
|
+
webmock
|
|
125
|
+
|
|
126
|
+
BUNDLED WITH
|
|
127
|
+
2.4.22
|
data/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# ECM Blockchain API
|
|
2
|
+
|
|
3
|
+
Client library to connect and transact with your [ECM Blockchain network](https://www.ecmsecure.com) and Certificate Authorities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'ecm_blockchain_api'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install through a CLI with:
|
|
18
|
+
|
|
19
|
+
$ gem install ecm_blockchain_api
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
Configure the library by initializing it with your access token.
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
ECMBlockchain.access_token = 'abc'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or create a Rails initializer file `ecm_api.rb`
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
# file: config/initializers/ecm_api.rb
|
|
32
|
+
|
|
33
|
+
require 'ecm_blockchain_api'
|
|
34
|
+
|
|
35
|
+
ECMBlockchain.access_token = ENV['ECM_ACCESS_TOKEN']
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Change the default production base_url
|
|
39
|
+
```ruby
|
|
40
|
+
ECMBlockchain.base_url = "https://sandbox.ecmsecure.com/v1"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Interact with your Certificate Authority
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# Register and enroll member on the Certificate Authority
|
|
47
|
+
@member = ECMBlockchain::CA.create(
|
|
48
|
+
uuid: "user@org1.example.com",
|
|
49
|
+
secret: "s3cr3t!",
|
|
50
|
+
customAttributes: [
|
|
51
|
+
{
|
|
52
|
+
name: "verified",
|
|
53
|
+
value: "true"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Retrieve a member by UUID
|
|
59
|
+
member = ECMBlockchain::CA.retrieve("user@org1.example.com")
|
|
60
|
+
member.custom_attributes
|
|
61
|
+
|
|
62
|
+
# Update a member
|
|
63
|
+
custom_attributes = [{ name: "verified", value: "false" }]
|
|
64
|
+
ECMBlockchain::CA.update(identity, custom_attributes)
|
|
65
|
+
|
|
66
|
+
# Delete a member
|
|
67
|
+
ECMBlockchain::CA.delete("user@org1.example.com")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
# Create an Asset on the blockchain
|
|
72
|
+
@asset = ECMBlockchain::Asset.create(
|
|
73
|
+
'creator_identity',
|
|
74
|
+
{
|
|
75
|
+
uuid: "823737e4-bdc4-401a-b309-ef4c4d4f4733",
|
|
76
|
+
groupId: "contract-bdc4-401a",
|
|
77
|
+
title: "signable contract",
|
|
78
|
+
summary: "updated asset",
|
|
79
|
+
owner: "owner_identity",
|
|
80
|
+
file: {
|
|
81
|
+
identifier: "fb77d3e2-03a7-4de0-b571-957dd146edf8",
|
|
82
|
+
base64: "data:@file/pdf;base64,JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9D...",
|
|
83
|
+
storage: true,
|
|
84
|
+
digitallySigned: {
|
|
85
|
+
standard: "simple",
|
|
86
|
+
signatureType: "certification",
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
content: {
|
|
90
|
+
unit_type: 'PU',
|
|
91
|
+
unit_id: 'TY23737e4-bdc4-401a-b309-ef4c4d4f4733',
|
|
92
|
+
date_purchased: '10th Jan 2025 09:02:41'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# Retrieve an Asset by UUID
|
|
98
|
+
@asset = ECMBlockchain::Asset.retrieve("823737e4-bdc4-401a-b309-ef4c4d4f4733")
|
|
99
|
+
@asset.title
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
# mint tokens
|
|
104
|
+
@tokens = ECMBlockchain::Tokens.create(
|
|
105
|
+
'creator_identity',
|
|
106
|
+
{
|
|
107
|
+
kind: "CarbonCoins",
|
|
108
|
+
quantity: 100
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Burn tokens
|
|
113
|
+
@tokens = ECMBlockchain::Tokens.burn(
|
|
114
|
+
'owner_identity',
|
|
115
|
+
{
|
|
116
|
+
kind: "CarbonCoins",
|
|
117
|
+
quantity: 100
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# Retrieve tokens
|
|
123
|
+
@tokens = ECMBlockchain::Tokens.retrieve(
|
|
124
|
+
'owner_identity',
|
|
125
|
+
kind # defaults to 'all'
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# returns ECMBlockchain::TokensCollection
|
|
129
|
+
|
|
130
|
+
@tokens.first.kind
|
|
131
|
+
@tokens.first.quanitity
|
|
132
|
+
@tokens.first.owner
|
|
133
|
+
@tokens.first.transferee
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
139
|
+
|
|
140
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
141
|
+
|
|
142
|
+
## Contributing
|
|
143
|
+
|
|
144
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ecm_blockchain_api.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "ecm_blockchain_api"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
ECMBlockchain.base_url = "http://localhost:3000/v1"
|
|
14
|
+
# ECMBlockchain.access_token = ""
|
|
15
|
+
ECMBlockchain.access_token = "W4nd3rl4nds!"
|
|
16
|
+
|
|
17
|
+
require "pry"
|
|
18
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/ecm-blockchain-api/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "ecm-blockchain-api"
|
|
7
|
+
spec.version = ECMBlockchain::VERSION
|
|
8
|
+
spec.authors = ["Wardy"]
|
|
9
|
+
spec.email = ["info@ecmsecure.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "ECM Distributed Ledger & Blockchain API"
|
|
12
|
+
spec.description = "Connect and transact with your ECM certificate authority and distributed ledger network."
|
|
13
|
+
spec.homepage = "https://www.ecmsecure.com"
|
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
15
|
+
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/ecmsecure/ecm-blockchain-api"
|
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/ecmsecure/ecm-blockchain-api/blob/main/CHANGELOG.md"
|
|
19
|
+
|
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = "exe"
|
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ["lib"]
|
|
28
|
+
|
|
29
|
+
# Uncomment to register a new dependency of your gem
|
|
30
|
+
spec.add_dependency "httparty", "~> 0.22.0"
|
|
31
|
+
spec.add_dependency 'activemodel', '~> 7.0', '>= 7.0.4.3'
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "pry"
|
|
34
|
+
spec.add_development_dependency "webmock"
|
|
35
|
+
|
|
36
|
+
# For more information and examples about making a new gem, checkout our
|
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
38
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class Asset
|
|
3
|
+
extend ECMBlockchain::Routes
|
|
4
|
+
extend ECMBlockchain::Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def create(identity, data)
|
|
8
|
+
verify_asset(data)
|
|
9
|
+
asset(request( :post, "/#{identity}#{ASSET_URL}", data ))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# def batch_create(identity, data)
|
|
13
|
+
# verify_batch_assets(data)
|
|
14
|
+
# request( :post, "/#{identity}#{ASSET_BATCH_URL}", data ).
|
|
15
|
+
# collect { |asset_response| asset(asset_response) }
|
|
16
|
+
# rescue => error; error
|
|
17
|
+
# end
|
|
18
|
+
|
|
19
|
+
# def retrieve(identity)
|
|
20
|
+
# response = request( :get, "/#{identity}#{MEMBERS_URL}" )
|
|
21
|
+
# return_any_errors(response)
|
|
22
|
+
# ECMBlockchain::Member.new(JSON.parse(response.body).with_indifferent_access)
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
# def update(identity, data)
|
|
26
|
+
# response = request( :patch, "/#{identity}#{MEMBERS_URL}", data )
|
|
27
|
+
# return_any_errors(response)
|
|
28
|
+
# ECMBlockchain::Member.new(JSON.parse(response.body).with_indifferent_access)
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
# def revoke(identity)
|
|
32
|
+
# response = request( :delete, "/#{identity}#{MEMBERS_URL}")
|
|
33
|
+
# return_any_errors(response)
|
|
34
|
+
# OpenStruct.new(success: true, details: "Certificate successfully revoked")
|
|
35
|
+
# end
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def asset(asset_data)
|
|
39
|
+
verify_asset(asset_data)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def verify_asset(asset)
|
|
43
|
+
ECMBlockchain::AssetModel.verify(asset)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def verify_batch_assets(arr)
|
|
47
|
+
arr.find_all { |asset| verify_asset(asset) }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class CA
|
|
3
|
+
extend ECMBlockchain::Routes
|
|
4
|
+
extend ECMBlockchain::Request
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def create(data)
|
|
8
|
+
member(request( :post, MEMBERS_URL, data ))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def retrieve(identity)
|
|
12
|
+
member(request( :get, "/#{identity}#{MEMBERS_URL}" ))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update(identity, data)
|
|
16
|
+
member(request( :patch, "/#{identity}#{MEMBERS_URL}", data ))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def revoke(identity)
|
|
20
|
+
response = request( :delete, "/#{identity}#{MEMBERS_URL}")
|
|
21
|
+
OpenStruct.new(success: true, details: "Certificate successfully revoked")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def member(params)
|
|
27
|
+
ECMBlockchain::Member.new(params)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module ECMBlockchain
|
|
2
|
+
class Error < StandardError
|
|
3
|
+
attr_reader :code, :details, :name
|
|
4
|
+
|
|
5
|
+
def self.raise_error(response)
|
|
6
|
+
klass = ERROR_CLASS_MAP[response.code] || self
|
|
7
|
+
res = response.body
|
|
8
|
+
res = '{}' if res == ''
|
|
9
|
+
err = JSON.parse(res).deep_symbolize_keys[:error]
|
|
10
|
+
raise klass.new(
|
|
11
|
+
message: err[:message] || response.headers["status"],
|
|
12
|
+
code: err[:statusCode] || response.code,
|
|
13
|
+
details: err[:details],
|
|
14
|
+
name: klass.to_s
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Initializes a new Error object
|
|
19
|
+
#
|
|
20
|
+
# @param message [Exception, String]
|
|
21
|
+
# @param code [Integer]
|
|
22
|
+
# @return [ECMBlockchain::Error]
|
|
23
|
+
def initialize(message: "", code: nil, details: nil, name: nil)
|
|
24
|
+
super(message)
|
|
25
|
+
|
|
26
|
+
@code = code
|
|
27
|
+
@details = details
|
|
28
|
+
@name = name
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class BadRequest < ECMBlockchain::Error;end;
|
|
33
|
+
class Unauthorized < ECMBlockchain::Error; end;
|
|
34
|
+
class PaymentRequired < ECMBlockchain::Error; end;
|
|
35
|
+
class Forbidden < ECMBlockchain::Error; end;
|
|
36
|
+
class RequestEntityTooLarge < ECMBlockchain::Error; end;
|
|
37
|
+
class NotFound < ECMBlockchain::Error; end;
|
|
38
|
+
class NotAcceptable < ECMBlockchain::Error; end;
|
|
39
|
+
class UnprocessableEntityError < ECMBlockchain::Error; end;
|
|
40
|
+
class TooManyRequests < ECMBlockchain::Error; end;
|
|
41
|
+
class ServerError < ECMBlockchain::Error; end;
|
|
42
|
+
class InternalServerError < ECMBlockchain::Error; end;
|
|
43
|
+
class BadGateway < ECMBlockchain::Error; end;
|
|
44
|
+
class ServiceUnavailable < ECMBlockchain::Error; end;
|
|
45
|
+
class GatewayTimeout < ECMBlockchain::Error; end;
|
|
46
|
+
class TimeoutError < ECMBlockchain::Error; end;
|
|
47
|
+
|
|
48
|
+
ERROR_CLASS_MAP = {
|
|
49
|
+
400 => ECMBlockchain::BadRequest,
|
|
50
|
+
401 => ECMBlockchain::Unauthorized,
|
|
51
|
+
402 => ECMBlockchain::PaymentRequired,
|
|
52
|
+
403 => ECMBlockchain::Forbidden,
|
|
53
|
+
404 => ECMBlockchain::NotFound,
|
|
54
|
+
406 => ECMBlockchain::NotAcceptable,
|
|
55
|
+
413 => ECMBlockchain::RequestEntityTooLarge,
|
|
56
|
+
422 => ECMBlockchain::UnprocessableEntityError,
|
|
57
|
+
429 => ECMBlockchain::TooManyRequests,
|
|
58
|
+
500 => ECMBlockchain::InternalServerError,
|
|
59
|
+
502 => ECMBlockchain::BadGateway,
|
|
60
|
+
503 => ECMBlockchain::ServiceUnavailable,
|
|
61
|
+
504 => ECMBlockchain::GatewayTimeout,
|
|
62
|
+
}.freeze
|
|
63
|
+
|
|
64
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
|
|
3
|
+
module ECMBlockchain
|
|
4
|
+
class AssetModel
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
|
|
7
|
+
attr_accessor :uuid, :txId, :groupId, :title, :summary, :createdBy, :owner,
|
|
8
|
+
:file, :content, :created_at, :access, :lastInteraction, :events
|
|
9
|
+
|
|
10
|
+
validates :uuid, :title, presence: true
|
|
11
|
+
validate :data_file_or_content?
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def verify(data={})
|
|
15
|
+
asset = self.new(data)
|
|
16
|
+
raise ECMBlockchain::UnprocessableEntityError.new(
|
|
17
|
+
asset.errors.full_messages.first, 422
|
|
18
|
+
) unless asset.valid?
|
|
19
|
+
asset
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def initialize(data={})
|
|
24
|
+
@uuid = data.fetch(:uuid) { nil }
|
|
25
|
+
@txId = data.fetch(:txId) { nil }
|
|
26
|
+
@groupId = data.fetch(:groupId) { nil }
|
|
27
|
+
@title = data.fetch(:title) { nil }
|
|
28
|
+
@summary = data.fetch(:summary) { nil }
|
|
29
|
+
@createdBy = data.fetch(:createdBy) { nil }
|
|
30
|
+
@owner = data.fetch(:owner) { nil }
|
|
31
|
+
@file = ECMBlockchain::DataFile.new(data.fetch(:file) { })
|
|
32
|
+
@content = ECMBlockchain::DataContent.new(data.fetch(:content) { })
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def success?
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def error
|
|
40
|
+
nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def data_file_or_content?
|
|
46
|
+
unless file.valid? || content.valid?
|
|
47
|
+
errors.add(:base, "Please supply either a file object or content object")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
|
|
3
|
+
module ECMBlockchain
|
|
4
|
+
class CustomAttribute
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
|
|
7
|
+
attr_accessor :name, :value
|
|
8
|
+
|
|
9
|
+
validates :name, presence: true
|
|
10
|
+
validates :value, presence: true
|
|
11
|
+
|
|
12
|
+
def initialize(data = {})
|
|
13
|
+
@name = data.fetch(:name)
|
|
14
|
+
@value = data.fetch(:value)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|