Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade json_api_client gem #158

Merged
merged 56 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f7f4f41
Update client gem
JoshuaTatterton Aug 16, 2018
9e70d94
Update patches code
JoshuaTatterton Aug 16, 2018
44eaebb
Update jsonapi page size param
JoshuaTatterton Aug 16, 2018
b33d9ca
Same as before but it works
JoshuaTatterton Aug 16, 2018
a88e9b2
Update page number param
JoshuaTatterton Aug 16, 2018
7279a3c
Fix pagination params
JoshuaTatterton Aug 16, 2018
cf595a7
Update patch
JoshuaTatterton Aug 21, 2018
1f2245e
Narrow down version
Sep 3, 2018
ae5dc63
Puts gem version
Sep 3, 2018
01c92a1
Fix version of json_api_client
Sep 4, 2018
17fa4cb
Try v1.6.0 of json_api_client
Sep 4, 2018
18ad0ce
Fix 'unknown keyword: data'
Sep 4, 2018
eb0f265
Fix 'unknown keyword: data' in 'update'
Sep 4, 2018
b0c130d
Fix 'unknown keyword: filter' and maybe others
Sep 4, 2018
93761c9
Potentially fix 'unknown keywords: ...'
Sep 4, 2018
e7ae593
Fix more
Sep 4, 2018
40525d3
Fix syntax issue
Sep 4, 2018
35f0181
Fix 'wrong number of arguments'
Sep 4, 2018
22062d0
Update stubs
Sep 4, 2018
8561880
Temporarily revert 1.6.0 to 1.5.3
Sep 5, 2018
606f745
Revert to 1.6.0
Sep 5, 2018
bb9a314
Try just setting Accept-Encoding header
Sep 5, 2018
52d7451
Revert to Faraday Gzip middleware
Sep 6, 2018
e8464b5
Remove unneeded middleware
Sep 10, 2018
98df40d
Remove stub
Sep 10, 2018
52b6424
CustomerAccountSpec extra request stub
Sep 10, 2018
6ea38f9
Test without webhook stub
Sep 10, 2018
1997da8
Revert
Sep 10, 2018
178c115
Revert spec changes completely
Sep 10, 2018
e0c0715
Remove unneeded patch
Sep 10, 2018
f426663
Revert to 1.5.3 and remove workarounds for 1.6.0
Sep 10, 2018
138d3e9
Add patch back in
Sep 10, 2018
462d041
Remove patch
Sep 10, 2018
4c52a04
Merge branch 'master' into update_json_api_client_gem
Sep 19, 2018
d12a665
Only use gzip compression for known compatible adapters
Sep 19, 2018
bc607da
Add big obvious puts
Sep 19, 2018
a891c26
Remove big obvious puts
Sep 19, 2018
af6d0be
Add logging
Sep 20, 2018
f3c2671
Move logging
Sep 20, 2018
e9ec373
Add config option for disabling gzip
Sep 20, 2018
75ee4ea
Disable gzip in paypal specs
Sep 20, 2018
5e90eb3
Add patch back in
Sep 21, 2018
a1c93bb
Remove GZIP
Sep 24, 2018
64ee648
More removing of GZIP
Sep 24, 2018
88640c4
Fix tax code error spec failure
Sep 24, 2018
691358e
Remove unused transaltion, move error message into lib
Sep 24, 2018
493fc40
Add failing spec
Sep 26, 2018
3fa2b98
Add fix (hopefully?)
Sep 27, 2018
e20e9a8
Remove fix
Sep 27, 2018
63e9970
Override path method to automatically set path param
Sep 27, 2018
62eaea0
Update fix
Sep 27, 2018
e8f2fae
Update again
Sep 27, 2018
891c75f
Hack
Sep 28, 2018
eb1894c
Add fix for 'last' link
Oct 1, 2018
ea571c5
Remove hardcoded timeout
Oct 1, 2018
a330196
Tweak fix and update comment
Oct 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flex-commerce-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "json_matchers", ["~> 0.5", ">= 0.5.1"]

