Class: Euston::Websites::ApiCommandRequestParsing::AbstractParser
- Inherits:
-
Object
- Object
- Euston::Websites::ApiCommandRequestParsing::AbstractParser
- Includes:
- Hollywood
- Defined in:
- lib/euston-websites/api_command_request_parsing/abstract_parser.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(request) ⇒ AbstractParser
constructor
A new instance of AbstractParser.
- #parse ⇒ Object
Constructor Details
#initialize(request) ⇒ AbstractParser
Returns a new instance of AbstractParser.
7 8 9 |
# File 'lib/euston-websites/api_command_request_parsing/abstract_parser.rb', line 7 def initialize request @body = request.body.read end |
Instance Method Details
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/euston-websites/api_command_request_parsing/abstract_parser.rb', line 11 def parse valid = true begin commands = [transform_hash_to_commands(ActiveSupport::JSON.decode(@body))].flatten rescue StandardError => e callback :not_parseable valid = false end return unless valid invalid_commands = commands.reject { |c| c.valid? } if invalid_commands.any? callback :invalid, invalid_commands else callback :valid, commands end end |