Class: AppStoreDevApi::Client::Utils
- Inherits:
-
Object
- Object
- AppStoreDevApi::Client::Utils
- Defined in:
- lib/app_store_dev_api/client/utils.rb
Class Method Summary collapse
-
.decode(string, content_type = 'application/json') ⇒ Object
Right now this only supports gzip and json responses.
- .encode(hash) ⇒ Object
Class Method Details
.decode(string, content_type = 'application/json') ⇒ Object
Right now this only supports gzip and json responses. If you need to support a different type then add it.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/app_store_dev_api/client/utils.rb', line 14 def self.decode(string, content_type = 'application/json') decoded_data = nil case content_type when 'application/a-gzip' sio = StringIO.new string gz = Zlib::GzipReader.new sio decoded_data = gz.read else # Assume JSON decoded_data = JSON .parse(string) .deep_transform_keys { |k| k.underscore.to_sym } end decoded_data end |
.encode(hash) ⇒ Object
6 7 8 9 10 |
# File 'lib/app_store_dev_api/client/utils.rb', line 6 def self.encode(hash) hash .deep_transform_keys { |s| s.to_s.camelize(:lower) } .to_json end |