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 +8 -9
- data/harpy.gemspec +1 -1
- data/lib/harpy/resource.rb +100 -102
- data/lib/harpy/version.rb +1 -1
- metadata +21 -21
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
harpy (0.4.
|
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
|
15
|
-
activesupport (= 3.1
|
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
|
25
|
+
multi_json (1.1.0)
|
26
26
|
mustache (0.99.4)
|
27
|
-
rake (0.
|
28
|
-
redcarpet (1.
|
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 (
|
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", ["
|
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
|
data/lib/harpy/resource.rb
CHANGED
@@ -122,130 +122,128 @@ module Harpy
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
135
|
+
@attrs[key] = value
|
157
136
|
end
|
158
137
|
end
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
171
|
+
def url
|
172
|
+
link "self"
|
173
|
+
end
|
175
174
|
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
def url_collection
|
176
|
+
Harpy.entry_point.resource_url self.class.resource_name
|
177
|
+
end
|
179
178
|
|
180
|
-
|
181
|
-
|
182
|
-
|
179
|
+
def id
|
180
|
+
@attrs["urn"].split(":").last if @attrs["urn"]
|
181
|
+
end
|
183
182
|
|
184
|
-
|
185
|
-
|
186
|
-
|
183
|
+
def persisted?
|
184
|
+
@attrs["urn"].present?
|
185
|
+
end
|
187
186
|
|
188
|
-
|
189
|
-
|
190
|
-
|
187
|
+
def inspect
|
188
|
+
"<#{self.class.name} @attrs:#{@attrs.inspect} @errors:#{errors.full_messages.inspect} persisted:#{persisted?}>"
|
189
|
+
end
|
191
190
|
|
192
|
-
|
193
|
-
|
194
|
-
|
191
|
+
def has_key?(key)
|
192
|
+
@attrs.has_key? key.to_s
|
193
|
+
end
|
195
194
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|
-
|
204
|
+
private
|
206
205
|
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
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.
|
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:
|
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: &
|
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: *
|
25
|
+
version_requirements: *2156516020
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
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: *
|
36
|
+
version_requirements: *2156514400
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: activemodel
|
39
|
-
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: *
|
47
|
+
version_requirements: *2156512580
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: hash-deep-merge
|
50
|
-
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: *
|
58
|
+
version_requirements: *2156527640
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: yajl-ruby
|
61
|
-
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: *
|
69
|
+
version_requirements: *2156540080
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
|
-
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: *
|
80
|
+
version_requirements: *2156536940
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rspec
|
83
|
-
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: *
|
91
|
+
version_requirements: *2156534880
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: rocco
|
94
|
-
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: *
|
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:
|
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:
|
154
|
+
hash: -4195259765713612817
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
157
|
rubygems_version: 1.8.10
|