stellar_federation-rails 0.1.0 → 0.2.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: b52f4c6be8d224343880279ca916a5a7db62164d87ea92e6e2104b26957ddccd
4
- data.tar.gz: f42f86334b6564cb22364da7fcb67bb29c69a0245bf783b31da3c5709e402c7f
3
+ metadata.gz: e2a5dd9c599f9a33cd232b074bebb2c94f7cb429d824cc0a7b559e4a11736bd6
4
+ data.tar.gz: 4011c7b3bd8dc0d51ed2f1ba0d36c3721109f18e2e05ae48a6901e5a56d4e850
5
5
  SHA512:
6
- metadata.gz: 48d0a350099900e65ab44f3e58d0da996d196d0628422d28cd7b17b2aa230fb17c82351e5b1781101d75bd0d8c3e829e2342084bdbb3aa9f1206d5284c7d4629
7
- data.tar.gz: d0be5f0b258cfcc918aa34ec0c09dc26f8c35d536560bbbbb4de68a3ef7e93cd7cb46b6d2081eb02781735abfb004001e7b7e74a8d19364b362ff231c06ac6ef
6
+ metadata.gz: 3e5192333665c01abf43ec5e33de7363df91ea03552ef3df2f4d41737e1a14507ec8f837e6f92eafbff59a34bb9800cedac7669174b4aa3e978fd2027730c980
7
+ data.tar.gz: c68aa010040e7bcb817242af6f541d168cf0b44c745f8933ded7513cd73ec86292b9b37676d51ea2a3811cc8cd8c3572194158814e18596ea29298dd3e9a875d
data/README.md CHANGED
@@ -47,8 +47,10 @@ StellarFederation.configure do |c|
47
47
  end
48
48
  ```
49
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:
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`, that accepts a `StellarFederation::Query` object
51
51
  - `address_name` - ex: `tunder_adebayo*your_org.com`
52
+ - `address_id` - ex: `tunder_adebayo`
53
+ - `address_domain` - ex: `your_org.com`
52
54
 
53
55
  Add to your routes:
54
56
 
@@ -3,30 +3,23 @@ module StellarFederation
3
3
  module V1
4
4
  class QueriesController < ApplicationController
5
5
  def index
6
- check_parameters = Queries::CheckParameters.(query_params)
6
+ result = Queries::ProcessQuery.(query_params: query_params)
7
7
 
8
- if check_parameters
9
- @query_response = Queries::ProcessQuery.(query_params: query_params)
10
- .query_response
8
+ respond_to do |format|
9
+ format.json do
10
+ if result.success?
11
+ @query_response = result.query_response
11
12
 
12
- respond_to do |format|
13
- format.json do
14
13
  render json: @query_response.to_json, status: :ok
14
+ else
15
+ json_status = {
16
+ status: "Unprocessable Entity",
17
+ message: result.message,
18
+ }
19
+
20
+ render json: json_status, status: :unprocessable_entity
15
21
  end
16
22
  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
23
  end
31
24
 
32
25
  end
@@ -0,0 +1,8 @@
1
+ module StellarFederation
2
+ class Query < BaseModel
3
+
4
+ attribute :address_id, DryTypes::String.optional
5
+ attribute :address_domain, DryTypes::String.optional
6
+ attribute :address_name, DryTypes::String.optional
7
+ end
8
+ end
@@ -1,8 +1,13 @@
1
1
  module StellarFederation
2
2
  module Queries
3
3
  class CheckParameters
4
- def self.call(params)
5
- params[:q].present? && check_type(params[:type])
4
+ extend LightService::Action
5
+ expects :query_params
6
+
7
+ executed do |c|
8
+ unless c.query_params[:q].present? && check_type(c.query_params[:type])
9
+ c.fail! "Invalid Parameters"
10
+ end
6
11
  end
7
12
 
8
13
  private
@@ -0,0 +1,19 @@
1
+ module StellarFederation
2
+ module Queries
3
+ class ParseAddressName
4
+ extend LightService::Action
5
+ expects :query_params
6
+ promises :query
7
+
8
+ executed do |c|
9
+ address_name = c.query_params[:address_name]
10
+ split_address_name = address_name.split("*")
11
+ c.query = Query.new(
12
+ address_id: split_address_name[0],
13
+ address_domain: split_address_name[1],
14
+ address_name: address_name,
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,7 +5,9 @@ module StellarFederation
5
5
 
6
6
  def self.call(query_params:)
7
7
  with(query_params: query_params).reduce(
8
+ CheckParameters,
8
9
  PrepareOnQueryParameters,
10
+ ParseAddressName,
9
11
  TriggerOnQueryCallbackClass,
10
12
  )
11
13
  end
@@ -2,12 +2,12 @@ module StellarFederation
2
2
  module Queries
3
3
  class TriggerOnQueryCallbackClass
4
4
  extend LightService::Action
5
- expects :query_params
5
+ expects :query
6
6
  promises :query_response
7
7
 
8
8
  executed do |c|
9
9
  begin
10
- c.query_response = callback_class.(c.query_params)
10
+ c.query_response = callback_class.(c.query)
11
11
 
12
12
  if !c.query_response.is_a? StellarFederation::QueryResponse
13
13
  raise_return_error
@@ -1,3 +1,3 @@
1
1
  module StellarFederation
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_federation-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-04-20 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -114,8 +114,10 @@ files:
114
114
  - app/mailers/stellar_federation/application_mailer.rb
115
115
  - app/models/stellar_federation/application_record.rb
116
116
  - app/models/stellar_federation/base_model.rb
117
+ - app/models/stellar_federation/query.rb
117
118
  - app/models/stellar_federation/query_response.rb
118
119
  - app/services/stellar_federation/queries/check_parameters.rb
120
+ - app/services/stellar_federation/queries/parse_address_name.rb
119
121
  - app/services/stellar_federation/queries/prepare_on_query_parameters.rb
120
122
  - app/services/stellar_federation/queries/process_query.rb
121
123
  - app/services/stellar_federation/queries/trigger_on_query_callback_class.rb