flexirest 1.6.3 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +3 -3
- data/README.md +13 -1
- data/{doc → docs}/FLEXIREST.svg +0 -0
- data/{doc → docs}/FLEXIREST@2x.png +0 -0
- data/doc/Flexirest Internals.graffle b/data/docs/Flexirest → Internals.graffle +0 -0
- data/doc/Flexirest Internals.png b/data/docs/Flexirest → Internals.png +0 -0
- data/doc/Flexirest Logo.sketch b/data/docs/Flexirest → Logo.sketch +0 -0
- data/docs/issue_template.md +26 -0
- data/lib/flexirest/request.rb +10 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +14 -2
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c109cfab49994ec4c27fb6b65745b504f717d3
|
4
|
+
data.tar.gz: 73a93865b5fb49e59a3e080a9a5679e674acf57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94809b3ca647b8b60bb155eff4f3defe4b824129a2ba0c3d1525fe2d357799a1ac1f5795e7820112119c36ca702d2b05959f574d14e46a321ac0eba5745049ca
|
7
|
+
data.tar.gz: 776efc1bf75d74c44e197dfef3d8222bb911f57f97e205700b87a847b7191ecd4597b6dbedbffbfac4fec7d932df376b7bb59f5d2634b23175cbc0bf835f4e1b
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Flexirest (ARC) Contributing Guide
|
2
2
|
|
3
|
-
##
|
3
|
+
## Introduction
|
4
4
|
|
5
5
|
This project was built at Which? Ltd in the UK as ActiveRestClient, but was released as open source in 2014 under the MIT Licence. This is Andy Jeffries' fork of the project as the original seems not to be maintained by Which? and there's been no communication back about the project.
|
6
6
|
|
7
7
|
We're happy to receive contributions from the community for features and bugfixes and hopefully this guide helps new developers to the project to understand how to get started with the internals of Flexirest.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Overview
|
10
10
|
|
11
|
-
![Component Overview Diagram](https://raw.githubusercontent.com/andyjeffries/flexirest/master/
|
11
|
+
![Component Overview Diagram](https://raw.githubusercontent.com/andyjeffries/flexirest/master/docs/Flexirest%20Internals.png)
|
12
12
|
|
13
13
|
## Components
|
14
14
|
|
data/README.md
CHANGED
@@ -900,7 +900,19 @@ NB: Updating relationships is not yet supported.
|
|
900
900
|
|
901
901
|
### Proxying APIs
|
902
902
|
|
903
|
-
Sometimes you may be working with an old API that returns JSON in a less than ideal format or the URL or parameters required have changed.
|
903
|
+
Sometimes you may be working with an old API that returns JSON in a less than ideal format or the URL or parameters required have changed.
|
904
|
+
|
905
|
+
If it's simply that you want attribute names like `SomeName` or `someName` to be more Ruby-style `some_name` then you can simply do that by setting `:rubify_names` when mapping an API call.
|
906
|
+
|
907
|
+
```ruby
|
908
|
+
class Article < Flexirest::Base
|
909
|
+
base_url "http://www.example.com"
|
910
|
+
|
911
|
+
get :all, "/all", rubify_names: true
|
912
|
+
end
|
913
|
+
```
|
914
|
+
|
915
|
+
In more complex cases you can define a descendent of `Flexirest::ProxyBase`, pass it to your model as the proxy and have it rework URLs/parameters on the way out and the response on the way back in (already converted to a Ruby hash/array). By default any non-proxied URLs are just passed through to the underlying connection layer. For example:
|
904
916
|
|
905
917
|
```ruby
|
906
918
|
class ArticleProxy < Flexirest::ProxyBase
|
data/{doc → docs}/FLEXIREST.svg
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
### Expected behaviour
|
2
|
+
|
3
|
+
When I use the (something) method, I get this exception xyz...
|
4
|
+
|
5
|
+
### Desired behaviour
|
6
|
+
|
7
|
+
It should call the remote server correctly and not raise an exception
|
8
|
+
|
9
|
+
### How to reproduce
|
10
|
+
|
11
|
+
1. Clone the Flexirest repo (`git clone https://github.com/flexirest/flexirest.git`)
|
12
|
+
2. Change to the flexirest folder (`cd flexirest`)
|
13
|
+
3. Install any dependencies (`bundle install`)
|
14
|
+
4. Run an interactive console (`rake c`)
|
15
|
+
5. Paste the following:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class MyObject < Flexirest::Base
|
19
|
+
base_url "https://requestb.in"
|
20
|
+
post :create, "/{CREATE_A_PASTEBIN_ID}"
|
21
|
+
end
|
22
|
+
|
23
|
+
my_object = MyObject.new(params: "something")
|
24
|
+
my_object.create
|
25
|
+
# => something is output to the terminal
|
26
|
+
```
|
data/lib/flexirest/request.rb
CHANGED
@@ -8,6 +8,7 @@ module Flexirest
|
|
8
8
|
class Request
|
9
9
|
include AttributeParsing
|
10
10
|
include JsonAPIProxy
|
11
|
+
include ActiveSupport::Inflector
|
11
12
|
attr_accessor :post_params, :get_params, :url, :path, :headers, :method, :object, :body, :forced_url, :original_url, :retrying
|
12
13
|
|
13
14
|
def initialize(method, object, params = {})
|
@@ -584,7 +585,11 @@ module Flexirest
|
|
584
585
|
end
|
585
586
|
|
586
587
|
attributes.each do |k,v|
|
587
|
-
|
588
|
+
if @method[:options][:rubify_names]
|
589
|
+
k = rubify_name(k)
|
590
|
+
else
|
591
|
+
k = k.to_sym
|
592
|
+
end
|
588
593
|
overridden_name = select_name(k, overridden_name)
|
589
594
|
if @method[:options][:lazy].include?(k)
|
590
595
|
object._attributes[k] = Flexirest::LazyAssociationLoader.new(overridden_name, v, self, overridden_name:(overridden_name))
|
@@ -756,6 +761,10 @@ module Flexirest
|
|
756
761
|
end
|
757
762
|
end
|
758
763
|
end
|
764
|
+
|
765
|
+
def rubify_name(k)
|
766
|
+
k.underscore.to_sym
|
767
|
+
end
|
759
768
|
end
|
760
769
|
|
761
770
|
class RequestException < StandardError ; end
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe Flexirest::Request do
|
|
32
32
|
get :find, "/:id", required: [:id]
|
33
33
|
get :change, "/change"
|
34
34
|
get :plain, "/plain/:id", plain: true
|
35
|
-
post :create, "/create"
|
35
|
+
post :create, "/create", rubify_names: true
|
36
36
|
post :test_encoding, "/encoding", request_body_type: :json
|
37
37
|
post :testing_no_content_headers, "/no-content"
|
38
38
|
put :update, "/put/:id"
|
@@ -468,6 +468,7 @@ describe Flexirest::Request do
|
|
468
468
|
object.debug = true
|
469
469
|
object.only_changed_1
|
470
470
|
end
|
471
|
+
|
471
472
|
it "should only send changed attributes within the :only_changed array if :only_changed is an array" do
|
472
473
|
expect_any_instance_of(Flexirest::Connection).to receive(:patch).with("/changed2", "debug2=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}, {\"debug\":\"true\"}]", status:200, response_headers:{})))
|
473
474
|
object = ExampleClient.new
|
@@ -478,6 +479,7 @@ describe Flexirest::Request do
|
|
478
479
|
object.debug2 = true
|
479
480
|
object.only_changed_2
|
480
481
|
end
|
482
|
+
|
481
483
|
it "should only send changed attributes marked true within the :only_changed hash when :only_changed is a hash" do
|
482
484
|
expect_any_instance_of(Flexirest::Connection).to receive(:patch).with("/changed3", "debug1=false&debug2=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}, {\"debug\":\"true\"}]", status:200, response_headers:{})))
|
483
485
|
object = ExampleClient.new
|
@@ -489,6 +491,7 @@ describe Flexirest::Request do
|
|
489
491
|
object.debug2 = true
|
490
492
|
object.only_changed_3
|
491
493
|
end
|
494
|
+
|
492
495
|
it "should always send changed attributes marked false within the :only_changed hash when :only_changed is an hash" do
|
493
496
|
expect_any_instance_of(Flexirest::Connection).to receive(:patch).with("/changed3", "debug1=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}, {\"debug\":\"true\"}]", status:200, response_headers:{})))
|
494
497
|
object = ExampleClient.new
|
@@ -499,7 +502,6 @@ describe Flexirest::Request do
|
|
499
502
|
object.only_changed_3
|
500
503
|
end
|
501
504
|
|
502
|
-
|
503
505
|
it "should instantiate other classes using has_many when required to do so" do
|
504
506
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
|
505
507
|
object = ExampleClient.all
|
@@ -536,6 +538,16 @@ describe Flexirest::Request do
|
|
536
538
|
expect(object.id).to eq(1234)
|
537
539
|
end
|
538
540
|
|
541
|
+
it "should rubify attribute names" do
|
542
|
+
expect_any_instance_of(Flexirest::Connection).
|
543
|
+
to receive(:post).
|
544
|
+
with("/create", "", an_instance_of(Hash)).
|
545
|
+
and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"firstName\":\"John\", \"OtherProperty\":1234}", response_headers:{})))
|
546
|
+
object = ExampleClient.create
|
547
|
+
expect(object.first_name).to eq("John")
|
548
|
+
expect(object.other_property).to eq(1234)
|
549
|
+
end
|
550
|
+
|
539
551
|
it "should expose etag if available" do
|
540
552
|
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
|
541
553
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
@@ -225,11 +225,12 @@ files:
|
|
225
225
|
- README.md
|
226
226
|
- Rakefile
|
227
227
|
- Ruby-on-Rails-Integration.md
|
228
|
-
-
|
229
|
-
-
|
230
|
-
-
|
231
|
-
-
|
232
|
-
-
|
228
|
+
- docs/FLEXIREST.svg
|
229
|
+
- docs/FLEXIREST@2x.png
|
230
|
+
- docs/Flexirest Internals.graffle
|
231
|
+
- docs/Flexirest Internals.png
|
232
|
+
- docs/Flexirest Logo.sketch
|
233
|
+
- docs/issue_template.md
|
233
234
|
- flexirest.gemspec
|
234
235
|
- lib/flexirest.rb
|
235
236
|
- lib/flexirest/associations.rb
|