--- !ruby/object:RI::ClassDescription 
attributes: []

class_methods: 
- !ruby/object:RI::MethodSummary 
  name: collection_path
- !ruby/object:RI::MethodSummary 
  name: connection
- !ruby/object:RI::MethodSummary 
  name: create
- !ruby/object:RI::MethodSummary 
  name: delete
- !ruby/object:RI::MethodSummary 
  name: element_path
- !ruby/object:RI::MethodSummary 
  name: exists?
- !ruby/object:RI::MethodSummary 
  name: find
- !ruby/object:RI::MethodSummary 
  name: format
- !ruby/object:RI::MethodSummary 
  name: format=
- !ruby/object:RI::MethodSummary 
  name: headers
- !ruby/object:RI::MethodSummary 
  name: new
- !ruby/object:RI::MethodSummary 
  name: password
- !ruby/object:RI::MethodSummary 
  name: password=
- !ruby/object:RI::MethodSummary 
  name: prefix
- !ruby/object:RI::MethodSummary 
  name: prefix=
- !ruby/object:RI::MethodSummary 
  name: prefix_source
- !ruby/object:RI::MethodSummary 
  name: site
- !ruby/object:RI::MethodSummary 
  name: site=
- !ruby/object:RI::MethodSummary 
  name: timeout
- !ruby/object:RI::MethodSummary 
  name: timeout=
- !ruby/object:RI::MethodSummary 
  name: user
- !ruby/object:RI::MethodSummary 
  name: user=
comment: 
- !ruby/struct:SM::Flow::P 
  body: ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application.
- !ruby/struct:SM::Flow::P 
  body: For an outline of what Active Resource is capable of, see link:files/vendor/rails/activeresource/README.html.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Automated mapping
- !ruby/struct:SM::Flow::P 
  body: Active Resource objects represent your RESTful resources as manipulatable Ruby objects. To map resources to Ruby objects, Active Resource only needs a class name that corresponds to the resource name (e.g., the class Person maps to the resources people, very similarly to Active Record) and a <tt>site</tt> value, which holds the URI of the resources.
- !ruby/struct:SM::Flow::VERB 
  body: "  class Person &lt; ActiveResource::Base\n    self.site = &quot;http://api.people.com:3000/&quot;\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: Now the Person class is mapped to RESTful resources located at <tt>http://api.people.com:3000/people/</tt>, and you can now use Active Resource's lifecycles methods to manipulate resources. In the case where you already have an existing model with the same name as the desired RESTful resource you can set the <tt>element_name</tt> value.
- !ruby/struct:SM::Flow::VERB 
  body: "  class PersonResource &lt; ActiveResource::Base\n    self.site = &quot;http://api.people.com:3000/&quot;\n    self.element_name = &quot;person&quot;\n  end\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Lifecycle methods
- !ruby/struct:SM::Flow::P 
  body: Active Resource exposes methods for creating, finding, updating, and deleting resources from REST web services.
- !ruby/struct:SM::Flow::VERB 
  body: "  ryan = Person.new(:first =&gt; 'Ryan', :last =&gt; 'Daigle')\n  ryan.save                # =&gt; true\n  ryan.id                  # =&gt; 2\n  Person.exists?(ryan.id)  # =&gt; true\n  ryan.exists?             # =&gt; true\n\n  ryan = Person.find(1)\n  # Resource holding our newly created Person object\n\n  ryan.first = 'Rizzle'\n  ryan.save                # =&gt; true\n\n  ryan.destroy             # =&gt; true\n"
- !ruby/struct:SM::Flow::P 
  body: As you can see, these are very similar to Active Record's lifecycle methods for database records. You can read more about each of these methods in their respective documentation.
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Custom REST methods
- !ruby/struct:SM::Flow::P 
  body: Since simple CRUD/lifecycle methods can't accomplish every task, Active Resource also supports defining your own custom REST methods. To invoke them, Active Resource provides the <tt>get</tt>, <tt>post</tt>, <tt>put</tt> and <tt>\delete</tt> methods where you can specify a custom REST method name to invoke.
