hyperclient 0.0.8 → 0.1.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.
- data/Gemfile +2 -1
- data/Readme.md +15 -21
- data/examples/cyberscore.rb +28 -16
- data/examples/hal_shop.rb +15 -22
- data/hyperclient.gemspec +2 -0
- data/lib/hyperclient.rb +2 -84
- data/lib/hyperclient/attributes.rb +20 -0
- data/lib/hyperclient/collection.rb +53 -0
- data/lib/hyperclient/entry_point.rb +49 -0
- data/lib/hyperclient/http.rb +38 -37
- data/lib/hyperclient/link.rb +93 -0
- data/lib/hyperclient/link_collection.rb +24 -0
- data/lib/hyperclient/resource.rb +26 -65
- data/lib/hyperclient/resource_collection.rb +33 -0
- data/lib/hyperclient/version.rb +1 -1
- data/test/fixtures/element.json +4 -15
- data/test/hyperclient/attributes_test.rb +26 -0
- data/test/hyperclient/collection_test.rb +39 -0
- data/test/hyperclient/entry_point_test.rb +51 -0
- data/test/hyperclient/http_test.rb +37 -23
- data/test/hyperclient/link_collection_test.rb +29 -0
- data/test/hyperclient/link_test.rb +93 -0
- data/test/hyperclient/resource_collection_test.rb +34 -0
- data/test/hyperclient/resource_test.rb +36 -42
- data/test/test_helper.rb +10 -1
- metadata +55 -16
- data/lib/hyperclient/discoverer.rb +0 -84
- data/lib/hyperclient/representation.rb +0 -43
- data/lib/hyperclient/resource_factory.rb +0 -53
- data/test/hyperclient/discoverer_test.rb +0 -101
- data/test/hyperclient/representation_test.rb +0 -52
- data/test/hyperclient/resource_factory_test.rb +0 -32
- data/test/hyperclient_test.rb +0 -68
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'hyperclient/resource_factory'
|
3
|
-
|
4
|
-
module Hyperclient
|
5
|
-
describe ResourceFactory do
|
6
|
-
let(:resource) do
|
7
|
-
ResourceFactory.resource('/path/to/resource')
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
Hyperclient::Resource.entry_point = 'http://myapi.org'
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'resource' do
|
15
|
-
it 'creates a new resource when is not present in the identity map' do
|
16
|
-
resource = ResourceFactory.resource('/path/to/resource')
|
17
|
-
|
18
|
-
resource.url.must_include '/path/to/resource'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns the resource when is already present in the identity map' do
|
22
|
-
new_resource = ResourceFactory.resource('/path/to/resource')
|
23
|
-
|
24
|
-
new_resource.object_id.must_equal resource.object_id
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises if the given url is nil' do
|
28
|
-
proc { ResourceFactory.resource(nil) }.must_raise MissingURLException
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/test/hyperclient_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'hyperclient'
|
3
|
-
|
4
|
-
describe Hyperclient do
|
5
|
-
let(:api) do
|
6
|
-
Class.new do
|
7
|
-
include Hyperclient
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'entry point' do
|
12
|
-
it 'sets the entry point for Hyperclient::Resource' do
|
13
|
-
api.entry_point {'http://my.api.org'}
|
14
|
-
|
15
|
-
Hyperclient::Resource.new('/').url.must_include 'http://my.api.org'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'entry' do
|
20
|
-
before do
|
21
|
-
api.entry_point {'http://my.api.org'}
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'initializes a Resource at the entry point' do
|
25
|
-
api.new.entry.url.must_equal 'http://my.api.org'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'also works with entry points that are not in the root' do
|
29
|
-
api.entry_point {'http://my.api.org/api'}
|
30
|
-
api.new.entry.url.must_equal 'http://my.api.org/api'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'sets the Resource name' do
|
34
|
-
api.new.name.must_equal 'Entry point'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'auth' do
|
39
|
-
it 'sets authentication type' do
|
40
|
-
api.auth{ {type: :digest, user: nil, password: nil} }
|
41
|
-
|
42
|
-
api.http_options[:http][:auth][:type].must_equal :digest
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'sets the authentication credentials' do
|
46
|
-
api.auth{ {type: :digest, user: 'user', password: 'secret'} }
|
47
|
-
|
48
|
-
api.http_options[:http][:auth][:credentials].must_include 'user'
|
49
|
-
api.http_options[:http][:auth][:credentials].must_include 'secret'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'method missing' do
|
54
|
-
class Hyperclient::Resource
|
55
|
-
def foo
|
56
|
-
'foo'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'delegates undefined methods to the API when they exist' do
|
61
|
-
api.new.foo.must_equal 'foo'
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'raises an error when the method does not exist in the API' do
|
65
|
-
lambda { api.new.this_method_does_not_exist }.must_raise(NoMethodError)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|