Class: Hibp::Parsers::Json
- Inherits:
-
Object
- Object
- Hibp::Parsers::Json
- Includes:
- Helpers::JsonConversion
- Defined in:
- lib/hibp/parsers/json.rb
Overview
Hibp::Parsers::Json
Used to parse API JSON response and transform(convert) this
raw data to the model specified by converter
Instance Method Summary collapse
-
#parse_response(response) {|attributes| ... } ⇒ Object
Parse API response.
Instance Method Details
#parse_response(response) {|attributes| ... } ⇒ Object
Note:
If block with conversion not set than parser returns raw data (useful in cases when response returns array of strings)
Parse API response
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hibp/parsers/json.rb', line 27 def parse_response(response, &block) return nil if empty_response?(response) begin _, body = prepare_response(response) block_given? ? convert(body, &block) : body rescue Oj::ParseError raise_error(response.body) end end |