haipa 0.0.6 → 0.0.7

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/lib/haipa/links.rb CHANGED
@@ -14,7 +14,7 @@ module Haipa
14
14
  def method_missing(name, *args, &block)
15
15
  if @data.has_key?(name)
16
16
  href = @data[name]['href']
17
- if @data[name]['template'] == true
17
+ if @data[name]['templated'] == true
18
18
  template = Addressable::Template.new(href)
19
19
  options = args.last.is_a?(::Hash) ? args.pop : {}
20
20
  href = template.expand(options).to_s
@@ -21,7 +21,7 @@ module Haipa
21
21
  return {} unless uri
22
22
  response = api.get(uri)
23
23
  raise FailureResponseError unless response.success?
24
- raise EmptyResponseError if response.body.blank?
24
+ raise EmptyResponseError if !response.body || response.body.empty?
25
25
  @data ||= ::Hashie::Mash.new(JSON.parse(response.body))
26
26
  end
27
27
 
data/lib/haipa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Haipa
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
2
2
 
3
3
  describe Haipa::Resource do
4
4
  let(:uri) { '/api/v1' }
5
- let(:response) { double('response', body:body.to_json) }
5
+ let(:response) { double('response', body:body.to_json, success?:true) }
6
6
  let(:api) { double('api', get:response) }
7
7
  subject { Haipa::Resource.new(api, uri) }
8
8
 
@@ -14,9 +14,20 @@ describe Haipa::Resource do
14
14
  specify { subject.links.self.should be }
15
15
  end
16
16
 
17
- it 'works' do
18
- # template = Addressable::Template.new('/api{?q1,q2}')
19
- # ap template.expand({'q1' => 'hello', 'q2' => 'bye'}).to_s
17
+ context "with a templated find" do
18
+ let(:body) do
19
+ {
20
+ '_embedded' => { },
21
+ '_links' => {
22
+ 'self' => {'href' => uri},
23
+ 'find' => {'href' => uri+'/things/{id}{?filter1,filter2}', 'templated' => true}
24
+ }
25
+ }
26
+ end
27
+ it 'resolves the template' do
28
+ subject.links.find(id:1, filter1:'hello', filter2:'world').uri.should be ==
29
+ uri+'/things/1?filter1=hello&filter2=world'
30
+ end
20
31
  end
21
32
 
22
33
  context "with embedded resources" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haipa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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: 2013-04-06 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  segments:
148
148
  - 0
149
- hash: -4563439703560977047
149
+ hash: 2472982524793577646
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
@@ -155,10 +155,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: -4563439703560977047
158
+ hash: 2472982524793577646
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 1.8.25
161
+ rubygems_version: 1.8.23
162
162
  signing_key:
163
163
  specification_version: 3
164
164
  summary: HAL hypermedia client