harpy 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- harpy (0.4.0)
4
+ harpy (0.4.1)
5
5
  activemodel (>= 3.1.0)
6
6
  activesupport (>= 3.1.0)
7
7
  hash-deep-merge (~> 0.1.1)
@@ -11,21 +11,21 @@ PATH
11
11
  GEM
12
12
  remote: http://rubygems.org/
13
13
  specs:
14
- activemodel (3.1.3)
15
- activesupport (= 3.1.3)
14
+ activemodel (3.2.1)
15
+ activesupport (= 3.2.1)
16
16
  builder (~> 3.0.0)
17
+ activesupport (3.2.1)
17
18
  i18n (~> 0.6)
18
- activesupport (3.1.3)
19
19
  multi_json (~> 1.0)
20
20
  builder (3.0.0)
21
21
  diff-lcs (1.1.3)
22
22
  hash-deep-merge (0.1.1)
23
23
  i18n (0.6.0)
24
24
  mime-types (1.17.2)
25
- multi_json (1.0.4)
25
+ multi_json (1.1.0)
26
26
  mustache (0.99.4)
27
- rake (0.8.7)
28
- redcarpet (1.17.2)
27
+ rake (0.9.2.2)
28
+ redcarpet (2.1.0)
29
29
  rocco (0.8.2)
30
30
  mustache
31
31
  redcarpet
@@ -42,11 +42,10 @@ GEM
42
42
  yajl-ruby (0.8.3)
43
43
 
44
44
  PLATFORMS
45
- java
46
45
  ruby
47
46
 
48
47
  DEPENDENCIES
49
48
  harpy!
50
- rake (~> 0.8.7)
49
+ rake (>= 0.8.7)
51
50
  rocco (~> 0.7)
52
51
  rspec (~> 2.6.0)
data/harpy.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency("hash-deep-merge", ["~> 0.1.1"])
24
24
  s.add_runtime_dependency("yajl-ruby", ["~> 0.8.2"])
25
25
 
26
- s.add_development_dependency("rake", ["~> 0.8.7"])
26
+ s.add_development_dependency("rake", [">= 0.8.7"])
27
27
  s.add_development_dependency("rspec", ["~> 2.6.0"])
28
28
  s.add_development_dependency("rocco", ["~> 0.7"])
29
29
  end
@@ -122,130 +122,128 @@ module Harpy
122
122
  end
123
123
  end
124
124
 
125
- module InstanceMethods
126
- def initialize(attrs = nil)
127
- @attrs = {}
128
- self.attributes = attrs || {}
129
- end
130
-
131
- def attributes=(attrs)
132
- attrs.each do |key, value|
133
- if respond_to? "#{key}="
134
- send "#{key}=", value
135
- else
136
- @attrs[key] = value
137
- end
138
- end
139
- end
140
-
141
- def as_json(*args)
142
- hash = @attrs.dup
143
- hash.delete "link"
144
- hash.delete "urn"
145
- hash
146
- end
147
-
148
- def save
149
- if valid?
150
- _run_save_callbacks do
151
- json = Yajl::Encoder.encode as_json
152
- raise BodyToBig, "Size: #{json.bytesize} bytes (max 1MB)" if json.bytesize > 1.megabyte
153
- persisted? ? update(json) : create(json)
154
- end
125
+ def initialize(attrs = nil)
126
+ @attrs = {}
127
+ self.attributes = attrs || {}
128
+ end
129
+
130
+ def attributes=(attrs)
131
+ attrs.each do |key, value|
132
+ if respond_to? "#{key}="
133
+ send "#{key}=", value
155
134
  else
156
- false
135
+ @attrs[key] = value
157
136
  end
158
137
  end
