flexirest 1.10.8 → 1.10.11

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
2
  SHA256:
3
- metadata.gz: 1b83cde99ff35cebe79fea42a56376731df479a41668d080adc68ff5be4a24dc
4
- data.tar.gz: 9170fdcf1afaa4d94d55d13b67c406ef470d3793ea9c7738416cd55b4fdc8107
3
+ metadata.gz: 60510339b01a0ade8d9cd94686ecec5f431bcb58570c66b48fdc76075faf4d4f
4
+ data.tar.gz: 203e88d288ba8fa7f46f757a9aa24177908df116a272b754dc9bd685b19302db
5
5
  SHA512:
6
- metadata.gz: 70e59dcfcfc93ce1af97961756bc92c6f53f3d438afea748c918cad5b00583afda7678de691a8ce0bf7f2e45619d73adba2b3c5be4a80c29fd80550fccb9e62b
7
- data.tar.gz: 953064ac2ad371bc5d793291ceef862092983a34489b6e5780b7f4d84a4d568e4520b50df41ebd8f9663412a80feeeac1562767ff879eedae235576284fc3771
6
+ metadata.gz: f2d51bcbce5d390baa8140cc222cbe69bfb873cb6db399a3e955358b36b39aea6241df15abd8458b79e03d87e3e4643551d2d809dabd0a4ae92c9131e9277da1
7
+ data.tar.gz: 73445e4f9be17c311354112a41e7a9290695da228d853e1a67ea063d8aae8a1370f7bf4991fa43bd70a264b608c94416ad005929aa055863686ca919c6fe19ce
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.11
4
+
5
+ Bugfix:
6
+
7
+ - HTTPClientException's instance body was return nil instead of the response. (thanks to @pinifloyd for the issue and PR)
8
+
9
+ ## 1.10.10
10
+
11
+ Bugfix:
12
+
13
+ - Specifically requiring a 1.x Faraday. They changed the engine inclusion in 2.x and it's not necessary for Flexirest to need that. If anyone does need it, feel free to raise a PR.
14
+
15
+ ## 1.10.9
16
+
17
+ Bugfix:
18
+
19
+ - Correctly handle a 204 response to not wipe an instance's attributes (thanks to @couchbelag for the issue)
20
+ - Add an option to handle a 200 response with an empty body to not wipe an instance's attributes (thanks to @couchbelag for the issue)
21
+ - Fixed a couple of typos in error messages (thanks to Sampat Badhe/@sampatbadhe for the PR)
22
+
3
23
  ## 1.10.8
4
24
 
5
25
  Bugfix:
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  >
5
5
  > Write your API classes in an ActiveRecord-style; like ActiveResource but Flexirest works where the resource naming doesn't follow Rails conventions, it has built-in caching and is much more flexible.
6
6
 
