Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

got nested hash specs passing...

  • Loading branch information...
commit 39eab03f66b04f45371b81435a35d0e91a449141 1 parent 9c3a208
@rimian rimian authored
Showing with 18 additions and 3 deletions.
  1. +17 −2 lib/switchvox/base.rb
  2. +1 −1  spec/switchvox/base_spec.rb
View
19 lib/switchvox/base.rb
@@ -8,6 +8,7 @@ module Switchvox
require 'digest/md5'
require 'rubygems'
require 'json'
+require 'ostruct'
# Raised when credentials are incorrect
class LoginError < RuntimeError
@@ -77,9 +78,23 @@ def request(method, parameters={})
end
end
+ # TODO - cover this with specs and return json not call other method
def json_parse(body)
- response_json = JSON.parse body
- response_json["response"]["result"].to_obj
+ json = JSON.parse body
+ convert_to_obj(json["response"]["result"])
+ end
+
+ def convert_to_obj(hash)
+ hash.each do |x, y|
+ unless y.is_a? String
+ y.map! do |v|
+ convert_to_obj(v)
+ end
+ end
+ end
+ o = OpenStruct.new
+ o.marshal_load Hash[hash.map {|k, v| [k.to_sym, v] }]
+ o
end
protected
View
2  spec/switchvox/base_spec.rb
@@ -52,7 +52,7 @@ def response_json(body)
]
}
obj = switchvox.json_parse(response_json(input))
- obj.kennels[1].frisco[0].name.should == 'west'
+ obj.kennels[1].frisco[1].name.should == 'west'
end
it 'should test test_deep_nest_hash' do
Please sign in to comment.
Something went wrong with that request. Please try again.