Skip to content

Commit

Permalink
Symbolize/Underscore Response (#91)
Browse files Browse the repository at this point in the history
* Symbolize/Underscore Response

* Inline Encoder
  • Loading branch information
kyledecot committed Oct 26, 2019
1 parent 27817f8 commit c06be05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/app_store_connect/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def call(web_service_endpoint, **kwargs)
@usage.track
response = request.execute

JSON.parse(response.body) if response.body
Utils.decode(response.body) if response.body
end

def build_uri(web_service_endpoint, **kwargs)
Expand Down
10 changes: 7 additions & 3 deletions lib/app_store_connect/client/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
module AppStoreConnect
class Client
class Utils
CAMELIZE = ->(s) { s.to_s.camelize(:lower) }

def self.encode(hash)
hash
.deep_transform_keys(&CAMELIZE)
.deep_transform_keys { |s| s.to_s.camelize(:lower) }
.to_json
end

def self.decode(string)
JSON
.parse(string)
.deep_transform_keys { |k| k.underscore.to_sym }
end
end
end
end
6 changes: 6 additions & 0 deletions spec/app_store_connect/client/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
expect(described_class.encode(first_name: 'Kyle')).to eq('{"firstName":"Kyle"}')
end
end

describe '.decode' do
it 'should symbolize/underscore' do
expect(described_class.decode('{"firstName":"Kyle"}')).to eq(first_name: 'Kyle')
end
end
end

0 comments on commit c06be05

Please sign in to comment.