159
-
160
- def destroy
161
- raise Harpy::UrlRequired unless url
162
- _run_destroy_callbacks do
163
- process_response Harpy.client.delete(url), :destroy
138
+ end
139
+
140
+ def as_json(*args)
141
+ hash = @attrs.dup
142
+ hash.delete "link"
143
+ hash.delete "urn"
144
+ hash
145
+ end
146
+
147
+ def save
148
+ if valid?
149
+ _run_save_callbacks do
150
+ json = Yajl::Encoder.encode as_json
151
+ raise BodyToBig, "Size: #{json.bytesize} bytes (max 1MB)" if json.bytesize > 1.megabyte
152
+ persisted? ? update(json) : create(json)
164
153
  end
154
+ else
155
+ false
165
156
  end
166
-
167
- def link(rel)
168
- link = (@attrs["link"]||[]).detect{|l| l["rel"]==rel.to_s}
169
- link["href"] if link
157
+ end
158
+
159
+ def destroy
160
+ raise Harpy::UrlRequired unless url
161
+ _run_destroy_callbacks do
162
+ process_response Harpy.client.delete(url), :destroy
170
163
  end
164
+ end
165
+
166
+ def link(rel)
167
+ link = (@attrs["link"]||[]).detect{|l| l["rel"]==rel.to_s}
168
+ link["href"] if link
169
+ end
171
170
 
172
- def url
173
- link "self"
174
- end
171
+ def url
172
+ link "self"
173
+ end
175
174
 
176
- def url_collection
177
- Harpy.entry_point.resource_url self.class.resource_name
178
- end
175
+ def url_collection
176
+ Harpy.entry_point.resource_url self.class.resource_name
177
+ end
179
178
 
180
- def id
181
- @attrs["urn"].split(":").last if @attrs["urn"]
182
- end
179
+ def id
180
+ @attrs["urn"].split(":").last if @attrs["urn"]
181
+ end
183
182
 
184
- def persisted?
185
- @attrs["urn"].present?
186
- end
183
+ def persisted?
184
+ @attrs["urn"].present?
185
+ end
187
186
 
188
- def inspect
189
- "<#{self.class.name} @attrs:#{@attrs.inspect} @errors:#{errors.full_messages.inspect} persisted:#{persisted?}>"
190
- end
187
+ def inspect
188
+ "<#{self.class.name} @attrs:#{@attrs.inspect} @errors:#{errors.full_messages.inspect} persisted:#{persisted?}>"
189
+ end
191
190
 
192
- def has_key?(key)
193
- @attrs.has_key? key.to_s
194
- end
191
+ def has_key?(key)
192
+ @attrs.has_key? key.to_s
193
+ end
195
194
 
196
- def hash
197
- urn.hash
198
- end
199
-
200
- def ==(other)
201
- other.equal?(self) || (urn && other.instance_of?(self.class) && other.urn == urn)
202
- end
203
- alias_method :eql?, :==
195
+ def hash
196
+ urn.hash
197
+ end
198
+
199
+ def ==(other)
200
+ other.equal?(self) || (urn && other.instance_of?(self.class) && other.urn == urn)
201
+ end
202
+ alias_method :eql?, :==
204
203
 
205
- private
204
+ private
206
205
 
207
- def create(json)
208
- _run_create_callbacks do
209
- process_response Harpy.client.post(url_collection, :body => json), :create
210
- end
206
+ def create(json)
207
+ _run_create_callbacks do
208
+ process_response Harpy.client.post(url_collection, :body => json), :create
211
209
  end
210
+ end
212
211
 
213
- def update(json)
214
- _run_update_callbacks do
215
- raise Harpy::UrlRequired unless url
216
- process_response Harpy.client.put(url, :body => json), :update
217
- end
212
+ def update(json)
213
+ _run_update_callbacks do
214
+ raise Harpy::UrlRequired unless url
215
+ process_response Harpy.client.put(url, :body => json), :update
218
216
  end
217
+ end
219
218
 
