Class: ZeroRailsAdapter::Request
- Inherits:
-
Object
- Object
- ZeroRailsAdapter::Request
- Defined in:
- lib/zero_rails_adapter/request.rb
Constant Summary collapse
- REQUIRED_KEYS =
%w[clientGroupID mutations pushVersion timestamp requestID].freeze
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#client_group_id ⇒ Object
readonly
Returns the value of attribute client_group_id.
-
#mutations ⇒ Object
readonly
Returns the value of attribute mutations.
-
#push_version ⇒ Object
readonly
Returns the value of attribute push_version.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**attributes) ⇒ Request
constructor
A new instance of Request.
- #mutation_ids ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ Request
Returns a new instance of Request.
85 86 87 |
# File 'lib/zero_rails_adapter/request.rb', line 85 def initialize(**attributes) attributes.each { |name, value| instance_variable_set(:"@#{name}", value) } end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def app_id @app_id end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def body @body end |
#client_group_id ⇒ Object (readonly)
Returns the value of attribute client_group_id.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def client_group_id @client_group_id end |
#mutations ⇒ Object (readonly)
Returns the value of attribute mutations.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def mutations @mutations end |
#push_version ⇒ Object (readonly)
Returns the value of attribute push_version.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def push_version @push_version end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def request_id @request_id end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def schema @schema end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/zero_rails_adapter/request.rb', line 7 def @timestamp end |
Class Method Details
.parse(body, query:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zero_rails_adapter/request.rb', line 10 def self.parse(body, query:) body = body.to_h.stringify_keys if body.respond_to?(:to_h) query = query.to_h.stringify_keys if query.respond_to?(:to_h) mutation_ids = extract_mutation_ids(body) validate_body!(body, mutation_ids:) validate_query!(query, mutation_ids:) unless body["pushVersion"] == 1 raise UnsupportedPushVersionError.new(body["pushVersion"], mutation_ids:) end mutations = body["mutations"].map { |value| Mutation.parse(value) } new( body:, client_group_id: body["clientGroupID"], mutations:, push_version: body["pushVersion"], timestamp: body["timestamp"], request_id: body["requestID"], schema: query["schema"], app_id: query["appID"] ) rescue ParseError => error if error.mutation_ids.empty? raise ParseError.new(error., mutation_ids:, source: error.source) end raise end |
Instance Method Details
#mutation_ids ⇒ Object
89 90 91 |
# File 'lib/zero_rails_adapter/request.rb', line 89 def mutation_ids mutations.map(&:identifier) end |