Class: Camunda::FirstLevelParseJSON
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Camunda::FirstLevelParseJSON
- Defined in:
- lib/camunda.rb
Instance Method Summary collapse
-
#on_complete(env) ⇒ Object
This method is triggered when the response has been received.
-
#parse(body) ⇒ Mixed
Taken from Her::Middleware::FirstLevelParseJSON Parse the response body.
Instance Method Details
#on_complete(env) ⇒ Object
This method is triggered when the response has been received. It modifies the value of ‘env`.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/camunda.rb', line 50 def on_complete(env) str = case env[:status] when 204 '{}' when 200 env[:body] when 400..599 env[:body] == '' ? '{}' : env[:body] end env[:body] = case env[:status] when 400..599 { data: nil, metadata: {}, errors: JSON.parse(str) } else parse str end end |
#parse(body) ⇒ Mixed
Taken from Her::Middleware::FirstLevelParseJSON Parse the response body
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/camunda.rb', line 30 def parse(body) json = JSON.parse body if json.respond_to?(:keys) errors = json.delete(:errors) = json.delete(:metadata) end errors ||= {} ||= {} { data: json, errors: errors, metadata: } end |