Skip to content

Commit b312e6d

Browse files
committed
Use Hashie Mash
1 parent 535f3a5 commit b312e6d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

cortex-client.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
2121
s.add_dependency 'faraday_middleware', '~> 0.9.0'
2222
s.add_dependency 'oauth2', '~>0.9'
2323
s.add_dependency 'cortex-exceptions', '~> 0.0.4'
24+
s.add_dependency 'hashie', '~> 3.4.0'
2425
end

lib/cortex/result.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
require 'hashie'
12
module Cortex
23
class Result
34
attr_reader :raw_headers, :contents, :total_items, :page, :per_page, :errors, :range_start, :range_end, :range, :status
45

56
def initialize(body, headers, status)
6-
@contents = body
7+
@contents = parse(body)
78
@raw_headers = headers
89
@status = status
910
@total_items = headers['x-total-items'] unless headers['x-total-items'].nil?
@@ -31,6 +32,17 @@ def parse_headers(headers)
3132
end
3233
end
3334

35+
def parse(body)
36+
case body
37+
when Hash
38+
::Hashie::Mash.new(body)
39+
when Array
40+
body.map { |item| parse(item) }
41+
else
42+
body
43+
end
44+
end
45+
3446
def find_errors
3547
if is_error?
3648
if @contents.is_a?(Hash)
@@ -47,4 +59,4 @@ def find_errors
4759
end
4860
end
4961
end
50-
end
62+
end

0 commit comments

Comments
 (0)