aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r--activeresource/lib/active_resource/base.rb72
-rw-r--r--activeresource/lib/active_resource/custom_methods.rb20
-rw-r--r--activeresource/lib/active_resource/http_mock.rb46
3 files changed, 69 insertions, 69 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 935cfe5ecf..65d285249b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -81,19 +81,19 @@ module ActiveResource
# <tt>post</tt>, <tt>put</tt> and <tt>\delete</tt> methods where you can specify a custom REST method
# name to invoke.
#
- # # POST to the custom 'register' REST method, i.e. POST /people/new/register.xml.
+ # # POST to the custom 'register' REST method, i.e. POST /people/new/register.json.
# Person.new(:name => 'Ryan').post(:register)
# # => { :id => 1, :name => 'Ryan', :position => 'Clerk' }
#
- # # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.xml?position=Manager.
+ # # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.json?position=Manager.
# Person.find(1).put(:promote, :position => 'Manager')
# # => { :id => 1, :name => 'Ryan', :position => 'Manager' }
#
- # # GET all the positions available, i.e. GET /people/positions.xml.
+ # # GET all the positions available, i.e. GET /people/positions.json.
# Person.get(:positions)
# # => [{:name => 'Manager'}, {:name => 'Clerk'}]
#
- # # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.xml.
+ # # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.json.
# Person.find(1).delete(:fire)
#
# For more information on using custom REST methods, see the
@@ -164,7 +164,7 @@ module ActiveResource
# response code will be returned from the server which will raise an ActiveResource::ResourceNotFound
# exception.
#
- # # GET http://api.people.com:3000/people/999.xml
+ # # GET http://api.people.com:3000/people/999.json
# ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound
#
#
@@ -218,7 +218,7 @@ module ActiveResource
# ryan.save # => false
#
# # When
- # # PUT http://api.people.com:3000/people/1.xml
+ # # PUT http://api.people.com:3000/people/1.json
# # or
# # PUT http://api.people.com:3000/people/1.json
# # is requested with invalid values, the response is:
@@ -489,7 +489,7 @@ module ActiveResource
# Person.format = ActiveResource::Formats::XmlFormat
# Person.find(1) # => GET /people/1.xml
#
- # Default format is <tt>:xml</tt>.
+ # Default format is <tt>:json</tt>.
def format=(mime_type_reference_or_format)
format = mime_type_reference_or_format.is_a?(Symbol) ?
ActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format
@@ -570,7 +570,7 @@ module ActiveResource
attr_accessor_with_default(:primary_key, 'id') #:nodoc:
- # Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
+ # Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>)
# This method is regenerated at runtime based on what the \prefix is set to.
def prefix(options={})
default = site.path
@@ -587,7 +587,7 @@ module ActiveResource
prefix_source
end
- # Sets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>).
+ # Sets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>).
# Default value is <tt>site.path</tt>.
def prefix=(value = '/')
# Replace :placeholders with '#{embedded options[:lookups]}'
@@ -618,21 +618,21 @@ module ActiveResource
#
# ==== Options
# +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
- # would yield a URL like <tt>/accounts/19/purchases.xml</tt>).
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
# +query_options+ - A \hash to add items to the query string for the request.
#
# ==== Examples
# Post.element_path(1)
- # # => /posts/1.xml
+ # # => /posts/1.json
#
# Comment.element_path(1, :post_id => 5)
- # # => /posts/5/comments/1.xml
+ # # => /posts/5/comments/1.json
#
# Comment.element_path(1, :post_id => 5, :active => 1)
- # # => /posts/5/comments/1.xml?active=1
+ # # => /posts/5/comments/1.json?active=1
#
# Comment.element_path(1, {:post_id => 5}, {:active => 1})
- # # => /posts/5/comments/1.xml?active=1
+ # # => /posts/5/comments/1.json?active=1
#
def element_path(id, prefix_options = {}, query_options = nil)
check_prefix_options(prefix_options)
@@ -645,14 +645,14 @@ module ActiveResource
#
# ==== Options
# * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
- # would yield a URL like <tt>/accounts/19/purchases/new.xml</tt>).
+ # would yield a URL like <tt>/accounts/19/purchases/new.json</tt>).
#
# ==== Examples
# Post.new_element_path
- # # => /posts/new.xml
+ # # => /posts/new.json
#
# Comment.collection_path(:post_id => 5)
- # # => /posts/5/comments/new.xml
+ # # => /posts/5/comments/new.json
def new_element_path(prefix_options = {})
"#{prefix(prefix_options)}#{collection_name}/new.#{format.extension}"
end
@@ -662,21 +662,21 @@ module ActiveResource
#
# ==== Options
# * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
- # would yield a URL like <tt>/accounts/19/purchases.xml</tt>).
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
# * +query_options+ - A hash to add items to the query string for the request.
#
# ==== Examples
# Post.collection_path
- # # => /posts.xml
+ # # => /posts.json
#
# Comment.collection_path(:post_id => 5)
- # # => /posts/5/comments.xml
+ # # => /posts/5/comments.json
#
# Comment.collection_path(:post_id => 5, :active => 1)
- # # => /posts/5/comments.xml?active=1
+ # # => /posts/5/comments.json?active=1
#
# Comment.collection_path({:post_id => 5}, {:active => 1})
- # # => /posts/5/comments.xml?active=1
+ # # => /posts/5/comments.json?active=1
#
def collection_path(prefix_options = {}, query_options = nil)
check_prefix_options(prefix_options)
@@ -745,34 +745,34 @@ module ActiveResource
#
# ==== Examples
# Person.find(1)
- # # => GET /people/1.xml
+ # # => GET /people/1.json
#
# Person.find(:all)
- # # => GET /people.xml
+ # # => GET /people.json
#
# Person.find(:all, :params => { :title => "CEO" })
- # # => GET /people.xml?title=CEO
+ # # => GET /people.json?title=CEO
#
# Person.find(:first, :from => :managers)
- # # => GET /people/managers.xml
+ # # => GET /people/managers.json
#
# Person.find(:last, :from => :managers)
- # # => GET /people/managers.xml
+ # # => GET /people/managers.json
#
- # Person.find(:all, :from => "/companies/1/people.xml")
- # # => GET /companies/1/people.xml
+ # Person.find(:all, :from => "/companies/1/people.json")
+ # # => GET /companies/1/people.json
#
# Person.find(:one, :from => :leader)
- # # => GET /people/leader.xml
+ # # => GET /people/leader.json
#
# Person.find(:all, :from => :developers, :params => { :language => 'ruby' })
- # # => GET /people/developers.xml?language=ruby
+ # # => GET /people/developers.json?language=ruby
#
- # Person.find(:one, :from => "/companies/1/manager.xml")
- # # => GET /companies/1/manager.xml
+ # Person.find(:one, :from => "/companies/1/manager.json")
+ # # => GET /companies/1/manager.json
#
# StreetAddress.find(1, :params => { :person_id => 1 })
- # # => GET /people/1/street_addresses/1.xml
+ # # => GET /people/1/street_addresses/1.json
#
# == Failure or missing data
# A failure to find the requested object raises a ResourceNotFound
@@ -833,7 +833,7 @@ module ActiveResource
# my_event = Event.find(:first) # let's assume this is event with ID 7
# Event.delete(my_event.id) # sends DELETE /events/7
#
- # # Let's assume a request to events/5/cancel.xml
+ # # Let's assume a request to events/5/cancel.json
# Event.delete(params[:id]) # sends DELETE /events/5
def delete(id, options = {})
connection.delete(element_path(id, options))
@@ -1121,7 +1121,7 @@ module ActiveResource
# Saves (+POST+) or \updates (+PUT+) a resource. Delegates to +create+ if the object is \new,
# +update+ if it exists. If the response to the \save includes a body, it will be assumed that this body
- # is XML for the final object as it looked after the \save (which would include attributes like +created_at+
+ # is Json for the final object as it looked after the \save (which would include attributes like +created_at+
# that weren't part of the original submit).
#
# ==== Examples
diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb
index 38473c6cf7..c1931b2758 100644
--- a/activeresource/lib/active_resource/custom_methods.rb
+++ b/activeresource/lib/active_resource/custom_methods.rb
@@ -11,10 +11,10 @@ module ActiveResource
#
# This route set creates routes for the following HTTP requests:
#
- # POST /people/new/register.xml # PeopleController.register
- # PUT /people/1/promote.xml # PeopleController.promote with :id => 1
- # DELETE /people/1/deactivate.xml # PeopleController.deactivate with :id => 1
- # GET /people/active.xml # PeopleController.active
+ # POST /people/new/register.json # PeopleController.register
+ # PUT /people/1/promote.json # PeopleController.promote with :id => 1
+ # DELETE /people/1/deactivate.json # PeopleController.deactivate with :id => 1
+ # GET /people/active.json # PeopleController.active
#
# Using this module, Active Resource can use these custom REST methods just like the
# standard methods.
@@ -23,13 +23,13 @@ module ActiveResource
# self.site = "http://37s.sunrise.i:3000"
# end
#
- # Person.new(:name => 'Ryan).post(:register) # POST /people/new/register.xml
+ # Person.new(:name => 'Ryan).post(:register) # POST /people/new/register.json
# # => { :id => 1, :name => 'Ryan' }
#
- # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.xml
- # Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.xml
+ # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.json
+ # Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.json
#
- # Person.get(:active) # GET /people/active.xml
+ # Person.get(:active) # GET /people/active.json
# # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
#
module CustomMethods
@@ -41,10 +41,10 @@ module ActiveResource
# Invokes a GET to a given custom REST method. For example:
#
- # Person.get(:active) # GET /people/active.xml
+ # Person.get(:active) # GET /people/active.json
# # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
#
- # Person.get(:active, :awesome => true) # GET /people/active.xml?awesome=true
+ # Person.get(:active, :awesome => true) # GET /people/active.json?awesome=true
# # => [{:id => 1, :name => 'Ryan'}]
#
# Note: the objects returned from this method are not automatically converted
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 3bfd536b29..e90580be4f 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -20,10 +20,10 @@ module ActiveResource
# * <tt>path</tt> - A string, starting with a "/", defining the URI that is expected to be
# called.
# * <tt>request_headers</tt> - Headers that are expected along with the request. This argument uses a
- # hash format, such as <tt>{ "Content-Type" => "application/xml" }</tt>. This mock will only trigger
+ # hash format, such as <tt>{ "Content-Type" => "application/json" }</tt>. This mock will only trigger
# if your tests sends a request with identical headers.
# * <tt>body</tt> - The data to be returned. This should be a string of Active Resource parseable content,
- # such as XML.
+ # such as Json.
# * <tt>status</tt> - The HTTP response code, as an integer, to return with the response.
# * <tt>response_headers</tt> - Headers to be returned with the response. Uses the same hash format as
# <tt>request_headers</tt> listed above.
@@ -35,12 +35,12 @@ module ActiveResource
#
# ==== Example
# def setup
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
# ActiveResource::HttpMock.respond_to do |mock|
- # mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
- # mock.get "/people/1.xml", {}, @matz
- # mock.put "/people/1.xml", {}, nil, 204
- # mock.delete "/people/1.xml", {}, nil, 200
+ # mock.post "/people.json", {}, @matz, 201, "Location" => "/people/1.json"
+ # mock.get "/people/1.json", {}, @matz
+ # mock.put "/people/1.json", {}, nil, 204
+ # mock.delete "/people/1.json", {}, nil, 200
# end
# end
#
@@ -85,9 +85,9 @@ module ActiveResource
#
# ==== Example
# def setup
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
# ActiveResource::HttpMock.respond_to do |mock|
- # mock.get "/people/1.xml", {}, @matz
+ # mock.get "/people/1.json", {}, @matz
# end
# end
#
@@ -95,7 +95,7 @@ module ActiveResource
# person = Person.find(1) # Call the remote service
#
# # This request object has the same HTTP method and path as declared by the mock
- # expected_request = ActiveResource::Request.new(:get, "/people/1.xml")
+ # expected_request = ActiveResource::Request.new(:get, "/people/1.json")
#
# # Assert that the mock received, and responded to, the expected request from the model
# assert ActiveResource::HttpMock.requests.include?(expected_request)
@@ -117,12 +117,12 @@ module ActiveResource
#
# === Example
#
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
# ActiveResource::HttpMock.respond_to do |mock|
- # mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
- # mock.get "/people/1.xml", {}, @matz
- # mock.put "/people/1.xml", {}, nil, 204
- # mock.delete "/people/1.xml", {}, nil, 200
+ # mock.post "/people.json", {}, @matz, 201, "Location" => "/people/1.json"
+ # mock.get "/people/1.json", {}, @matz
+ # mock.put "/people/1.json", {}, nil, 204
+ # mock.delete "/people/1.json", {}, nil, 200
# end
#
# Alternatively, accepts a hash of <tt>{Request => Response}</tt> pairs allowing you to generate
@@ -135,11 +135,11 @@ module ActiveResource
#
# Request.new(:#{method}, path, nil, request_headers)
#
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
#
- # create_matz = ActiveResource::Request.new(:post, '/people.xml', @matz, {})
- # created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"})
- # get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
+ # create_matz = ActiveResource::Request.new(:post, '/people.json', @matz, {})
+ # created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.json"})
+ # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)
# ok_response = ActiveResource::Response.new("", 200, {})
#
# pairs = {create_matz => created_response, get_matz => ok_response}
@@ -154,12 +154,12 @@ module ActiveResource
# === Example
#
# ActiveResource::HttpMock.respond_to do |mock|
- # mock.send(:get, "/people/1", {}, "XML1")
+ # mock.send(:get, "/people/1", {}, "JSON1")
# end
# ActiveResource::HttpMock.responses.length #=> 1
#
# ActiveResource::HttpMock.respond_to(false) do |mock|
- # mock.send(:get, "/people/2", {}, "XML2")
+ # mock.send(:get, "/people/2", {}, "JSON2")
# end
# ActiveResource::HttpMock.responses.length #=> 2
#
@@ -169,11 +169,11 @@ module ActiveResource
# === Example
#
# ActiveResource::HttpMock.respond_to do |mock|
- # mock.send(:get, "/people/1", {}, "XML1")
+ # mock.send(:get, "/people/1", {}, "JSON1")
# end
# ActiveResource::HttpMock.responses.length #=> 1
#
- # get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
+ # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)
# ok_response = ActiveResource::Response.new("", 200, {})
#
# pairs = {get_matz => ok_response}