Class: Orchestrate::API::ResponseBody

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrate_api/response.rb

Overview

Decodes body from json into a hash; provides the original body content via the ‘content’ method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ ResponseBody

Initialize instance variables, based on response body contents.



90
91
92
93
94
# File 'lib/orchestrate_api/response.rb', line 90

def initialize(body)
  @content = body
  @to_hash = body.blank? ? {} : ActiveSupport::JSON.decode(body)
  to_hash.each { |k,v| instance_variable_set "@#{k}", v }
end

Instance Attribute Details

#codeObject (readonly)

Error code from the orchestrate.io api.



87
88
89
# File 'lib/orchestrate_api/response.rb', line 87

def code
  @code
end

#contentObject (readonly)

Original response body from HTTParty.



66
67
68
# File 'lib/orchestrate_api/response.rb', line 66

def content
  @content
end

#countObject (readonly)

Set for list, search, get_events, and get_graph results.



75
76
77
# File 'lib/orchestrate_api/response.rb', line 75

def count
  @count
end

#messageObject (readonly)

Error message from the orchestrate.io api.



84
85
86
# File 'lib/orchestrate_api/response.rb', line 84

def message
  @message
end

#nextObject (readonly)

Set for list results.



81
82
83
# File 'lib/orchestrate_api/response.rb', line 81

def next
  @next
end

#resultsObject (readonly)

Set for all results.



72
73
74
# File 'lib/orchestrate_api/response.rb', line 72

def results
  @results
end

#to_hashObject (readonly)

The json response body converted to a hash.



69
70
71
# File 'lib/orchestrate_api/response.rb', line 69

def to_hash
  @to_hash
end

#total_countObject (readonly)

Set for search results.



78
79
80
# File 'lib/orchestrate_api/response.rb', line 78

def total_count
  @total_count
end

Instance Method Details

#result_keysObject



96
97
98
# File 'lib/orchestrate_api/response.rb', line 96

def result_keys
  results.map { |result| result['path']['key'] } if results
end