perry 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/perry/adapters/restful_http_adapter.rb +16 -16
- data/lib/perry/version.rb +2 -2
- metadata +6 -6
@@ -25,7 +25,7 @@ module Perry::Adapters
|
|
25
25
|
|
26
26
|
def write(options)
|
27
27
|
object = options[:object]
|
28
|
-
params =
|
28
|
+
params = build_write_params_from_attributes(object)
|
29
29
|
object.new_record? ? post_http(object, params) : put_http(object, params)
|
30
30
|
end
|
31
31
|
|
@@ -60,11 +60,8 @@ module Perry::Adapters
|
|
60
60
|
end
|
61
61
|
|
62
62
|
req_uri = self.build_uri(object, method, params || {})
|
63
|
-
|
64
|
-
if [:
|
65
|
-
request = request_klass.new([req_uri.path, req_uri.query].join('?'))
|
66
|
-
else
|
67
|
-
request = request_klass.new(req_uri.path)
|
63
|
+
request = request_klass.new([req_uri.path, req_uri.query].join('?'))
|
64
|
+
if [:post, :put].include?(method)
|
68
65
|
request.set_form_data(params)
|
69
66
|
end
|
70
67
|
|
@@ -95,16 +92,12 @@ module Perry::Adapters
|
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
98
|
-
def
|
95
|
+
def build_write_params_from_attributes(object)
|
99
96
|
if self.config[:post_body_wrapper]
|
100
|
-
|
101
|
-
params = defaults ? defaults.dup : {}
|
102
|
-
params.merge!(object.write_options[:default_options]) if object.write_options.is_a?(Hash) && object.write_options[:default_options].is_a?(Hash)
|
103
|
-
|
97
|
+
params = {}
|
104
98
|
object.attributes.each do |attribute, value|
|
105
99
|
params.merge!({"#{self.config[:post_body_wrapper]}[#{attribute}]" => value})
|
106
100
|
end
|
107
|
-
|
108
101
|
params
|
109
102
|
else
|
110
103
|
object.attributes
|
@@ -121,11 +114,18 @@ module Perry::Adapters
|
|
121
114
|
|
122
115
|
uri = URI.parse "#{url.join('/')}#{self.config[:format]}"
|
123
116
|
|
124
|
-
#
|
125
|
-
# the query string
|
126
|
-
|
127
|
-
|
117
|
+
# append any config `:default_options` and any object `:default_options`
|
118
|
+
# onto the query string. if GET or DELETE, also append the params
|
119
|
+
# since they don't use a post body
|
120
|
+
defaults = self.config[:default_options] || {}
|
121
|
+
if object.respond_to?(:write_options) && object.write_options.is_a?(Hash) && object.write_options[:default_options].is_a?(Hash)
|
122
|
+
defaults.merge!(object.write_options[:default_options])
|
128
123
|
end
|
124
|
+
uri.query = if [:get, :delete].include?(method)
|
125
|
+
defaults.merge(params)
|
126
|
+
else
|
127
|
+
defaults
|
128
|
+
end.to_query
|
129
129
|
|
130
130
|
uri
|
131
131
|
end
|
data/lib/perry/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Petticrew
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-08-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
requirements: []
|
202
202
|
|
203
203
|
rubyforge_project:
|
204
|
-
rubygems_version: 1.8.
|
204
|
+
rubygems_version: 1.8.15
|
205
205
|
signing_key:
|
206
206
|
specification_version: 3
|
207
207
|
summary: Ruby library for querying and mapping data through generic interfaces
|