- !ruby/struct:SM::Flow::VERB 
  body: "  # POST to the custom 'register' REST method, i.e. POST /people/new/register.xml.\n  Person.new(:name =&gt; 'Ryan').post(:register)\n  # =&gt; { :id =&gt; 1, :name =&gt; 'Ryan', :position =&gt; 'Clerk' }\n\n  # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.xml?position=Manager.\n  Person.find(1).put(:promote, :position =&gt; 'Manager')\n  # =&gt; { :id =&gt; 1, :name =&gt; 'Ryan', :position =&gt; 'Manager' }\n\n  # GET all the positions available, i.e. GET /people/positions.xml.\n  Person.get(:positions)\n  # =&gt; [{:name =&gt; 'Manager'}, {:name =&gt; 'Clerk'}]\n\n  # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.xml.\n  Person.find(1).delete(:fire)\n"
- !ruby/struct:SM::Flow::P 
  body: For more information on using custom REST methods, see the ActiveResource::CustomMethods documentation.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Validations
- !ruby/struct:SM::Flow::P 
  body: You can validate resources client side by overriding validation methods in the base class.
- !ruby/struct:SM::Flow::VERB 
  body: "  class Person &lt; ActiveResource::Base\n     self.site = &quot;http://api.people.com:3000/&quot;\n     protected\n       def validate\n         errors.add(&quot;last&quot;, &quot;has invalid characters&quot;) unless last =~ /[a-zA-Z]*/\n       end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: See the ActiveResource::Validations documentation for more information.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Authentication
- !ruby/struct:SM::Flow::P 
  body: "Many REST APIs will require authentication, usually in the form of basic HTTP authentication. Authentication can be specified by:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: putting the credentials in the URL for the <tt>site</tt> variable.
  - !ruby/struct:SM::Flow::VERB 
    body: " class Person &lt; ActiveResource::Base\n   self.site = &quot;http://ryan:password@api.people.com:3000/&quot;\n end\n"
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: defining <tt>user</tt> and/or <tt>password</tt> variables
  - !ruby/struct:SM::Flow::VERB 
    body: " class Person &lt; ActiveResource::Base\n   self.site = &quot;http://api.people.com:3000/&quot;\n   self.user = &quot;ryan&quot;\n   self.password = &quot;password&quot;\n end\n"
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: For obvious security reasons, it is probably best if such services are available over HTTPS.
- !ruby/struct:SM::Flow::P 
  body: "Note: Some values cannot be provided in the URL passed to site. e.g. email addresses as usernames. In those situations you should use the separate user and password option."
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Errors &amp; Validation
- !ruby/struct:SM::Flow::P 
  body: Error handling and validation is handled in much the same manner as you're used to seeing in Active Record. Both the response code in the HTTP response and the body of the response are used to indicate that an error occurred.
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Resource errors
- !ruby/struct:SM::Flow::P 
  body: When a GET is requested for a resource that does not exist, the HTTP <tt>404</tt> (Resource Not Found) response code will be returned from the server which will raise an ActiveResource::ResourceNotFound exception.
- !ruby/struct:SM::Flow::VERB 
  body: "  # GET http://api.people.com:3000/people/999.xml\n  ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound\n"
- !ruby/struct:SM::Flow::P 
  body: "<tt>404</tt> is just one of the HTTP error response codes that Active Resource will handle with its own exception. The following HTTP response codes will also result in these exceptions:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 200..399 - Valid response, no exception (other than 301, 302)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 301, 302 - ActiveResource::Redirection
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 400 - ActiveResource::BadRequest
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 401 - ActiveResource::UnauthorizedAccess
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 403 - ActiveResource::ForbiddenAccess
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 404 - ActiveResource::ResourceNotFound
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 405 - ActiveResource::MethodNotAllowed
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 409 - ActiveResource::ResourceConflict
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 422 - ActiveResource::ResourceInvalid (rescued by save as validation errors)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 401..499 - ActiveResource::ClientError
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: 500..599 - ActiveResource::ServerError
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Other - ActiveResource::ConnectionError
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "These custom exceptions allow you to deal with resource errors more naturally and with more precision rather than returning a general HTTP error. For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  begin\n    ryan = Person.find(my_id)\n  rescue ActiveResource::ResourceNotFound\n    redirect_to :action =&gt; 'not_found'\n  rescue ActiveResource::ResourceConflict, ActiveResource::ResourceInvalid\n    redirect_to :action =&gt; 'new'\n  end\n"
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Validation errors
- !ruby/struct:SM::Flow::P 
  body: Active Resource supports validations on resources and will return errors if any these validations fail (e.g., &quot;First name can not be blank&quot; and so on). These types of errors are denoted in the response by a response code of <tt>422</tt> and an XML representation of the validation errors. The save operation will then fail (with a <tt>false</tt> return value) and the validation errors can be accessed on the resource in question.
