Class: ElephantInTheRoom::TheOneApiSdk::Pipeline::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/elephant_in_the_room/the_one_api_sdk/pipeline/json.rb

Overview

Pipeline stage to transform an HTTP body to JSON

Instance Method Summary collapse

Constructor Details

#initialize(next_pipeline_stage) ⇒ Json

Returns a new instance of Json.



9
10
11
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/json.rb', line 9

def initialize(next_pipeline_stage)
  @next_pipeline_stage = next_pipeline_stage
end

Instance Method Details

#execute_http_request(request_details) ⇒ Object



13
14
15
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/json.rb', line 13

def execute_http_request(request_details)
  @result = @next_pipeline_stage.execute_http_request(request_details)
end

#result_hashObject



17
18
19
20
21
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/json.rb', line 17

def result_hash
  JSON.parse(@next_pipeline_stage.http_body, symbolize_names: true)
rescue JSON::ParserError => e
  raise ElephantInTheRoom::TheOneApiSdk::Errors::JsonParseError, "JSON response could not be parsed: #{e.message}"
end