perry 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module Perry::Adapters
25
25
 
26
26
  def write(options)
27
27
  object = options[:object]
28
- params = build_params_from_attributes(object)
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 [:get, :delete].include?(method)
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 build_params_from_attributes(object)
95
+ def build_write_params_from_attributes(object)
99
96
  if self.config[:post_body_wrapper]
100
- defaults = self.config[:default_options]
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
- # TRP: method GET and DELETE have no POST body so we have to append any default options onto
125
- # the query string
126
- if [:get, :delete].include?(method)
127
- uri.query = (self.config[:default_options] || {}).merge(params).to_query
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
@@ -2,8 +2,8 @@ module Perry
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 7
6
- TINY = 1
5
+ MINOR = 8
6
+ TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
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: 1
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 1
10
- version: 0.7.1
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: 2011-11-11 00:00:00 Z
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.9
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