activeresource 3.2.22.5 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeresource might be problematic. Click here for more details.

@@ -0,0 +1,114 @@
1
+ module ActiveResource
2
+ module Singleton
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ attr_writer :singleton_name
7
+
8
+ def singleton_name
9
+ @singleton_name ||= model_name.element
10
+ end
11
+
12
+ # Gets the singleton path for the object. If the +query_options+ parameter is omitted, Rails
13
+ # will split from the \prefix options.
14
+ #
15
+ # ==== Options
16
+ # * +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
17
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
18
+ #
19
+ # * +query_options+ - A \hash to add items to the query string for the request.
20
+ #
21
+ # ==== Examples
22
+ # Weather.singleton_path
23
+ # # => /weather.json
24
+ #
25
+ # class Inventory < ActiveResource::Base
26
+ # self.site = "https://37s.sunrise.com"
27
+ # self.prefix = "/products/:product_id/"
28
+ # end
29
+ #
30
+ # Inventory.singleton_path(:product_id => 5)
31
+ # # => /products/5/inventory.json
32
+ #
33
+ # Inventory.singleton_path({:product_id => 5}, {:sold => true})
34
+ # # => /products/5/inventory.json?sold=true
35
+ #
36
+ def singleton_path(prefix_options = {}, query_options = nil)
37
+ check_prefix_options(prefix_options)
38
+
39
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
40
+ "#{prefix(prefix_options)}#{singleton_name}#{format_extension}#{query_string(query_options)}"
41
+ end
42
+
43
+ # Core method for finding singleton resources.
44
+ #
45
+ # ==== Arguments
46
+ # Takes a single argument of options
47
+ #
48
+ # ==== Options
49
+ # * <tt>:params</tt> - Sets the query and \prefix (nested URL) parameters.
50
+ #
51
+ # ==== Examples
52
+ # Weather.find
53
+ # # => GET /weather.json
54
+ #
55
+ # Weather.find(:params => {:degrees => 'fahrenheit'})
56
+ # # => GET /weather.json?degrees=fahrenheit
57
+ #
58
+ # == Failure or missing data
59
+ # A failure to find the requested object raises a ResourceNotFound exception.
60
+ #
61
+ # Inventory.find
62
+ # # => raises ResourceNotFound
63
+ def find(options={})
64
+ find_singleton(options)
65
+ end
66
+
67
+ private
68
+ # Find singleton resource
69
+ def find_singleton(options)
70
+ prefix_options, query_options = split_options(options[:params])
71
+
72
+ path = singleton_path(prefix_options, query_options)
73
+ resp = self.format.decode(self.connection.get(path, self.headers).body)
74
+ instantiate_record(resp, {})
75
+ end
76
+
77
+ end
78
+ # Deletes the resource from the remote service.
79
+ #
80
+ # ==== Examples
81
+ # weather = Weather.find
82
+ # weather.destroy
83
+ # Weather.find # 404 (Resource Not Found)
84
+ def destroy
85
+ connection.delete(singleton_path, self.class.headers)
86
+ end
87
+
88
+
89
+ protected
90
+
91
+ # Update the resource on the remote service
92
+ def update
93
+ connection.put(singleton_path(prefix_options), encode, self.class.headers).tap do |response|
94
+ load_attributes_from_response(response)
95
+ end
96
+ end
97
+
98
+ # Create (i.e. \save to the remote service) the \new resource.
99
+ def create
100
+ connection.post(singleton_path, encode, self.class.headers).tap do |response|
101
+ self.id = id_from_response(response)
102
+ load_attributes_from_response(response)
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def singleton_path(options = nil)
109
+ self.class.singleton_path(options || prefix_options)
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -15,20 +15,57 @@ module ActiveResource
15
15
  clear unless save_cache
16
16
  humanized_attributes = Hash[@base.attributes.keys.map { |attr_name| [attr_name.humanize, attr_name] }]
17
17
  messages.each do |message|
18
- attr_message = humanized_attributes.keys.detect do |attr_name|
18
+ attr_message = humanized_attributes.keys.sort_by { |a| -a.length }.detect do |attr_name|
19
19
  if message[0, attr_name.size + 1] == "#{attr_name} "
20
20
  add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
21
21
  end
22
22
  end
23
-
24
23
  self[:base] << message if attr_message.nil?
25
24
  end
26
25
  end
27
26
 
