heroics 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0effae3c006baa9114cb3878ae9c7fc2fdc8f9b7
4
- data.tar.gz: 8f0504e1fb8b25ac738fd90cf7aadc3a8b5d281e
3
+ metadata.gz: 259b6035c675a64b2a0c1243765f22f1c3358844
4
+ data.tar.gz: e698d60d9f9f1afb43530587b5f54e3ad5da1765
5
5
  SHA512:
6
- metadata.gz: 3a6e38662083ef292abbee6120036e74ebc865fb02728f47e6eaf1a65fdf9b6b45333db618de163f8c1e7775b4c4dff4b54a713d230ac1946c10ea2f5dbcc0c3
7
- data.tar.gz: b56f94aa12117967c28116830637e0650c5ef1b5d1b45b7d67618344400e6ba28f4f19ae77ff0e1bd0a6648edae11665ee9c76de033a3498dca42e117f61a85c
6
+ metadata.gz: 93fa2f9040ad82ee8572ac916e156fe3948dc3db45248e1c875d3e808d5b4589b6d21468993a7eb4acab46c80fd6653e633e3342bc908d185ecac84c87e5ad03
7
+ data.tar.gz: c9baf8841b6386ec09f1cbacf12b4a6cbad2839bb09f2b176f75440e8d62cbb64aee40512f1d79d01bf34f61cfa8eeacddf3d437598d7399673ae425952e93ac
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Build Status](https://travis-ci.org/heroku/heroics.png?branch=master)](https://travis-ci.org/heroku/heroics)
1
2
  # Heroics
2
3
 
3
4
  Ruby HTTP client for APIs represented with JSON schema.
@@ -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
- def initialize(resources)
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
- # TODO(jkakar) Do we care about resource names in the schema specified
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
@@ -1,3 +1,3 @@
1
1
  module Heroics
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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
- assert_match(
14
- /undefined method `unknown' for #<Heroics::Client:0x[0-9a-f]{14}>/,
15
- error.message)
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'])
@@ -11,7 +11,7 @@ class ResourceTest < MiniTest::Unit::TestCase
11
11
  resource.unknown
12
12
  end
13
13
  assert_match(
14
- /undefined method `unknown' for #<Heroics::Resource:0x[0-9a-f]{14}>/,
14
+ /undefined method `unknown' for #<Heroics::Resource:0x.*>/,
15
15
  error.message)
16
16
  end
17
17
 
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.3
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 00:00:00.000000000 Z
12
+ date: 2014-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler