her 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c0f87d36e43920519c831bffab58456dd03219dd
4
- data.tar.gz: 8f347722b32acb8f9a7f8f372683b09e9c305d8f
2
+ SHA256:
3
+ metadata.gz: 58af9f15de50854cfb0920b84a7cb76ec1869f50d9d92a2e9db08bf296340438
4
+ data.tar.gz: 441585f5ccc641455c402db3c8fbbb9a67cbb6b6cbb37beaa9a1ab63f69def89
5
5
  SHA512:
6
- metadata.gz: 4a239ac856dd17577b9adcfbf96d454a20ec12cdfa605bd45625261aeb93a31b04d95712b2ed5c7901f48371eadbfb08076a4318cc85276373e3e0dfb6de31a8
7
- data.tar.gz: 9a9b886cc0050fecb2d3bff8fcec90dddd3ffac98c1af8c61c177ef5314036f19939ab29542a52305c427ebd6f8b78100199d2fddf66a4031299cbb800dff9fa
6
+ metadata.gz: 7a4433d1d5999b70b14130b39d8817b97b873f259988c0bbf091e83a3e7795e5413b95fd0abb0b61d012982d498149678475f89133ad7d28c0deed9bc3b5637b
7
+ data.tar.gz: 1f834a4c000b91a5605653f3e3bd19b3849ef05f82d77d8626b671cd3f42719a312d429cf645a66a8ece087d790f61266816868be35c8404bb629ba55e22bd27
data/.travis.yml CHANGED
@@ -6,15 +6,18 @@ rvm:
6
6
  - 1.9.3
7
7
  - 2.0.0
8
8
  - 2.1.6
9
- - 2.2.8
10
- - 2.3.5
11
- - 2.4.2
9
+ - 2.2.10
10
+ - 2.3.7
11
+ - 2.4.3
12
+ - 2.5.1
13
+ - 2.6.6
12
14
 
13
15
  gemfile:
14
16
  - gemfiles/Gemfile.activemodel-4.2
15
17
  - gemfiles/Gemfile.activemodel-5.0
16
18
  - gemfiles/Gemfile.activemodel-5.1
17
19
  - gemfiles/Gemfile.activemodel-5.2
20
+ - gemfiles/Gemfile.faraday-1.0
18
21
 
19
22
  matrix:
20
23
  exclude:
@@ -36,6 +39,14 @@ matrix:
36
39
  rvm: 2.0.0
37
40
  - gemfile: gemfiles/Gemfile.activemodel-5.2
38
41
  rvm: 2.1.6
42
+ - gemfile: gemfiles/Gemfile.faraday-1.0
43
+ rvm: 1.9.3
44
+ - gemfile: gemfiles/Gemfile.faraday-1.0
45
+ rvm: 2.0.0
46
+ - gemfile: gemfiles/Gemfile.faraday-1.0
47
+ rvm: 2.1.6
48
+ - gemfile: gemfiles/Gemfile.faraday-1.0
49
+ rvm: 2.2.10
39
50
 
40
51
  before_install:
41
52
  - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
data/README.md CHANGED
@@ -675,7 +675,7 @@ class User
675
675
  include Her::Model
676
676
 
677
677
  custom_get :popular, :unpopular
678
- custom_post :from_default
678
+ custom_post :from_default, :activate
679
679
  end
680
680
 
681
681
  User.popular
@@ -689,6 +689,10 @@ User.unpopular
689
689
  User.from_default(name: "Maeby Fünke")
690
690
  # POST "/users/from_default" with `name=Maeby+Fünke`
691
691
  # => #<User id=5 name="Maeby Fünke">