27
+ # Grabs errors from a hash of attribute => array of errors elements
28
+ # The second parameter directs the errors cache to be cleared (default)
29
+ # or not (by passing true)
30
+ #
31
+ # Unrecognized attribute names will be humanized and added to the record's
32
+ # base errors.
33
+ def from_hash(messages, save_cache = false)
34
+ clear unless save_cache
35
+
36
+ messages.each do |(key,errors)|
37
+ errors.each do |error|
38
+ if @base.attributes.keys.include?(key)
39
+ add key, error
40
+ elsif key == 'base'
41
+ self[:base] << error
42
+ else
43
+ # reporting an error on an attribute not in attributes
44
+ # format and add them to base
45
+ self[:base] << "#{key.humanize} #{error}"
46
+ end
47
+ end
48
+ end
49
+ end
50
+
28
51
  # Grabs errors from a json response.
29
52
  def from_json(json, save_cache = false)
30
- array = Array.wrap(ActiveSupport::JSON.decode(json)['errors']) rescue []
31
- from_array array, save_cache
53
+ decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
54
+ if decoded.kind_of?(Hash) && (decoded.has_key?('errors') || decoded.empty?)
55
+ errors = decoded['errors'] || {}
56
+ if errors.kind_of?(Array)
57
+ # 3.2.1-style with array of strings
58
+ ActiveSupport::Deprecation.warn('Returning errors as an array of strings is deprecated.')
59
+ from_array errors, save_cache
60
+ else
61
+ # 3.2.2+ style
62
+ from_hash errors, save_cache
63
+ end
64
+ else
65
+ # <3.2-style respond_with - lacks 'errors' key
66
+ ActiveSupport::Deprecation.warn('Returning errors as a hash without a root "errors" key is deprecated.')
67
+ from_hash decoded, save_cache
68
+ end
32
69
  end
33
70
 
34
71
  # Grabs errors from an XML response.
@@ -121,9 +158,11 @@ module ActiveResource
121
158
  # # => false
122
159
  #
123
160
  def valid?
124
- super
125
- load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?
126
- errors.empty?
161
+ run_callbacks :validate do
162
+ super
163
+ load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?
164
+ errors.empty?
165
+ end
127
166
  end
128
167
 
129
168
  # Returns the Errors object that holds all information about attribute error messages.
@@ -1,9 +1,9 @@
1
1
  module ActiveResource
2
2
  module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 2
5
- TINY = 22
6
- PRE = "5"
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ TINY = 0
6
+ PRE = "beta1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,43 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.22.5
4
+ version: 4.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2013-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.22.5
19
+ version: 4.0.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.22.5
26
+ version: 4.0.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.22.5
33
+ version: 4.0.0.beta1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.2.22.5
40
+ version: 4.0.0.beta1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails-observers
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.13.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.13.0
41
83
  description: REST on Rails. Wrap your RESTful web app with Ruby classes and work with
42
84
  them like Active Record models.
43
85
  email: david@loudthinking.com
@@ -46,50 +88,55 @@ extensions: []
46
88
  extra_rdoc_files:
47
89
  - README.rdoc
48
90
  files:
49
- - CHANGELOG.md
50
- - MIT-LICENSE
51
91
  - README.rdoc
52
- - examples/performance.rb
53
- - lib/active_resource.rb
92
+ - lib/active_resource/associations/builder/association.rb
93
+ - lib/active_resource/associations/builder/belongs_to.rb
94
+ - lib/active_resource/associations/builder/has_many.rb
95
+ - lib/active_resource/associations/builder/has_one.rb
96
+ - lib/active_resource/associations.rb
54
97
  - lib/active_resource/base.rb
98
+ - lib/active_resource/callbacks.rb
99
+ - lib/active_resource/collection.rb
55
100
  - lib/active_resource/connection.rb
56
101
  - lib/active_resource/custom_methods.rb
57
102
  - lib/active_resource/exceptions.rb
58
- - lib/active_resource/formats.rb
59
103
  - lib/active_resource/formats/json_format.rb
60
104
  - lib/active_resource/formats/xml_format.rb
105
+ - lib/active_resource/formats.rb
61
106
  - lib/active_resource/http_mock.rb
62
107
  - lib/active_resource/log_subscriber.rb
63
108
  - lib/active_resource/observing.rb
64
109
  - lib/active_resource/railtie.rb
110
+ - lib/active_resource/reflection.rb
65
111
  - lib/active_resource/schema.rb
