excon-hypermedia 0.3.0 → 0.4.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/README.md +194 -30
- data/lib/excon/hypermedia/ext/response.rb +2 -0
- data/lib/excon/hypermedia/helpers/collection.rb +62 -0
- data/lib/excon/hypermedia/link_object.rb +153 -0
- data/lib/excon/hypermedia/middleware.rb +2 -0
- data/lib/excon/hypermedia/resource_object/embedded.rb +23 -0
- data/lib/excon/hypermedia/resource_object/links.rb +19 -0
- data/lib/excon/hypermedia/resource_object/properties.rb +17 -0
- data/lib/excon/hypermedia/resource_object.rb +69 -0
- data/lib/excon/hypermedia/response.rb +18 -11
- data/lib/excon/hypermedia/version.rb +1 -1
- data/lib/excon/hypermedia.rb +4 -2
- data/test/excon/integration_test.rb +99 -0
- data/test/excon/link_object_test.rb +91 -0
- data/test/excon/links_test.rb +43 -0
- data/test/excon/properties_test.rb +67 -0
- data/test/excon/resource_object_test.rb +49 -0
- data/test/test_helper.rb +141 -0
- metadata +13 -7
- data/lib/excon/hypermedia/link.rb +0 -40
- data/lib/excon/hypermedia/resource.rb +0 -49
- data/test/excon/hypermedia_test.rb +0 -100
- data/test/excon/link_test.rb +0 -56
- data/test/excon/resource_test.rb +0 -47
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Metrics/LineLength
|
4
|
-
require_relative '../test_helper'
|
5
|
-
|
6
|
-
module Excon
|
7
|
-
# HypermediaTest
|
8
|
-
#
|
9
|
-
# Verifies the Excon connection consuming HyperMedia APIs.
|
10
|
-
#
|
11
|
-
class HypermediaTest < Minitest::Test
|
12
|
-
def entrypoint
|
13
|
-
'{ "_links": { "hello": { "href":"http://www.example.com/hello/{location}" } } }'
|
14
|
-
end
|
15
|
-
|
16
|
-
def hello_world # rubocop:disable Metrics/MethodLength
|
17
|
-
<<~EOF
|
18
|
-
{
|
19
|
-
"_links": {
|
20
|
-
"goodbye": {
|
21
|
-
"href":"http://www.example.com/hello/world/goodbye{?message}"
|
22
|
-
}
|
23
|
-
},
|
24
|
-
"uid": "hello",
|
25
|
-
"message": "goodbye!"
|
26
|
-
}
|
27
|
-
EOF
|
28
|
-
end
|
29
|
-
|
30
|
-
def setup
|
31
|
-
Excon.defaults[:mock] = true
|
32
|
-
Excon.defaults[:middlewares].push(Excon::HyperMedia::Middleware)
|
33
|
-
|
34
|
-
response = { headers: { 'Content-Type' => 'application/hal+json' } }
|
35
|
-
Excon.stub({ method: :get, path: '/api' }, response.merge(body: entrypoint))
|
36
|
-
Excon.stub({ method: :get, path: '/hello/world' }, response.merge(body: hello_world))
|
37
|
-
Excon.stub({ method: :get, path: '/hello/world/goodbye', query: nil }, response.merge(body: 'bye!'))
|
38
|
-
Excon.stub({ method: :get, path: '/hello/world/goodbye', query: 'message=farewell' }, response.merge(body: 'farewell'))
|
39
|
-
end
|
40
|
-
|
41
|
-
def client
|
42
|
-
Excon.get('http://www.example.com/api')
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_request
|
46
|
-
response = client.hello(expand: { location: 'world' }).get
|
47
|
-
|
48
|
-
assert response.body.include?('http://www.example.com/hello/world/goodbye{?message}')
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_request_using_link
|
52
|
-
response = client.rel('hello', expand: { location: 'world' }).get
|
53
|
-
|
54
|
-
assert response.body.include?('http://www.example.com/hello/world/goodbye{?message}')
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_nested_request
|
58
|
-
hello = client.hello(expand: { location: 'world' })
|
59
|
-
response = hello.get.goodbye.get
|
60
|
-
|
61
|
-
assert_equal 'bye!', response.body
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_nested_query_parameters
|
65
|
-
hello = client.hello(expand: { location: 'world' })
|
66
|
-
response = hello.get.goodbye(expand: { message: 'farewell' }).get
|
67
|
-
|
68
|
-
assert_equal 'farewell', response.body
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_expand_in_get
|
72
|
-
response = client.hello.get(expand: { location: 'world' })
|
73
|
-
|
74
|
-
assert response.body.include?('http://www.example.com/hello/world/goodbye{?message}')
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_links
|
78
|
-
response = client.hello(expand: { location: 'world' }).get
|
79
|
-
|
80
|
-
assert_equal response.links.first.name, 'goodbye'
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_link
|
84
|
-
response = client.hello(expand: { location: 'world' }).get
|
85
|
-
|
86
|
-
assert_equal response.link('goodbye').name, 'goodbye'
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_attributes
|
90
|
-
response = client.hello(expand: { location: 'world' }).get
|
91
|
-
|
92
|
-
assert_equal response.attributes.to_h, uid: 'hello', message: 'goodbye!'
|
93
|
-
assert_equal response.attributes.uid, 'hello'
|
94
|
-
end
|
95
|
-
|
96
|
-
def teardown
|
97
|
-
Excon.stubs.clear
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/test/excon/link_test.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative '../test_helper'
|
3
|
-
|
4
|
-
module Excon
|
5
|
-
# LinkTest
|
6
|
-
#
|
7
|
-
# Validate the workings of `Excon::HyperResource::Link`.
|
8
|
-
#
|
9
|
-
class LinkTest < Minitest::Test
|
10
|
-
def body # rubocop:disable Metrics/MethodLength
|
11
|
-
<<~EOF
|
12
|
-
{
|
13
|
-
"_links": {
|
14
|
-
"hello": {
|
15
|
-
"href": "http://www.example.com/hello/{location}"
|
16
|
-
}
|
17
|
-
},
|
18
|
-
"uid": "universe",
|
19
|
-
"hello": "world"
|
20
|
-
}
|
21
|
-
EOF
|
22
|
-
end
|
23
|
-
|
24
|
-
def data
|
25
|
-
JSON.parse(body)
|
26
|
-
end
|
27
|
-
|
28
|
-
def link
|
29
|
-
@link ||= Excon::HyperMedia::Link.new(name: 'hello', hash: data)
|
30
|
-
end
|
31
|
-
|
32
|
-
def invalid_link
|
33
|
-
@invalid_link ||= Excon::HyperMedia::Link.new(name: 'goodbye', hash: data)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_link
|
37
|
-
assert_equal link.name, 'hello'
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_valid_link
|
41
|
-
assert link.valid?
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_invalid_link
|
45
|
-
refute invalid_link.valid?
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_uri
|
49
|
-
assert_equal link.uri.to_s, data['_links']['hello']['href']
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_href
|
53
|
-
assert_equal link.href, data['_links']['hello']['href']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/test/excon/resource_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative '../test_helper'
|
3
|
-
|
4
|
-
module Excon
|
5
|
-
# ResourceTest
|
6
|
-
#
|
7
|
-
# Validate the workings of `Excon::HyperResource::Resource`.
|
8
|
-
#
|
9
|
-
class ResourceTest < Minitest::Test
|
10
|
-
def body # rubocop:disable Metrics/MethodLength
|
11
|
-
<<~EOF
|
12
|
-
{
|
13
|
-
"_links": {
|
14
|
-
"hello": {
|
15
|
-
"href": "http://www.example.com/hello/{location}"
|
16
|
-
}
|
17
|
-
},
|
18
|
-
"uid": "universe",
|
19
|
-
"hello": "world"
|
20
|
-
}
|
21
|
-
EOF
|
22
|
-
end
|
23
|
-
|
24
|
-
def data
|
25
|
-
@data ||= JSON.parse(body)
|
26
|
-
end
|
27
|
-
|
28
|
-
def resource
|
29
|
-
@resource ||= Excon::HyperMedia::Resource.new(body)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_resource
|
33
|
-
assert_equal data, resource.data
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_links
|
37
|
-
assert_equal data['_links']['hello']['href'], resource.links.first.href
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_attributes
|
41
|
-
assert_equal resource.attributes.uid, 'universe'
|
42
|
-
assert_equal resource.attributes.hello, 'world'
|
43
|
-
|
44
|
-
refute resource.attributes.respond_to?('_links')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|