692
+
693
+ User.activate(id: 6)
694
+ # POST "/users/6/activate"
695
+ # => #<User id=6>
692
696
  ```
693
697
 
694
698
  You can also use `get`, `post`, `put` or `delete` (which maps the returned data to either a collection or a resource).
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem 'activemodel', '~> 4.2.1'
6
+ gem 'faraday', '~> 1.0'
data/her.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "rspec", "~> 3.5"
24
24
 
25
25
  s.add_runtime_dependency "activemodel", ">= 4.2.1"
26
- s.add_runtime_dependency "faraday", ">= 0.8", "< 1.0"
26
+ s.add_runtime_dependency "faraday", ">= 0.8"
27
27
  s.add_runtime_dependency "multi_json", "~> 1.7"
28
28
  end
@@ -97,7 +97,12 @@ module Her
97
97
 
98
98
  def custom_#{method}(*paths)
99
99
  metaclass = (class << self; self; end)
100
- opts = paths.last.is_a?(Hash) ? paths.pop : Hash.new
100
+
101
+ # TODO: Remove this check after January 2020
102
+ if paths.last.is_a?(Hash)
103
+ warn("[DEPRECATION] options for custom request methods are deprecated and will be removed on or after January 2020.")
104
+ paths.pop
105
+ end
101
106
 
102
107
  paths.each do |path|
103
108
  metaclass.send(:define_method, path) do |*params|
data/lib/her/model/orm.rb CHANGED
@@ -228,8 +228,15 @@ module Her
228
228
  # @user = User.save_existing(1, { :fullname => "Tobias Fünke" })
229
229
  # # Called via PUT "/users/1"
230
230
  def save_existing(id, params)
231
+ save_existing!(id, params)
232
+ rescue Her::Errors::ResourceInvalid => e
233
+ e.resource
234
+ end
235
+
236
+ # Similar to .save_existing but raises ResourceInvalid if save fails
237
+ def save_existing!(id, params)
231
238
  resource = new(params.merge(primary_key => id))
232
- resource.save
239
+ resource.save!
233
240
  resource
234
241
  end
235
242
 
data/lib/her/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Her
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -460,6 +460,9 @@ describe Her::Model::Associations do
460
460
  Her::API.setup url: "https://api.example.com" do |builder|
461
461
  builder.use Her::Middleware::FirstLevelParseJSON
462
462
  builder.use Faraday::Request::UrlEncoded
463
+ builder.adapter :test do |stub|
464
+ stub.get("/users/1") { [200, {}, { id: 1, name: "Lindsay Fünke", organization_id: 2 }.to_json] }
465
+ end
463
466
  end
464
467
  end
465
468
 
@@ -158,33 +158,43 @@ describe Her::Model::HTTP do
158
158
  subject { Foo::User }
159
159
 
160
160
  describe :custom_get do
161
- context "without cache" do
162
- before { Foo::User.custom_get :popular, :recent }
163
- it { is_expected.to respond_to(:popular) }
164
- it { is_expected.to respond_to(:recent) }
161
+ before do
162
+ Foo::User.custom_get :popular, :recent
163
+ end
165
164
 
166
- context "making the HTTP request" do
167
- subject { Foo::User.popular }
165
+ it { is_expected.to respond_to(:popular) }
166
+ it { is_expected.to respond_to(:recent) }
168
167
 
169
- describe "#length" do
170
- subject { super().length }
171
- it { is_expected.to eq(2) }
172
- end
173
- end
168
+ it "makes HTTP request" do
169
+ expect(Foo::User.popular.length).to be 2
174
170
  end
175
171
  end
176
172
 
177
173
  describe :custom_post do
178
- before { Foo::User.custom_post :from_default }
174
+ before do
175
+ Foo::User.custom_post :from_default
176
+ end
177
+
179
178
  it { is_expected.to respond_to(:from_default) }
180
179
 
181
- context "making the HTTP request" do
182
- subject { Foo::User.from_default(name: "Tobias Fünke") }
180
+ it "makes HTTP request" do
181
+ user = Foo::User.from_default(name: "Tobias Fünke")
182
+ expect(user.id).to be 4
183
+ end
184
+ end
183
185
 
184
- describe "#id" do
185
- subject { super().id }
186
- it { is_expected.to eq(4) }
187
- end
186
+ context "with options" do
187
+ before do
188
+ allow(Foo::User).to receive(:warn)
189
+ Foo::User.custom_get :popular, foo: "bar"
190
+ end
191
+
192
+ it "issues DEPRECATION warning" do
193
+ expect(Foo::User).to have_received(:warn).with("[DEPRECATION] options for custom request methods are deprecated and will be removed on or after January 2020.")
194
+ end
195
+
196
+ it "makes HTTP request" do
197
+ expect(Foo::User.popular.length).to be 2
188
198
  end
189
199
  end
190
200
  end
@@ -402,6 +402,7 @@ describe Her::Model::ORM do
402
402
  builder.adapter :test do |stub|
403
403
  stub.get("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", admin: false }.to_json] }
404
404
  stub.put("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke", admin: true }.to_json] }
405
+ stub.put("/users/2") { [200, {}, { id: 2, errors: ["fullname has already been taken"] }.to_json] }
405
406
  stub.get("/pages/1") { [200, {}, { id: 1, views: 1, unique_visitors: 4 }.to_json] }
406
407
  stub.put("/pages/1") { [200, {}, { id: 1, views: 2, unique_visitors: 3 }.to_json] }
407
408
  end
@@ -423,6 +424,15 @@ describe Her::Model::ORM do
423
424
  expect(@user.fullname).to eq("Lindsay Fünke")
424
425
  end
425
426
 
427
+ it "handle resource update through .save_existing!" do
428
+ @user = Foo::User.save_existing!(1, fullname: "Lindsay Fünke")
429
+ expect(@user.fullname).to eq("Lindsay Fünke")
430
+ end
431
+
432
+ it "raises ResourceInvalid when .save_existing! has errors" do
433
+ expect { Foo::User.save_existing!(2, fullname: "Lindsay Fünke") }.to raise_error(Her::Errors::ResourceInvalid)
434
+ end
435
+
426
436
  it "handle resource update through #save on an existing resource" do
427
437
  @user = Foo::User.find(1)
428
438
  @user.fullname = "Lindsay Fünke"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: her
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2021-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -73,9 +73,6 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.8'
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '1.0'
79
76
  type: :runtime
80
77
  prerelease: false
81
78
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,9 +80,6 @@ dependencies:
83
80
  - - ">="
84
81
  - !ruby/object:Gem::Version
85
82
  version: '0.8'
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '1.0'
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: multi_json
91
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +118,7 @@ files:
124
118
  - gemfiles/Gemfile.activemodel-5.0
125
119
  - gemfiles/Gemfile.activemodel-5.1
126
120
  - gemfiles/Gemfile.activemodel-5.2
121
+ - gemfiles/Gemfile.faraday-1.0
127
122
  - her.gemspec
128
123
  - lib/her.rb
129
124
  - lib/her/api.rb
@@ -200,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
195
  - !ruby/object:Gem::Version
201
196
  version: '0'
202
197
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.4.5.1
198
+ rubygems_version: 3.1.2
205
199
  signing_key:
206
200
  specification_version: 4
207
201
  summary: A simple Representational State Transfer-based Hypertext Transfer Protocol-powered