112
+ - lib/active_resource/singleton.rb
66
113
  - lib/active_resource/validations.rb
67
114
  - lib/active_resource/version.rb
115
+ - lib/active_resource.rb
68
116
  homepage: http://www.rubyonrails.org
69
117
  licenses:
70
118
  - MIT
71
119
  metadata: {}
72
120
  post_install_message:
73
121
  rdoc_options:
74
- - "--main"
122
+ - --main
75
123
  - README.rdoc
76
124
  require_paths:
77
125
  - lib
78
126
  required_ruby_version: !ruby/object:Gem::Requirement
79
127
  requirements:
80
- - - ">="
128
+ - - '>='
81
129
  - !ruby/object:Gem::Version
82
- version: 1.8.7
130
+ version: 1.9.3
83
131
  required_rubygems_version: !ruby/object:Gem::Requirement
84
132
  requirements:
85
- - - ">="
133
+ - - '>'
86
134
  - !ruby/object:Gem::Version
87
- version: '0'
135
+ version: 1.3.1
88
136
  requirements: []
89
137
  rubyforge_project:
90
- rubygems_version: 2.6.6
138
+ rubygems_version: 2.0.0
91
139
  signing_key:
92
140
  specification_version: 4
93
141
  summary: REST modeling framework (part of Rails).
94
142
  test_files: []
