hyperresource 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hyper_resource/adapter/hal_json.rb +7 -2
- data/lib/hyper_resource/attributes.rb +19 -10
- data/lib/hyper_resource/link.rb +6 -4
- data/lib/hyper_resource/links.rb +6 -2
- data/lib/hyper_resource/modules/http.rb +10 -3
- data/lib/hyper_resource/objects.rb +7 -3
- data/lib/hyper_resource/version.rb +2 -2
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832cf096d42bc62e2a0908b8a180daa50e74e995
|
4
|
+
data.tar.gz: 575f2ffc7974d107b48492e074a03cc614a0e587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569688d842532fbb2676bf5058fdb259dbad3bec69cf751509bf32ea623853f0ad43c152b760a68d93a68e82b8f713795d3a561323295c67197fb055c78ad466
|
7
|
+
data.tar.gz: 41fc74dc8cab7d2100639c73849348086a55aab19b0d3b28d31660940df0418fe0406f2e713d4197f04c14f9896b81f0b323b8cfa254c9f5815c0464850f0c03
|
@@ -46,12 +46,16 @@ class HyperResource
|
|
46
46
|
|
47
47
|
resp['_embedded'].each do |name, collection|
|
48
48
|
if collection.is_a? Hash
|
49
|
-
r = rc.new(:root => rsrc.root,
|
49
|
+
r = rc.new(:root => rsrc.root,
|
50
|
+
:headers => rsrc.headers,
|
51
|
+
:namespace => rsrc.namespace)
|
50
52
|
r.body = collection
|
51
53
|
objs[name] = apply(collection, r)
|
52
54
|
else
|
53
55
|
objs[name] = collection.map do |obj|
|
54
|
-
r = rc.new(:root => rsrc.root,
|
56
|
+
r = rc.new(:root => rsrc.root,
|
57
|
+
:headers => rsrc.headers,
|
58
|
+
:namespace => rsrc.namespace)
|
55
59
|
r.body = obj
|
56
60
|
apply(obj, r)
|
57
61
|
end
|
@@ -101,6 +105,7 @@ class HyperResource
|
|
101
105
|
rsrc.attributes[attr] = filtered_attrs[attr]
|
102
106
|
end
|
103
107
|
|
108
|
+
rsrc.attributes._hr_clear_changed
|
104
109
|
rsrc.attributes._hr_create_methods!
|
105
110
|
end
|
106
111
|
|
@@ -11,8 +11,10 @@ class HyperResource
|
|
11
11
|
## Protects against method creation into HyperResource::Attributes and
|
12
12
|
## HyperResource classes. Just subclasses, please!
|
13
13
|
def _hr_create_methods!(opts={}) # @private
|
14
|
-
return if self.class.to_s == 'HyperResource::Attributes'
|
15
|
-
|
14
|
+
return if self.class.to_s == 'HyperResource::Attributes'
|
15
|
+
return if self._resource.class.to_s == 'HyperResource'
|
16
|
+
return if self.class.send(
|
17
|
+
:class_variable_defined?, :@@_hr_created_attributes_methods)
|
16
18
|
|
17
19
|
self.keys.each do |attr|
|
18
20
|
attr_sym = attr.to_sym
|
@@ -40,6 +42,8 @@ class HyperResource
|
|
40
42
|
|
41
43
|
## This is a good time to mark this object as not-changed
|
42
44
|
_hr_clear_changed
|
45
|
+
|
46
|
+
self.class.send(:class_variable_set, :@@_hr_created_attributes_methods, true)
|
43
47
|
end
|
44
48
|
|
45
49
|
## Returns +true+ if the given attribute has been changed since creation
|
@@ -59,7 +63,8 @@ class HyperResource
|
|
59
63
|
end
|
60
64
|
|
61
65
|
def []=(attr, value) # @private
|
62
|
-
|
66
|
+
return self[attr] if self[attr] == value
|
67
|
+
_hr_mark_changed(attr)
|
63
68
|
super(attr.to_s, value)
|
64
69
|
end
|
65
70
|
|
@@ -70,11 +75,19 @@ class HyperResource
|
|
70
75
|
end
|
71
76
|
|
72
77
|
def method_missing(method, *args) # @private
|
73
|
-
|
74
|
-
|
78
|
+
method = method.to_s
|
79
|
+
if self[method]
|
80
|
+
self[method]
|
81
|
+
elsif method[-1,1] == '='
|
82
|
+
self[method[0..-2]] = args.first
|
83
|
+
else
|
84
|
+
raise NoMethodError, "undefined method `#{method}' for #{self.inspect}"
|
85
|
+
end
|
75
86
|
end
|
76
87
|
|
77
|
-
|
88
|
+
def _hr_clear_changed # @private
|
89
|
+
@_hr_changed = nil
|
90
|
+
end
|
78
91
|
|
79
92
|
def _hr_mark_changed(attr, is_changed=true) # @private
|
80
93
|
attr = attr.to_sym
|
@@ -82,10 +95,6 @@ class HyperResource
|
|
82
95
|
@_hr_changed[attr] = is_changed
|
83
96
|
end
|
84
97
|
|
85
|
-
def _hr_clear_changed
|
86
|
-
@_hr_changed = nil
|
87
|
-
end
|
88
|
-
|
89
98
|
end
|
90
99
|
end
|
91
100
|
|
data/lib/hyper_resource/link.rb
CHANGED
@@ -44,10 +44,12 @@ class HyperResource::Link
|
|
44
44
|
parent_resource._hr_new_from_link(self.href)
|
45
45
|
end
|
46
46
|
|
47
|
-
##
|
48
|
-
def get
|
49
|
-
|
50
|
-
end
|
47
|
+
## Delegate HTTP methods to the resource.
|
48
|
+
def get(*args); self.resource.get(*args) end
|
49
|
+
def post(*args); self.resource.post(*args) end
|
50
|
+
def patch(*args); self.resource.patch(*args) end
|
51
|
+
def put(*args); self.resource.put(*args) end
|
52
|
+
def delete(*args); self.resource.delete(*args) end
|
51
53
|
|
52
54
|
## If we were called with a method we don't know, load this resource
|
53
55
|
## and pass the message along. This achieves implicit loading.
|
data/lib/hyper_resource/links.rb
CHANGED
@@ -10,8 +10,10 @@ class HyperResource
|
|
10
10
|
## Protects against method creation into HyperResource::Links and
|
11
11
|
## HyperResource classes. Just subclasses, please!
|
12
12
|
def _hr_create_methods!(opts={}) # @private
|
13
|
-
return if self.class.to_s == 'HyperResource::Links'
|
14
|
-
|
13
|
+
return if self.class.to_s == 'HyperResource::Links'
|
14
|
+
return if self._resource.class.to_s == 'HyperResource'
|
15
|
+
return if self.class.send(
|
16
|
+
:class_variable_defined?, :@@_hr_created_links_methods)
|
15
17
|
|
16
18
|
self.keys.each do |attr|
|
17
19
|
attr_sym = attr.to_sym
|
@@ -30,6 +32,8 @@ class HyperResource
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
36
|
+
self.class.send(:class_variable_set, :@@_hr_created_links_methods, true)
|
33
37
|
end
|
34
38
|
|
35
39
|
def []=(attr, value) # @private
|
@@ -22,7 +22,8 @@ class HyperResource
|
|
22
22
|
|
23
23
|
## POSTs the given attributes to this resource's href, and returns
|
24
24
|
## the response resource.
|
25
|
-
def post(attrs)
|
25
|
+
def post(attrs=nil)
|
26
|
+
attrs || self.attributes
|
26
27
|
self.response = faraday_connection.post do |req|
|
27
28
|
req.body = adapter.serialize(attrs)
|
28
29
|
end
|
@@ -67,7 +68,13 @@ class HyperResource
|
|
67
68
|
## headers (including auth). Threadsafe.
|
68
69
|
def faraday_connection(url=nil)
|
69
70
|
url ||= URI.join(self.root, self.href)
|
70
|
-
key =
|
71
|
+
key = Digest::MD5.hexdigest({
|
72
|
+
'faraday_connection' => {
|
73
|
+
'url' => url,
|
74
|
+
'headers' => self.headers,
|
75
|
+
'ba' => self.auth[:basic]
|
76
|
+
}
|
77
|
+
}.to_json)
|
71
78
|
return Thread.current[key] if Thread.current[key]
|
72
79
|
|
73
80
|
fc = Faraday.new(self.faraday_options.merge(:url => url))
|
@@ -83,7 +90,7 @@ class HyperResource
|
|
83
90
|
|
84
91
|
def finish_up
|
85
92
|
begin
|
86
|
-
self.body = self.adapter.deserialize(self.response.body)
|
93
|
+
self.body = self.adapter.deserialize(self.response.body) unless self.response.body.nil?
|
87
94
|
rescue StandardError => e
|
88
95
|
raise HyperResource::ResponseError.new(
|
89
96
|
"Error when deserializing response body",
|
@@ -2,7 +2,7 @@ class HyperResource
|
|
2
2
|
class Objects < Hash
|
3
3
|
attr_accessor :_resource
|
4
4
|
|
5
|
-
def initialize(resource=nil)
|
5
|
+
def initialize(resource=nil)
|
6
6
|
self._resource = resource || HyperResource.new
|
7
7
|
end
|
8
8
|
|
@@ -10,8 +10,10 @@ class HyperResource
|
|
10
10
|
## Protects against method creation into HyperResource::Objects and
|
11
11
|
## HyperResource classes. Just subclasses, please!
|
12
12
|
def _hr_create_methods!(opts={}) # @private
|
13
|
-
return if self.class.to_s == 'HyperResource::Objects'
|
14
|
-
|
13
|
+
return if self.class.to_s == 'HyperResource::Objects'
|
14
|
+
return if self._resource.class.to_s == 'HyperResource'
|
15
|
+
return if self.class.send(
|
16
|
+
:class_variable_defined?, :@@_hr_created_objects_methods)
|
15
17
|
|
16
18
|
self.keys.each do |attr|
|
17
19
|
attr_sym = attr.to_sym
|
@@ -27,6 +29,8 @@ class HyperResource
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
32
|
+
|
33
|
+
self.class.send(:class_variable_set, :@@_hr_created_objects_methods, true)
|
30
34
|
end
|
31
35
|
|
32
36
|
def []=(attr, value) # @private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Gamache
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uri_template
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.4.0
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: yard
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.8.5
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '>='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.8.5
|
125
111
|
description: |2
|
126
112
|
HyperResource is a hypermedia client library for Ruby. Its goals are to
|
127
113
|
interface directly with well-behaved hypermedia APIs, to allow the data
|
@@ -132,8 +118,9 @@ executables: []
|
|
132
118
|
extensions: []
|
133
119
|
extra_rdoc_files: []
|
134
120
|
files:
|
135
|
-
- lib/hyper_resource
|
121
|
+
- lib/hyper_resource.rb
|
136
122
|
- lib/hyper_resource/adapter.rb
|
123
|
+
- lib/hyper_resource/adapter/hal_json.rb
|
137
124
|
- lib/hyper_resource/attributes.rb
|
138
125
|
- lib/hyper_resource/exceptions.rb
|
139
126
|
- lib/hyper_resource/link.rb
|
@@ -143,7 +130,6 @@ files:
|
|
143
130
|
- lib/hyper_resource/objects.rb
|
144
131
|
- lib/hyper_resource/response.rb
|
145
132
|
- lib/hyper_resource/version.rb
|
146
|
-
- lib/hyper_resource.rb
|
147
133
|
- lib/hyperresource.rb
|
148
134
|
homepage: https://github.com/gamache/hyperresource
|
149
135
|
licenses:
|
@@ -165,9 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
151
|
version: '0'
|
166
152
|
requirements: []
|
167
153
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
154
|
+
rubygems_version: 2.2.0
|
169
155
|
signing_key:
|
170
156
|
specification_version: 4
|
171
157
|
summary: Extensible hypermedia client for Ruby
|
172
158
|
test_files: []
|
173
|
-
has_rdoc: true
|