- !ruby/struct:SM::Flow::VERB 
  body: "  ryan = Person.find(1)\n  ryan.first # =&gt; ''\n  ryan.save  # =&gt; false\n\n  # When\n  # PUT http://api.people.com:3000/people/1.xml\n  # is requested with invalid values, the response is:\n  #\n  # Response (422):\n  # &lt;errors type=&quot;array&quot;&gt;&lt;error&gt;First cannot be empty&lt;/error&gt;&lt;/errors&gt;\n  #\n\n  ryan.errors.invalid?(:first)  # =&gt; true\n  ryan.errors.full_messages     # =&gt; ['First cannot be empty']\n"
- !ruby/struct:SM::Flow::P 
  body: Learn more about Active Resource's validation features in the ActiveResource::Validations documentation.
- !ruby/struct:SM::Flow::H 
  level: 3
  text: Timeouts
- !ruby/struct:SM::Flow::P 
  body: Active Resource relies on HTTP to access RESTful APIs and as such is inherently susceptible to slow or unresponsive servers. In such cases, your Active Resource method calls could \timeout. You can control the amount of time before Active Resource times out with the <tt>timeout</tt> variable.
- !ruby/struct:SM::Flow::VERB 
  body: "  class Person &lt; ActiveResource::Base\n    self.site = &quot;http://api.people.com:3000/&quot;\n    self.timeout = 5\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: This sets the <tt>timeout</tt> to 5 seconds. You can adjust the <tt>timeout</tt> to a value suitable for the RESTful API you are accessing. It is recommended to set this to a reasonably low value to allow your Active Resource clients (especially if you are using Active Resource in a Rails application) to fail-fast (see http://en.wikipedia.org/wiki/Fail-fast) rather than cause cascading failures that could incapacitate your server.
- !ruby/struct:SM::Flow::P 
  body: When a \timeout occurs, an ActiveResource::TimeoutError is raised. You should rescue from ActiveResource::TimeoutError in your Active Resource method calls.
- !ruby/struct:SM::Flow::P 
  body: Internally, Active Resource relies on Ruby's Net::HTTP library to make HTTP requests. Setting <tt>timeout</tt> sets the <tt>read_timeout</tt> of the internal Net::HTTP instance to the same value. The default <tt>read_timeout</tt> is 60 seconds on most Ruby implementations.
constants: []

full_name: ActiveResource::Base
includes: []

instance_methods: 
- !ruby/object:RI::MethodSummary 
  name: ==
- !ruby/object:RI::MethodSummary 
  name: clone
- !ruby/object:RI::MethodSummary 
  name: collection_path
- !ruby/object:RI::MethodSummary 
  name: connection
- !ruby/object:RI::MethodSummary 
  name: create
- !ruby/object:RI::MethodSummary 
  name: destroy
- !ruby/object:RI::MethodSummary 
  name: dup
- !ruby/object:RI::MethodSummary 
  name: element_path
- !ruby/object:RI::MethodSummary 
  name: encode
- !ruby/object:RI::MethodSummary 
  name: eql?
- !ruby/object:RI::MethodSummary 
  name: exists?
- !ruby/object:RI::MethodSummary 
  name: hash
- !ruby/object:RI::MethodSummary 
  name: id
- !ruby/object:RI::MethodSummary 
  name: id=
- !ruby/object:RI::MethodSummary 
  name: id_from_response
- !ruby/object:RI::MethodSummary 
  name: load
- !ruby/object:RI::MethodSummary 
  name: load_attributes_from_response
- !ruby/object:RI::MethodSummary 
  name: new?
- !ruby/object:RI::MethodSummary 
  name: reload
- !ruby/object:RI::MethodSummary 
  name: respond_to?
- !ruby/object:RI::MethodSummary 
  name: save
- !ruby/object:RI::MethodSummary 
  name: to_json
- !ruby/object:RI::MethodSummary 
  name: to_param
- !ruby/object:RI::MethodSummary 
  name: to_xml
- !ruby/object:RI::MethodSummary 
  name: update
name: Base
superclass: Object
