hyperclient 0.0.2 → 0.0.3

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/Readme.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Hyperclient [![Build Status](https://secure.travis-ci.org/codegram/hyperclient.png)](http://travis-ci.org/codegram/hyperclient) [![Dependency Status](https://gemnasium.com/codegram/hyperclient.png)](http://gemnasium.com/codegram/hyperclient)
2
2
 
3
- Hyperclient is a Ruby Hypermedia API client.
3
+ Hyperclient is a Ruby Hypermedia API client written in Ruby.
4
4
 
5
5
  ## Documentation
6
6
 
7
- [Hyperclient on documentup][documentup]
7
+ [Hyperclient on documentup][documentup] and [Hyperclient API documentation on rdoc.info][rdoc]
8
8
 
9
9
  ## Usage
10
10
 
@@ -142,4 +142,5 @@ MIT License. Copyright 2012 [Codegram Technologies][codegram]
142
142
  [documentup]: http://codegram.github.com/hyperclient
143
143
  [httparty]: http://github.com/jnunemaker/httparty
144
144
  [examples]: http://github.com/codegram/hyperclient/tree/master/examples
145
- [enumerable]: http://ruby-doc.org/core-1.9.3/Enumerable.html
145
+ [enumerable]: http://ruby-doc.org/core-1.9.3/Enumerable.html
146
+ [rdoc]: http://rubydoc.org/github/codegram/hyperclient/master/frames
@@ -55,9 +55,9 @@ module Hyperclient
55
55
  def build_resource(response, name = nil)
56
56
  return response.map(&method(:build_resource)) if response.is_a?(Array)
57
57
 
58
- Resource.new(response.delete('href'), {response: response, name: name})
58
+ ResourceFactory.resource(response.delete('href'), {response: response, name: name})
59
59
  end
60
60
  end
61
61
  end
62
62
 
63
- require 'hyperclient/resource'
63
+ require 'hyperclient/resource_factory'
@@ -0,0 +1,33 @@
1
+ module Hyperclient
2
+ # Public: This class acts as an interface to build Resources. It has a simple
3
+ # identity map so a user can save HTTP calls when interacting with the same
4
+ # resource.
5
+ #
6
+ # Examples
7
+ #
8
+ # ResourceFactory.resource('http://myapi.org/resource/1')
9
+ # => #<Hyperclient::Resource url: 'http://myapi.org/resource/1'>
10
+ #
11
+ class ResourceFactory
12
+ # Public: A factory method to build Resources. It will try to find a
13
+ # Resource in the identity map or build a new one if does not exist.
14
+ #
15
+ # url - A String to identify the Resource
16
+ # args - An Array to pass other arguments to the Resource initialization.
17
+ def self.resource(url, *args)
18
+ identity_map.fetch(url) do |url|
19
+ resource = Resource.new(url, *args)
20
+ identity_map.update(url => resource)
21
+ resource
22
+ end
23
+ end
24
+
25
+ private
26
+ # Internal: Returns a Hash that acts as identity map.
27
+ def self.identity_map
28
+ @identity_map ||= {}
29
+ end
30
+ end
31
+ end
32
+
33
+ require 'hyperclient/resource'
@@ -1,3 +1,3 @@
1
1
  module Hyperclient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,28 @@
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
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-29 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -98,6 +98,7 @@ files:
98
98
  - lib/hyperclient/discoverer.rb
99
99
  - lib/hyperclient/http.rb
100
100
  - lib/hyperclient/resource.rb
101
+ - lib/hyperclient/resource_factory.rb
101
102
  - lib/hyperclient/response.rb
102
103
  - lib/hyperclient/version.rb
103
104
  - test/fixtures/collection.json
@@ -105,6 +106,7 @@ files:
105
106
  - test/fixtures/root.json
106
107
  - test/hyperclient/discoverer_test.rb
107
108
  - test/hyperclient/http_test.rb
109
+ - test/hyperclient/resource_factory_test.rb
108
110
  - test/hyperclient/resource_test.rb
109
111
  - test/hyperclient/response_test.rb
110
112
  - test/hyperclient_test.rb
@@ -123,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
125
  version: '0'
124
126
  segments:
125
127
  - 0
126
- hash: -2437981689318086472
128
+ hash: 2448296263010756108
127
129
  required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  none: false
129
131
  requirements:
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  version: '0'
133
135
  segments:
134
136
  - 0
135
- hash: -2437981689318086472
137
+ hash: 2448296263010756108
136
138
  requirements: []
137
139
  rubyforge_project:
138
140
  rubygems_version: 1.8.23
@@ -145,6 +147,7 @@ test_files:
145
147
  - test/fixtures/root.json
146
148
  - test/hyperclient/discoverer_test.rb
147
149
  - test/hyperclient/http_test.rb
150
+ - test/hyperclient/resource_factory_test.rb
148
151
  - test/hyperclient/resource_test.rb
149
152
  - test/hyperclient/response_test.rb
150
153
  - test/hyperclient_test.rb