mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Replace the JSON round-trip with #stringify.
Let's use a proper method to emulate what round-tripping data structures through the JSON API will do.
This commit is contained in:
parent
2ead5257b2
commit
2e872342dc
2 changed files with 21 additions and 4 deletions
|
@ -232,6 +232,23 @@ module Fog
|
||||||
def self.zulu_time
|
def self.zulu_time
|
||||||
Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.stringify(message)
|
||||||
|
case message
|
||||||
|
when Symbol
|
||||||
|
message.to_s
|
||||||
|
when Hash
|
||||||
|
result = Hash.new
|
||||||
|
message.each do |key, value|
|
||||||
|
nk = stringify(key)
|
||||||
|
nv = stringify(value)
|
||||||
|
result[nk] = nv
|
||||||
|
end
|
||||||
|
result
|
||||||
|
else
|
||||||
|
message
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,10 +39,10 @@ module Fog
|
||||||
|
|
||||||
raise BadRequest.new if body.nil? || body.empty?
|
raise BadRequest.new if body.nil? || body.empty?
|
||||||
|
|
||||||
# Round-trip +body+ through the JSON parser to turn Symbols into Strings, as though
|
# Ensure that any Symbol keys within +body+ are converted to Strings, just as being
|
||||||
# it's coming back from the server.
|
# round-tripped through the API will.
|
||||||
encoded = Fog::JSON.decode(Fog::JSON.encode(body))
|
converted = MockData.stringify(body)
|
||||||
message = queue.add_message(client_id, encoded, ttl)
|
message = queue.add_message(client_id, converted, ttl)
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 201
|
response.status = 201
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue