heroics 0.0.3 → 0.0.4
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 +1 -0
- data/lib/heroics/client.rb +11 -7
- data/lib/heroics/version.rb +1 -1
- data/test/client_test.rb +16 -6
- data/test/resource_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 259b6035c675a64b2a0c1243765f22f1c3358844
|
4
|
+
data.tar.gz: e698d60d9f9f1afb43530587b5f54e3ad5da1765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93fa2f9040ad82ee8572ac916e156fe3948dc3db45248e1c875d3e808d5b4589b6d21468993a7eb4acab46c80fd6653e633e3342bc908d185ecac84c87e5ad03
|
7
|
+
data.tar.gz: c9baf8841b6386ec09f1cbacf12b4a6cbad2839bb09f2b176f75440e8d62cbb64aee40512f1d79d01bf34f61cfa8eeacddf3d437598d7399673ae425952e93ac
|
data/README.md
CHANGED
data/lib/heroics/client.rb
CHANGED
@@ -5,8 +5,10 @@ module Heroics
|
|
5
5
|
#
|
6
6
|
# @param resources [Hash<String,Resource>] A hash that maps method names
|
7
7
|
# to resources.
|
8
|
-
|
8
|
+
# @param url [String] The URL used by this client.
|
9
|
+
def initialize(resources, url)
|
9
10
|
@resources = resources
|
11
|
+
@url = url
|
10
12
|
end
|
11
13
|
|
12
14
|
# Find a resource.
|
@@ -18,14 +20,16 @@ module Heroics
|
|
18
20
|
name = name.to_s.gsub('_', '-')
|
19
21
|
resource = @resources[name]
|
20
22
|
if resource.nil?
|
21
|
-
|
22
|
-
# with underscores? If so, we should check to make sure the name
|
23
|
-
# mangling we did above was actually a bad idea.
|
24
|
-
address = "<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>"
|
25
|
-
raise NoMethodError.new("undefined method `#{name}' for ##{address}")
|
23
|
+
raise NoMethodError.new("undefined method `#{name}' for #{to_s}")
|
26
24
|
end
|
27
25
|
resource
|
28
26
|
end
|
27
|
+
|
28
|
+
# Get a simple human-readable representation of this client instance.
|
29
|
+
def inspect
|
30
|
+
"#<Heroics::Client url=\"#{@url}\">"
|
31
|
+
end
|
32
|
+
alias to_s inspect
|
29
33
|
end
|
30
34
|
|
31
35
|
# Create an HTTP client from a JSON schema.
|
@@ -49,6 +53,6 @@ module Heroics
|
|
49
53
|
end
|
50
54
|
resources[resource_schema.name] = Resource.new(links)
|
51
55
|
end
|
52
|
-
Client.new(resources)
|
56
|
+
Client.new(resources, url)
|
53
57
|
end
|
54
58
|
end
|
data/lib/heroics/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -3,16 +3,24 @@ require 'helper'
|
|
3
3
|
class ClientTest < MiniTest::Unit::TestCase
|
4
4
|
include ExconHelper
|
5
5
|
|
6
|
+
# Client.to_s returns a simple human-readable description of the client
|
7
|
+
# instance with the URL embedded in it.
|
8
|
+
def test_to_s
|
9
|
+
client = Heroics::Client.new({}, 'http://foo:bar@example.com')
|
10
|
+
assert_equal('#<Heroics::Client url="http://foo:bar@example.com">',
|
11
|
+
client.to_s)
|
12
|
+
end
|
13
|
+
|
6
14
|
# Client.<resource> raises a NoMethodError when a method is invoked
|
7
15
|
# without a matching resource.
|
8
16
|
def test_invalid_resource
|
9
|
-
client = Heroics::Client.new({})
|
17
|
+
client = Heroics::Client.new({}, 'http://example.com')
|
10
18
|
error = assert_raises NoMethodError do
|
11
19
|
client.unknown
|
12
20
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
assert_equal("undefined method `unknown' for " +
|
22
|
+
'#<Heroics::Client url="http://example.com">',
|
23
|
+
error.message)
|
16
24
|
end
|
17
25
|
|
18
26
|
# Client.<resource>.<link> finds the appropriate link and invokes it.
|
@@ -21,7 +29,8 @@ class ClientTest < MiniTest::Unit::TestCase
|
|
21
29
|
link = Heroics::Link.new('https://username:secret@example.com',
|
22
30
|
schema.resource('resource').link('list'))
|
23
31
|
resource = Heroics::Resource.new({'link' => link})
|
24
|
-
client = Heroics::Client.new({'resource' => resource}
|
32
|
+
client = Heroics::Client.new({'resource' => resource},
|
33
|
+
'http://example.com')
|
25
34
|
Excon.stub(method: :get) do |request|
|
26
35
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
27
36
|
request[:headers]['Authorization'])
|
@@ -41,7 +50,8 @@ class ClientTest < MiniTest::Unit::TestCase
|
|
41
50
|
link = Heroics::Link.new('https://username:secret@example.com',
|
42
51
|
schema.resource('another-resource').link('list'))
|
43
52
|
resource = Heroics::Resource.new({'link' => link})
|
44
|
-
client = Heroics::Client.new({'another-resource' => resource}
|
53
|
+
client = Heroics::Client.new({'another-resource' => resource},
|
54
|
+
'http://example.com')
|
45
55
|
Excon.stub(method: :get) do |request|
|
46
56
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
47
57
|
request[:headers]['Authorization'])
|
data/test/resource_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|