Skip to content

Commit 07bc724

Browse files
authored
use original gem (#9)
* use original gem * temporary monkey patch till bug gets fixed in gem
1 parent 276e187 commit 07bc724

File tree

8 files changed

+71
-20
lines changed

8 files changed

+71
-20
lines changed

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ gemspec
55

66
gem 'rake', '~> 12.0'
77
gem 'rspec', '~> 3.0'
8-
# tempprary till my PR gets approved in original gem
9-
gem 'json_api_client', git: 'https://github.com/inderps/json_api_client'
108

119
group :development do
1210
gem 'faker'

Gemfile.lock

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
GIT
2-
remote: https://github.com/inderps/json_api_client
3-
revision: 675e1c8b1bf9978ca4722c2aa19314fb0aa5860b
4-
specs:
5-
json_api_client (1.17.1)
6-
activemodel (>= 3.2.0)
7-
activesupport (>= 3.2.0)
8-
addressable (~> 2.2)
9-
faraday (>= 0.15.2, < 1.2.0)
10-
faraday_middleware (>= 0.9.0, < 1.2.0)
11-
rack (>= 0.2)
12-
131
PATH
142
remote: .
153
specs:
16-
cirro-ruby-client (1.1.0)
4+
cirro-ruby-client (1.2.1)
175
faraday_middleware
6+
json_api_client
187
jwt
198

209
GEM
@@ -37,13 +26,21 @@ GEM
3726
diff-lcs (1.4.4)
3827
faker (2.14.0)
3928
i18n (>= 1.6, < 2)
40-
faraday (1.0.1)
29+
faraday (1.1.0)
4130
multipart-post (>= 1.2, < 3)
31+
ruby2_keywords
4232
faraday_middleware (1.0.0)
4333
faraday (~> 1.0)
4434
hashdiff (1.0.1)
4535
i18n (1.8.5)
4636
concurrent-ruby (~> 1.0)
37+
json_api_client (1.17.1)
38+
activemodel (>= 3.2.0)
39+
activesupport (>= 3.2.0)
40+
addressable (~> 2.2)
41+
faraday (>= 0.15.2, < 1.2.0)
42+
faraday_middleware (>= 0.9.0, < 1.2.0)
43+
rack (>= 0.2)
4744
jwt (2.2.2)
4845
method_source (1.0.0)
4946
minitest (5.14.2)
@@ -87,6 +84,7 @@ GEM
8784
rubocop-rspec (1.43.2)
8885
rubocop (~> 0.87)
8986
ruby-progressbar (1.10.1)
87+
ruby2_keywords (0.0.2)
9088
thread_safe (0.3.6)
9189
tzinfo (1.2.8)
9290
thread_safe (~> 0.1)
@@ -103,7 +101,6 @@ PLATFORMS
103101
DEPENDENCIES
104102
cirro-ruby-client!
105103
faker
106-
json_api_client!
107104
pry
108105
rake (~> 12.0)
109106
rspec (~> 3.0)

cirro-ruby-client.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_runtime_dependency 'jwt'
2929
spec.add_runtime_dependency 'faraday_middleware'
30+
spec.add_runtime_dependency 'json_api_client'
3031
end

lib/cirro_io/base_association.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module JsonApiClient
2+
module Associations
3+
class BaseAssociation
4+
attr_reader :attr_name, :klass, :options
5+
def initialize(attr_name, klass, options = {})
6+
@attr_name = attr_name
7+
@klass = klass
8+
@options = options
9+
end
10+
11+
def association_class
12+
@association_class ||= Utils.compute_type(klass, options.fetch(:class_name) do
13+
attr_name.to_s.classify
14+
end)
15+
end
16+
17+
def data(url)
18+
from_result_set(association_class.requestor.linked(url))
19+
end
20+
21+
def from_result_set(result_set)
22+
result_set.to_a
23+
end
24+
25+
def load_records(data)
26+
data.map do |d|
27+
record_class = Utils.compute_type(klass, klass.key_formatter.unformat(d['type']).classify)
28+
record_class.load id: d['id']
29+
end
30+
end
31+
end
32+
end
33+
end

lib/cirro_io/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
require 'json_api_client'
2+
3+
# temporary monkey patch code to fix gem bug
4+
require 'cirro_io/has_one'
5+
require 'cirro_io/base_association'
6+
# temporary monkey patch code to fix gem bug
7+
28
require 'cirro_io/client/version'
39
require 'cirro_io/client/configuration'
410
require 'cirro_io/client/response_debugging_middleware'

lib/cirro_io/client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rubocop:disable Style/MutableConstant
22
module CirroIO
33
module Client
4-
VERSION = '1.2.0'
4+
VERSION = '1.2.1'
55
end
66
end
77
# rubocop:enable Style/MutableConstant

lib/cirro_io/has_one.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module JsonApiClient
2+
module Associations
3+
module HasOne
4+
class Association < BaseAssociation
5+
def from_result_set(result_set)
6+
result_set.first
7+
end
8+
9+
def load_records(data)
10+
record_class = Utils.compute_type(klass, klass.key_formatter.unformat(data['type']).classify)
11+
record_class.load id: data['id']
12+
end
13+
end
14+
end
15+
end
16+
end

spec/cirro_io/client/base_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'Accept' => 'application/vnd.api+json',
1313
'Accept-Encoding' => 'gzip,deflate',
1414
'Content-Type' => 'application/vnd.api+json',
15-
'User-Agent' => 'Faraday v1.0.1',
15+
'User-Agent' => 'Faraday v1.1.0',
1616
'Authorization' => 'Bearer jwt-token',
1717
})
1818
.to_return(body: File.read('./spec/fixtures/app_worker.json'), headers: { 'Content-Type' => 'application/json' })
@@ -30,7 +30,7 @@
3030
'Accept' => '*/*',
3131
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
3232
'Content-Type' => 'application/json',
33-
'User-Agent' => 'Faraday v1.0.1',
33+
'User-Agent' => 'Faraday v1.1.0',
3434
'Authorization' => 'Bearer jwt-token',
3535
})
3636
.to_return(status: 201, body: '{}', headers: {})

0 commit comments

Comments
 (0)