stellar_base-rails 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb6ead7f2864989a152ec231b9f320433c14e940371fe949eb496b5f23a29aba
4
- data.tar.gz: e7690ffa217717e9f2f9dd2c874cca7f9b2b806e6cba1091184604147883364f
3
+ metadata.gz: 0df38a89228d4c990c8e2eaa9c44e355dd327c4a2a064ac87f299ba630f38943
4
+ data.tar.gz: 3a1431e4c406d8922aeb9dce46a4445bd573a3a282de9a9702d28d39560c872c
5
5
  SHA512:
6
- metadata.gz: 9b66865fe56899570bd53211966355517b36bec6f90bd807494f8cd0db94b5969957eca420e33b03ebd141e20b0215651d4605f1ff9c0a63cb83774eca938126
7
- data.tar.gz: 895c7d45a3eef849c1034f9f1d99162c76c58eda9605ad20896a71a97fba898eb241e37b9cc3b91027aa074d2ecaa14621d7bbee5fb48869ced9e4d15ac07de6
6
+ metadata.gz: ef07f9dab7dd4083a1382d079eac8649fb871a603fa013dca4e8e37b06ee053c2ba7a64868c28cb0043390cda7f306f322c622acadf2fce9c389300c2f3746aa
7
+ data.tar.gz: bfa822784f4a078d0eab736f981d7ea9c18eac76493f78b97e24d1dc98208d875c9ba5a7ca56cac1d7b82eb28d53e7ada0a6c1776d7062515c7ce3f1f51d787d
data/README.md CHANGED
@@ -8,7 +8,10 @@ When building Rails apps, we’d always implement /.well-known/stellar and other
8
8
  Adding modules to your routes:
9
9
 
10
10
  ```
11
- mount StellarBase::Engine => "/stellar_base"
11
+ mount StellarBase::Engine => "/stellar"
12
+
13
+ # Optionally, you can mount /.well-known/stellar
14
+ mount_stellar_base_well_known
12
15
  ```
13
16
 
14
17
  ```sh
@@ -33,7 +36,6 @@ StellarBase.configure do |c|
33
36
  end
34
37
  ```
35
38
 
36
-
37
39
  #### c.modules
38
40
  You can supply what endpoints you want to activate with the gem
39
41
 
@@ -50,6 +52,23 @@ This is the same distribution account that is setup in bridge. Currently, it is
50
52
  - Default: https://horizon.stellar.org
51
53
  - This is where the engine will check bridge callbacks if `c.check_bridge_callbacks_authenticity` is turned on
52
54
 
55
+ ### c.stellar_toml
56
+ - Value(s): Hash, follow Stellar's [documentation](https://www.stellar.org/developers/guides/concepts/stellar-toml.html) for `stellar.toml`
57
+ - Example:
58
+ ```
59
+ c.stellar_toml = {
60
+ TRANSFER_SERVER: ...,
61
+ FEDERATION_SERVER: ...,
62
+ AUTH_SERVER: ...,
63
+ }
64
+ ```
65
+ - Default:
66
+ ```
67
+ c.stellar_toml = {
68
+ TRANSFER_SERVER: # if withdraw module is set, this is automatically set to the withdraw_endpoint unless overridden
69
+ }
70
+ ```
71
+
53
72
  ## Installation
54
73
  Add this line to your application's Gemfile:
55
74
 
@@ -62,7 +81,7 @@ And then execute:
62
81
  $ bundle
63
82
  ```
64
83
 
65
- ## Contributing
84
+ ## Development
66
85
 
67
86
  ```ruby
68
87
  cp spec/config.yml{.sample,}
@@ -70,5 +89,13 @@ cp spec/config.yml{.sample,}
70
89
 
71
90
  Edit the `spec/config.yml` file.
72
91
 
92
+ ```sh
93
+ cd spec/dummy
94
+ rails db:migrate
95
+ rails db:migrate RAILS_ENV=test
96
+ ```
97
+
98
+ Now you can run `rspec spec`
99
+
73
100
  ## License
74
101
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ module StellarBase
2
+ class HomeController < ApplicationController
3
+
4
+ before_action :set_cors_headers, only: %i[show]
5
+ skip_before_action :verify_authenticity_token
6
+
7
+ def show
8
+ stellar_toml = StellarToml.new(StellarBase.configuration.stellar_toml)
9
+
10
+ respond_to do |f|
11
+ f.toml do
12
+ render plain: TomlRB.dump(stellar_toml.to_hash)
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def set_cors_headers
20
+ response.headers["Access-Control-Allow-Origin"] = "*"
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module StellarBase
2
+ class StellarToml
3
+
4
+ include Virtus.model
5
+
6
+ attribute(:TRANSFER_SERVER, String, {
7
+ lazy: true, default: :default_transfer_server
8
+ })
9
+
10
+ def default_transfer_server
11
+ return "" unless StellarBase.included_module?(:withdraw)
12
+ StellarBase::Engine.routes.url_helpers.withdraw_url
13
+ end
14
+
15
+ end
16
+ end
data/config/spring.rb ADDED
@@ -0,0 +1 @@
1
+ Spring.application_root = "./spec/dummy"
data/lib/stellar_base.rb CHANGED
@@ -28,6 +28,8 @@ module StellarBase
28
28
 
