stellar_base-rails 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d0e5b43c48cfd30442bc1a761a5d17ddf3f4b196c1735a88961c4b77a453de9
4
+ data.tar.gz: 21533790d1d003725f0af18694e4af58bf258c3cbe0564fd87f36e9046481bb8
5
+ SHA512:
6
+ metadata.gz: d620231cb1bc60a96b3db04532f275a8d57524477ba7b9bd709d01217f9df061267e8a47bbf849620a8bb979ccfa045f76f62c3a0070f57d06cf9fc76057c8a4
7
+ data.tar.gz: d6cf26b7969fb6915a6d1f12f1425f2804fb216a0fc926a0a7bfb15dbcab656d01b2dfa47d2e8397893b38d7a60713c0517a275598fd0f932ea4ff01b55a8d5c
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,51 @@
1
+ # stellar_base-rails
2
+
3
+ When building Rails apps, we’d always implement /.well-known/stellar and other bits and pieces of the required endpoints in the Stellar Protocol. This gem solves receiving and responding to requests from some parts of the Stellar Protocol
4
+
5
+ ## Usage
6
+
7
+ ### Mounting
8
+ Adding modules to your routes:
9
+
10
+ ```
11
+ mount StellarBase::Engine => "/stellar_base"
12
+ ```
13
+
14
+ ### Configuration
15
+ Create an initializer in your rails application:
16
+
17
+ ```
18
+ # config/initializers/stellar_base-rails.rb
19
+
20
+ StellarBase.configure do |c|
21
+ c.modules = %i(bridge_callbacks)
22
+ c.on_bridge_callback = "StellarBridgeReceive::SaveTxn"
23
+ end
24
+ ```
25
+
26
+ #### c.modules
27
+ - You can supply what endpoints you want to activate with the gem
28
+ - `bridge_callbacks` - this will mount a HTTP/S POST endpoint that acts as callback receiver for bridge server payments on the path. It will call your `.on_bridge_callback` class.
29
+
30
+ #### c.on_bridge_callback
31
+ - Once the bridge_receive endpoint receives a callback, the class will be called with .call
32
+ - The class will be passed with the bridge server callback payload contained in a `StellarBase::BridgeCallback` object.
33
+ - The class will be expected to return a boolean, return true if the callback was processed properly
34
+
35
+ ## Installation
36
+ Add this line to your application's Gemfile:
37
+
38
+ ```ruby
39
+ gem 'stellar_base-rails'
40
+ ```
41
+
42
+ And then execute:
43
+ ```bash
44
+ $ bundle
45
+ ```
46
+
47
+ ## Contributing
48
+ Contribution directions go here.
49
+
50
+ ## License
51
+ 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 = 'StellarBase'
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,2 @@
1
+ //= link_directory ../javascripts/stellar_base .js
2
+ //= link_directory ../stylesheets/stellar_base .css
@@ -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,5 @@
1
+ module StellarBase
2
+ class ApplicationContract < Reform::Form
3
+ include Reform::Form::Coercion
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module StellarBase
2
+ class ApplicationOperation < Trailblazer::Operation
3
+
4
+ end
5
+
6
+ end
@@ -0,0 +1,20 @@
1
+ module StellarBase
2
+ module BridgeCallbacks
3
+ module Contracts
4
+ class Process < ApplicationContract
5
+
6
+ property :id
7
+ property :from
8
+ property :route
9
+ property :amount
10
+ property :asset_code
11
+ property :asset_issuer
12
+ property :memo_type
13
+ property :memo
14
+ property :data
15
+ property :transaction_id
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module StellarBase
2
+ module BridgeCallbacks
3
+ module Operations
4
+ class Process < ApplicationOperation
5
+ step :model!
6
+ step Contract::Build(constant: Contracts::Process)
7
+ step Contract::Validate(key: :bridge_callback)
8
+ step Contract::Persist(method: :sync)
9
+ step :process!
10
+
11
+ def model!(options, **)
12
+ options["model"] = BridgeCallback.new
13
+ end
14
+
15
+ def process!(options, **)
16
+ BridgeCallbacks::Process.(options["model"])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module StellarBase
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ skip_before_action :verify_authenticity_token
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ module StellarBase
2
+ class BridgeCallbacksController < ApplicationController
3
+ def create
4
+ op = BridgeCallbacks::Operations::Process.(bridge_callback: callback_params)
5
+
6
+ respond_to do |f|
7
+ f.json do
8
+ if op.success?
9
+ head :ok
10
+ else
11
+ head :unprocessable_entity
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def callback_params
20
+ params.permit(
21
+ :id,
22
+ :from,
23
+ :route,
24
+ :amount,
25
+ :asset_code,
26
+ :asset_issuer,
27
+ :memo_type,
28
+ :memo,
29
+ :data,
30
+ :transaction_id,
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module StellarBase
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module StellarBase
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module StellarBase
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module StellarBase
2
+ module DryTypes
3
+ include Dry::Types.module
4
+ end
5
+
6
+ class ApplicationDataModel < Dry::Struct
7
+ constructor_type :schema
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module StellarBase
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ module StellarBase
2
+ class BridgeCallback < ApplicationDataModel
3
+ # Attributes and params from
4
+ # https://github.com/stellar/bridge-server/blob/master/readme_bridge.md#callbacksreceive
5
+ attribute :id, DryTypes::String.optional
6
+ attribute :from, DryTypes::String.optional
7
+ attribute :route, DryTypes::String.optional
8
+ attribute :amount, DryTypes::Decimal.optional
9
+ attribute :asset_code, DryTypes::String.optional
10
+ attribute :asset_issuer, DryTypes::String.optional
11
+ attribute :memo_type, DryTypes::String.optional
12
+ attribute :memo, DryTypes::String.optional
13
+ attribute :data, DryTypes::String.optional
14
+ attribute :transaction_id, DryTypes::String.optional
15
+
16
+ attr_writer :id
17
+ attr_writer :from
18
+ attr_writer :route
19
+ attr_writer :amount
20
+ attr_writer :asset_code
21
+ attr_writer :asset_issuer
22
+ attr_writer :memo_type
23
+ attr_writer :memo
24
+ attr_writer :data
25
+ attr_writer :transaction_id
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module StellarBase
2
+ module BridgeCallbacks
3
+ class Process
4
+ def self.call(callback)
5
+ callback_class.(callback)
6
+ rescue NameError => e
7
+ error_message = [
8
+ "StellarBase.on_bridge_callback isn't configured or the",
9
+ "configured callback class doesn't exist:",
10
+ StellarBase.configuration.on_bridge_callback,
11
+ ].join(" ")
12
+
13
+ raise NameError, error_message
14
+ end
15
+
16
+ private
17
+
18
+ def self.callback_class
19
+ StellarBase.configuration.on_bridge_callback.constantize
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Stellar base</title>
5
+ <%= stylesheet_link_tag "stellar_base/application", media: "all" %>
6
+ <%= javascript_include_tag "stellar_base/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,6 @@
1
+ StellarBase::Engine.routes.draw do
2
+ if StellarBase.included_module?(:bridge_callbacks)
3
+ resources :bridge_callbacks, only: [:create], defaults: { format: "json" }
4
+ end
5
+ end
6
+
@@ -0,0 +1,15 @@
1
+ module StellarBase
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace StellarBase
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
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module StellarBase
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1 @@
1
+ require "stellar_base"
@@ -0,0 +1,23 @@
1
+ require "gem_config"
2
+ require "light-service"
3
+ require "dry-struct"
4
+ require "trailblazer-rails"
5
+ require "disposable"
6
+ require "reform"
7
+ require "reform/form/coercion"
8
+ require "stellar_base/engine"
9
+
10
+ module StellarBase
11
+ include GemConfig::Base
12
+
13
+ with_configuration do
14
+ has :modules, default: [:bridge_callbacks]
15
+ has :on_bridge_callback
16
+ end
17
+
18
+ def self.included_module?(module_name)
19
+ self.configuration.modules&.include?(module_name)
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :stellar_base do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stellar_base-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-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.1.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.1.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: trailblazer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: trailblazer-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: API Endpoints for the Stellar Protocol
126
+ email:
127
+ - ace.subido@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - README.md
134
+ - Rakefile
135
+ - app/assets/config/stellar_base_manifest.js
136
+ - app/assets/javascripts/stellar_base/application.js
137
+ - app/assets/stylesheets/stellar_base/application.css
138
+ - app/concepts/stellar_base/application_contract.rb
139
+ - app/concepts/stellar_base/application_operation.rb
140
+ - app/concepts/stellar_base/bridge_callbacks/contracts/process.rb
141
+ - app/concepts/stellar_base/bridge_callbacks/operations/process.rb
142
+ - app/controllers/stellar_base/application_controller.rb
143
+ - app/controllers/stellar_base/bridge_callbacks_controller.rb
144
+ - app/helpers/stellar_base/application_helper.rb
145
+ - app/jobs/stellar_base/application_job.rb
146
+ - app/mailers/stellar_base/application_mailer.rb
147
+ - app/models/stellar_base/application_data_model.rb
148
+ - app/models/stellar_base/application_record.rb
149
+ - app/models/stellar_base/bridge_callback.rb
150
+ - app/services/stellar_base/bridge_callbacks/process.rb
151
+ - app/views/layouts/stellar_base/application.html.erb
152
+ - config/routes.rb
153
+ - lib/stellar_base-rails.rb
154
+ - lib/stellar_base.rb
155
+ - lib/stellar_base/engine.rb
156
+ - lib/stellar_base/version.rb
157
+ - lib/tasks/stellar_base_tasks.rake
158
+ homepage: https://github.com/bloom-solutions/stellar_base-rails
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.7.3
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Mountable Stellar API Endpoints for Rails
182
+ test_files: []