hyperclient 0.8.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +14 -42
- data/.travis.yml +10 -13
- data/CHANGELOG.md +61 -18
- data/Dangerfile +2 -2
- data/Gemfile +10 -7
- data/LICENSE +1 -1
- data/README.md +47 -36
- data/Rakefile +2 -8
- data/UPGRADING.md +16 -0
- data/features/api_navigation.feature +5 -0
- data/features/steps/api_navigation.rb +17 -4
- data/features/steps/default_config.rb +3 -3
- data/features/support/api.rb +8 -2
- data/features/support/fixtures.rb +96 -2
- data/hyperclient.gemspec +4 -8
- data/lib/hyperclient/collection.rb +1 -1
- data/lib/hyperclient/curie.rb +2 -1
- data/lib/hyperclient/entry_point.rb +15 -9
- data/lib/hyperclient/link.rb +31 -15
- data/lib/hyperclient/link_collection.rb +3 -1
- data/lib/hyperclient/resource.rb +35 -6
- data/lib/hyperclient/resource_collection.rb +3 -1
- data/lib/hyperclient/version.rb +1 -1
- data/test/fixtures/element.json +15 -15
- data/test/hyperclient/attributes_test.rb +9 -9
- data/test/hyperclient/collection_test.rb +15 -15
- data/test/hyperclient/curie_test.rb +4 -4
- data/test/hyperclient/entry_point_test.rb +44 -53
- data/test/hyperclient/link_collection_test.rb +15 -15
- data/test/hyperclient/link_test.rb +53 -239
- data/test/hyperclient/resource_collection_test.rb +6 -6
- data/test/hyperclient/resource_test.rb +40 -24
- data/test/hyperclient_test.rb +9 -10
- data/test/test_helper.rb +8 -9
- metadata +33 -58
- data/lib/faraday/connection.rb +0 -17
- data/test/faraday/connection_test.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f55cb82362d8eca25347e15c91387bbf2957f1f1241af27fccff1086b412d1b
|
4
|
+
data.tar.gz: f31325a293b0aec888b94910b8c3dc28d2f30a6666fe59063b4112251f46e7c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b17e112614d3c600497c6c7cfd56268195427da789629d006742ff96e70d2b6972ba16fbfa075ab62613eeace923d8fdb4f231b9d86a04f82b75fa5d4a4826
|
7
|
+
data.tar.gz: 8a8861e266967702c86d5762ec5b786687298c37e797a5c324583c9d3c9d2fe4dc83cf8841c912db3d14a0bf731d1dbee0c1c85b3d43961589c5741b43b3f128
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,39 +1,14 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2020-12-03 14:08:14 -0500 using RuboCop version 0.81.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 1
|
10
|
-
# Configuration parameters: CountComments.
|
11
|
-
Metrics/ClassLength:
|
12
|
-
Max: 109
|
13
|
-
|
14
|
-
# Offense count: 89
|
15
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
16
|
-
# URISchemes: http, https
|
17
|
-
Metrics/LineLength:
|
18
|
-
Max: 142
|
19
|
-
|
20
|
-
# Offense count: 4
|
21
|
-
# Configuration parameters: CountComments.
|
22
|
-
Metrics/MethodLength:
|
23
|
-
Max: 25
|
24
|
-
|
25
|
-
# Offense count: 3
|
26
|
-
# Configuration parameters: CountComments.
|
27
|
-
Metrics/ModuleLength:
|
28
|
-
Max: 398
|
29
|
-
|
30
|
-
# Offense count: 1
|
31
|
-
Style/AsciiComments:
|
32
|
-
Exclude:
|
33
|
-
- 'lib/hyperclient/collection.rb'
|
34
|
-
|
35
9
|
# Offense count: 2
|
36
|
-
#
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
37
12
|
# SupportedStyles: nested, compact
|
38
13
|
Style/ClassAndModuleChildren:
|
39
14
|
Exclude:
|
@@ -56,25 +31,22 @@ Style/DoubleNegation:
|
|
56
31
|
- 'lib/hyperclient/curie.rb'
|
57
32
|
- 'lib/hyperclient/link.rb'
|
58
33
|
|
59
|
-
# Offense count:
|
34
|
+
# Offense count: 3
|
60
35
|
# Cop supports --auto-correct.
|
61
|
-
|
62
|
-
# SupportedStyles: line_count_dependent, lambda, literal
|
63
|
-
Style/Lambda:
|
36
|
+
Style/IfUnlessModifier:
|
64
37
|
Exclude:
|
65
|
-
- '
|
66
|
-
- '
|
67
|
-
- '
|
38
|
+
- 'lib/hyperclient/link_collection.rb'
|
39
|
+
- 'lib/hyperclient/resource.rb'
|
40
|
+
- 'lib/hyperclient/resource_collection.rb'
|
68
41
|
|
69
42
|
# Offense count: 1
|
70
|
-
Style/
|
43
|
+
Style/MethodMissingSuper:
|
71
44
|
Exclude:
|
72
45
|
- 'lib/hyperclient/collection.rb'
|
73
46
|
|
74
|
-
# Offense count:
|
47
|
+
# Offense count: 101
|
75
48
|
# Cop supports --auto-correct.
|
76
|
-
# Configuration parameters:
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
- 'features/support/api.rb'
|
49
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
50
|
+
# URISchemes: http, https
|
51
|
+
Layout/LineLength:
|
52
|
+
Max: 147
|
data/.travis.yml
CHANGED
@@ -4,24 +4,21 @@ sudo: false
|
|
4
4
|
|
5
5
|
matrix:
|
6
6
|
include:
|
7
|
-
- rvm: 2.
|
7
|
+
- rvm: 2.6.6
|
8
|
+
env: FARADAY_VERSION=0.9.0
|
9
|
+
- rvm: 2.6.6
|
10
|
+
env: FARADAY_VERSION=0.17.0
|
11
|
+
- rvm: 2.6.6
|
12
|
+
env: FARADAY_VERSION="~> 1.0"
|
13
|
+
- rvm: 2.6.6
|
8
14
|
script:
|
9
15
|
- bundle exec danger
|
10
|
-
- rvm: 2.3.
|
11
|
-
- rvm: 2.
|
12
|
-
- rvm: 2.2.5
|
13
|
-
- rvm: 2.4.0
|
14
|
-
- rvm: rbx-2
|
15
|
-
- rvm: ruby-head
|
16
|
+
- rvm: 2.3.8
|
17
|
+
- rvm: jruby-9.2.7.0
|
16
18
|
- rvm: jruby-head
|
17
|
-
- rvm:
|
19
|
+
- rvm: ruby-head
|
18
20
|
allow_failures:
|
19
21
|
- rvm: ruby-head
|
20
22
|
- rvm: jruby-head
|
21
|
-
- rvm: rbx-2
|
22
|
-
|
23
|
-
before_install:
|
24
|
-
- gem update --system
|
25
|
-
- gem install bundler
|
26
23
|
|
27
24
|
bundler_args: --without development
|
data/CHANGELOG.md
CHANGED
@@ -1,56 +1,99 @@
|
|
1
|
-
|
1
|
+
## Changelog
|
2
|
+
|
3
|
+
### 1.0.1 (2021/01/02)
|
4
|
+
|
5
|
+
* [#193](https://github.com/codegram/hyperclient/pull/193): Auto-paginate collections - [@dblock](https://github.com/dblock).
|
6
|
+
* [#163](https://github.com/codegram/hyperclient/pull/163): Test against Faraday 0.9, 0.17 and 1.0+ - [@dblock](https://github.com/dblock).
|
7
|
+
* [#199](https://github.com/codegram/hyperclient/pull/199): Use digest_auth from faraday-digestauth - [@dblock](https://github.com/dblock).
|
8
|
+
|
9
|
+
### 1.0.0 (2021/01/02)
|
10
|
+
|
11
|
+
* NOTE: **⚠ This version has been yanked ⚠** - [@dblock](https://github.com/dblock).
|
12
|
+
|
13
|
+
### 0.9.3 (2020/05/14)
|
14
|
+
|
15
|
+
* [#149](https://github.com/codegram/hyperclient/pull/149): Address Faraday warnings - [@yuki24](https://github.com/yuki24).
|
16
|
+
* [#160](https://github.com/codegram/hyperclient/pull/160): Require newer 'faraday-digestauth' - [@dblock](https://github.com/dblock).
|
17
|
+
|
18
|
+
### 0.9.2 (2020/05/12)
|
19
|
+
|
20
|
+
* NOTE: **⚠ This version has been yanked ⚠** - [@dblock](https://github.com/dblock).
|
21
|
+
|
22
|
+
### 0.9.1 (2019/08/25)
|
23
|
+
|
24
|
+
* NOTE: **⚠ This version is no longer tested with Ruby < 2.3 ⚠** - [@ivoanjo](https://github.com/ivoanjo).
|
25
|
+
|
26
|
+
* [#135](https://github.com/codegram/hyperclient/pull/135): Fix validation for empty body responses - [@paulocdf](https://github.com/paulocdf).
|
27
|
+
* [#139](https://github.com/codegram/hyperclient/pull/139): Test `hyperclient` against newer versions of MRI Ruby, up until 2.6.x - [@mrcasals](https://github.com/mrcasals).
|
28
|
+
* [#141](https://github.com/codegram/hyperclient/pull/141): Replace `uri_template` with `addressable` library - [@mrcasals](https://github.com/mrcasals).
|
29
|
+
* [#136](https://github.com/codegram/hyperclient/pull/136), [#146](https://github.com/codegram/hyperclient/pull/146): Upgraded Danger plugins - [@dblock](https://github.com/dblock), [@ivoanjo](https://github.com/ivoanjo).
|
30
|
+
|
31
|
+
### 0.9.0 (2018/01/10)
|
32
|
+
|
33
|
+
* [#133](https://github.com/codegram/hyperclient/pull/133): Removed futuroscope - [@dblock](https://github.com/dblock).
|
34
|
+
* [#131](https://github.com/codegram/hyperclient/pull/131): Upgrade to Rubocop 0.50.0, fix Bundler's insecure git source warning - [@nebolsin](https://github.com/nebolsin).
|
35
|
+
* [#132](https://github.com/codegram/hyperclient/pull/132): Swapped yard dependency for danger-toc - [@dblock](https://github.com/dblock).
|
36
|
+
|
37
|
+
### 0.8.6 (2017/08/27)
|
38
|
+
|
39
|
+
* [#122](https://github.com/codegram/hyperclient/pull/122): Improve error message when server returns invalid data - [@ivoanjo](https://github.com/ivoanjo).
|
40
|
+
* [#125](https://github.com/codegram/hyperclient/pull/125): Add table of contents to readme and add note asking users to add their projects to the wiki - [@ivoanjo](https://github.com/ivoanjo).
|
41
|
+
* [#127](https://github.com/codegram/hyperclient/pull/127): Minor fixes: Fix warnings, and pry-byebug to dev Gemfile and tweak rubocop execution - [@ivoanjo](https://github.com/ivoanjo).
|
42
|
+
* [#128](https://github.com/codegram/hyperclient/pull/128): Fix link delegation returning nil for field with value false - [@ivoanjo](https://github.com/ivoanjo).
|
43
|
+
|
44
|
+
### 0.8.5 (2017/07/05)
|
2
45
|
|
3
46
|
* [#120](https://github.com/codegram/hyperclient/pull/120): Replace non-working homepage link in gemspec - [@ivoanjo](https://github.com/ivoanjo).
|
4
47
|
|
5
|
-
### 0.8.4 (
|
48
|
+
### 0.8.4 (2017/05/16)
|
6
49
|
|
7
50
|
* [#117](https://github.com/codegram/hyperclient/issues/117): Require Faraday >= 0.9.0 in gemspec - [@ivoanjo](https://github.com/ivoanjo).
|
8
51
|
|
9
|
-
### 0.8.3 (
|
52
|
+
### 0.8.3 (2017/03/30)
|
10
53
|
|
11
54
|
* [#115](https://github.com/codegram/hyperclient/pull/115): Fix dropped values from queries by using FlatParamsEncoder - [@ivoanjo](https://github.com/ivoanjo).
|
12
55
|
|
13
|
-
### 0.8.2 (
|
56
|
+
### 0.8.2 (2016/12/31)
|
14
57
|
|
15
|
-
|
58
|
+
* NOTE: **⚠ This version is no longer tested with Ruby < 2.2 ⚠** - [@dblock](https://github.com/dblock).
|
16
59
|
|
17
60
|
* [#105](https://github.com/codegram/hyperclient/pull/105), [#108](https://github.com/codegram/hyperclient/pull/108): Added Danger, PR linter - [@dblock](https://github.com/dblock).
|
18
61
|
* [#109](https://github.com/codegram/hyperclient/pull/109): Allow disabling asynchronous behavior per-instance - [@Talkdesk](https://github.com/Talkdesk).
|
19
62
|
* [#110](https://github.com/codegram/hyperclient/pull/110): Fixed ruby warnings - [@ivoanjo](https://github.com/ivoanjo).
|
20
63
|
|
21
|
-
### 0.8.1 (
|
64
|
+
### 0.8.1 (2016/03/15)
|
22
65
|
|
23
66
|
* [#97](https://github.com/codegram/hyperclient/issues/97): Fix: curies are no longer used as link shorteners - [@joshco](https://github.com/joshco), [@dblock](https://github.com/dblock).
|
24
67
|
* [#95](https://github.com/codegram/hyperclient/issues/95): Fix: re-add eager delegation for `resource.each` - [@dblock](https://github.com/dblock).
|
25
68
|
|
26
|
-
### 0.7.2 (
|
69
|
+
### 0.7.2 (2015/08/23)
|
27
70
|
|
28
71
|
* [#95](https://github.com/codegram/hyperclient/issues/95): Fix: re-add eager delegation for `resource.x._embeddded.x` - [@dblock](https://github.com/dblock).
|
29
72
|
|
30
|
-
### 0.7.1 (
|
73
|
+
### 0.7.1 (2015/08/15)
|
31
74
|
|
32
75
|
* [#89](https://github.com/codegram/hyperclient/issues/89): Added `Hyperclient::Resource#fetch` - [@alabeduarte](https://github.com/alabeduarte).
|
33
76
|
* [#87](https://github.com/codegram/hyperclient/pull/87): Fix: eager delegation causes link skipping - [@dblock](https://github.com/dblock).
|
34
77
|
|
35
|
-
### 0.7.0 (
|
78
|
+
### 0.7.0 (2015/02/23)
|
36
79
|
|
37
|
-
|
80
|
+
* NOTE: **⚠ This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details ⚠** - [@dblock](https://github.com/dblock).
|
38
81
|
|
39
82
|
* [#80](https://github.com/codegram/hyperclient/pull/80): Faraday options can be passed to the connection on initialization - [@koenpunt](https://github.com/koenpunt).
|
40
83
|
* [#81](https://github.com/codegram/hyperclient/pull/81): The default Content-Type is now `application/hal+json` - [@koenpunt](https://github.com/koenpunt).
|
41
84
|
|
42
|
-
### 0.6.1 (
|
85
|
+
### 0.6.1 (2014/10/17)
|
43
86
|
|
44
|
-
|
87
|
+
* NOTE: **⚠ This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details ⚠** - [@dblock](https://github.com/dblock).
|
45
88
|
|
46
89
|
* [#51](https://github.com/codegram/hyperclient/issues/51), [#75](https://github.com/codegram/hyperclient/pull/75): Added support for setting headers and overriding or extending the default Faraday connection block before a connection is constructed - [@dblock](https://github.com/dblock).
|
47
90
|
* [#41](https://github.com/codegram/hyperclient/issues/41), [#73](https://github.com/codegram/hyperclient/pull/73): All Link HTTP methods now return a Resource, including `_get`, which has been aliased to `_resource`, `_post`, `_put`, `_patch`, `_head` and `_options` - [@dblock](https://github.com/dblock).
|
48
91
|
* [#72](https://github.com/codegram/hyperclient/pull/72): The default Faraday block now uses `Faraday::Response::RaiseError` and will cause HTTP errors to be raised as exceptions - [@dblock](https://github.com/dblock).
|
49
92
|
* [#77](https://github.com/codegram/hyperclient/pull/77): Added support for templated links with all optional arguments - [@dblock](https://github.com/dblock).
|
50
93
|
|
51
|
-
### 0.5.0 (
|
94
|
+
### 0.5.0 (2014/10/01)
|
52
95
|
|
53
|
-
|
96
|
+
* NOTE: **⚠ This version introduces several backwards incompatible changes. See [UPGRADING](UPGRADING.md) for details ⚠** - [@dblock](https://github.com/dblock).
|
54
97
|
|
55
98
|
* [#63](https://github.com/codegram/hyperclient/pull/63): Navigational methods, including `links`, `get` or `post`, have been renamed to `_links`, `_get`, or `_post` respectively - [@dblock](https://github.com/dblock).
|
56
99
|
* [#64](https://github.com/codegram/hyperclient/issues/64): Added support for curies - [@dblock](https://github.com/dblock).
|
@@ -58,12 +101,12 @@
|
|
58
101
|
* [#63](https://github.com/codegram/hyperclient/pull/63): You can omit the navigational elements, `api.links.products` is now equivalent to `api.products` - [@dblock](https://github.com/dblock).
|
59
102
|
* [#61](https://github.com/codegram/hyperclient/pull/61): Implemented Rubocop, Ruby-style linter - [@dblock](https://github.com/dblock).
|
60
103
|
|
61
|
-
### 0.4.0 (
|
104
|
+
### 0.4.0 (2014/05/05)
|
62
105
|
|
63
106
|
* [#54](https://github.com/codegram/hyperclient/pull/54): Support Faraday 0.9.0 - [@lucianapazos](https://github.com/lucianapazos).
|
64
107
|
* [#30](https://github.com/codegram/hyperclient/pull/30): Use futuroscope to run API calls in the background - [@josepjaume](https://github.com/josepjaume).
|
65
108
|
|
66
|
-
### 0.3.2 (
|
109
|
+
### 0.3.2 (2013/12/20)
|
67
110
|
|
68
111
|
* [#48](https://github.com/codegram/hyperclient/pull/48): Added support for fetch on the collection class - [@col](https://github.com/col).
|
69
112
|
* [#50](https://github.com/codegram/hyperclient/pull/50): Fixed Resource/Attributes mutating the response body - [@col](https://github.com/col).
|
@@ -77,10 +120,10 @@
|
|
77
120
|
* [#31](https://github.com/codegram/hyperclient/pull/31): Allowed underscored attribute names other than the ones reserved by the HAL spec - [@karlin](https://github.com/karlin).
|
78
121
|
* [#29](https://github.com/codegram/hyperclient/pull/29): Handled JSON that includes a link with a null value - [@arbylee](https://github.com/arbylee).
|
79
122
|
|
80
|
-
### 0.3.1 (
|
123
|
+
### 0.3.1 (2013/04/03)
|
81
124
|
|
82
125
|
* [#27](https://github.com/codegram/hyperclient/pull/27): Added support for collections of links - [@rehevkor5](https://github.com/rehevkor5).
|
83
126
|
|
84
|
-
### 0.3.0 (
|
127
|
+
### 0.3.0 (2013/02/03)
|
85
128
|
|
86
129
|
* Initial public release - [@oriolgual](https://github.com/oriolgual).
|
data/Dangerfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
changelog.check!
|
2
|
+
toc.check!
|
data/Gemfile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
# NOTE: this is temporary until Bundler 2.0 changes how github: references work.
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo['/'] ? repo : "#{repo}/#{repo}"}.git" }
|
3
|
+
|
1
4
|
source 'https://rubygems.org'
|
2
5
|
|
6
|
+
gem 'faraday', ENV['FARADAY_VERSION'] if ENV.key?('FARADAY_VERSION')
|
7
|
+
|
3
8
|
gemspec
|
4
9
|
|
5
10
|
group :development do
|
@@ -8,23 +13,21 @@ group :development do
|
|
8
13
|
gem 'guard-minitest'
|
9
14
|
gem 'guard-spinach'
|
10
15
|
gem 'pry'
|
16
|
+
gem 'pry-byebug', platforms: :ruby
|
11
17
|
end
|
12
18
|
|
13
19
|
group :development, :test do
|
14
|
-
gem 'yard', '~> 0.8'
|
15
|
-
gem 'yard-tomdoc'
|
16
20
|
gem 'rake'
|
21
|
+
gem 'rubocop', '0.81.0', require: false
|
17
22
|
gem 'simplecov', require: false
|
18
|
-
gem 'rubocop', '~> 0.42.0', require: false
|
19
23
|
end
|
20
24
|
|
21
25
|
group :test do
|
22
|
-
gem '
|
23
|
-
gem 'danger-
|
26
|
+
gem 'danger-changelog', '~> 0.6.0'
|
27
|
+
gem 'danger-toc', '~> 0.2.0'
|
24
28
|
gem 'minitest'
|
25
|
-
gem 'turn'
|
26
|
-
gem 'webmock'
|
27
29
|
gem 'mocha'
|
28
30
|
gem 'rack-test'
|
29
31
|
gem 'spinach'
|
32
|
+
gem 'webmock'
|
30
33
|
end
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,17 +2,32 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](http://img.shields.io/gem/v/hyperclient.svg)](http://badge.fury.io/rb/hyperclient)
|
4
4
|
[![Build Status](http://img.shields.io/travis/codegram/hyperclient.svg)](https://travis-ci.org/codegram/hyperclient)
|
5
|
-
[![Dependency Status](https://gemnasium.com/codegram/hyperclient.svg)](https://gemnasium.com/codegram/hyperclient)
|
6
5
|
[![Code Climate](https://codeclimate.com/github/codegram/hyperclient.svg)](https://codeclimate.com/github/codegram/hyperclient)
|
7
6
|
[![Coverage Status](https://img.shields.io/coveralls/codegram/hyperclient.svg)](https://coveralls.io/r/codegram/hyperclient?branch=master)
|
8
7
|
|
9
8
|
Hyperclient is a Hypermedia API client written in Ruby. It fully supports [JSON HAL](http://stateless.co/hal_specification.html).
|
10
9
|
|
11
|
-
|
10
|
+
# Table of Contents
|
11
|
+
|
12
|
+
- [Usage](#usage)
|
13
|
+
- [API Client](#api-client)
|
14
|
+
- [Resources and Attributes](#resources-and-attributes)
|
15
|
+
- [Links and Embedded Resources](#links-and-embedded-resources)
|
16
|
+
- [Templated Links](#templated-links)
|
17
|
+
- [Curies](#curies)
|
18
|
+
- [Attributes](#attributes)
|
19
|
+
- [HTTP](#http)
|
20
|
+
- [Testing Using Hyperclient](#testing-using-hyperclient)
|
21
|
+
- [Reference](#reference)
|
22
|
+
- [Hyperclient Users](#hyperclient-users)
|
23
|
+
- [Contributing](#contributing)
|
24
|
+
- [License](#license)
|
25
|
+
|
26
|
+
# Usage
|
12
27
|
|
13
28
|
The examples in this README use the [Splines Demo API](https://github.com/ruby-grape/grape-with-roar) running [here](https://grape-with-roar.herokuapp.com/api). If you're upgrading from a previous version, please make sure to read [UPGRADING](UPGRADING.md).
|
14
29
|
|
15
|
-
|
30
|
+
## API Client
|
16
31
|
|
17
32
|
Create an API client.
|
18
33
|
|
@@ -70,12 +85,19 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
|
|
70
85
|
end
|
71
86
|
```
|
72
87
|
|
73
|
-
You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or Digest auth as well as many other Faraday extensions.
|
88
|
+
You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or [Digest auth](https://github.com/bhaberer/faraday-digestauth) as well as many other Faraday extensions.
|
74
89
|
|
75
90
|
```ruby
|
76
|
-
|
77
|
-
|
78
|
-
api.
|
91
|
+
require 'faraday/digestauth'
|
92
|
+
|
93
|
+
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
|
94
|
+
client.connection(default: false) do |conn|
|
95
|
+
conn.request :digest, 'username', 'password'
|
96
|
+
conn.request :json
|
97
|
+
conn.response :json, content_type: /\bjson$/
|
98
|
+
conn.adapter :net_http
|
99
|
+
end
|
100
|
+
end
|
79
101
|
```
|
80
102
|
|
81
103
|
You can access the Faraday connection directly after it has been created and add middleware to it. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache).
|
@@ -85,9 +107,9 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
|
|
85
107
|
api.connection.use :http_cache
|
86
108
|
```
|
87
109
|
|
88
|
-
|
110
|
+
## Resources and Attributes
|
89
111
|
|
90
|
-
Hyperclient will fetch and discover the resources from your API.
|
112
|
+
Hyperclient will fetch and discover the resources from your API and automatically paginate when possible.
|
91
113
|
|
92
114
|
```ruby
|
93
115
|
api.splines.each do |spline|
|
@@ -104,7 +126,7 @@ api.splines.each do |spline|
|
|
104
126
|
end
|
105
127
|
```
|
106
128
|
|
107
|
-
|
129
|
+
## Links and Embedded Resources
|
108
130
|
|
109
131
|
The splines example above followed a link called "splines". While you can, you do not need to specify the HAL navigational structure, including links or embedded resources. Hyperclient will resolve these for you. If you prefer, you can explicitly navigate the link structure via `_links`. In the following example the "splines" link leads to a collection of embedded splines. Invoking `api.splines` is equivalent to `api._links.splines._embedded.splines`.
|
110
132
|
|
@@ -112,7 +134,7 @@ The splines example above followed a link called "splines". While you can, you d
|
|
112
134
|
api._links.splines
|
113
135
|
```
|
114
136
|
|
115
|
-
|
137
|
+
## Templated Links
|
116
138
|
|
117
139
|
Templated links require variables to be expanded. For example, the demo API has a link called "spline" that requires a spline "uuid".
|
118
140
|
|
@@ -125,7 +147,7 @@ Invoking `api.spline(uuid: 'uuid').reticulated` is equivalent to `api._links.spl
|
|
125
147
|
|
126
148
|
The client is responsible for supplying all the necessary parameters. Templated links don't do any strict parameter name checking and don't support required vs. optional parameters. Parameters not declared by the API will be dropped and will not have any effect when passed to `_expand`.
|
127
149
|
|
128
|
-
|
150
|
+
## Curies
|
129
151
|
|
130
152
|
Curies are a suggested means by which to link documentation of a given resource. For example, the demo API contains very long links to images that use an "images" curie.
|
131
153
|
|
@@ -134,7 +156,7 @@ puts spline['image:thumbnail'] # => https://grape-with-roar.herokuapp.com/api/sp
|
|
134
156
|
puts spline.links._curies['image'].expand('thumbnail') # => /docs/images/thumbnail
|
135
157
|
```
|
136
158
|
|
137
|
-
|
159
|
+
## Attributes
|
138
160
|
|
139
161
|
Resource attributes can also be accessed as a hash.
|
140
162
|
|
@@ -144,7 +166,7 @@ puts spline.to_h # => {"uuid" => "uuid", "reticulated" => true}
|
|
144
166
|
|
145
167
|
The above is equivalent to `spline._attributes.to_h`.
|
146
168
|
|
147
|
-
|
169
|
+
## HTTP
|
148
170
|
|
149
171
|
Hyperclient uses [Faraday](http://github.com/lostisland/faraday) under the hood to perform HTTP calls. You can call any valid HTTP method on any resource.
|
150
172
|
|
@@ -187,24 +209,7 @@ spline._delete
|
|
187
209
|
|
188
210
|
HTTP methods always return a new instance of Resource.
|
189
211
|
|
190
|
-
|
191
|
-
|
192
|
-
By default, Hyperclient requests are performed asynchronously in a background thread pool via the [Futuroscope](https://github.com/codegram/futuroscope) gem. You can control the size of this pool by setting the `min_workers` and `max_workers` settings:
|
193
|
-
|
194
|
-
```ruby
|
195
|
-
Futuroscope.default_pool.min_workers = 10
|
196
|
-
Futuroscope.default_pool.max_workers = 20
|
197
|
-
```
|
198
|
-
|
199
|
-
If you want to disable this behavior and have all requests performed synchronously, you can use the client `options` to disable this behavior:
|
200
|
-
|
201
|
-
```ruby
|
202
|
-
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
|
203
|
-
client.options[:async] = false
|
204
|
-
end
|
205
|
-
```
|
206
|
-
|
207
|
-
## Testing Using Hyperclient
|
212
|
+
# Testing Using Hyperclient
|
208
213
|
|
209
214
|
You can combine RSpec, Faraday::Adapter::Rack and Hyperclient to test your HAL API without having to ever examine the raw JSON response.
|
210
215
|
|
@@ -233,14 +238,20 @@ end
|
|
233
238
|
|
234
239
|
For a complete example refer to [this Splines Demo API test](https://github.com/ruby-grape/grape-with-roar/blob/master/spec/api/splines_endpoint_with_hyperclient_spec.rb).
|
235
240
|
|
236
|
-
|
241
|
+
# Reference
|
237
242
|
|
238
243
|
[Hyperclient API Reference](http://rubydoc.org/github/codegram/hyperclient/master/frames).
|
239
244
|
|
240
|
-
|
245
|
+
# Hyperclient Users
|
246
|
+
|
247
|
+
Using Hyperclient? Add your project to our wiki, please: <https://github.com/codegram/hyperclient/wiki>.
|
248
|
+
|
249
|
+
# Contributing
|
241
250
|
|
242
251
|
Hyperclient is work of [many people](https://github.com/codegram/hyperclient/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/codegram/hyperclient/pulls), [propose features and discuss issues](https://github.com/codegram/hyperclient/issues). See [CONTRIBUTING](CONTRIBUTING.md) for details.
|
243
252
|
|
244
|
-
|
253
|
+
# License
|
254
|
+
|
255
|
+
MIT License, see [LICENSE](LICENSE) for details.
|
245
256
|
|
246
|
-
|
257
|
+
Copyright (c) 2012-2018 Oriol Gual, [Codegram Technologies](http://codegram.com) and Contributors
|