hyperclient 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/coverage.yml +14 -10
- data/.github/workflows/danger-comment.yml +18 -0
- data/.github/workflows/danger.yml +8 -17
- data/.github/workflows/lint.yml +10 -3
- data/.github/workflows/release.yml +26 -0
- data/.github/workflows/test.yml +21 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +8 -5
- data/AGENTS.md +26 -0
- data/CHANGELOG.md +25 -4
- data/CONTRIBUTING.md +10 -0
- data/Dangerfile +2 -0
- data/Gemfile +14 -3
- data/README.md +110 -41
- data/RELEASING.md +32 -43
- data/Rakefile +18 -0
- data/examples/oxford/README.md +42 -0
- data/examples/oxford/app.rb +48 -0
- data/examples/oxford/client.rb +14 -0
- data/examples/oxford/places.json +21 -0
- data/examples/oxford/server.rb +13 -0
- data/features/support/env.rb +2 -1
- data/gemfiles/release.gemfile +6 -0
- data/lib/hyperclient/entry_point.rb +14 -0
- data/lib/hyperclient/link.rb +133 -8
- data/lib/hyperclient/resource.rb +27 -0
- data/lib/hyperclient/version.rb +1 -1
- data/test/hyperclient/attributes_test.rb +9 -0
- data/test/hyperclient/collection_test.rb +22 -0
- data/test/hyperclient/curie_test.rb +7 -0
- data/test/hyperclient/entry_point_test.rb +36 -0
- data/test/hyperclient/link_collection_test.rb +10 -0
- data/test/hyperclient/link_test.rb +434 -1
- data/test/hyperclient/resource_test.rb +65 -1
- data/test/hyperclient_test.rb +1 -0
- data/test/oxford_example_test.rb +63 -0
- data/test/test_helper.rb +1 -2
- metadata +13 -8
- data/.DS_Store +0 -0
- data/examples/splines_api.rb +0 -39
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'hyperclient'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
require_relative '../examples/oxford/app'
|
|
6
|
+
|
|
7
|
+
describe OxfordExample::App do
|
|
8
|
+
let(:app) { OxfordExample::App.new }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
WebMock.enable!
|
|
12
|
+
WebMock.stub_request(:any, %r{\Ahttp://127\.0\.0\.1:9292/}).to_return do |request|
|
|
13
|
+
status, headers, body = app.call('REQUEST_METHOD' => request.method.to_s.upcase,
|
|
14
|
+
'PATH_INFO' => request.uri.path)
|
|
15
|
+
{ status: status, headers: headers, body: body.join }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
after do
|
|
20
|
+
WebMock.reset!
|
|
21
|
+
WebMock.disable!
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'runs the documented client without external requests' do
|
|
25
|
+
output, = capture_io { load File.expand_path('../examples/oxford/client.rb', __dir__) }
|
|
26
|
+
|
|
27
|
+
_(output).must_include 'Balliol College: Broad Street OX1 3BJ'
|
|
28
|
+
_(output).must_include 'Followed primary_place: Balliol College'
|
|
29
|
+
_(output).must_include 'Archived depiction URL (not fetched):'
|
|
30
|
+
_(output).must_include 'CURIE: /docs/places'
|
|
31
|
+
_(output).must_include 'Places profile: /docs/places'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'supports explicit navigation, hash attributes, and embedded resources' do
|
|
35
|
+
api = Hyperclient.new('http://127.0.0.1:9292/')
|
|
36
|
+
place = api._links.places._embedded.places.first
|
|
37
|
+
|
|
38
|
+
_(place[:name]).must_equal 'Balliol College'
|
|
39
|
+
_(place.to_h['id']).must_equal 'oxpoints:23232339'
|
|
40
|
+
_(place._embedded.files.first.type).must_equal 'depiction'
|
|
41
|
+
_(api._links['oxford:places']._embedded.places.first.name).must_equal 'Balliol College'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'exposes link properties, including a profile that can be fetched' do
|
|
45
|
+
api = Hyperclient.new('http://127.0.0.1:9292/')
|
|
46
|
+
places = api._links.places
|
|
47
|
+
|
|
48
|
+
_(places._title).must_equal 'Oxford places'
|
|
49
|
+
_(places._profile).must_equal '/docs/places'
|
|
50
|
+
_(places._deprecation).must_be_nil
|
|
51
|
+
_(api.connection.get(places._profile).body['description']).must_include 'Oxford place facts'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'serves HAL, rejects writes, and reports missing resources' do
|
|
55
|
+
status, headers, = app.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/')
|
|
56
|
+
|
|
57
|
+
_(status).must_equal 200
|
|
58
|
+
_(headers['content-type']).must_equal 'application/hal+json'
|
|
59
|
+
_(app.call('REQUEST_METHOD' => 'POST', 'PATH_INFO' => '/').first).must_equal 405
|
|
60
|
+
_(app.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/missing').first).must_equal 404
|
|
61
|
+
_(app.call('REQUEST_METHOD' => 'HEAD', 'PATH_INFO' => '/').last).must_equal []
|
|
62
|
+
end
|
|
63
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -17,14 +17,13 @@ end
|
|
|
17
17
|
|
|
18
18
|
require 'minitest/autorun'
|
|
19
19
|
require 'minitest/pride'
|
|
20
|
-
require 'minitest/unit'
|
|
21
20
|
require 'mocha/minitest'
|
|
22
21
|
require 'json'
|
|
23
22
|
|
|
24
23
|
require 'faraday'
|
|
25
24
|
require 'faraday/request/instrumentation'
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
Minitest::Assertions.class_eval do
|
|
28
27
|
def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
|
|
29
28
|
adapter_handler = conn.builder.handlers.find { |h| h.klass < Faraday::Adapter }
|
|
30
29
|
if adapter_handler
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hyperclient
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oriol Gual
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: addressable
|
|
@@ -73,16 +72,18 @@ executables: []
|
|
|
73
72
|
extensions: []
|
|
74
73
|
extra_rdoc_files: []
|
|
75
74
|
files:
|
|
76
|
-
- ".DS_Store"
|
|
77
75
|
- ".github/dependabot.yml"
|
|
78
76
|
- ".github/workflows/coverage.yml"
|
|
77
|
+
- ".github/workflows/danger-comment.yml"
|
|
79
78
|
- ".github/workflows/danger.yml"
|
|
80
79
|
- ".github/workflows/lint.yml"
|
|
80
|
+
- ".github/workflows/release.yml"
|
|
81
81
|
- ".github/workflows/test.yml"
|
|
82
82
|
- ".gitignore"
|
|
83
83
|
- ".rubocop.yml"
|
|
84
84
|
- ".rubocop_todo.yml"
|
|
85
85
|
- ".yardopts"
|
|
86
|
+
- AGENTS.md
|
|
86
87
|
- CHANGELOG.md
|
|
87
88
|
- CONTRIBUTING.md
|
|
88
89
|
- Dangerfile
|
|
@@ -93,7 +94,11 @@ files:
|
|
|
93
94
|
- RELEASING.md
|
|
94
95
|
- Rakefile
|
|
95
96
|
- UPGRADING.md
|
|
96
|
-
- examples/
|
|
97
|
+
- examples/oxford/README.md
|
|
98
|
+
- examples/oxford/app.rb
|
|
99
|
+
- examples/oxford/client.rb
|
|
100
|
+
- examples/oxford/places.json
|
|
101
|
+
- examples/oxford/server.rb
|
|
97
102
|
- features/api_navigation.feature
|
|
98
103
|
- features/default_config.feature
|
|
99
104
|
- features/steps/api_navigation.rb
|
|
@@ -101,6 +106,7 @@ files:
|
|
|
101
106
|
- features/support/api.rb
|
|
102
107
|
- features/support/env.rb
|
|
103
108
|
- features/support/fixtures.rb
|
|
109
|
+
- gemfiles/release.gemfile
|
|
104
110
|
- hyperclient.gemspec
|
|
105
111
|
- lib/hyperclient.rb
|
|
106
112
|
- lib/hyperclient/attributes.rb
|
|
@@ -124,12 +130,12 @@ files:
|
|
|
124
130
|
- test/hyperclient/resource_collection_test.rb
|
|
125
131
|
- test/hyperclient/resource_test.rb
|
|
126
132
|
- test/hyperclient_test.rb
|
|
133
|
+
- test/oxford_example_test.rb
|
|
127
134
|
- test/test_helper.rb
|
|
128
135
|
homepage: https://github.com/codegram/hyperclient/
|
|
129
136
|
licenses: []
|
|
130
137
|
metadata:
|
|
131
138
|
rubygems_mfa_required: 'true'
|
|
132
|
-
post_install_message:
|
|
133
139
|
rdoc_options: []
|
|
134
140
|
require_paths:
|
|
135
141
|
- lib
|
|
@@ -144,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
150
|
- !ruby/object:Gem::Version
|
|
145
151
|
version: '0'
|
|
146
152
|
requirements: []
|
|
147
|
-
rubygems_version:
|
|
148
|
-
signing_key:
|
|
153
|
+
rubygems_version: 4.0.20
|
|
149
154
|
specification_version: 4
|
|
150
155
|
summary: ''
|
|
151
156
|
test_files: []
|
data/.DS_Store
DELETED
|
Binary file
|
data/examples/splines_api.rb
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'hyperclient'
|
|
2
|
-
|
|
3
|
-
puts "Using Hyperclient #{Hyperclient::VERSION} ..."
|
|
4
|
-
|
|
5
|
-
# create a new client
|
|
6
|
-
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
|
|
7
|
-
|
|
8
|
-
# enumerate splines
|
|
9
|
-
api.splines.each do |spline|
|
|
10
|
-
puts spline.uuid.to_s
|
|
11
|
-
puts " reticulated: #{spline.reticulated ? 'yes' : 'no'}"
|
|
12
|
-
puts " thumbnail: #{spline['images:thumbnail']}"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
api._links.splines._embedded.splines.each do |_spline|
|
|
16
|
-
# ... equivalent to the above
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
puts '*' * 10
|
|
20
|
-
|
|
21
|
-
# retrieve an existing spline
|
|
22
|
-
spline = api.spline(uuid: 123)
|
|
23
|
-
puts "Spline #{spline.uuid} is #{spline.reticulated ? 'reticulated' : 'not reticulated'}."
|
|
24
|
-
|
|
25
|
-
# puts api._links.spline._expand(uuid: 'uuid')._resource._attributes.reticulated
|
|
26
|
-
|
|
27
|
-
# spline.to_h
|
|
28
|
-
|
|
29
|
-
# create a new spline
|
|
30
|
-
spline = api.splines._post(spline: { reticulated: true })
|
|
31
|
-
puts "Created a #{spline.reticulated ? 'reticulated' : 'unreticulated'} spline #{spline.uuid}."
|
|
32
|
-
|
|
33
|
-
# update an existing spline
|
|
34
|
-
spline = api.spline(uuid: 123)._put(spline: { reticulated: true })
|
|
35
|
-
puts "Updated spline #{spline.uuid}, now #{spline.reticulated ? 'reticulated' : 'not reticulated'}."
|
|
36
|
-
|
|
37
|
-
# delete an existing spline
|
|
38
|
-
spline = api.spline(uuid: 123)._delete
|
|
39
|
-
puts "Deleted spline #{spline.uuid}."
|