220
- def process_response(response, context)
221
- case response.code
222
- when 200, 201, 302
223
- @attrs.merge! Yajl::Parser.parse(response.body)
224
- true
225
- when 204
226
- context==:create ? Harpy.client.invalid_code(response) : true
227
- when 401
228
- raise Harpy::Unauthorized, "Server returned a 401 response code"
229
- when 422
230
- Yajl::Parser.parse(response.body)["errors"].each do |attr, attr_errors|
231
- attr_errors.each{|attr_error| errors[attr] = attr_error }
232
- end
233
- false
234
- else
235
- Harpy.client.invalid_code response
219
+ def process_response(response, context)
220
+ case response.code
221
+ when 200, 201, 302
222
+ @attrs.merge! Yajl::Parser.parse(response.body)
223
+ true
224
+ when 204
225
+ context==:create ? Harpy.client.invalid_code(response) : true
226
+ when 401
227
+ raise Harpy::Unauthorized, "Server returned a 401 response code"
228
+ when 422
229
+ Yajl::Parser.parse(response.body)["errors"].each do |attr, attr_errors|
230
+ attr_errors.each{|attr_error| errors[attr] = attr_error }
236
231
  end
232
+ false
233
+ else
234
+ Harpy.client.invalid_code response
237
235
  end
236
+ end
238
237
 
239
- def method_missing(method, *args)
240
- key = method.to_s
241
- if persisted? && !@attrs.has_key?(key)
242
- super
243
- elsif key=~/[\]=]\z/
244
- super
245
- else
246
- @attrs[key]
247
- end
238
+ def method_missing(method, *args)
239
+ key = method.to_s
240
+ if persisted? && !@attrs.has_key?(key)
241
+ super
242
+ elsif key=~/[\]=]\z/
243
+ super
244
+ else
245
+ @attrs[key]
248
246
  end
249
247
  end
250
248
  end
251
- end
249
+ end
data/lib/harpy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Harpy
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-29 00:00:00.000000000 Z
13
+ date: 2012-02-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: typhoeus
17
- requirement: &70308967151200 !ruby/object:Gem::Requirement
17
+ requirement: &2156516020 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.3.3
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70308967151200
25
+ version_requirements: *2156516020
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70308967148440 !ruby/object:Gem::Requirement
28
+ requirement: &2156514400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70308967148440
36
+ version_requirements: *2156514400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: activemodel
39
- requirement: &70308967159800 !ruby/object:Gem::Requirement
39
+ requirement: &2156512580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 3.1.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70308967159800
47
+ version_requirements: *2156512580
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: hash-deep-merge
50
- requirement: &70308975424920 !ruby/object:Gem::Requirement
50
+ requirement: &2156527640 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.1.1
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70308975424920
58
+ version_requirements: *2156527640
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: yajl-ruby
61
- requirement: &70308975444760 !ruby/object:Gem::Requirement
61
+ requirement: &2156540080 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,21 +66,21 @@ dependencies:
66
66
  version: 0.8.2
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70308975444760
69
+ version_requirements: *2156540080
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rake
72
- requirement: &70308975452500 !ruby/object:Gem::Requirement
72
+ requirement: &2156536940 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.8.7
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70308975452500
80
+ version_requirements: *2156536940
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &70308975454700 !ruby/object:Gem::Requirement
83
+ requirement: &2156534880 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 2.6.0
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70308975454700
91
+ version_requirements: *2156534880
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rocco
94
- requirement: &70308975467260 !ruby/object:Gem::Requirement
94
+ requirement: &2156547760 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0.7'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70308975467260
102
+ version_requirements: *2156547760
103
103
  description: Client for REST API with HATEOAS
104
104
  email:
105
105
  - joseph.halter@thetalentbox.com
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 289143157224719983
145
+ hash: -4195259765713612817
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements:
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  segments:
153
153
  - 0
154
- hash: 289143157224719983
154
+ hash: -4195259765713612817
155
155
  requirements: []
156
156
  rubyforge_project:
157
157
  rubygems_version: 1.8.10