stellar_federation-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +36 -0
- data/app/assets/config/stellar_federation_manifest.js +2 -0
- data/app/assets/javascripts/stellar_federation/application.js +13 -0
- data/app/assets/stylesheets/stellar_federation/application.css +15 -0
- data/app/controllers/stellar_federation/api/v1/queries_controller.rb +42 -0
- data/app/controllers/stellar_federation/application_controller.rb +5 -0
- data/app/helpers/stellar_federation/application_helper.rb +4 -0
- data/app/jobs/stellar_federation/application_job.rb +4 -0
- data/app/mailers/stellar_federation/application_mailer.rb +6 -0
- data/app/models/stellar_federation/application_record.rb +5 -0
- data/app/models/stellar_federation/base_model.rb +9 -0
- data/app/models/stellar_federation/query_response.rb +22 -0
- data/app/services/stellar_federation/queries/check_parameters.rb +16 -0
- data/app/services/stellar_federation/queries/prepare_on_query_parameters.rb +13 -0
- data/app/services/stellar_federation/queries/process_query.rb +14 -0
- data/app/services/stellar_federation/queries/trigger_on_query_callback_class.rb +38 -0
- data/app/views/layouts/stellar_federation/application.html.erb +14 -0
- data/config/routes.rb +7 -0
- data/lib/stellar_federation-rails.rb +2 -0
- data/lib/stellar_federation.rb +13 -0
- data/lib/stellar_federation/engine.rb +14 -0
- data/lib/stellar_federation/version.rb +3 -0
- data/lib/tasks/stellar_federation_tasks.rake +4 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b52f4c6be8d224343880279ca916a5a7db62164d87ea92e6e2104b26957ddccd
|
4
|
+
data.tar.gz: f42f86334b6564cb22364da7fcb67bb29c69a0245bf783b31da3c5709e402c7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48d0a350099900e65ab44f3e58d0da996d196d0628422d28cd7b17b2aa230fb17c82351e5b1781101d75bd0d8c3e829e2342084bdbb3aa9f1206d5284c7d4629
|
7
|
+
data.tar.gz: d0be5f0b258cfcc918aa34ec0c09dc26f8c35d536560bbbbb4de68a3ef7e93cd7cb46b6d2081eb02781735abfb004001e7b7e74a8d19364b362ff231c06ac6ef
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Ace Subido
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# StellarFederation
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'stellar_federation'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install stellar_federation
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Configure
|
27
|
+
|
28
|
+
|
29
|
+
A [federation server](https://www.stellar.org/developers/guides/anchor/3-federation-server.html) will respond to the following request with a response:
|
30
|
+
|
31
|
+
```
|
32
|
+
curl "https://www.your_org.com:8002/federation?q=tunde_adebayo*your_org.com&type=name"
|
33
|
+
|
34
|
+
{
|
35
|
+
"stellar_address": "tunde_adebayo*your_org.com",
|
36
|
+
"account_id": "GAIGZHHWK3REZQPLQX5DNUN4A32CSEONTU6CMDBO7GDWLPSXZDSYA4BU",
|
37
|
+
"memo_type": "text",
|
38
|
+
"memo": "tunde_adebayo"
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
The engine helps produce that output by configuring the engine in an initializer:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
StellarFederation.configure do |c|
|
46
|
+
c.on_query = "FindStellarFederatedAddress"
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
`c.on_query` - is a class the you define: The `on_query` class should also return a `StellarFederation::QueryResponse`. If it doesn't, the Rails engine will throw an exception. The `on_query` class will be called with `.call`, it should have a method that accepts a hash with the following parameters:
|
51
|
+
- `address_name` - ex: `tunder_adebayo*your_org.com`
|
52
|
+
|
53
|
+
Add to your routes:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
mount StellarFederation::Engine => "/stellar_federation"
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
Contribution directions go here.
|
61
|
+
|
62
|
+
## License
|
63
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'StellarFederation'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class QueriesController < ApplicationController
|
5
|
+
def index
|
6
|
+
check_parameters = Queries::CheckParameters.(query_params)
|
7
|
+
|
8
|
+
if check_parameters
|
9
|
+
@query_response = Queries::ProcessQuery.(query_params: query_params)
|
10
|
+
.query_response
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.json do
|
14
|
+
render json: @query_response.to_json, status: :ok
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
respond_to do |format|
|
19
|
+
format.json do
|
20
|
+
render(
|
21
|
+
json: {
|
22
|
+
status: "Unprocessable Entity",
|
23
|
+
message: "Invalid Parameters",
|
24
|
+
},
|
25
|
+
status: :unprocessable_entity,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def query_params
|
37
|
+
params.permit(:q, :type).to_hash.with_indifferent_access
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
class QueryResponse < BaseModel
|
3
|
+
|
4
|
+
attribute :account_id, DryTypes::String.optional
|
5
|
+
attribute :memo, DryTypes::String.optional
|
6
|
+
attribute :stellar_address, DryTypes::String.optional
|
7
|
+
attr_writer :memo, :account_id, :stellar_address
|
8
|
+
|
9
|
+
def memo_type
|
10
|
+
"text"
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json
|
14
|
+
{
|
15
|
+
account_id: account_id,
|
16
|
+
stellar_address: stellar_address,
|
17
|
+
memo_type: memo_type,
|
18
|
+
memo: memo,
|
19
|
+
}.to_json
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
module Queries
|
3
|
+
class CheckParameters
|
4
|
+
def self.call(params)
|
5
|
+
params[:q].present? && check_type(params[:type])
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.check_type(type)
|
11
|
+
type.present? && type == "name"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
module Queries
|
3
|
+
class PrepareOnQueryParameters
|
4
|
+
extend LightService::Action
|
5
|
+
expects :query_params
|
6
|
+
|
7
|
+
executed do |c|
|
8
|
+
c.query_params[:address_name] = c.query_params[:q]
|
9
|
+
c.query_params.except!(:q, :type)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
module Queries
|
3
|
+
class ProcessQuery
|
4
|
+
extend LightService::Organizer
|
5
|
+
|
6
|
+
def self.call(query_params:)
|
7
|
+
with(query_params: query_params).reduce(
|
8
|
+
PrepareOnQueryParameters,
|
9
|
+
TriggerOnQueryCallbackClass,
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
module Queries
|
3
|
+
class TriggerOnQueryCallbackClass
|
4
|
+
extend LightService::Action
|
5
|
+
expects :query_params
|
6
|
+
promises :query_response
|
7
|
+
|
8
|
+
executed do |c|
|
9
|
+
begin
|
10
|
+
c.query_response = callback_class.(c.query_params)
|
11
|
+
|
12
|
+
if !c.query_response.is_a? StellarFederation::QueryResponse
|
13
|
+
raise_return_error
|
14
|
+
end
|
15
|
+
rescue NameError => e
|
16
|
+
raise NameError, "StellarFederation.on_query isn't configured"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.callback_class
|
23
|
+
StellarFederation.configuration.on_query.constantize
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.raise_return_error
|
27
|
+
raise(
|
28
|
+
StandardError,
|
29
|
+
[
|
30
|
+
StellarFederation.configuration.on_query,
|
31
|
+
"must return a StellarFederation::QueryResponse",
|
32
|
+
].join(" ")
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Stellar federation</title>
|
5
|
+
<%= stylesheet_link_tag "stellar_federation/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "stellar_federation/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module StellarFederation
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace StellarFederation
|
4
|
+
|
5
|
+
config.to_prepare do
|
6
|
+
Engine.routes.default_url_options =
|
7
|
+
Rails.application.routes.default_url_options
|
8
|
+
end
|
9
|
+
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stellar_federation-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ace Subido
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gem_config
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: light-service
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-struct
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: API Endpoint to query for federated addresses
|
98
|
+
email:
|
99
|
+
- ace.subido@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- app/assets/config/stellar_federation_manifest.js
|
108
|
+
- app/assets/javascripts/stellar_federation/application.js
|
109
|
+
- app/assets/stylesheets/stellar_federation/application.css
|
110
|
+
- app/controllers/stellar_federation/api/v1/queries_controller.rb
|
111
|
+
- app/controllers/stellar_federation/application_controller.rb
|
112
|
+
- app/helpers/stellar_federation/application_helper.rb
|
113
|
+
- app/jobs/stellar_federation/application_job.rb
|
114
|
+
- app/mailers/stellar_federation/application_mailer.rb
|
115
|
+
- app/models/stellar_federation/application_record.rb
|
116
|
+
- app/models/stellar_federation/base_model.rb
|
117
|
+
- app/models/stellar_federation/query_response.rb
|
118
|
+
- app/services/stellar_federation/queries/check_parameters.rb
|
119
|
+
- app/services/stellar_federation/queries/prepare_on_query_parameters.rb
|
120
|
+
- app/services/stellar_federation/queries/process_query.rb
|
121
|
+
- app/services/stellar_federation/queries/trigger_on_query_callback_class.rb
|
122
|
+
- app/views/layouts/stellar_federation/application.html.erb
|
123
|
+
- config/routes.rb
|
124
|
+
- lib/stellar_federation-rails.rb
|
125
|
+
- lib/stellar_federation.rb
|
126
|
+
- lib/stellar_federation/engine.rb
|
127
|
+
- lib/stellar_federation/version.rb
|
128
|
+
- lib/tasks/stellar_federation_tasks.rake
|
129
|
+
homepage: https://github.com/bloom-solutions/stellar_federation-rails
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.7.3
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Mountable Stellar Federation API Endpoint for Rails
|
153
|
+
test_files: []
|