spec.add_dependency "oj", "~> 2.12"
spec.add_runtime_dependency "json_api_client", "1.1.1"
spec.add_runtime_dependency "json_api_client", "1.6.0"
spec.add_runtime_dependency "activesupport", ">= 4.0"
spec.add_runtime_dependency "rack", ">= 1.6"
spec.add_runtime_dependency "faraday-http-cache", "1.3.0"
Expand Down
4 changes: 4 additions & 0 deletions lib/flex_commerce_api/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
require "flex_commerce_api/json_api_client_extension/remote_builder"

module FlexCommerceApi
# Set the pagination param
JsonApiClientExtension::Paginator.page_param = "number"
JsonApiClientExtension::Paginator.per_page_param = "size"

#
# Base class for all flex commerce models
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(options = {})
include_previewed = options.fetch :include_previewed, false
@faraday = Faraday.new(site) do |builder|
builder.request :json
builder.use FaradayMiddleware::Gzip
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including this middleware 1) adds Accept-Encoding: gzip,deflate header by default and 2) includes support for Gzip decoding

builder.use JsonApiClientExtension::SaveRequestBodyMiddleware
builder.use JsonApiClientExtension::JsonFormatMiddleware if add_json_api_extension
builder.use JsonApiClientExtension::PreviewedRequestMiddleware if include_previewed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module FlexCommerceApi
module JsonApiClientExtension
class RemoteBuilder < ::JsonApiClient::Query::Builder
def initialize(klass, path: klass.path, connection: klass.connection)
super(klass)
self.connection = connection
self.path = path
def initialize(klass, opts = {})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to bring us in line with interface changes within the json_api_client gem we're extending

super(klass, opts)
self.connection = opts.fetch(:connection, klass.connection)
self.path = opts.fetch(:path, klass.path)
end

def find(args = {})
Expand All @@ -21,7 +21,7 @@ def find(args = {})
private

def get_request(params)
klass.parser.parse(klass, connection.run(:get, path, params, klass.custom_headers))
klass.parser.parse(klass, connection.run(:get, path, params: params, headers: klass.custom_headers))
end
attr_accessor :path, :connection
end
Expand Down
8 changes: 4 additions & 4 deletions lib/flex_commerce_api/json_api_client_extension/requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ class Requestor < ::JsonApiClient::Query::Requestor
# expects a record
def create(record)
request(:post, klass.path(record.attributes, record), {
data: record.as_json_api
body: { data: record.as_json_api }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to bring us in line with interface changes within the json_api_client gem we're extending

})
end

def update(record)
request(:patch, resource_path(record.attributes, record), {
data: record.as_json_api
body: { data: record.as_json_api }
})
end

def get(params = {})
path = resource_path(params)
params.delete(klass.primary_key)
request(:get, path, params)
request(:get, path, params: params)
end

def destroy(record)
Expand All @@ -39,4 +39,4 @@ def encoded(part)
end
end
end
end
end
17 changes: 5 additions & 12 deletions lib/patches/json_api_client/resource.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "json_api_client/version"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we require this patch anymore?

if ["1.1.1"].include?(JsonApiClient::VERSION)

if ["1.1.1", "1.5.3"].include?(JsonApiClient::VERSION)
require "json_api_client/resource"
module JsonApiClient
class Resource
Expand All @@ -13,20 +14,13 @@ def save
end

if last_result_set.has_errors?
last_result_set.errors.each do |error|
if error.source_parameter
errors.add(error.source_parameter, error.title || error.detail)
else
errors.add(:base, error.title || error.detail)
end
end
fill_errors
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our patch needed updating to use the json_api_client gem's latest method of dealing with errors

false
else
self.errors.clear if self.errors
mark_as_persisted!
if updated = last_result_set.first
self.attributes = updated.attributes
# This line has been added as part of https://github.com/chingor13/json_api_client/pull/238
self.links.attributes = updated.links.attributes
self.relationships.attributes = updated.relationships.attributes
clear_changes_information
Expand All @@ -39,9 +33,8 @@ def save
end
end
else
raise %q(
Please check these two PRs:
* https://github.com/chingor13/json_api_client/pull/238 (This was released in version 1.5.0)
puts %q(
Please check this PR:
* https://github.com/JsonApiClient/json_api_client/pull/285 (This hasn't yet been released at the time of writing this)

If both have been merged into the gem version you are using, remove this file (#{__FILE__}).
Expand Down