lib/keikokuc/client.rb in keikokuc-0.6 vs lib/keikokuc/client.rb in keikokuc-0.7
- old
+ new
@@ -1,7 +1,7 @@
require 'rest-client'
-require 'yajl'
+require 'keikokuc/okjson'
require 'timeout'
# Internal: Handles HTTP requests/responses to the keikoku API
#
# This class is meant to be used internally by Keikokuc
@@ -114,15 +114,15 @@
def api_url # :nodoc:
"https://keikoku.herokuapp.com/api/v1/notifications"
end
def encode_json(hash) # :nodoc:
- Yajl::Encoder.encode(hash)
+ Keikokuc::OkJson.encode(stringify_hash_keys(hash))
end
def parse_json(data) # :nodoc:
- symbolize_keys(Yajl::Parser.parse(data)) if data
+ symbolize_keys(Keikokuc::OkJson.decode(data)) if data
end
def symbolize_keys(object) # :nodoc:
case object
when Hash
@@ -133,9 +133,16 @@
end
def symbolize_hash_keys(hash)
hash.inject({}) do |result, (k, v)|
result[k.to_sym] = v
+ result
+ end
+ end
+
+ def stringify_hash_keys(hash)
+ hash.inject({}) do |result, (k, v)|
+ result[k.to_s] = v
result
end
end
end