95
- has_rdoc:
@@ -1,437 +0,0 @@
1
- ## Rails 3.2.22 (Jun 16, 2015) ##
2
-
3
- * No changes.
4
-
5
-
6
- ## Rails 3.2.19 (Jul 2, 2014) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 3.2.18 (May 6, 2014) ##
12
-
13
- * No changes.
14
-
15
-
16
- ## Rails 3.2.17 (Feb 18, 2014) ##
17
-
18
- * No changes.
19
-
20
-
21
- ## Rails 3.2.16 (Dec 3, 2013) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 3.2.15 (Oct 16, 2013) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 3.2.14 (Jul 22, 2013) ##
32
-
33
- * Fixes an issue that ActiveResource models ignores ActiveResource::Base.include_root_in_json.
34
- Backported from the now separate repo rails/activeresouce.
35
-
36
- *Xinjiang Lu*
37
-
38
-
39
- ## Rails 3.2.13 (Mar 18, 2013) ##
40
-
41
- * No changes.
42
-
43
-
44
- ## Rails 3.2.12 (Feb 11, 2013) ##
45
-
46
- * No changes.
47
-
48
-
49
- ## Rails 3.2.11 (Jan 8, 2013) ##
50
-
51
- * No changes.
52
-
53
-
54
- ## Rails 3.2.10 (Jan 2, 2013) ##
55
-
56
- * No changes.
57
-
58
-
59
- ## Rails 3.2.9 (Nov 12, 2012) ##
60
-
61
- * No changes.
62
-
63
-
64
- ## Rails 3.2.8 (Aug 9, 2012) ##
65
-
66
- * No changes.
67
-
68
-
69
- ## Rails 3.2.7 (Jul 26, 2012) ##
70
-
71
- * No changes.
72
-
73
-
74
- ## Rails 3.2.6 (Jun 12, 2012) ##
75
-
76
- * No changes.
77
-
78
-
79
- ## Rails 3.2.5 (Jun 1, 2012) ##
80
-
81
- * No changes.
82
-
83
-
84
- ## Rails 3.2.4 (May 31, 2012) ##
85
-
86
- * No changes.
87
-
88
-
89
- ## Rails 3.2.3 (March 30, 2012) ##
90
-
91
- * No changes.
92
-
93
-
94
- ## Rails 3.2.2 (March 1, 2012) ##
95
-
96
- * No changes.
97
-
98
-
99
- ## Rails 3.2.1 (January 26, 2012) ##
100
-
101
- * Documentation fixes.
102
-
103
-
104
- ## Rails 3.2.0 (January 20, 2012) ##
105
-
106
- * Redirect responses: 303 See Other and 307 Temporary Redirect now behave like
107
- 301 Moved Permanently and 302 Found. GH #3302.
108
-
109
- *Jim Herz*
110
-
111
-
112
- ## Rails 3.1.1 (October 7, 2011) ##
113
-
114
- * No changes.
115
-
116
-
117
- ## Rails 3.1.0 (August 30, 2011) ##
118
-
119
- * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set `self.format = :xml` in the class. eg.
120
-
121
- class User < ActiveResource::Base self.format = :xml
122
- end
123
-
124
- ## Rails 3.0.7 (April 18, 2011) ##
125
-
126
- * No changes.
127
-
128
-
129
- * Rails 3.0.6 (April 5, 2011)
130
-
131
- * No changes.
132
-
133
-
134
- ## Rails 3.0.5 (February 26, 2011) ##
135
-
136
- * No changes.
137
-
138
-
139
- ## Rails 3.0.4 (February 8, 2011) ##
140
-
141
- * No changes.
142
-
143
-
144
- ## Rails 3.0.3 (November 16, 2010) ##
145
-
146
- * No changes.
147
-
148
-
149
- ## Rails 3.0.2 (November 15, 2010) ##
150
-
151
- * No changes
152
-
153
-
154
- ## Rails 3.0.1 (October 15, 2010) ##
155
-
156
- * No Changes, just a version bump.
157
-
158
-
159
- ## Rails 3.0.0 (August 29, 2010) ##
160
-
161
- * JSON: set Base.include_root_in_json = true to include a root value in the JSON: {"post": {"title": ...}}. Mirrors the Active Record option. *Santiago Pastorino*
162
-
163
- * Add support for errors in JSON format. #1956 *Fabien Jakimowicz*
164
-
165
- * Recognizes 410 as Resource Gone. #2316 *Jordan Brough, Jatinder Singh*
166
-
167
- * More thorough SSL support. #2370 *Roy Nicholson*
168
-
169
- * HTTP proxy support. #2133 *Marshall Huss, Sébastien Dabet*
170
-
171
-
172
- ## 2.3.2 Final (March 15, 2009) ##
173
-
174
- * Nothing new, just included in 2.3.2
175
-
176
-
177
- ## 2.2.1 RC2 (November 14th, 2008) ##
178
-
179
- * Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 *Paolo Angelini*
180
-
181
-
182
- ## 2.2.0 RC1 (October 24th, 2008) ##
183
-
184
- * Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 *Rasik Pandey, Cody Fauser*
185
-
186
- * Add ActiveResource::Base.find(:last). [#754 state:resolved] (Adrian Mugnolo)
187
-
188
- * Fixed problems with the logger used if the logging string included %'s [#840 state:resolved] (Jamis Buck)
189
-
190
- * Fixed Base#exists? to check status code as integer [#299 state:resolved] (Wes Oldenbeuving)
191
-
192
-
193
- ## 2.1.0 (May 31st, 2008) ##
194
-
195
- * Fixed response logging to use length instead of the entire thing (seangeo) *#27*
196
-
197
- * Fixed that to_param should be used and honored instead of hardcoding the id #11406 *gspiers*
198
-
199
- * Improve documentation. *Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert*
200
-
201
- * Use HEAD instead of GET in exists? *bscofield*
202
-
203
- * Fix small documentation typo. Closes #10670 *Luca Guidi*
204
-
205
- * find_or_create_resource_for handles module nesting. #10646 *xavier*
206
-
207
- * Allow setting ActiveResource::Base#format before #site. *Rick Olson*
208
-
209
- * Support agnostic formats when calling custom methods. Closes #10635 *joerichsen*
210
-
211
- * Document custom methods. #10589 *Cheah Chu Yeow*
212
-
213
- * Ruby 1.9 compatibility. *Jeremy Kemper*
214
-
215
-
216
- ## 2.0.2 (December 16th, 2007) ##
217
-
218
- * Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 *trek*
219
-
220
- * Correct empty response handling. #10445 *seangeo*
221
-
222
-
223
- ## 2.0.1 (December 7th, 2007) ##
224
-
225
- * Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 *kou*
226
-
227
- * Update XML documentation examples to include explicit type attributes. Closes #9754 *Josh Susser*
228
-
229
- * Added one-off declarations of mock behavior [David Heinemeier Hansson]. Example:
230
-
231
- Before:
232
- ActiveResource::HttpMock.respond_to do |mock|
233
- mock.get "/people/1.xml", {}, "<person><name>David</name></person>"
234
- end
235
-
236
- Now:
237
- ActiveResource::HttpMock.respond_to.get "/people/1.xml", {}, "<person><name>David</name></person>"
238
-
239
- * Added ActiveResource.format= which defaults to :xml but can also be set to :json [David Heinemeier Hansson]. Example:
240
-
241
- class Person < ActiveResource::Base
242
- self.site = "http://app/"
243
- self.format = :json
244
- end
245
-
246
- person = Person.find(1) # => GET http://app/people/1.json
247
- person.name = "David"
248
- person.save # => PUT http://app/people/1.json {name: "David"}
249
-
250
- Person.format = :xml
251
- person.name = "Mary"
252
- person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>
253
-
254
- * Fix reload error when path prefix is used. #8727 *Ian Warshak*
255
-
256
- * Remove ActiveResource::Struct because it hasn't proven very useful. Creating a new ActiveResource::Base subclass is often less code and always clearer. #8612 *Josh Peek*
257
-
258
- * Fix query methods on resources. *Cody Fauser*
259
-
260
- * pass the prefix_options to the instantiated record when using find without a specific id. Closes #8544 *Eloy Duran*
261
-
262
- * Recognize and raise an exception on 405 Method Not Allowed responses. #7692 *Josh Peek*
263
-
264
- * Handle string and symbol param keys when splitting params into prefix params and query params.
265
-
266
- Comment.find(:all, :params => { :article_id => 5, :page => 2 }) or Comment.find(:all, :params => { 'article_id' => 5, :page => 2 })
267
-
268
- * Added find-one with symbol [David Heinemeier Hansson]. Example: Person.find(:one, :from => :leader) # => GET /people/leader.xml
269
-
270
- * BACKWARDS INCOMPATIBLE: Changed the finder API to be more extensible with :params and more strict usage of scopes [David Heinemeier Hansson]. Changes:
271
-
272
- Person.find(:all, :title => "CEO") ...becomes: Person.find(:all, :params => { :title => "CEO" })
273
- Person.find(:managers) ...becomes: Person.find(:all, :from => :managers)
274
- Person.find("/companies/1/manager.xml") ...becomes: Person.find(:one, :from => "/companies/1/manager.xml")
275
-
276
- * Add support for setting custom headers per Active Resource model *Rick Olson*
277
-
278
- class Project
279
- headers['X-Token'] = 'foo'
280
- end
281
-
282
- \# makes the GET request with the custom X-Token header
283
- Project.find(:all)
284
-
285
- * Added find-by-path options to ActiveResource::Base.find [David Heinemeier Hansson]. Examples:
286
-
287
- employees = Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml
288
- manager = Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml
289
-
290
-
291
- * Added support for using classes from within a single nested module [David Heinemeier Hansson]. Example:
292
-
293
- module Highrise
294
- class Note < ActiveResource::Base
295
- self.site = "http://37s.sunrise.i:3000"
296
- end
297
-
298
- class Comment < ActiveResource::Base
299
- self.site = "http://37s.sunrise.i:3000"
300
- end
301
- end
302
-
303
- assert_kind_of Highrise::Comment, Note.find(1).comments.first
304
-
305
-
306
- * Added load_attributes_from_response as a way of loading attributes from other responses than just create *David Heinemeier Hansson*
307
-
308
- class Highrise::Task < ActiveResource::Base
309
- def complete
310
- load_attributes_from_response(post(:complete))
311
- end
312
- end
313
-
314
- ...will set "done_at" when complete is called.
315
-
316
-
317
- * Added support for calling custom methods #6979 *rwdaigle*
318
-
319
- Person.find(:managers) # => GET /people/managers.xml
320
- Kase.find(1).post(:close) # => POST /kases/1/close.xml
321
-
322
- * Remove explicit prefix_options parameter for ActiveResource::Base#initialize. *Rick Olson*
323
- ActiveResource splits the prefix_options from it automatically.
324
-
325
- * Allow ActiveResource::Base.delete with custom prefix. *Rick Olson*
326
-
327
- * Add ActiveResource::Base#dup *Rick Olson*
328
-
329
- * Fixed constant warning when fetching the same object multiple times *David Heinemeier Hansson*
330
-
331
- * Added that saves which get a body response (and not just a 201) will use that response to update themselves *David Heinemeier Hansson*
332
-
333
- * Disregard namespaces from the default element name, so Highrise::Person will just try to fetch from "/people", not "/highrise/people" *David Heinemeier Hansson*
334
-
335
- * Allow array and hash query parameters. #7756 *Greg Spurrier*
336
-
337
- * Loading a resource preserves its prefix_options. #7353 *Ryan Daigle*
338
-
339
- * Carry over the convenience of #create from ActiveRecord. Closes #7340. *Ryan Daigle*
340
-
341
- * Increase ActiveResource::Base test coverage. Closes #7173, #7174 *Rich Collins*
342
-
343
- * Interpret 422 Unprocessable Entity as ResourceInvalid. #7097 *dkubb*
344
-
345
- * Mega documentation patches. #7025, #7069 *rwdaigle*
346
-
347
- * Base.exists?(id, options) and Base#exists? check whether the resource is found. #6970 *rwdaigle*
348
-
349
- * Query string support. *untext, Jeremy Kemper*
350
- # GET /forums/1/topics.xml?sort=created_at
351
- Topic.find(:all, :forum_id => 1, :sort => 'created_at')
352
-
353
- * Base#==, eql?, and hash methods. == returns true if its argument is identical to self or if it's an instance of the same class, is not new?, and has the same id. eql? is an alias for ==. hash delegates to id. *Jeremy Kemper*
354
-
355
- * Allow subclassed resources to share the site info *Rick Olson, Jeremy Kemper*
356
- d class BeastResource < ActiveResource::Base
357
- self.site = 'http://beast.caboo.se'
358
- end
359
-
360
- class Forum < BeastResource
361
- # taken from BeastResource
362
- # self.site = 'http://beast.caboo.se'
363
- end
364
-
365
- class Topic < BeastResource
366
- self.site += '/forums/:forum_id'
367
- end
368
-
369
- * Fix issues with ActiveResource collection handling. Closes #6291. *bmilekic*
370
-
371
- * Use attr_accessor_with_default to dry up attribute initialization. References #6538. *Stuart Halloway*
372
-
373
- * Add basic logging support for logging outgoing requests. *Jamis Buck*
374
-
375
- * Add Base.delete for deleting resources without having to instantiate them first. *Jamis Buck*
376
-
377
- * Make #save behavior mimic AR::Base#save (true on success, false on failure). *Jamis Buck*
378
-
379
- * Add Basic HTTP Authentication to ActiveResource (closes #6305). *jonathan*
380
-
381
- * Extracted #id_from_response as an entry point for customizing how a created resource gets its own ID.
382
- By default, it extracts from the Location response header.
383
-
384
- * Optimistic locking: raise ActiveResource::ResourceConflict on 409 Conflict response. *Jeremy Kemper*
385
-
386
- # Example controller action
387
- def update
388
- @person.save!
389
- rescue ActiveRecord::StaleObjectError
390
- render :xml => @person.reload.to_xml, :status => '409 Conflict'
391
- end
392
-
393
- * Basic validation support *Rick Olson*
394
-
395
- Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.
396
-
397
- render :xml => @person.errors.to_xml, :status => '400 Validation Error'
398
-
399
- * Deep hashes are converted into collections of resources. *Jeremy Kemper*
400
- Person.new :name => 'Bob',
401
- :address => { :id => 1, :city => 'Portland' },
402
- :contacts => [{ :id => 1 }, { :id => 2 }]
403
- Looks for Address and Contact resources and creates them if unavailable.
404
- So clients can fetch a complex resource in a single request if you e.g.
405
- render :xml => @person.to_xml(:include => [:address, :contacts])
406
- in your controller action.
407
-
408
- * Major updates *Rick Olson*
409
-
410
- * Add full support for find/create/update/destroy
411
- * Add support for specifying prefixes.
412
- * Allow overriding of element_name, collection_name, and primary key
413
- * Provide simpler HTTP mock interface for testing
414
-
415
- # rails routing code
416
- map.resources :posts do |post|
417
- post.resources :comments
418
- end
419
-
420
- # ActiveResources
421
- class Post < ActiveResource::Base
422
- self.site = "http://37s.sunrise.i:3000/"
423
- end
424
-
425
- class Comment < ActiveResource::Base
426
- self.site = "http://37s.sunrise.i:3000/posts/:post_id/"
427
- end
428
-
429
- @post = Post.find 5
430
- @comments = Comment.find :all, :post_id => @post.id
431
-
432
- @comment = Comment.new({:body => 'hello world'}, {:post_id => @post.id})
433
- @comment.save
434
-
435
- * Base.site= accepts URIs. 200...400 are valid response codes. PUT and POST request bodies default to ''. *Jeremy Kemper*
436
-
437
- * Initial checkin: object-oriented client for restful HTTP resources which follow the Rails convention. *David Heinemeier Hansson*