29
29
  has :withdrawable_assets, classes: [NilClass, Array, String, Pathname]
30
30
  has :on_withdraw
31
+
32
+ has :stellar_toml, classes: Hash
31
33
  end
32
34
 
33
35
  after_configuration_change do
@@ -58,7 +60,7 @@ module StellarBase
58
60
  YAML.load_file(str.to_s)
59
61
  rescue Errno::ENOENT
60
62
  end
61
-
62
63
  end
63
64
 
64
65
  require "stellar_base/horizon_client"
66
+ require "stellar_base/rails/routes"
@@ -1,5 +1,6 @@
1
1
  module StellarBase
2
2
  class Engine < ::Rails::Engine
3
+
3
4
  isolate_namespace StellarBase
4
5
 
5
6
  config.to_prepare do
@@ -7,6 +8,11 @@ module StellarBase
7
8
  Rails.application.routes.default_url_options
8
9
  end
9
10
 
11
+ initializer "register.mime_types" do
12
+ return if Mime::Type.lookup_by_extension("toml").present?
13
+ Mime::Type.register "application/toml", :toml
14
+ end
15
+
10
16
  config.generators do |g|
11
17
  g.test_framework :rspec
12
18
  end
@@ -0,0 +1,15 @@
1
+ module ActionDispatch
2
+ module Routing
3
+ class Mapper
4
+
5
+ def mount_stellar_base_well_known
6
+ get(
7
+ "/.well-known/stellar" => "stellar_base/home#show",
8
+ :as => :stellar_toml,
9
+ :defaults => { format: "toml" },
10
+ )
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module StellarBase
2
- VERSION = '0.4.1'
2
+ VERSION = "0.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_base-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Subido
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -285,12 +285,14 @@ files:
285
285
  - app/concepts/stellar_base/withdrawal_requests/withdrawal_request_policy.rb
286
286
  - app/controllers/stellar_base/application_controller.rb
287
287
  - app/controllers/stellar_base/bridge_callbacks_controller.rb
288
+ - app/controllers/stellar_base/home_controller.rb
288
289
  - app/controllers/stellar_base/withdraw_controller.rb
289
290
  - app/helpers/stellar_base/application_helper.rb
290
291
  - app/jobs/stellar_base/application_job.rb
291
292
  - app/mailers/stellar_base/application_mailer.rb
292
293
  - app/models/stellar_base/application_record.rb
293
294
  - app/models/stellar_base/bridge_callback.rb
295
+ - app/models/stellar_base/stellar_toml.rb
294
296
  - app/models/stellar_base/withdrawal_request.rb
295
297
  - app/representers/application_representer.rb
296
298
  - app/representers/withdrawal_request_representer.rb
@@ -316,6 +318,7 @@ files:
316
318
  - app/twins/withdrawal_request_twin.rb
317
319
  - app/views/layouts/stellar_base/application.html.erb
318
320
  - config/routes.rb
321
+ - config/spring.rb
319
322
  - db/migrate/20180816014433_create_stellar_base_bridge_callbacks.rb
320
323
  - db/migrate/20180816110314_create_stellar_base_withdrawal_requests.rb
321
324
  - db/migrate/20180816135847_unique_stellar_base_bridge_callbacks_operation_id.rb
@@ -326,6 +329,7 @@ files:
326
329
  - lib/stellar_base/factories/bridge_callbacks.rb
327
330
  - lib/stellar_base/factories/withdrawal_requests.rb
328
331
  - lib/stellar_base/horizon_client.rb
332
+ - lib/stellar_base/rails/routes.rb
329
333
  - lib/stellar_base/version.rb
330
334
  - lib/tasks/stellar_base_tasks.rake
331
335
  homepage: https://github.com/bloom-solutions/stellar_base-rails
@@ -348,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
352
  version: '0'
349
353
  requirements: []
350
354
  rubyforge_project:
351
- rubygems_version: 2.7.7
355
+ rubygems_version: 2.7.6
352
356
  signing_key:
353
357
  specification_version: 4
354
358
  summary: Mountable Stellar API Endpoints for Rails