7
- [![Build](https://github.com/flexirest/flexirest/actions/workflows/build_test.yml/badge.svg)](https://github.com/flexirest/flexirest/actions/workflows/build.yml)
7
+ [![Build](https://github.com/flexirest/flexirest/actions/workflows/build.yml/badge.svg)](https://github.com/flexirest/flexirest/actions/workflows/build.yml)
8
8
  [![Coverage Status](https://coveralls.io/repos/github/flexirest/flexirest/badge.svg?branch=master)](https://coveralls.io/github/flexirest/flexirest?branch=master)
9
9
  [![Code Climate](https://codeclimate.com/github/flexirest/flexirest.png)](https://codeclimate.com/github/flexirest/flexirest)
10
10
  [![Gem Version](https://badge.fury.io/rb/flexirest.png)](http://badge.fury.io/rb/flexirest)
@@ -49,8 +49,8 @@ You can then use your new class like this:
49
49
  ```ruby
50
50
  # Create a new person
51
51
  @person = Person.create(
52
- first_name:"John"
53
- last_name:"Smith"
52
+ first_name: "John",
53
+ last_name: "Smith"
54
54
  )
55
55
 
56
56
  # Find a person (not needed after creating)
@@ -82,6 +82,7 @@ I've written a TON of documentation on how to use Flexirest and a LITTLE bit on
82
82
  - [Lazy loading](docs/lazy-loading.md)
83
83
  - [Authentication](docs/authentication.md)
84
84
  - [Body types](docs/body-types.md)
85
+ - [Empty body handling](docs/empty-body-handling.md)
85
86
  - [Parallel requests](docs/parallel-requests.md)
86
87
  - [Faking calls](docs/faking-calls.md)
87
88
  - [Per-request timeouts](docs/per-request-timeouts.md)
data/docs/body-types.md CHANGED
@@ -45,10 +45,10 @@ class Person < Flexirest::Base
45
45
  put :save, '/person/:id/logs', request_body_type: :plain
46
46
  end
47
47
 
48
- Person.save(id: 1, body: '["Something here"]',
48
+ Person.save(id: 1, body: '["Something here"]',
49
49
  content_type: "application/json")
50
50
  ```
51
51
 
52
52
  -----
53
53
 
54
- [< Authentication](authentication.md) | [Parallel requests >](parallel-requests.md)
54
+ [< Authentication](authentication.md) | [Empty body handling >](empty-body-handling.md)
@@ -0,0 +1,26 @@
1
+ # *Flexirest:* Empty body handling
2
+
3
+ If you call a RESTful method that correctly returns a 204 when the request was accepted, but no body is supplied, Flexirest will return `true`. If you call this on an instance of a Flexirest subclass, it will not affect the existing attributes.
4
+
5
+ ```ruby
6
+ class Person < Flexirest::Base
7
+ put :save, "/people/:id"
8
+ end
9
+
10
+ p = Person.new(id: "1", name: "Jenny")
11
+ saved = p.save
12
+ puts saved === true # true
13
+ puts p.name # Jenny
14
+ ```
15
+
16
+ If your API returns a 200 OK status with an empty body, by default this is handled in the normal way - the attributes are set to an empty set. If you intend to handle it as above for the 204, you can set an extra option on the mapped method like this:
17
+
18
+ ```ruby
19
+ class Person < Flexirest::Base
20
+ put :save, "/people/:id", ignore_empty_response: true
21
+ end
22
+ ```
23
+
24
+ -----
25
+
26
+ [< Body types](body-types.md) | [Parallel requests >](parallel-requests.md)
@@ -25,4 +25,4 @@ puts @employers.size #=> 7
25
25
 
26
26
  -----
27
27
 
28
- [< Body types](body-types.md) | [Faking calls >](faking-calls.md)
28
+ [< Empty body handling](empty-body-handling.md) | [Faking calls >](faking-calls.md)
@@ -105,6 +105,7 @@ class Animal < Flexirest::Base
105
105
  Flexirest::Logger.info(" \033[1;4;32m#{Flexirest.name}\033[0m Invalidating cache for #{self.class.name} #{request.url}")
106
106
  Rails.cache.delete("#{self.class.name}:#{request.url}")
107
107
  end
108
+ nil
108
109
  end
109
110
 
110
111
  def cache(name, response)
data/flexirest.gemspec CHANGED
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
44
44
  spec.add_runtime_dependency "mime-types"
45
45
  spec.add_runtime_dependency "multi_json"
46
46
  spec.add_runtime_dependency "crack"
47
- spec.add_runtime_dependency "faraday"
47
+ spec.add_runtime_dependency "faraday", "~> 1.0"
48
48
 
49
49
  # Use Gem::Version to parse the Ruby version for reliable comparison
50
50
  # ActiveSupport 5+ requires Ruby 2.2.2
@@ -66,7 +66,7 @@ module Flexirest
66
66
  @dirty_attributes.keys
67
67
  end
68
68
 
69
- # Returns hash of old and new vaules for each changed field
69
+ # Returns hash of old and new values for each changed field
70
70
  def changes
71
71
  @dirty_attributes
72
72
  end
@@ -404,7 +404,7 @@ module Flexirest
404
404
  end
405
405
  end
406
406
  if missing.any?
407
- raise Flexirest::MissingParametersException.new("The following parameters weren't specifed: #{missing.join(", ")}")
407
+ raise Flexirest::MissingParametersException.new("The following parameters weren't specified: #{missing.join(", ")}")
408
408
  end
409
409
  end
410
410
  end
@@ -434,7 +434,7 @@ module Flexirest
434
434
  end
435
435
 
436
436
  if missing.present?
437
- raise Flexirest::MissingParametersException.new("The following parameters weren't specifed: #{missing.join(", ")}")
437
+ raise Flexirest::MissingParametersException.new("The following parameters weren't specified: #{missing.join(", ")}")
438
438
  end
439
439
  end
440
440
 
@@ -627,7 +627,7 @@ module Flexirest
627
627
  def handle_response(response, cached = nil)
628
628
  @response = response
629
629
  status = @response.status || 200
630
- if @response.body.blank?
630
+ if @response.body.blank? && !@method[:options][:ignore_empty_response]
631
631
  @response.response_headers['Content-Type'] = "application/json"
632
632
  @response.body = "{}"
633
633
  end
@@ -639,6 +639,10 @@ module Flexirest
639
639
  end
640
640
 
641
641
  if (200..399).include?(status)
642
+ if status == 204 || (@response.body.blank? && @method[:options][:ignore_empty_response])
643
+ return true
644
+ end
645
+
642
646
  if @method[:options][:plain]
643
647
  return @response = Flexirest::PlainResponse.from_response(@response)
644
648
  elsif is_json_response? || is_xml_response?
@@ -930,7 +934,7 @@ module Flexirest
930
934
  end
931
935
 
932
936
  class HTTPException < RequestException
933
- attr_accessor :status, :result, :request_url, :body, :raw_response
937
+ attr_accessor :status, :result, :request_url, :body
934
938
  def initialize(options)
935
939
  @status = options[:status]
936
940
  @result = options[:result]
@@ -938,7 +942,7 @@ module Flexirest
938
942
  @body = options[:raw_response]
939
943
  @method = options[:method]
940
944
  end
941
- alias_method :body, :raw_response
945
+ alias_method :raw_response, :body
942
946
 
943
947
  def message
944
948
  method = @method.try(:upcase)
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.10.8"
2
+ VERSION = "1.10.11"
3
3
  end
@@ -114,12 +114,12 @@ describe Flexirest::BaseWithoutValidation do
114
114
  expect(client["test"]).to be_an_instance_of(DateTime)
115
115
  end
116
116
 
117
- it "should allow strings of 4 digits and not intepret them as dates" do
117
+ it "should allow strings of 4 digits and not interpret them as dates" do
118
118
  client = EmptyExample.new(test: "2015")
119
119
  expect(client["test"]).to be_an_instance_of(String)
120
120
  end
121
121
 
122
- it "should allow strings of 8 digits and not intepret them as dates" do
122
+ it "should allow strings of 8 digits and not interpret them as dates" do
123
123
  client = EmptyExample.new(test: "1266129")
124
124
  expect(client["test"]).to be_an_instance_of(String)
125
125
  end
@@ -209,7 +209,7 @@ describe Flexirest::Configuration do
209
209
  end
210
210
  end
211
211
 
212
- it "should default to non-verbose loggingg" do
212
+ it "should default to non-verbose logging" do
213
213
  class VerboseConfigurationExample1
214
214
  include Flexirest::Configuration
215
215
  end
@@ -10,7 +10,7 @@ describe Flexirest::Connection do
10
10
  @connection.reconnect
11
11
  end
12
12
 
13
- it "should contain a Farday connection" do
13
+ it "should contain a Faraday connection" do
14
14
  expect(@connection.session).to be_a_kind_of(Faraday::Connection)
15
15
  end
16
16
 
@@ -48,6 +48,7 @@ describe Flexirest::Request do
48
48
  post :test_encoding, "/encoding", request_body_type: :json
49
49
  post :testing_no_content_headers, "/no-content"
50
50
  put :update, "/put/:id"
51
+ put :update_with_empty, "/put/:id", ignore_empty_response: true
51
52
  put :wrapped, "/put/:id", wrap_root: "example"
52
53
  put :conversion, "/put/:id", parse_fields: [:converted]
53
54
  put :conversion_child, "/put/:id", parse_fields: [:converted_child]
@@ -522,6 +523,24 @@ describe Flexirest::Request do
522
523
  ExampleClient.find("1234")
523
524
  end
524
525
 
526
+ it "should handle a 204 response and not erase the instance's attributes" do
527
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).and_return(::FaradayResponseMock.new(OpenStruct.new(body: "", response_headers: {}, status: 204)))
528
+ client = ExampleClient.new
529
+ client.id = "1234"
530
+ ret = client.update
531
+ expect(client.id).to eq("1234")
532
+ expect(ret).to be_truthy
533
+ end
534
+
535
+ it "should handle a 200 response with an empty body and not erase the instance's attributes" do
536
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).and_return(::FaradayResponseMock.new(OpenStruct.new(body: "", response_headers: {}, status: 200)))
537
+ client = ExampleClient.new
538
+ client.id = "1234"
539
+ ret = client.update_with_empty
540
+ expect(client.id).to eq("1234")
541
+ expect(ret).to be_truthy
542
+ end
543
+
525
544
  it "should pass through url parameters and get parameters" do
526
545
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/1234?debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
527
546
  ExampleClient.find id:1234, debug:true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.8
4
+ version: 1.10.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-01 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -230,16 +230,16 @@ dependencies:
230
230
  name: faraday
231
231
  requirement: !ruby/object:Gem::Requirement
232
232
  requirements:
233
- - - ">="
233
+ - - "~>"
234
234
  - !ruby/object:Gem::Version
235
- version: '0'
235
+ version: '1.0'
236
236
  type: :runtime
237
237
  prerelease: false
238
238
  version_requirements: !ruby/object:Gem::Requirement
239
239
  requirements:
240
- - - ">="
240
+ - - "~>"
241
241
  - !ruby/object:Gem::Version
242
- version: '0'
242
+ version: '1.0'
243
243
  - !ruby/object:Gem::Dependency
244
244
  name: activesupport
245
245
  requirement: !ruby/object:Gem::Requirement
@@ -282,6 +282,7 @@ files:
282
282
  - docs/combined-example.md
283
283
  - docs/debugging.md
284
284
  - docs/default-parameters.md
285
+ - docs/empty-body-handling.md
285
286
  - docs/faking-calls.md
286
287
  - docs/faraday-configuration.md
287
288
  - docs/filtering-result-lists.md
@@ -369,7 +370,7 @@ licenses:
369
370
  - MIT
370
371
  metadata:
371
372
  source_code_uri: https://github.com/flexirest/flexirest
372
- post_install_message:
373
+ post_install_message:
373
374
  rdoc_options: []
374
375
  require_paths:
375
376
  - lib
@@ -384,8 +385,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
385
  - !ruby/object:Gem::Version
385
386
  version: '0'
386
387
  requirements: []
387
- rubygems_version: 3.1.2
388
- signing_key:
388
+ rubygems_version: 3.3.7
389
+ signing_key:
389
390
  specification_version: 4
390
391
  summary: This gem is for accessing REST services in a flexible way. ActiveResource
391
392
  already exists for this, but it doesn't work where the resource naming doesn't follow