Skip to content

Instantly share code, notes, and snippets.

@aronlindberg
Last active August 29, 2015 14:14
Show Gist options
  • Save aronlindberg/b6b934b39e3c3378c3b2 to your computer and use it in GitHub Desktop.
Save aronlindberg/b6b934b39e3c3378c3b2 to your computer and use it in GitHub Desktop.
structure(list(ok = TRUE, content = list(structure(list(sha = "0d218844b2c56759f7f7c8f6988f1254dc6d02f8",
filename = "Rakefile", status = "modified", additions = 1L,
deletions = 7L, changes = 8L, blob_url = "https://github.com/rails/rails/blob/f1637bf2bb00490203503fbd943b73406e043d1d/Rakefile",
raw_url = "https://github.com/rails/rails/raw/f1637bf2bb00490203503fbd943b73406e043d1d/Rakefile",
contents_url = "https://api.github.com/repos/rails/rails/contents/Rakefile?ref=f1637bf2bb00490203503fbd943b73406e043d1d",
patch = "@@ -13,7 +13,7 @@ task :build => \"all:build\"\n desc \"Release all gems to gemcutter and create a tag\"\n task :release => \"all:release\"\n \n-PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties)\n+PROJECTS = %w(activesupport activemodel actionpack actionmailer activerecord railties)\n \n desc 'Run all tests by default'\n task :default => %w(test test:isolated)\n@@ -109,11 +109,6 @@ RDoc::Task.new do |rdoc|\n rdoc.rdoc_files.include('activerecord/lib/active_record/**/*.rb')\n rdoc.rdoc_files.exclude('activerecord/lib/active_record/vendor/*')\n \n- rdoc.rdoc_files.include('activeresource/README.rdoc')\n- rdoc.rdoc_files.include('activeresource/CHANGELOG.md')\n- rdoc.rdoc_files.include('activeresource/lib/active_resource.rb')\n- rdoc.rdoc_files.include('activeresource/lib/active_resource/*')\n-\n rdoc.rdoc_files.include('actionpack/README.rdoc')\n rdoc.rdoc_files.include('actionpack/CHANGELOG.md')\n rdoc.rdoc_files.include('actionpack/lib/abstract_controller/**/*.rb')\n@@ -157,7 +152,6 @@ task :update_versions do\n \"activemodel\" => \"ActiveModel\",\n \"actionpack\" => \"ActionPack\",\n \"actionmailer\" => \"ActionMailer\",\n- \"activeresource\" => \"ActiveResource\",\n \"activerecord\" => \"ActiveRecord\",\n \"railties\" => \"Rails\"\n }"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "18dda978b321ca0652db875aafd946ab67c28bf5",
filename = "actionpack/lib/action_controller/record_identifier.rb",
status = "modified", additions = 2L, deletions = 2L, changes = 4L,
blob_url = "https://github.com/rails/rails/blob/f1637bf2bb00490203503fbd943b73406e043d1d/actionpack/lib/action_controller/record_identifier.rb",
raw_url = "https://github.com/rails/rails/raw/f1637bf2bb00490203503fbd943b73406e043d1d/actionpack/lib/action_controller/record_identifier.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/actionpack/lib/action_controller/record_identifier.rb?ref=f1637bf2bb00490203503fbd943b73406e043d1d",
patch = "@@ -2,8 +2,8 @@\n \n module ActionController\n # The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or\n- # Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate\n- # the view actions to a higher logical level. Example:\n+ # pretty much any other model type that has an id. These patterns are then used to try elevate the view actions to\n+ # a higher logical level. Example:\n #\n # # routes\n # resources :posts"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "29f556502b3ae4464e6cc1631ad6bb1c2bc06211",
filename = "actionpack/lib/action_view/helpers/url_helper.rb",
status = "modified", additions = 1L, deletions = 1L, changes = 2L,
blob_url = "https://github.com/rails/rails/blob/f1637bf2bb00490203503fbd943b73406e043d1d/actionpack/lib/action_view/helpers/url_helper.rb",
raw_url = "https://github.com/rails/rails/raw/f1637bf2bb00490203503fbd943b73406e043d1d/actionpack/lib/action_view/helpers/url_helper.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/actionpack/lib/action_view/helpers/url_helper.rb?ref=f1637bf2bb00490203503fbd943b73406e043d1d",
patch = "@@ -60,7 +60,7 @@ def optimize_routes_generation? #:nodoc:\n #\n # ==== Relying on named routes\n #\n- # Passing a record (like an Active Record or Active Resource) instead of a Hash as the options parameter will\n+ # Passing a record (like an Active Record) instead of a Hash as the options parameter will\n # trigger the named route for that record. The lookup will happen on the name of the class. So passing a\n # Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as\n # +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route)."), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "f2d004fb0a0cd004e3c3dd2dd7130f07ea6abfe2",
filename = "activemodel/activemodel.gemspec", status = "modified",
additions = 1L, deletions = 1L, changes = 2L, blob_url = "https://github.com/rails/rails/blob/f1637bf2bb00490203503fbd943b73406e043d1d/activemodel/activemodel.gemspec",
raw_url = "https://github.com/rails/rails/raw/f1637bf2bb00490203503fbd943b73406e043d1d/activemodel/activemodel.gemspec",
contents_url = "https://api.github.com/repos/rails/rails/contents/activemodel/activemodel.gemspec?ref=f1637bf2bb00490203503fbd943b73406e043d1d",
patch = "@@ -5,7 +5,7 @@ Gem::Specification.new do |s|\n s.name = 'activemodel'\n s.version = version\n s.summary = 'A toolkit for building modeling frameworks (part of Rails).'\n- s.description = 'A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.'\n+ s.description = 'A toolkit for building modeling frameworks like Active Record. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.'\n \n s.required_ruby_version = '>= 1.9.3'\n "), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "670cb19f5703bf09eb33b20e0602e833aefb6ac7",
filename = "activeresource/CHANGELOG.md", status = "removed",
additions = 0L, deletions = 390L, changes = 390L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/CHANGELOG.md",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/CHANGELOG.md",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/CHANGELOG.md?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,390 +0,0 @@\n-## Rails 4.0.0 (unreleased) ##\n-\n-* Adds support for PATCH requests. *dlee*\n-\n-\n-## Rails 3.2.2 (March 1, 2012) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.2.1 (January 26, 2012) ##\n-\n-* Documentation fixes.\n-\n-\n-## Rails 3.2.0 (January 20, 2012) ##\n-\n-* Redirect responses: 303 See Other and 307 Temporary Redirect now behave like\n- 301 Moved Permanently and 302 Found. GH #3302.\n-\n- *Jim Herz*\n-\n-\n-## Rails 3.1.4 (March 1, 2012) ##\n-\n-* No changes\n-\n-\n-## Rails 3.1.3 (November 20, 2011) ##\n-\n-* No changes\n-\n-\n-## Rails 3.1.2 (November 18, 2011) ##\n-\n-* No changes\n-\n-\n-## Rails 3.1.1 (October 7, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.1.0 (August 30, 2011) ##\n-\n-* 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.\n-\n- class User < ActiveResource::Base self.format = :xml\n- end\n-\n-\n-## Rails 3.0.12 (March 1, 2012) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.11 (November 18, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.10 (August 16, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.9 (June 16, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.8 (June 7, 2011) ##\n-\n-* No Changes\n-\n-\n-## Rails 3.0.7 (April 18, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.6 (April 5, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.5 (February 26, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.4 (February 8, 2011) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.3 (November 16, 2010) ##\n-\n-* No changes.\n-\n-\n-## Rails 3.0.2 (November 15, 2010) ##\n-\n-* No changes\n-\n-\n-## Rails 3.0.1 (October 15, 2010) ##\n-\n-* No Changes, just a version bump.\n-\n-\n-## Rails 3.0.0 (August 29, 2010) ##\n-\n-* 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*\n-\n-* Add support for errors in JSON format. #1956 *Fabien Jakimowicz*\n-\n-* Recognizes 410 as Resource Gone. #2316 *Jordan Brough, Jatinder Singh*\n-\n-* More thorough SSL support. #2370 *Roy Nicholson*\n-\n-* HTTP proxy support. #2133 *Marshall Huss, Sébastien Dabet*\n-\n-\n-## 2.3.2 Final (March 15, 2009) ##\n-\n-* Nothing new, just included in 2.3.2\n-\n-\n-## 2.2.1 RC2 (November 14th, 2008) ##\n-\n-* Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 *Paolo Angelini*\n-\n-\n-## 2.2.0 RC1 (October 24th, 2008) ##\n-\n-* Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 *Rasik Pandey, Cody Fauser*\n-\n-* Add ActiveResource::Base.find(:last). [#754 state:resolved] (Adrian Mugnolo)\n-\n-* Fixed problems with the logger used if the logging string included %'s [#840 state:resolved] (Jamis Buck)\n-\n-* Fixed Base#exists? to check status code as integer [#299 state:resolved] (Wes Oldenbeuving)\n-\n-\n-## 2.1.0 (May 31st, 2008) ##\n-\n-* Fixed response logging to use length instead of the entire thing (seangeo) *#27*\n-\n-* Fixed that to_param should be used and honored instead of hardcoding the id #11406 *gspiers*\n-\n-* Improve documentation. *Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert*\n-\n-* Use HEAD instead of GET in exists? *bscofield*\n-\n-* Fix small documentation typo. Closes #10670 *Luca Guidi*\n-\n-* find_or_create_resource_for handles module nesting. #10646 *xavier*\n-\n-* Allow setting ActiveResource::Base#format before #site. *Rick Olson*\n-\n-* Support agnostic formats when calling custom methods. Closes #10635 *joerichsen*\n-\n-* Document custom methods. #10589 *Cheah Chu Yeow*\n-\n-* Ruby 1.9 compatibility. *Jeremy Kemper*\n-\n-\n-## 2.0.2 (December 16th, 2007) ##\n-\n-* Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 *trek*\n-\n-* Correct empty response handling. #10445 *seangeo*\n-\n-\n-## 2.0.1 (December 7th, 2007) ##\n-\n-* Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 *kou*\n-\n-* Update XML documentation examples to include explicit type attributes. Closes #9754 *Josh Susser*\n-\n-* Added one-off declarations of mock behavior [David Heinemeier Hansson]. Example:\n-\n- Before:\n- ActiveResource::HttpMock.respond_to do |mock|\n- mock.get \"/people/1.xml\", {}, \"<person><name>David</name></person>\"\n- end\n-\n- Now:\n- ActiveResource::HttpMock.respond_to.get \"/people/1.xml\", {}, \"<person><name>David</name></person>\"\n-\n-* Added ActiveResource.format= which defaults to :xml but can also be set to :json [David Heinemeier Hansson]. Example:\n-\n- class Person < ActiveResource::Base\n- self.site = \"http://app/\"\n- self.format = :json\n- end\n-\n- person = Person.find(1) # => GET http://app/people/1.json\n- person.name = \"David\"\n- person.save # => PUT http://app/people/1.json {name: \"David\"}\n-\n- Person.format = :xml\n- person.name = \"Mary\"\n- person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>\n-\n-* Fix reload error when path prefix is used. #8727 *Ian Warshak*\n-\n-* 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*\n-\n-* Fix query methods on resources. *Cody Fauser*\n-\n-* pass the prefix_options to the instantiated record when using find without a specific id. Closes #8544 *Eloy Duran*\n-\n-* Recognize and raise an exception on 405 Method Not Allowed responses. #7692 *Josh Peek*\n-\n-* Handle string and symbol param keys when splitting params into prefix params and query params.\n-\n- Comment.find(:all, :params => { :article_id => 5, :page => 2 }) or Comment.find(:all, :params => { 'article_id' => 5, :page => 2 })\n-\n-* Added find-one with symbol [David Heinemeier Hansson]. Example: Person.find(:one, :from => :leader) # => GET /people/leader.xml\n-\n-* BACKWARDS INCOMPATIBLE: Changed the finder API to be more extensible with :params and more strict usage of scopes [David Heinemeier Hansson]. Changes:\n-\n- Person.find(:all, :title => \"CEO\") ...becomes: Person.find(:all, :params => { :title => \"CEO\" })\n- Person.find(:managers) ...becomes: Person.find(:all, :from => :managers)\n- Person.find(\"/companies/1/manager.xml\") ...becomes: Person.find(:one, :from => \"/companies/1/manager.xml\")\n-\n-* Add support for setting custom headers per Active Resource model *Rick Olson*\n-\n- class Project\n- headers['X-Token'] = 'foo'\n- end\n-\n- \\# makes the GET request with the custom X-Token header\n- Project.find(:all)\n-\n-* Added find-by-path options to ActiveResource::Base.find [David Heinemeier Hansson]. Examples:\n-\n- employees = Person.find(:all, :from => \"/companies/1/people.xml\") # => GET /companies/1/people.xml\n- manager = Person.find(\"/companies/1/manager.xml\") # => GET /companies/1/manager.xml\n-\n-\n-* Added support for using classes from within a single nested module [David Heinemeier Hansson]. Example:\n-\n- module Highrise\n- class Note < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-\n- class Comment < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n- end\n-\n- assert_kind_of Highrise::Comment, Note.find(1).comments.first\n-\n-\n-* Added load_attributes_from_response as a way of loading attributes from other responses than just create *David Heinemeier Hansson*\n-\n- class Highrise::Task < ActiveResource::Base\n- def complete\n- load_attributes_from_response(post(:complete))\n- end\n- end\n-\n- ...will set \"done_at\" when complete is called.\n-\n-\n-* Added support for calling custom methods #6979 *rwdaigle*\n-\n- Person.find(:managers) # => GET /people/managers.xml\n- Kase.find(1).post(:close) # => POST /kases/1/close.xml\n-\n-* Remove explicit prefix_options parameter for ActiveResource::Base#initialize. *Rick Olson*\n- ActiveResource splits the prefix_options from it automatically.\n-\n-* Allow ActiveResource::Base.delete with custom prefix. *Rick Olson*\n-\n-* Add ActiveResource::Base#dup *Rick Olson*\n-\n-* Fixed constant warning when fetching the same object multiple times *David Heinemeier Hansson*\n-\n-* Added that saves which get a body response (and not just a 201) will use that response to update themselves *David Heinemeier Hansson*\n-\n-* Disregard namespaces from the default element name, so Highrise::Person will just try to fetch from \"/people\", not \"/highrise/people\" *David Heinemeier Hansson*\n-\n-* Allow array and hash query parameters. #7756 *Greg Spurrier*\n-\n-* Loading a resource preserves its prefix_options. #7353 *Ryan Daigle*\n-\n-* Carry over the convenience of #create from ActiveRecord. Closes #7340. *Ryan Daigle*\n-\n-* Increase ActiveResource::Base test coverage. Closes #7173, #7174 *Rich Collins*\n-\n-* Interpret 422 Unprocessable Entity as ResourceInvalid. #7097 *dkubb*\n-\n-* Mega documentation patches. #7025, #7069 *rwdaigle*\n-\n-* Base.exists?(id, options) and Base#exists? check whether the resource is found. #6970 *rwdaigle*\n-\n-* Query string support. *untext, Jeremy Kemper*\n- # GET /forums/1/topics.xml?sort=created_at\n- Topic.find(:all, :forum_id => 1, :sort => 'created_at')\n-\n-* 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*\n-\n-* Allow subclassed resources to share the site info *Rick Olson, Jeremy Kemper*\n- d class BeastResource < ActiveResource::Base\n- self.site = 'http://beast.caboo.se'\n- end\n-\n- class Forum < BeastResource\n- # taken from BeastResource\n- # self.site = 'http://beast.caboo.se'\n- end\n-\n- class Topic < BeastResource\n- self.site += '/forums/:forum_id'\n- end\n-\n-* Fix issues with ActiveResource collection handling. Closes #6291. *bmilekic*\n-\n-* Use attr_accessor_with_default to dry up attribute initialization. References #6538. *Stuart Halloway*\n-\n-* Add basic logging support for logging outgoing requests. *Jamis Buck*\n-\n-* Add Base.delete for deleting resources without having to instantiate them first. *Jamis Buck*\n-\n-* Make #save behavior mimic AR::Base#save (true on success, false on failure). *Jamis Buck*\n-\n-* Add Basic HTTP Authentication to ActiveResource (closes #6305). *jonathan*\n-\n-* Extracted #id_from_response as an entry point for customizing how a created resource gets its own ID.\n- By default, it extracts from the Location response header.\n-\n-* Optimistic locking: raise ActiveResource::ResourceConflict on 409 Conflict response. *Jeremy Kemper*\n-\n- # Example controller action\n- def update\n- @person.save!\n- rescue ActiveRecord::StaleObjectError\n- render :xml => @person.reload.to_xml, :status => '409 Conflict'\n- end\n-\n-* Basic validation support *Rick Olson*\n-\n- Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.\n-\n- render :xml => @person.errors.to_xml, :status => '400 Validation Error'\n-\n-* Deep hashes are converted into collections of resources. *Jeremy Kemper*\n- Person.new :name => 'Bob',\n- :address => { :id => 1, :city => 'Portland' },\n- :contacts => [{ :id => 1 }, { :id => 2 }]\n- Looks for Address and Contact resources and creates them if unavailable.\n- So clients can fetch a complex resource in a single request if you e.g.\n- render :xml => @person.to_xml(:include => [:address, :contacts])\n- in your controller action.\n-\n-* Major updates *Rick Olson*\n-\n- * Add full support for find/create/update/destroy\n- * Add support for specifying prefixes.\n- * Allow overriding of element_name, collection_name, and primary key\n- * Provide simpler HTTP mock interface for testing\n-\n- # rails routing code\n- map.resources :posts do |post|\n- post.resources :comments\n- end\n-\n- # ActiveResources\n- class Post < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000/\"\n- end\n-\n- class Comment < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000/posts/:post_id/\"\n- end\n-\n- @post = Post.find 5\n- @comments = Comment.find :all, :post_id => @post.id\n-\n- @comment = Comment.new({:body => 'hello world'}, {:post_id => @post.id})\n- @comment.save\n-\n-* Base.site= accepts URIs. 200...400 are valid response codes. PUT and POST request bodies default to ''. *Jeremy Kemper*\n-\n-* Initial checkin: object-oriented client for restful HTTP resources which follow the Rails convention. *David Heinemeier Hansson*"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "187e748f831a252ac0b9b8e9e5ce0ed90fb5df1c",
filename = "activeresource/MIT-LICENSE", status = "removed",
additions = 0L, deletions = 20L, changes = 20L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/MIT-LICENSE",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/MIT-LICENSE",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/MIT-LICENSE?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,20 +0,0 @@\n-Copyright (c) 2006-2012 David Heinemeier Hansson\n-\n-Permission is hereby granted, free of charge, to any person obtaining\n-a copy of this software and associated documentation files (the\n-\"Software\"), to deal in the Software without restriction, including\n-without limitation the rights to use, copy, modify, merge, publish,\n-distribute, sublicense, and/or sell copies of the Software, and to\n-permit persons to whom the Software is furnished to do so, subject to\n-the following conditions:\n-\n-The above copyright notice and this permission notice shall be\n-included in all copies or substantial portions of the Software.\n-\n-THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\\ No newline at end of file"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "8170f299738541d5b6a4a437e67289665e3c88cb",
filename = "activeresource/README.rdoc", status = "removed",
additions = 0L, deletions = 189L, changes = 189L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/README.rdoc",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/README.rdoc",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/README.rdoc?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,189 +0,0 @@\n-= Active Resource\n-\n-Active Resource (ARes) connects business objects and Representational State Transfer (REST)\n-web services. It implements object-relational mapping for REST web services to provide transparent\n-proxying capabilities between a client (ActiveResource) and a RESTful service (which is provided by Simply RESTful routing\n-in ActionController::Resources).\n-\n-== Philosophy\n-\n-Active Resource attempts to provide a coherent wrapper object-relational mapping for REST\n-web services. It follows the same philosophy as Active Record, in that one of its prime aims\n-is to reduce the amount of code needed to map to these resources. This is made possible\n-by relying on a number of code- and protocol-based conventions that make it easy for Active Resource\n-to infer complex relations and structures. These conventions are outlined in detail in the documentation\n-for ActiveResource::Base.\n-\n-== Overview\n-\n-Model classes are mapped to remote REST resources by Active Resource much the same way Active Record maps model classes to database\n-tables. When a request is made to a remote resource, a REST XML request is generated, transmitted, and the result\n-received and serialized into a usable Ruby object.\n-\n-== Download and installation\n-\n-The latest version of Active Support can be installed with RubyGems:\n-\n- % [sudo] gem install activeresource\n-\n-Source code can be downloaded as part of the Rails project on GitHub\n-\n-* https://github.com/rails/rails/tree/master/activeresource\n-\n-=== Configuration and Usage\n-\n-Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class\n-that inherits from ActiveResource::Base and providing a <tt>site</tt> class variable to it:\n-\n- class Person < ActiveResource::Base\n- self.site = \"http://api.people.com:3000\"\n- end\n-\n-Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes\n-life cycle methods that operate against a persistent store.\n-\n- # Find a person with id = 1\n- ryan = Person.find(1)\n- Person.exists?(1) # => true\n-\n-As you can see, the methods are quite similar to Active Record's methods for dealing with database\n-records. But rather than dealing directly with a database record, you're dealing with HTTP resources (which may or may not be database records).\n-\n-==== Protocol\n-\n-Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing\n-built into Action Controller but will also work with any other REST service that properly implements the protocol.\n-REST uses HTTP, but unlike \"typical\" web applications, it makes use of all the verbs available in the HTTP specification:\n-\n-* GET requests are used for finding and retrieving resources.\n-* POST requests are used to create new resources.\n-* PUT requests are used to update existing resources.\n-* DELETE requests are used to delete resources.\n-\n-For more information on how this protocol works with Active Resource, see the ActiveResource::Base documentation;\n-for more general information on REST web services, see the article here[http://en.wikipedia.org/wiki/Representational_State_Transfer].\n-\n-==== Find\n-\n-Find requests use the GET method and expect the XML form of whatever resource/resources is/are being requested. So,\n-for a request for a single element, the XML of that item is expected in response:\n-\n- # Expects a response of\n- #\n- # <person><id type=\"integer\">1</id><attribute1>value1</attribute1><attribute2>..</attribute2></person>\n- #\n- # for GET http://api.people.com:3000/people/1.xml\n- #\n- ryan = Person.find(1)\n-\n-The XML document that is received is used to build a new object of type Person, with each\n-XML element becoming an attribute on the object.\n-\n- ryan.is_a? Person # => true\n- ryan.attribute1 # => 'value1'\n-\n-Any complex element (one that contains other elements) becomes its own object:\n-\n- # With this response:\n- #\n- # <person><id>1</id><attribute1>value1</attribute1><complex><attribute2>value2</attribute2></complex></person>\n- #\n- # for GET http://api.people.com:3000/people/1.xml\n- #\n- ryan = Person.find(1)\n- ryan.complex # => <Person::Complex::xxxxx>\n- ryan.complex.attribute2 # => 'value2'\n-\n-Collections can also be requested in a similar fashion\n-\n- # Expects a response of\n- #\n- # <people type=\"array\">\n- # <person><id type=\"integer\">1</id><first>Ryan</first></person>\n- # <person><id type=\"integer\">2</id><first>Jim</first></person>\n- # </people>\n- #\n- # for GET http://api.people.com:3000/people.xml\n- #\n- people = Person.all\n- people.first # => <Person::xxx 'first' => 'Ryan' ...>\n- people.last # => <Person::xxx 'first' => 'Jim' ...>\n-\n-==== Create\n-\n-Creating a new resource submits the XML form of the resource as the body of the request and expects\n-a 'Location' header in the response with the RESTful URL location of the newly created resource. The\n-id of the newly created resource is parsed out of the Location response header and automatically set\n-as the id of the ARes object.\n-\n- # <person><first>Ryan</first></person>\n- #\n- # is submitted as the body on\n- #\n- # POST http://api.people.com:3000/people.xml\n- #\n- # when save is called on a new Person object. An empty response is\n- # is expected with a 'Location' header value:\n- #\n- # Response (201): Location: http://api.people.com:3000/people/2\n- #\n- ryan = Person.new(:first => 'Ryan')\n- ryan.new? # => true\n- ryan.save # => true\n- ryan.new? # => false\n- ryan.id # => 2\n-\n-==== Update\n-\n-'save' is also used to update an existing resource and follows the same protocol as creating a resource\n-with the exception that no response headers are needed -- just an empty response when the update on the\n-server side was successful.\n-\n- # <person><first>Ryan</first></person>\n- #\n- # is submitted as the body on\n- #\n- # PUT http://api.people.com:3000/people/1.xml\n- #\n- # when save is called on an existing Person object. An empty response is\n- # is expected with code (204)\n- #\n- ryan = Person.find(1)\n- ryan.first # => 'Ryan'\n- ryan.first = 'Rizzle'\n- ryan.save # => true\n-\n-==== Delete\n-\n-Destruction of a resource can be invoked as a class and instance method of the resource.\n-\n- # A request is made to\n- #\n- # DELETE http://api.people.com:3000/people/1.xml\n- #\n- # for both of these forms. An empty response with\n- # is expected with response code (200)\n- #\n- ryan = Person.find(1)\n- ryan.destroy # => true\n- ryan.exists? # => false\n- Person.delete(2) # => true\n- Person.exists?(2) # => false\n-\n-== License\n-\n-Active Support is released under the MIT license:\n-\n-* http://www.opensource.org/licenses/MIT\n-\n-== Support\n-\n-API documentation is at\n-\n-* http://api.rubyonrails.org\n-\n-Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:\n-\n-* https://github.com/rails/rails/issues\n-\n-You can find more usage information in the ActiveResource::Base documentation."), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "b85d8c7eb5c43b836be02f0b91a027da3b00e7b9",
filename = "activeresource/Rakefile", status = "removed",
additions = 0L, deletions = 66L, changes = 66L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/Rakefile",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/Rakefile",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/Rakefile?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,66 +0,0 @@\n-#!/usr/bin/env rake\n-require 'rake/testtask'\n-require 'rake/packagetask'\n-require 'rubygems/package_task'\n-\n-desc \"Default Task\"\n-task :default => [ :test ]\n-\n-# Run the unit tests\n-\n-Rake::TestTask.new { |t|\n- t.libs << \"test\"\n- t.pattern = 'test/**/*_test.rb'\n- t.warning = true\n- t.verbose = true\n-}\n-\n-namespace :test do\n- task :isolated do\n- ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))\n- activesupport_path = \"#{File.dirname(__FILE__)}/../activesupport/lib\"\n- Dir.glob(\"test/**/*_test.rb\").all? do |file|\n- sh(ruby, '-w', \"-Ilib:test:#{activesupport_path}\", file)\n- end or raise \"Failures\"\n- end\n-end\n-\n-spec = eval(File.read('activeresource.gemspec'))\n-\n-Gem::PackageTask.new(spec) do |p|\n- p.gem_spec = spec\n-end\n-\n-task :lines do\n- lines, codelines, total_lines, total_codelines = 0, 0, 0, 0\n-\n- FileList[\"lib/active_resource/**/*.rb\"].each do |file_name|\n- next if file_name =~ /vendor/\n- f = File.open(file_name)\n-\n- while line = f.gets\n- lines += 1\n- next if line =~ /^\\s*$/\n- next if line =~ /^\\s*#/\n- codelines += 1\n- end\n- puts \"L: #{sprintf(\"%4d\", lines)}, LOC #{sprintf(\"%4d\", codelines)} | #{file_name}\"\n-\n- total_lines += lines\n- total_codelines += codelines\n-\n- lines, codelines = 0, 0\n- end\n-\n- puts \"Total: Lines #{total_lines}, LOC #{total_codelines}\"\n-end\n-\n-\n-# Publishing ------------------------------------------------------\n-\n-desc \"Release to gemcutter\"\n-task :release => :package do\n- require 'rake/gemcutter'\n- Rake::Gemcutter::Tasks.new(spec).define\n- Rake::Task['gem:push'].invoke\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "ae1972a7d717e85bd06448a7f6288874970adfd6",
filename = "activeresource/activeresource.gemspec", status = "removed",
additions = 0L, deletions = 24L, changes = 24L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/activeresource.gemspec",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/activeresource.gemspec",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/activeresource.gemspec?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,24 +0,0 @@\n-version = File.read(File.expand_path(\"../../RAILS_VERSION\", __FILE__)).strip\n-\n-Gem::Specification.new do |s|\n- s.platform = Gem::Platform::RUBY\n- s.name = 'activeresource'\n- s.version = version\n- s.summary = 'REST modeling framework (part of Rails).'\n- s.description = 'REST on Rails. Wrap your RESTful web app with Ruby classes and work with them like Active Record models.'\n-\n- s.required_ruby_version = '>= 1.9.3'\n-\n- s.author = 'David Heinemeier Hansson'\n- s.email = 'david@loudthinking.com'\n- s.homepage = 'http://www.rubyonrails.org'\n-\n- s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.rdoc', 'examples/**/*', 'lib/**/*']\n- s.require_path = 'lib'\n-\n- s.extra_rdoc_files = %w( README.rdoc )\n- s.rdoc_options.concat ['--main', 'README.rdoc']\n-\n- s.add_dependency('activesupport', version)\n- s.add_dependency('activemodel', version)\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "e4df7a38a402fca884585f8cc4666033e5acc2c0",
filename = "activeresource/examples/performance.rb", status = "removed",
additions = 0L, deletions = 70L, changes = 70L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/examples/performance.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/examples/performance.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/examples/performance.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,70 +0,0 @@\n-require 'rubygems'\n-require 'active_resource'\n-require 'benchmark'\n-\n-TIMES = (ENV['N'] || 10_000).to_i\n-\n-# deep nested resource\n-attrs = {\n- :id => 1,\n- :name => 'Luis',\n- :age => 21,\n- :friends => [\n- {\n- :name => 'JK',\n- :age => 24,\n- :colors => ['red', 'green', 'blue'],\n- :brothers => [\n- {\n- :name => 'Mateo',\n- :age => 35,\n- :children => [{ :name => 'Edith', :age => 5 }, { :name => 'Martha', :age => 4 }]\n- },\n- {\n- :name => 'Felipe',\n- :age => 33,\n- :children => [{ :name => 'Bryan', :age => 1 }, { :name => 'Luke', :age => 0 }]\n- }\n- ]\n- },\n- {\n- :name => 'Eduardo',\n- :age => 20,\n- :colors => [],\n- :brothers => [\n- {\n- :name => 'Sebas',\n- :age => 23,\n- :children => [{ :name => 'Andres', :age => 0 }, { :name => 'Jorge', :age => 2 }]\n- },\n- {\n- :name => 'Elsa',\n- :age => 19,\n- :children => [{ :name => 'Natacha', :age => 1 }]\n- },\n- {\n- :name => 'Milena',\n- :age => 16,\n- :children => []\n- }\n- ]\n- }\n- ]\n-}\n-\n-class Customer < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n-end\n-\n-module Nested\n- class Customer < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-end\n-\n-Benchmark.bm(40) do |x|\n- x.report('Model.new (instantiation)') { TIMES.times { Customer.new } }\n- x.report('Nested::Model.new (instantiation)') { TIMES.times { Nested::Customer.new } }\n- x.report('Model.new (setting attributes)') { TIMES.times { Customer.new attrs } }\n- x.report('Nested::Model.new (setting attributes)') { TIMES.times { Nested::Customer.new attrs } }\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "ab06086631c437c77ac624eeeacea04f783b1fcb",
filename = "activeresource/lib/active_resource.rb", status = "removed",
additions = 0L, deletions = 45L, changes = 45L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,45 +0,0 @@\n-#--\n-# Copyright (c) 2006-2012 David Heinemeier Hansson\n-#\n-# Permission is hereby granted, free of charge, to any person obtaining\n-# a copy of this software and associated documentation files (the\n-# \"Software\"), to deal in the Software without restriction, including\n-# without limitation the rights to use, copy, modify, merge, publish,\n-# distribute, sublicense, and/or sell copies of the Software, and to\n-# permit persons to whom the Software is furnished to do so, subject to\n-# the following conditions:\n-#\n-# The above copyright notice and this permission notice shall be\n-# included in all copies or substantial portions of the Software.\n-#\n-# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n-#++\n-\n-activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)\n-$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)\n-\n-activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)\n-$:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path)\n-\n-require 'active_support'\n-require 'active_model'\n-require 'active_resource/version'\n-\n-module ActiveResource\n- extend ActiveSupport::Autoload\n-\n- autoload :Base\n- autoload :Connection\n- autoload :CustomMethods\n- autoload :Formats\n- autoload :HttpMock\n- autoload :Observing\n- autoload :Schema\n- autoload :Validations\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "0c2d070aef58aa9defc660c37dc48fbfc3a202f7",
filename = "activeresource/lib/active_resource/base.rb",
status = "removed", additions = 0L, deletions = 1515L, changes = 1515L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/base.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/base.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/base.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,1515 +0,0 @@\n-require 'active_support'\n-require 'active_support/core_ext/class/attribute_accessors'\n-require 'active_support/core_ext/class/attribute'\n-require 'active_support/core_ext/hash/indifferent_access'\n-require 'active_support/core_ext/kernel/reporting'\n-require 'active_support/core_ext/module/delegation'\n-require 'active_support/core_ext/module/aliasing'\n-require 'active_support/core_ext/object/blank'\n-require 'active_support/core_ext/object/to_query'\n-require 'active_support/core_ext/object/duplicable'\n-require 'set'\n-require 'uri'\n-\n-require 'active_support/core_ext/uri'\n-require 'active_resource/exceptions'\n-require 'active_resource/connection'\n-require 'active_resource/formats'\n-require 'active_resource/schema'\n-require 'active_resource/log_subscriber'\n-\n-module ActiveResource\n- # ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application.\n- #\n- # For an outline of what Active Resource is capable of, see its {README}[link:files/activeresource/README_rdoc.html].\n- #\n- # == Automated mapping\n- #\n- # Active Resource objects represent your RESTful resources as manipulatable Ruby objects. To map resources\n- # to Ruby objects, Active Resource only needs a class name that corresponds to the resource name (e.g., the class\n- # Person maps to the resources people, very similarly to Active Record) and a +site+ value, which holds the\n- # URI of the resources.\n- #\n- # class Person < ActiveResource::Base\n- # self.site = \"https://api.people.com\"\n- # end\n- #\n- # Now the Person class is mapped to RESTful resources located at <tt>https://api.people.com/people/</tt>, and\n- # you can now use Active Resource's life cycle methods to manipulate resources. In the case where you already have\n- # an existing model with the same name as the desired RESTful resource you can set the +element_name+ value.\n- #\n- # class PersonResource < ActiveResource::Base\n- # self.site = \"https://api.people.com\"\n- # self.element_name = \"person\"\n- # end\n- #\n- # If your Active Resource object is required to use an HTTP proxy you can set the +proxy+ value which holds a URI.\n- #\n- # class PersonResource < ActiveResource::Base\n- # self.site = \"https://api.people.com\"\n- # self.proxy = \"https://user:password@proxy.people.com:8080\"\n- # end\n- #\n- #\n- # == Life cycle methods\n- #\n- # Active Resource exposes methods for creating, finding, updating, and deleting resources\n- # from REST web services.\n- #\n- # ryan = Person.new(:first => 'Ryan', :last => 'Daigle')\n- # ryan.save # => true\n- # ryan.id # => 2\n- # Person.exists?(ryan.id) # => true\n- # ryan.exists? # => true\n- #\n- # ryan = Person.find(1)\n- # # Resource holding our newly created Person object\n- #\n- # ryan.first = 'Rizzle'\n- # ryan.save # => true\n- #\n- # ryan.destroy # => true\n- #\n- # As you can see, these are very similar to Active Record's life cycle methods for database records.\n- # You can read more about each of these methods in their respective documentation.\n- #\n- # === Custom REST methods\n- #\n- # Since simple CRUD/life cycle methods can't accomplish every task, Active Resource also supports\n- # defining your own custom REST methods. To invoke them, Active Resource provides the <tt>get</tt>,\n- # <tt>post</tt>, <tt>put</tt> and <tt>\\delete</tt> methods where you can specify a custom REST method\n- # name to invoke.\n- #\n- # # POST to the custom 'register' REST method, i.e. POST /people/new/register.json.\n- # Person.new(:name => 'Ryan').post(:register)\n- # # => { :id => 1, :name => 'Ryan', :position => 'Clerk' }\n- #\n- # # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.json?position=Manager.\n- # Person.find(1).put(:promote, :position => 'Manager')\n- # # => { :id => 1, :name => 'Ryan', :position => 'Manager' }\n- #\n- # # GET all the positions available, i.e. GET /people/positions.json.\n- # Person.get(:positions)\n- # # => [{:name => 'Manager'}, {:name => 'Clerk'}]\n- #\n- # # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.json.\n- # Person.find(1).delete(:fire)\n- #\n- # For more information on using custom REST methods, see the\n- # ActiveResource::CustomMethods documentation.\n- #\n- # == Validations\n- #\n- # You can validate resources client side by overriding validation methods in the base class.\n- #\n- # class Person < ActiveResource::Base\n- # self.site = \"https://api.people.com\"\n- # protected\n- # def validate\n- # errors.add(\"last\", \"has invalid characters\") unless last =~ /[a-zA-Z]*/\n- # end\n- # end\n- #\n- # See the ActiveResource::Validations documentation for more information.\n- #\n- # == Authentication\n- #\n- # Many REST APIs require authentication. The HTTP spec describes two ways to\n- # make requests with a username and password (see RFC 2617).\n- #\n- # Basic authentication simply sends a username and password along with HTTP\n- # requests. These sensitive credentials are sent unencrypted, visible to\n- # any onlooker, so this scheme should only be used with SSL.\n- #\n- # Digest authentication sends a crytographic hash of the username, password,\n- # HTTP method, URI, and a single-use secret key provided by the server.\n- # Sensitive credentials aren't visible to onlookers, so digest authentication\n- # doesn't require SSL. However, this doesn't mean the connection is secure!\n- # Just the username and password.\n- #\n- # (You really, really want to use SSL. There's little reason not to.)\n- #\n- # === Picking an authentication scheme\n- #\n- # Basic authentication is the default. To switch to digest authentication,\n- # set +auth_type+ to +:digest+:\n- #\n- # class Person < ActiveResource::Base\n- # self.auth_type = :digest\n- # end\n- #\n- # === Setting the username and password\n- #\n- # Set +user+ and +password+ on the class, or include them in the +site+ URL.\n- #\n- # class Person < ActiveResource::Base\n- # # Set user and password directly:\n- # self.user = \"ryan\"\n- # self.password = \"password\"\n- #\n- # # Or include them in the site:\n- # self.site = \"https://ryan:password@api.people.com\"\n- # end\n- #\n- # === Certificate Authentication\n- #\n- # You can also authenticate using an X509 certificate. <tt>See ssl_options=</tt> for all options.\n- #\n- # class Person < ActiveResource::Base\n- # self.site = \"https://secure.api.people.com/\"\n- #\n- # File.open(pem_file_path, 'rb') do |pem_file|\n- # self.ssl_options = {\n- # cert: OpenSSL::X509::Certificate.new(pem_file),\n- # key: OpenSSL::PKey::RSA.new(pem_file),\n- # ca_path: \"/path/to/OpenSSL/formatted/CA_Certs\",\n- # verify_mode: OpenSSL::SSL::VERIFY_PEER }\n- # end\n- # end\n- #\n- #\n- # == Errors & Validation\n- #\n- # Error handling and validation is handled in much the same manner as you're used to seeing in\n- # Active Record. Both the response code in the HTTP response and the body of the response are used to\n- # indicate that an error occurred.\n- #\n- # === Resource errors\n- #\n- # When a GET is requested for a resource that does not exist, the HTTP <tt>404</tt> (Resource Not Found)\n- # response code will be returned from the server which will raise an ActiveResource::ResourceNotFound\n- # exception.\n- #\n- # # GET https://api.people.com/people/999.json\n- # ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound\n- #\n- #\n- # <tt>404</tt> is just one of the HTTP error response codes that Active Resource will handle with its own exception. The\n- # following HTTP response codes will also result in these exceptions:\n- #\n- # * 200..399 - Valid response. No exceptions, other than these redirects:\n- # * 301, 302, 303, 307 - ActiveResource::Redirection\n- # * 400 - ActiveResource::BadRequest\n- # * 401 - ActiveResource::UnauthorizedAccess\n- # * 403 - ActiveResource::ForbiddenAccess\n- # * 404 - ActiveResource::ResourceNotFound\n- # * 405 - ActiveResource::MethodNotAllowed\n- # * 409 - ActiveResource::ResourceConflict\n- # * 410 - ActiveResource::ResourceGone\n- # * 422 - ActiveResource::ResourceInvalid (rescued by save as validation errors)\n- # * 401..499 - ActiveResource::ClientError\n- # * 500..599 - ActiveResource::ServerError\n- # * Other - ActiveResource::ConnectionError\n- #\n- # These custom exceptions allow you to deal with resource errors more naturally and with more precision\n- # rather than returning a general HTTP error. For example:\n- #\n- # begin\n- # ryan = Person.find(my_id)\n- # rescue ActiveResource::ResourceNotFound\n- # redirect_to :action => 'not_found'\n- # rescue ActiveResource::ResourceConflict, ActiveResource::ResourceInvalid\n- # redirect_to :action => 'new'\n- # end\n- #\n- # When a GET is requested for a nested resource and you don't provide the prefix_param\n- # an ActiveResource::MissingPrefixParam will be raised.\n- #\n- # class Comment < ActiveResource::Base\n- # self.site = \"https://someip.com/posts/:post_id\"\n- # end\n- #\n- # Comment.find(1)\n- # # => ActiveResource::MissingPrefixParam: post_id prefix_option is missing\n- #\n- # === Validation errors\n- #\n- # Active Resource supports validations on resources and will return errors if any of these validations fail\n- # (e.g., \"First name can not be blank\" and so on). These types of errors are denoted in the response by\n- # a response code of <tt>422</tt> and an XML or JSON representation of the validation errors. The save operation will\n- # then fail (with a <tt>false</tt> return value) and the validation errors can be accessed on the resource in question.\n- #\n- # ryan = Person.find(1)\n- # ryan.first # => ''\n- # ryan.save # => false\n- #\n- # # When\n- # # PUT https://api.people.com/people/1.xml\n- # # or\n- # # PUT https://api.people.com/people/1.json\n- # # is requested with invalid values, the response is:\n- # #\n- # # Response (422):\n- # # <errors><error>First cannot be empty</error></errors>\n- # # or\n- # # {\"errors\":{\"first\":[\"cannot be empty\"]}}\n- # #\n- #\n- # ryan.errors.invalid?(:first) # => true\n- # ryan.errors.full_messages # => ['First cannot be empty']\n- #\n- # For backwards-compatibility with older endpoints, the following formats are also supported in JSON responses:\n- #\n- # # {\"errors\":['First cannot be empty']}\n- # # This was the required format for previous versions of ActiveResource\n- # # {\"first\":[\"cannot be empty\"]}\n- # # This was the default format produced by respond_with in ActionController <3.2.1\n- #\n- # Parsing either of these formats will result in a deprecation warning.\n- #\n- # Learn more about Active Resource's validation features in the ActiveResource::Validations documentation.\n- #\n- # === Timeouts\n- #\n- # Active Resource relies on HTTP to access RESTful APIs and as such is inherently susceptible to slow or\n- # unresponsive servers. In such cases, your Active Resource method calls could \\timeout. You can control the\n- # amount of time before Active Resource times out with the +timeout+ variable.\n- #\n- # class Person < ActiveResource::Base\n- # self.site = \"https://api.people.com\"\n- # self.timeout = 5\n- # end\n- #\n- # This sets the +timeout+ to 5 seconds. You can adjust the +timeout+ to a value suitable for the RESTful API\n- # you are accessing. It is recommended to set this to a reasonably low value to allow your Active Resource\n- # clients (especially if you are using Active Resource in a Rails application) to fail-fast (see\n- # http://en.wikipedia.org/wiki/Fail-fast) rather than cause cascading failures that could incapacitate your\n- # server.\n- #\n- # When a \\timeout occurs, an ActiveResource::TimeoutError is raised. You should rescue from\n- # ActiveResource::TimeoutError in your Active Resource method calls.\n- #\n- # Internally, Active Resource relies on Ruby's Net::HTTP library to make HTTP requests. Setting +timeout+\n- # sets the <tt>read_timeout</tt> of the internal Net::HTTP instance to the same value. The default\n- # <tt>read_timeout</tt> is 60 seconds on most Ruby implementations.\n- class Base\n- ##\n- # :singleton-method:\n- # The logger for diagnosing and tracing Active Resource calls.\n- cattr_accessor :logger\n-\n- class_attribute :_format\n-\n- class << self\n- # Creates a schema for this resource - setting the attributes that are\n- # known prior to fetching an instance from the remote system.\n- #\n- # The schema helps define the set of <tt>known_attributes</tt> of the\n- # current resource.\n- #\n- # There is no need to specify a schema for your Active Resource. If\n- # you do not, the <tt>known_attributes</tt> will be guessed from the\n- # instance attributes returned when an instance is fetched from the\n- # remote system.\n- #\n- # example:\n- # class Person < ActiveResource::Base\n- # schema do\n- # # define each attribute separately\n- # attribute 'name', :string\n- #\n- # # or use the convenience methods and pass >=1 attribute names\n- # string 'eye_color', 'hair_color'\n- # integer 'age'\n- # float 'height', 'weight'\n- #\n- # # unsupported types should be left as strings\n- # # overload the accessor methods if you need to convert them\n- # attribute 'created_at', 'string'\n- # end\n- # end\n- #\n- # p = Person.new\n- # p.respond_to? :name # => true\n- # p.respond_to? :age # => true\n- # p.name # => nil\n- # p.age # => nil\n- #\n- # j = Person.find_by_name('John') # <person><name>John</name><age>34</age><num_children>3</num_children></person>\n- # j.respond_to? :name # => true\n- # j.respond_to? :age # => true\n- # j.name # => 'John'\n- # j.age # => '34' # note this is a string!\n- # j.num_children # => '3' # note this is a string!\n- #\n- # p.num_children # => NoMethodError\n- #\n- # Attribute-types must be one of:\n- # string, integer, float\n- #\n- # Note: at present the attribute-type doesn't do anything, but stay\n- # tuned...\n- # Shortly it will also *cast* the value of the returned attribute.\n- # ie:\n- # j.age # => 34 # cast to an integer\n- # j.weight # => '65' # still a string!\n- #\n- def schema(&block)\n- if block_given?\n- schema_definition = Schema.new\n- schema_definition.instance_eval(&block)\n-\n- # skip out if we didn't define anything\n- return unless schema_definition.attrs.present?\n-\n- @schema ||= {}.with_indifferent_access\n- @known_attributes ||= []\n-\n- schema_definition.attrs.each do |k,v|\n- @schema[k] = v\n- @known_attributes << k\n- end\n-\n- schema\n- else\n- @schema ||= nil\n- end\n- end\n-\n- # Alternative, direct way to specify a <tt>schema</tt> for this\n- # Resource. <tt>schema</tt> is more flexible, but this is quick\n- # for a very simple schema.\n- #\n- # Pass the schema as a hash with the keys being the attribute-names\n- # and the value being one of the accepted attribute types (as defined\n- # in <tt>schema</tt>)\n- #\n- # example:\n- #\n- # class Person < ActiveResource::Base\n- # schema = {'name' => :string, 'age' => :integer }\n- # end\n- #\n- # The keys/values can be strings or symbols. They will be converted to\n- # strings.\n- #\n- def schema=(the_schema)\n- unless the_schema.present?\n- # purposefully nulling out the schema\n- @schema = nil\n- @known_attributes = []\n- return\n- end\n-\n- raise ArgumentError, \"Expected a hash\" unless the_schema.kind_of? Hash\n-\n- schema do\n- the_schema.each {|k,v| attribute(k,v) }\n- end\n- end\n-\n- # Returns the list of known attributes for this resource, gathered\n- # from the provided <tt>schema</tt>\n- # Attributes that are known will cause your resource to return 'true'\n- # when <tt>respond_to?</tt> is called on them. A known attribute will\n- # return nil if not set (rather than <t>MethodNotFound</tt>); thus\n- # known attributes can be used with <tt>validates_presence_of</tt>\n- # without a getter-method.\n- def known_attributes\n- @known_attributes ||= []\n- end\n-\n- # Gets the URI of the REST resources to map for this class. The site variable is required for\n- # Active Resource's mapping to work.\n- def site\n- # Not using superclass_delegating_reader because don't want subclasses to modify superclass instance\n- #\n- # With superclass_delegating_reader\n- #\n- # Parent.site = 'https://anonymous@test.com'\n- # Subclass.site # => 'https://anonymous@test.com'\n- # Subclass.site.user = 'david'\n- # Parent.site # => 'https://david@test.com'\n- #\n- # Without superclass_delegating_reader (expected behavior)\n- #\n- # Parent.site = 'https://anonymous@test.com'\n- # Subclass.site # => 'https://anonymous@test.com'\n- # Subclass.site.user = 'david' # => TypeError: can't modify frozen object\n- #\n- if defined?(@site)\n- @site\n- elsif superclass != Object && superclass.site\n- superclass.site.dup.freeze\n- end\n- end\n-\n- # Sets the URI of the REST resources to map for this class to the value in the +site+ argument.\n- # The site variable is required for Active Resource's mapping to work.\n- def site=(site)\n- @connection = nil\n- if site.nil?\n- @site = nil\n- else\n- @site = create_site_uri_from(site)\n- @user = URI.parser.unescape(@site.user) if @site.user\n- @password = URI.parser.unescape(@site.password) if @site.password\n- end\n- end\n-\n- # Gets the \\proxy variable if a proxy is required\n- def proxy\n- # Not using superclass_delegating_reader. See +site+ for explanation\n- if defined?(@proxy)\n- @proxy\n- elsif superclass != Object && superclass.proxy\n- superclass.proxy.dup.freeze\n- end\n- end\n-\n- # Sets the URI of the http proxy to the value in the +proxy+ argument.\n- def proxy=(proxy)\n- @connection = nil\n- @proxy = proxy.nil? ? nil : create_proxy_uri_from(proxy)\n- end\n-\n- # Gets the \\user for REST HTTP authentication.\n- def user\n- # Not using superclass_delegating_reader. See +site+ for explanation\n- if defined?(@user)\n- @user\n- elsif superclass != Object && superclass.user\n- superclass.user.dup.freeze\n- end\n- end\n-\n- # Sets the \\user for REST HTTP authentication.\n- def user=(user)\n- @connection = nil\n- @user = user\n- end\n-\n- # Gets the \\password for REST HTTP authentication.\n- def password\n- # Not using superclass_delegating_reader. See +site+ for explanation\n- if defined?(@password)\n- @password\n- elsif superclass != Object && superclass.password\n- superclass.password.dup.freeze\n- end\n- end\n-\n- # Sets the \\password for REST HTTP authentication.\n- def password=(password)\n- @connection = nil\n- @password = password\n- end\n-\n- def auth_type\n- if defined?(@auth_type)\n- @auth_type\n- end\n- end\n-\n- def auth_type=(auth_type)\n- @connection = nil\n- @auth_type = auth_type\n- end\n-\n- # Sets the format that attributes are sent and received in from a mime type reference:\n- #\n- # Person.format = :json\n- # Person.find(1) # => GET /people/1.json\n- #\n- # Person.format = ActiveResource::Formats::XmlFormat\n- # Person.find(1) # => GET /people/1.xml\n- #\n- # Default format is <tt>:json</tt>.\n- def format=(mime_type_reference_or_format)\n- format = mime_type_reference_or_format.is_a?(Symbol) ?\n- ActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format\n-\n- self._format = format\n- connection.format = format if site\n- end\n-\n- # Returns the current format, default is ActiveResource::Formats::JsonFormat.\n- def format\n- self._format || ActiveResource::Formats::JsonFormat\n- end\n-\n- # Sets the number of seconds after which requests to the REST API should time out.\n- def timeout=(timeout)\n- @connection = nil\n- @timeout = timeout\n- end\n-\n- # Gets the number of seconds after which requests to the REST API should time out.\n- def timeout\n- if defined?(@timeout)\n- @timeout\n- elsif superclass != Object && superclass.timeout\n- superclass.timeout\n- end\n- end\n-\n- # Options that will get applied to an SSL connection.\n- #\n- # * <tt>:key</tt> - An OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.\n- # * <tt>:cert</tt> - An OpenSSL::X509::Certificate object as client certificate\n- # * <tt>:ca_file</tt> - Path to a CA certification file in PEM format. The file can contain several CA certificates.\n- # * <tt>:ca_path</tt> - Path of a CA certification directory containing certifications in PEM format.\n- # * <tt>:verify_mode</tt> - Flags for server the certification verification at beginning of SSL/TLS session. (OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable)\n- # * <tt>:verify_callback</tt> - The verify callback for the server certification verification.\n- # * <tt>:verify_depth</tt> - The maximum depth for the certificate chain verification.\n- # * <tt>:cert_store</tt> - OpenSSL::X509::Store to verify peer certificate.\n- # * <tt>:ssl_timeout</tt> -The SSL timeout in seconds.\n- def ssl_options=(opts={})\n- @connection = nil\n- @ssl_options = opts\n- end\n-\n- # Returns the SSL options hash.\n- def ssl_options\n- if defined?(@ssl_options)\n- @ssl_options\n- elsif superclass != Object && superclass.ssl_options\n- superclass.ssl_options\n- end\n- end\n-\n- # An instance of ActiveResource::Connection that is the base \\connection to the remote service.\n- # The +refresh+ parameter toggles whether or not the \\connection is refreshed at every request\n- # or not (defaults to <tt>false</tt>).\n- def connection(refresh = false)\n- if defined?(@connection) || superclass == Object\n- @connection = Connection.new(site, format) if refresh || @connection.nil?\n- @connection.proxy = proxy if proxy\n- @connection.user = user if user\n- @connection.password = password if password\n- @connection.auth_type = auth_type if auth_type\n- @connection.timeout = timeout if timeout\n- @connection.ssl_options = ssl_options if ssl_options\n- @connection\n- else\n- superclass.connection\n- end\n- end\n-\n- def headers\n- @headers ||= {}\n- \n- if superclass != Object && superclass.headers\n- @headers = superclass.headers.merge(@headers)\n- else\n- @headers\n- end\n- end\n-\n- attr_writer :element_name\n-\n- def element_name\n- @element_name ||= model_name.element\n- end\n-\n- attr_writer :collection_name\n-\n- def collection_name\n- @collection_name ||= ActiveSupport::Inflector.pluralize(element_name)\n- end\n-\n- attr_writer :primary_key\n-\n- def primary_key\n- @primary_key ||= 'id'\n- end\n-\n- # Gets the \\prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>)\n- # This method is regenerated at runtime based on what the \\prefix is set to.\n- def prefix(options={})\n- default = site.path\n- default << '/' unless default[-1..-1] == '/'\n- # generate the actual method based on the current site path\n- self.prefix = default\n- prefix(options)\n- end\n-\n- # An attribute reader for the source string for the resource path \\prefix. This\n- # method is regenerated at runtime based on what the \\prefix is set to.\n- def prefix_source\n- prefix # generate #prefix and #prefix_source methods first\n- prefix_source\n- end\n-\n- # Sets the \\prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>).\n- # Default value is <tt>site.path</tt>.\n- def prefix=(value = '/')\n- # Replace :placeholders with '#{embedded options[:lookups]}'\n- prefix_call = value.gsub(/:\\w+/) { |key| \"\\#{URI.parser.escape options[#{key}].to_s}\" }\n-\n- # Clear prefix parameters in case they have been cached\n- @prefix_parameters = nil\n-\n- silence_warnings do\n- # Redefine the new methods.\n- instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1\n- def prefix_source() \"#{value}\" end\n- def prefix(options={}) \"#{prefix_call}\" end\n- RUBY_EVAL\n- end\n- rescue Exception => e\n- logger.error \"Couldn't set prefix: #{e}\\n #{code}\" if logger\n- raise\n- end\n-\n- alias_method :set_prefix, :prefix= #:nodoc:\n-\n- alias_method :set_element_name, :element_name= #:nodoc:\n- alias_method :set_collection_name, :collection_name= #:nodoc:\n-\n- # Gets the element path for the given ID in +id+. If the +query_options+ parameter is omitted, Rails\n- # will split from the \\prefix options.\n- #\n- # ==== Options\n- # +prefix_options+ - A \\hash to add a \\prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>\n- # would yield a URL like <tt>/accounts/19/purchases.json</tt>).\n- # +query_options+ - A \\hash to add items to the query string for the request.\n- #\n- # ==== Examples\n- # Post.element_path(1)\n- # # => /posts/1.json\n- #\n- # class Comment < ActiveResource::Base\n- # self.site = \"https://37s.sunrise.com/posts/:post_id\"\n- # end\n- #\n- # Comment.element_path(1, :post_id => 5)\n- # # => /posts/5/comments/1.json\n- #\n- # Comment.element_path(1, :post_id => 5, :active => 1)\n- # # => /posts/5/comments/1.json?active=1\n- #\n- # Comment.element_path(1, {:post_id => 5}, {:active => 1})\n- # # => /posts/5/comments/1.json?active=1\n- #\n- def element_path(id, prefix_options = {}, query_options = nil)\n- check_prefix_options(prefix_options)\n-\n- prefix_options, query_options = split_options(prefix_options) if query_options.nil?\n- \"#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}.#{format.extension}#{query_string(query_options)}\"\n- end\n-\n- # Gets the new element path for REST resources.\n- #\n- # ==== Options\n- # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>\n- # would yield a URL like <tt>/accounts/19/purchases/new.json</tt>).\n- #\n- # ==== Examples\n- # Post.new_element_path\n- # # => /posts/new.json\n- #\n- # class Comment < ActiveResource::Base\n- # self.site = \"https://37s.sunrise.com/posts/:post_id\"\n- # end\n- #\n- # Comment.collection_path(:post_id => 5)\n- # # => /posts/5/comments/new.json\n- def new_element_path(prefix_options = {})\n- \"#{prefix(prefix_options)}#{collection_name}/new.#{format.extension}\"\n- end\n-\n- # Gets the collection path for the REST resources. If the +query_options+ parameter is omitted, Rails\n- # will split from the +prefix_options+.\n- #\n- # ==== Options\n- # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>\n- # would yield a URL like <tt>/accounts/19/purchases.json</tt>).\n- # * +query_options+ - A hash to add items to the query string for the request.\n- #\n- # ==== Examples\n- # Post.collection_path\n- # # => /posts.json\n- #\n- # Comment.collection_path(:post_id => 5)\n- # # => /posts/5/comments.json\n- #\n- # Comment.collection_path(:post_id => 5, :active => 1)\n- # # => /posts/5/comments.json?active=1\n- #\n- # Comment.collection_path({:post_id => 5}, {:active => 1})\n- # # => /posts/5/comments.json?active=1\n- #\n- def collection_path(prefix_options = {}, query_options = nil)\n- check_prefix_options(prefix_options)\n- prefix_options, query_options = split_options(prefix_options) if query_options.nil?\n- \"#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}\"\n- end\n-\n- alias_method :set_primary_key, :primary_key= #:nodoc:\n-\n- # Builds a new, unsaved record using the default values from the remote server so\n- # that it can be used with RESTful forms.\n- #\n- # ==== Options\n- # * +attributes+ - A hash that overrides the default values from the server.\n- #\n- # Returns the new resource instance.\n- #\n- def build(attributes = {})\n- attrs = self.format.decode(connection.get(\"#{new_element_path}\").body).merge(attributes)\n- self.new(attrs)\n- end\n-\n- # Creates a new resource instance and makes a request to the remote service\n- # that it be saved, making it equivalent to the following simultaneous calls:\n- #\n- # ryan = Person.new(:first => 'ryan')\n- # ryan.save\n- #\n- # Returns the newly created resource. If a failure has occurred an\n- # exception will be raised (see <tt>save</tt>). If the resource is invalid and\n- # has not been saved then <tt>valid?</tt> will return <tt>false</tt>,\n- # while <tt>new?</tt> will still return <tt>true</tt>.\n- #\n- # ==== Examples\n- # Person.create(:name => 'Jeremy', :email => 'myname@nospam.com', :enabled => true)\n- # my_person = Person.find(:first)\n- # my_person.email # => myname@nospam.com\n- #\n- # dhh = Person.create(:name => 'David', :email => 'dhh@nospam.com', :enabled => true)\n- # dhh.valid? # => true\n- # dhh.new? # => false\n- #\n- # # We'll assume that there's a validation that requires the name attribute\n- # that_guy = Person.create(:name => '', :email => 'thatguy@nospam.com', :enabled => true)\n- # that_guy.valid? # => false\n- # that_guy.new? # => true\n- def create(attributes = {})\n- self.new(attributes).tap { |resource| resource.save }\n- end\n-\n- # Core method for finding resources. Used similarly to Active Record's +find+ method.\n- #\n- # ==== Arguments\n- # The first argument is considered to be the scope of the query. That is, how many\n- # resources are returned from the request. It can be one of the following.\n- #\n- # * <tt>:one</tt> - Returns a single resource.\n- # * <tt>:first</tt> - Returns the first resource found.\n- # * <tt>:last</tt> - Returns the last resource found.\n- # * <tt>:all</tt> - Returns every resource that matches the request.\n- #\n- # ==== Options\n- #\n- # * <tt>:from</tt> - Sets the path or custom method that resources will be fetched from.\n- # * <tt>:params</tt> - Sets query and \\prefix (nested URL) parameters.\n- #\n- # ==== Examples\n- # Person.find(1)\n- # # => GET /people/1.json\n- #\n- # Person.find(:all)\n- # # => GET /people.json\n- #\n- # Person.find(:all, :params => { :title => \"CEO\" })\n- # # => GET /people.json?title=CEO\n- #\n- # Person.find(:first, :from => :managers)\n- # # => GET /people/managers.json\n- #\n- # Person.find(:last, :from => :managers)\n- # # => GET /people/managers.json\n- #\n- # Person.find(:all, :from => \"/companies/1/people.json\")\n- # # => GET /companies/1/people.json\n- #\n- # Person.find(:one, :from => :leader)\n- # # => GET /people/leader.json\n- #\n- # Person.find(:all, :from => :developers, :params => { :language => 'ruby' })\n- # # => GET /people/developers.json?language=ruby\n- #\n- # Person.find(:one, :from => \"/companies/1/manager.json\")\n- # # => GET /companies/1/manager.json\n- #\n- # StreetAddress.find(1, :params => { :person_id => 1 })\n- # # => GET /people/1/street_addresses/1.json\n- #\n- # == Failure or missing data\n- # A failure to find the requested object raises a ResourceNotFound\n- # exception if the find was called with an id.\n- # With any other scope, find returns nil when no data is returned.\n- #\n- # Person.find(1)\n- # # => raises ResourceNotFound\n- #\n- # Person.find(:all)\n- # Person.find(:first)\n- # Person.find(:last)\n- # # => nil\n- def find(*arguments)\n- scope = arguments.slice!(0)\n- options = arguments.slice!(0) || {}\n-\n- case scope\n- when :all then find_every(options)\n- when :first then find_every(options).first\n- when :last then find_every(options).last\n- when :one then find_one(options)\n- else find_single(scope, options)\n- end\n- end\n-\n-\n- # A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass\n- # in all the same arguments to this method as you can to\n- # <tt>find(:first)</tt>.\n- def first(*args)\n- find(:first, *args)\n- end\n-\n- # A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass\n- # in all the same arguments to this method as you can to\n- # <tt>find(:last)</tt>.\n- def last(*args)\n- find(:last, *args)\n- end\n-\n- # This is an alias for find(:all). You can pass in all the same\n- # arguments to this method as you can to <tt>find(:all)</tt>\n- def all(*args)\n- find(:all, *args)\n- end\n-\n-\n- # Deletes the resources with the ID in the +id+ parameter.\n- #\n- # ==== Options\n- # All options specify \\prefix and query parameters.\n- #\n- # ==== Examples\n- # Event.delete(2) # sends DELETE /events/2\n- #\n- # Event.create(:name => 'Free Concert', :location => 'Community Center')\n- # my_event = Event.find(:first) # let's assume this is event with ID 7\n- # Event.delete(my_event.id) # sends DELETE /events/7\n- #\n- # # Let's assume a request to events/5/cancel.json\n- # Event.delete(params[:id]) # sends DELETE /events/5\n- def delete(id, options = {})\n- connection.delete(element_path(id, options))\n- end\n-\n- # Asserts the existence of a resource, returning <tt>true</tt> if the resource is found.\n- #\n- # ==== Examples\n- # Note.create(:title => 'Hello, world.', :body => 'Nothing more for now...')\n- # Note.exists?(1) # => true\n- #\n- # Note.exists(1349) # => false\n- def exists?(id, options = {})\n- if id\n- prefix_options, query_options = split_options(options[:params])\n- path = element_path(id, prefix_options, query_options)\n- response = connection.head(path, headers)\n- response.code.to_i == 200\n- end\n- # id && !find_single(id, options).nil?\n- rescue ActiveResource::ResourceNotFound, ActiveResource::ResourceGone\n- false\n- end\n-\n- private\n-\n- def check_prefix_options(prefix_options)\n- p_options = HashWithIndifferentAccess.new(prefix_options)\n- prefix_parameters.each do |p|\n- raise(MissingPrefixParam, \"#{p} prefix_option is missing\") if p_options[p].blank?\n- end\n- end\n-\n- # Find every resource\n- def find_every(options)\n- begin\n- case from = options[:from]\n- when Symbol\n- instantiate_collection(get(from, options[:params]))\n- when String\n- path = \"#{from}#{query_string(options[:params])}\"\n- instantiate_collection(format.decode(connection.get(path, headers).body) || [])\n- else\n- prefix_options, query_options = split_options(options[:params])\n- path = collection_path(prefix_options, query_options)\n- instantiate_collection( (format.decode(connection.get(path, headers).body) || []), prefix_options )\n- end\n- rescue ActiveResource::ResourceNotFound\n- # Swallowing ResourceNotFound exceptions and return nil - as per\n- # ActiveRecord.\n- nil\n- end\n- end\n-\n- # Find a single resource from a one-off URL\n- def find_one(options)\n- case from = options[:from]\n- when Symbol\n- instantiate_record(get(from, options[:params]))\n- when String\n- path = \"#{from}#{query_string(options[:params])}\"\n- instantiate_record(format.decode(connection.get(path, headers).body))\n- end\n- end\n-\n- # Find a single resource from the default URL\n- def find_single(scope, options)\n- prefix_options, query_options = split_options(options[:params])\n- path = element_path(scope, prefix_options, query_options)\n- instantiate_record(format.decode(connection.get(path, headers).body), prefix_options)\n- end\n-\n- def instantiate_collection(collection, prefix_options = {})\n- collection.collect! { |record| instantiate_record(record, prefix_options) }\n- end\n-\n- def instantiate_record(record, prefix_options = {})\n- new(record, true).tap do |resource|\n- resource.prefix_options = prefix_options\n- end\n- end\n-\n-\n- # Accepts a URI and creates the site URI from that.\n- def create_site_uri_from(site)\n- site.is_a?(URI) ? site.dup : URI.parse(site)\n- end\n-\n- # Accepts a URI and creates the proxy URI from that.\n- def create_proxy_uri_from(proxy)\n- proxy.is_a?(URI) ? proxy.dup : URI.parse(proxy)\n- end\n-\n- # contains a set of the current prefix parameters.\n- def prefix_parameters\n- @prefix_parameters ||= prefix_source.scan(/:\\w+/).map { |key| key[1..-1].to_sym }.to_set\n- end\n-\n- # Builds the query string for the request.\n- def query_string(options)\n- \"?#{options.to_query}\" unless options.nil? || options.empty?\n- end\n-\n- # split an option hash into two hashes, one containing the prefix options,\n- # and the other containing the leftovers.\n- def split_options(options = {})\n- prefix_options, query_options = {}, {}\n-\n- (options || {}).each do |key, value|\n- next if key.blank? || !key.respond_to?(:to_sym)\n- (prefix_parameters.include?(key.to_sym) ? prefix_options : query_options)[key.to_sym] = value\n- end\n-\n- [ prefix_options, query_options ]\n- end\n- end\n-\n- attr_accessor :attributes #:nodoc:\n- attr_accessor :prefix_options #:nodoc:\n-\n- # If no schema has been defined for the class (see\n- # <tt>ActiveResource::schema=</tt>), the default automatic schema is\n- # generated from the current instance's attributes\n- def schema\n- self.class.schema || self.attributes\n- end\n-\n- # This is a list of known attributes for this resource. Either\n- # gathered from the provided <tt>schema</tt>, or from the attributes\n- # set on this instance after it has been fetched from the remote system.\n- def known_attributes\n- self.class.known_attributes + self.attributes.keys.map(&:to_s)\n- end\n-\n-\n- # Constructor method for \\new resources; the optional +attributes+ parameter takes a \\hash\n- # of attributes for the \\new resource.\n- #\n- # ==== Examples\n- # my_course = Course.new\n- # my_course.name = \"Western Civilization\"\n- # my_course.lecturer = \"Don Trotter\"\n- # my_course.save\n- #\n- # my_other_course = Course.new(:name => \"Philosophy: Reason and Being\", :lecturer => \"Ralph Cling\")\n- # my_other_course.save\n- def initialize(attributes = {}, persisted = false)\n- @attributes = {}.with_indifferent_access\n- @prefix_options = {}\n- @persisted = persisted\n- load(attributes)\n- end\n-\n- # Returns a \\clone of the resource that hasn't been assigned an +id+ yet and\n- # is treated as a \\new resource.\n- #\n- # ryan = Person.find(1)\n- # not_ryan = ryan.clone\n- # not_ryan.new? # => true\n- #\n- # Any active resource member attributes will NOT be cloned, though all other\n- # attributes are. This is to prevent the conflict between any +prefix_options+\n- # that refer to the original parent resource and the newly cloned parent\n- # resource that does not exist.\n- #\n- # ryan = Person.find(1)\n- # ryan.address = StreetAddress.find(1, :person_id => ryan.id)\n- # ryan.hash = {:not => \"an ARes instance\"}\n- #\n- # not_ryan = ryan.clone\n- # not_ryan.new? # => true\n- # not_ryan.address # => NoMethodError\n- # not_ryan.hash # => {:not => \"an ARes instance\"}\n- def clone\n- # Clone all attributes except the pk and any nested ARes\n- cloned = Hash[attributes.reject {|k,v| k == self.class.primary_key || v.is_a?(ActiveResource::Base)}.map { |k, v| [k, v.clone] }]\n- # Form the new resource - bypass initialize of resource with 'new' as that will call 'load' which\n- # attempts to convert hashes into member objects and arrays into collections of objects. We want\n- # the raw objects to be cloned so we bypass load by directly setting the attributes hash.\n- resource = self.class.new({})\n- resource.prefix_options = self.prefix_options\n- resource.send :instance_variable_set, '@attributes', cloned\n- resource\n- end\n-\n-\n- # Returns +true+ if this object hasn't yet been saved, otherwise, returns +false+.\n- #\n- # ==== Examples\n- # not_new = Computer.create(:brand => 'Apple', :make => 'MacBook', :vendor => 'MacMall')\n- # not_new.new? # => false\n- #\n- # is_new = Computer.new(:brand => 'IBM', :make => 'Thinkpad', :vendor => 'IBM')\n- # is_new.new? # => true\n- #\n- # is_new.save\n- # is_new.new? # => false\n- #\n- def new?\n- !persisted?\n- end\n- alias :new_record? :new?\n-\n- # Returns +true+ if this object has been saved, otherwise returns +false+.\n- #\n- # ==== Examples\n- # persisted = Computer.create(:brand => 'Apple', :make => 'MacBook', :vendor => 'MacMall')\n- # persisted.persisted? # => true\n- #\n- # not_persisted = Computer.new(:brand => 'IBM', :make => 'Thinkpad', :vendor => 'IBM')\n- # not_persisted.persisted? # => false\n- #\n- # not_persisted.save\n- # not_persisted.persisted? # => true\n- #\n- def persisted?\n- @persisted\n- end\n-\n- # Gets the <tt>\\id</tt> attribute of the resource.\n- def id\n- attributes[self.class.primary_key]\n- end\n-\n- # Sets the <tt>\\id</tt> attribute of the resource.\n- def id=(id)\n- attributes[self.class.primary_key] = id\n- end\n-\n- # Test for equality. Resource are equal if and only if +other+ is the same object or\n- # is an instance of the same class, is not <tt>new?</tt>, and has the same +id+.\n- #\n- # ==== Examples\n- # ryan = Person.create(:name => 'Ryan')\n- # jamie = Person.create(:name => 'Jamie')\n- #\n- # ryan == jamie\n- # # => false (Different name attribute and id)\n- #\n- # ryan_again = Person.new(:name => 'Ryan')\n- # ryan == ryan_again\n- # # => false (ryan_again is new?)\n- #\n- # ryans_clone = Person.create(:name => 'Ryan')\n- # ryan == ryans_clone\n- # # => false (Different id attributes)\n- #\n- # ryans_twin = Person.find(ryan.id)\n- # ryan == ryans_twin\n- # # => true\n- #\n- def ==(other)\n- other.equal?(self) || (other.instance_of?(self.class) && other.id == id && other.prefix_options == prefix_options)\n- end\n-\n- # Tests for equality (delegates to ==).\n- def eql?(other)\n- self == other\n- end\n-\n- # Delegates to id in order to allow two resources of the same type and \\id to work with something like:\n- # [(a = Person.find 1), (b = Person.find 2)] & [(c = Person.find 1), (d = Person.find 4)] # => [a]\n- def hash\n- id.hash\n- end\n-\n- # Duplicates the current resource without saving it.\n- #\n- # ==== Examples\n- # my_invoice = Invoice.create(:customer => 'That Company')\n- # next_invoice = my_invoice.dup\n- # next_invoice.new? # => true\n- #\n- # next_invoice.save\n- # next_invoice == my_invoice # => false (different id attributes)\n- #\n- # my_invoice.customer # => That Company\n- # next_invoice.customer # => That Company\n- def dup\n- self.class.new.tap do |resource|\n- resource.attributes = @attributes\n- resource.prefix_options = @prefix_options\n- end\n- end\n-\n- # Saves (+POST+) or \\updates (+PUT+) a resource. Delegates to +create+ if the object is \\new,\n- # +update+ if it exists. If the response to the \\save includes a body, it will be assumed that this body\n- # is Json for the final object as it looked after the \\save (which would include attributes like +created_at+\n- # that weren't part of the original submit).\n- #\n- # ==== Examples\n- # my_company = Company.new(:name => 'RoleModel Software', :owner => 'Ken Auer', :size => 2)\n- # my_company.new? # => true\n- # my_company.save # sends POST /companies/ (create)\n- #\n- # my_company.new? # => false\n- # my_company.size = 10\n- # my_company.save # sends PUT /companies/1 (update)\n- def save\n- new? ? create : update\n- end\n-\n- # Saves the resource.\n- #\n- # If the resource is new, it is created via +POST+, otherwise the\n- # existing resource is updated via +PUT+.\n- #\n- # With <tt>save!</tt> validations always run. If any of them fail\n- # ActiveResource::ResourceInvalid gets raised, and nothing is POSTed to\n- # the remote system.\n- # See ActiveResource::Validations for more information.\n- #\n- # There's a series of callbacks associated with <tt>save!</tt>. If any\n- # of the <tt>before_*</tt> callbacks return +false+ the action is\n- # cancelled and <tt>save!</tt> raises ActiveResource::ResourceInvalid.\n- def save!\n- save || raise(ResourceInvalid.new(self))\n- end\n-\n- # Deletes the resource from the remote service.\n- #\n- # ==== Examples\n- # my_id = 3\n- # my_person = Person.find(my_id)\n- # my_person.destroy\n- # Person.find(my_id) # 404 (Resource Not Found)\n- #\n- # new_person = Person.create(:name => 'James')\n- # new_id = new_person.id # => 7\n- # new_person.destroy\n- # Person.find(new_id) # 404 (Resource Not Found)\n- def destroy\n- connection.delete(element_path, self.class.headers)\n- end\n-\n- # Evaluates to <tt>true</tt> if this resource is not <tt>new?</tt> and is\n- # found on the remote service. Using this method, you can check for\n- # resources that may have been deleted between the object's instantiation\n- # and actions on it.\n- #\n- # ==== Examples\n- # Person.create(:name => 'Theodore Roosevelt')\n- # that_guy = Person.find(:first)\n- # that_guy.exists? # => true\n- #\n- # that_lady = Person.new(:name => 'Paul Bean')\n- # that_lady.exists? # => false\n- #\n- # guys_id = that_guy.id\n- # Person.delete(guys_id)\n- # that_guy.exists? # => false\n- def exists?\n- !new? && self.class.exists?(to_param, :params => prefix_options)\n- end\n-\n- # Returns the serialized string representation of the resource in the configured\n- # serialization format specified in ActiveResource::Base.format. The options\n- # applicable depend on the configured encoding format.\n- def encode(options={})\n- send(\"to_#{self.class.format.extension}\", options)\n- end\n-\n- # A method to \\reload the attributes of this object from the remote web service.\n- #\n- # ==== Examples\n- # my_branch = Branch.find(:first)\n- # my_branch.name # => \"Wislon Raod\"\n- #\n- # # Another client fixes the typo...\n- #\n- # my_branch.name # => \"Wislon Raod\"\n- # my_branch.reload\n- # my_branch.name # => \"Wilson Road\"\n- def reload\n- self.load(self.class.find(to_param, :params => @prefix_options).attributes)\n- end\n-\n- # A method to manually load attributes from a \\hash. Recursively loads collections of\n- # resources. This method is called in +initialize+ and +create+ when a \\hash of attributes\n- # is provided.\n- #\n- # ==== Examples\n- # my_attrs = {:name => 'J&J Textiles', :industry => 'Cloth and textiles'}\n- # my_attrs = {:name => 'Marty', :colors => [\"red\", \"green\", \"blue\"]}\n- #\n- # the_supplier = Supplier.find(:first)\n- # the_supplier.name # => 'J&M Textiles'\n- # the_supplier.load(my_attrs)\n- # the_supplier.name('J&J Textiles')\n- #\n- # # These two calls are the same as Supplier.new(my_attrs)\n- # my_supplier = Supplier.new\n- # my_supplier.load(my_attrs)\n- #\n- # # These three calls are the same as Supplier.create(my_attrs)\n- # your_supplier = Supplier.new\n- # your_supplier.load(my_attrs)\n- # your_supplier.save\n- def load(attributes, remove_root = false)\n- raise ArgumentError, \"expected an attributes Hash, got #{attributes.inspect}\" unless attributes.is_a?(Hash)\n- @prefix_options, attributes = split_options(attributes)\n-\n- if attributes.keys.size == 1\n- remove_root = self.class.element_name == attributes.keys.first.to_s\n- end\n-\n- attributes = Formats.remove_root(attributes) if remove_root\n-\n- attributes.each do |key, value|\n- @attributes[key.to_s] =\n- case value\n- when Array\n- resource = nil\n- value.map do |attrs|\n- if attrs.is_a?(Hash)\n- resource ||= find_or_create_resource_for_collection(key)\n- resource.new(attrs)\n- else\n- attrs.duplicable? ? attrs.dup : attrs\n- end\n- end\n- when Hash\n- resource = find_or_create_resource_for(key)\n- resource.new(value)\n- else\n- value.duplicable? ? value.dup : value\n- end\n- end\n- self\n- end\n-\n- # Updates a single attribute and then saves the object.\n- #\n- # Note: Unlike ActiveRecord::Base.update_attribute, this method <b>is</b>\n- # subject to normal validation routines as an update sends the whole body\n- # of the resource in the request. (See Validations).\n- #\n- # As such, this method is equivalent to calling update_attributes with a single attribute/value pair.\n- #\n- # If the saving fails because of a connection or remote service error, an\n- # exception will be raised. If saving fails because the resource is\n- # invalid then <tt>false</tt> will be returned.\n- def update_attribute(name, value)\n- self.send(\"#{name}=\".to_sym, value)\n- self.save\n- end\n-\n- # Updates this resource with all the attributes from the passed-in Hash\n- # and requests that the record be saved.\n- #\n- # If the saving fails because of a connection or remote service error, an\n- # exception will be raised. If saving fails because the resource is\n- # invalid then <tt>false</tt> will be returned.\n- #\n- # Note: Though this request can be made with a partial set of the\n- # resource's attributes, the full body of the request will still be sent\n- # in the save request to the remote service.\n- def update_attributes(attributes)\n- load(attributes, false) && save\n- end\n-\n- # For checking <tt>respond_to?</tt> without searching the attributes (which is faster).\n- alias_method :respond_to_without_attributes?, :respond_to?\n-\n- # A method to determine if an object responds to a message (e.g., a method call). In Active Resource, a Person object with a\n- # +name+ attribute can answer <tt>true</tt> to <tt>my_person.respond_to?(:name)</tt>, <tt>my_person.respond_to?(:name=)</tt>, and\n- # <tt>my_person.respond_to?(:name?)</tt>.\n- def respond_to?(method, include_priv = false)\n- method_name = method.to_s\n- if attributes.nil?\n- super\n- elsif known_attributes.include?(method_name)\n- true\n- elsif method_name =~ /(?:=|\\?)$/ && attributes.include?($`)\n- true\n- else\n- # super must be called at the end of the method, because the inherited respond_to?\n- # would return true for generated readers, even if the attribute wasn't present\n- super\n- end\n- end\n-\n- def to_json(options={})\n- super({ :root => self.class.element_name }.merge(options))\n- end\n-\n- def to_xml(options={})\n- super({ :root => self.class.element_name }.merge(options))\n- end\n-\n- protected\n- def connection(refresh = false)\n- self.class.connection(refresh)\n- end\n-\n- # Update the resource on the remote service.\n- def update\n- connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response|\n- load_attributes_from_response(response)\n- end\n- end\n-\n- # Create (i.e., \\save to the remote service) the \\new resource.\n- def create\n- connection.post(collection_path, encode, self.class.headers).tap do |response|\n- self.id = id_from_response(response)\n- load_attributes_from_response(response)\n- end\n- end\n-\n- def load_attributes_from_response(response)\n- if (response_code_allows_body?(response.code) &&\n- (response['Content-Length'].nil? || response['Content-Length'] != \"0\") &&\n- !response.body.nil? && response.body.strip.size > 0)\n- load(self.class.format.decode(response.body), true)\n- @persisted = true\n- end\n- end\n-\n- # Takes a response from a typical create post and pulls the ID out\n- def id_from_response(response)\n- response['Location'][/\\/([^\\/]*?)(\\.\\w+)?$/, 1] if response['Location']\n- end\n-\n- def element_path(options = nil)\n- self.class.element_path(to_param, options || prefix_options)\n- end\n-\n- def new_element_path\n- self.class.new_element_path(prefix_options)\n- end\n-\n- def collection_path(options = nil)\n- self.class.collection_path(options || prefix_options)\n- end\n-\n- private\n-\n- def read_attribute_for_serialization(n)\n- attributes[n]\n- end\n-\n- # Determine whether the response is allowed to have a body per HTTP 1.1 spec section 4.4.1\n- def response_code_allows_body?(c)\n- !((100..199).include?(c) || [204,304].include?(c))\n- end\n-\n- # Tries to find a resource for a given collection name; if it fails, then the resource is created\n- def find_or_create_resource_for_collection(name)\n- find_or_create_resource_for(ActiveSupport::Inflector.singularize(name.to_s))\n- end\n-\n- # Tries to find a resource in a non empty list of nested modules\n- # if it fails, then the resource is created\n- def find_or_create_resource_in_modules(resource_name, module_names)\n- receiver = Object\n- namespaces = module_names[0, module_names.size-1].map do |module_name|\n- receiver = receiver.const_get(module_name)\n- end\n- const_args = [resource_name, false]\n- if namespace = namespaces.reverse.detect { |ns| ns.const_defined?(*const_args) }\n- namespace.const_get(*const_args)\n- else\n- create_resource_for(resource_name)\n- end\n- end\n-\n- # Tries to find a resource for a given name; if it fails, then the resource is created\n- def find_or_create_resource_for(name)\n- resource_name = name.to_s.camelize\n-\n- const_args = [resource_name, false]\n- if self.class.const_defined?(*const_args)\n- self.class.const_get(*const_args)\n- else\n- ancestors = self.class.name.split(\"::\")\n- if ancestors.size > 1\n- find_or_create_resource_in_modules(resource_name, ancestors)\n- else\n- if Object.const_defined?(*const_args)\n- Object.const_get(*const_args)\n- else\n- create_resource_for(resource_name)\n- end\n- end\n- end\n- end\n-\n- # Create and return a class definition for a resource inside the current resource\n- def create_resource_for(resource_name)\n- resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base))\n- resource.prefix = self.class.prefix\n- resource.site = self.class.site\n- resource\n- end\n-\n- def split_options(options = {})\n- self.class.__send__(:split_options, options)\n- end\n-\n- def method_missing(method_symbol, *arguments) #:nodoc:\n- method_name = method_symbol.to_s\n-\n- if method_name =~ /(=|\\?)$/\n- case $1\n- when \"=\"\n- attributes[$`] = arguments.first\n- when \"?\"\n- attributes[$`]\n- end\n- else\n- return attributes[method_name] if attributes.include?(method_name)\n- # not set right now but we know about it\n- return nil if known_attributes.include?(method_name)\n- super\n- end\n- end\n- end\n-\n- class Base\n- extend ActiveModel::Naming\n- include CustomMethods, Observing, Validations\n- include ActiveModel::Conversion\n- include ActiveModel::Serializers::JSON\n- include ActiveModel::Serializers::Xml\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "8a8dc3146d7f9c07a9704e80a7d17f742bd51d95",
filename = "activeresource/lib/active_resource/connection.rb",
status = "removed", additions = 0L, deletions = 284L, changes = 284L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/connection.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/connection.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/connection.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,284 +0,0 @@\n-require 'active_support/core_ext/benchmark'\n-require 'active_support/core_ext/uri'\n-require 'active_support/core_ext/object/inclusion'\n-require 'net/https'\n-require 'date'\n-require 'time'\n-require 'uri'\n-\n-module ActiveResource\n- # Class to handle connections to remote web services.\n- # This class is used by ActiveResource::Base to interface with REST\n- # services.\n- class Connection\n-\n- HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept',\n- :put => 'Content-Type',\n- :post => 'Content-Type',\n- :patch => 'Content-Type',\n- :delete => 'Accept',\n- :head => 'Accept'\n- }\n-\n- attr_reader :site, :user, :password, :auth_type, :timeout, :proxy, :ssl_options\n- attr_accessor :format\n-\n- class << self\n- def requests\n- @@requests ||= []\n- end\n- end\n-\n- # The +site+ parameter is required and will set the +site+\n- # attribute to the URI for the remote resource service.\n- def initialize(site, format = ActiveResource::Formats::JsonFormat)\n- raise ArgumentError, 'Missing site URI' unless site\n- @user = @password = nil\n- self.site = site\n- self.format = format\n- end\n-\n- # Set URI for remote service.\n- def site=(site)\n- @site = site.is_a?(URI) ? site : URI.parse(site)\n- @user = URI.parser.unescape(@site.user) if @site.user\n- @password = URI.parser.unescape(@site.password) if @site.password\n- end\n-\n- # Set the proxy for remote service.\n- def proxy=(proxy)\n- @proxy = proxy.is_a?(URI) ? proxy : URI.parse(proxy)\n- end\n-\n- # Sets the user for remote service.\n- def user=(user)\n- @user = user\n- end\n-\n- # Sets the password for remote service.\n- def password=(password)\n- @password = password\n- end\n-\n- # Sets the auth type for remote service.\n- def auth_type=(auth_type)\n- @auth_type = legitimize_auth_type(auth_type)\n- end\n-\n- # Sets the number of seconds after which HTTP requests to the remote service should time out.\n- def timeout=(timeout)\n- @timeout = timeout\n- end\n-\n- # Hash of options applied to Net::HTTP instance when +site+ protocol is 'https'.\n- def ssl_options=(opts={})\n- @ssl_options = opts\n- end\n-\n- # Executes a GET request.\n- # Used to get (find) resources.\n- def get(path, headers = {})\n- with_auth { request(:get, path, build_request_headers(headers, :get, self.site.merge(path))) }\n- end\n-\n- # Executes a DELETE request (see HTTP protocol documentation if unfamiliar).\n- # Used to delete resources.\n- def delete(path, headers = {})\n- with_auth { request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path))) }\n- end\n-\n- # Executes a PATCH request (see HTTP protocol documentation if unfamiliar).\n- # Used to update resources.\n- def patch(path, body = '', headers = {})\n- with_auth { request(:patch, path, body.to_s, build_request_headers(headers, :patch, self.site.merge(path))) }\n- end\n-\n- # Executes a PUT request (see HTTP protocol documentation if unfamiliar).\n- # Used to update resources.\n- def put(path, body = '', headers = {})\n- with_auth { request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path))) }\n- end\n-\n- # Executes a POST request.\n- # Used to create new resources.\n- def post(path, body = '', headers = {})\n- with_auth { request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path))) }\n- end\n-\n- # Executes a HEAD request.\n- # Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).\n- def head(path, headers = {})\n- with_auth { request(:head, path, build_request_headers(headers, :head, self.site.merge(path))) }\n- end\n-\n- private\n- # Makes a request to the remote service.\n- def request(method, path, *arguments)\n- result = ActiveSupport::Notifications.instrument(\"request.active_resource\") do |payload|\n- payload[:method] = method\n- payload[:request_uri] = \"#{site.scheme}://#{site.host}:#{site.port}#{path}\"\n- payload[:result] = http.send(method, path, *arguments)\n- end\n- handle_response(result)\n- rescue Timeout::Error => e\n- raise TimeoutError.new(e.message)\n- rescue OpenSSL::SSL::SSLError => e\n- raise SSLError.new(e.message)\n- end\n-\n- # Handles response and error codes from the remote service.\n- def handle_response(response)\n- case response.code.to_i\n- when 301, 302, 303, 307\n- raise(Redirection.new(response))\n- when 200...400\n- response\n- when 400\n- raise(BadRequest.new(response))\n- when 401\n- raise(UnauthorizedAccess.new(response))\n- when 403\n- raise(ForbiddenAccess.new(response))\n- when 404\n- raise(ResourceNotFound.new(response))\n- when 405\n- raise(MethodNotAllowed.new(response))\n- when 409\n- raise(ResourceConflict.new(response))\n- when 410\n- raise(ResourceGone.new(response))\n- when 422\n- raise(ResourceInvalid.new(response))\n- when 401...500\n- raise(ClientError.new(response))\n- when 500...600\n- raise(ServerError.new(response))\n- else\n- raise(ConnectionError.new(response, \"Unknown response code: #{response.code}\"))\n- end\n- end\n-\n- # Creates new Net::HTTP instance for communication with the\n- # remote service and resources.\n- def http\n- configure_http(new_http)\n- end\n-\n- def new_http\n- if @proxy\n- Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)\n- else\n- Net::HTTP.new(@site.host, @site.port)\n- end\n- end\n-\n- def configure_http(http)\n- apply_ssl_options(http).tap do |https|\n- # Net::HTTP timeouts default to 60 seconds.\n- if defined? @timeout\n- https.open_timeout = @timeout\n- https.read_timeout = @timeout\n- end\n- end\n- end\n-\n- def apply_ssl_options(http)\n- http.tap do |https|\n- # Skip config if site is already a https:// URI.\n- if defined? @ssl_options\n- http.use_ssl = true\n-\n- # Default to no cert verification (WTF? FIXME)\n- http.verify_mode = OpenSSL::SSL::VERIFY_NONE\n-\n- # All the SSL options have corresponding http settings.\n- @ssl_options.each { |key, value| http.send \"#{key}=\", value }\n- end\n- end\n- end\n-\n- def default_header\n- @default_header ||= {}\n- end\n-\n- # Builds headers for request to remote service.\n- def build_request_headers(headers, http_method, uri)\n- authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers)\n- end\n-\n- def response_auth_header\n- @response_auth_header ||= \"\"\n- end\n-\n- def with_auth\n- retried ||= false\n- yield\n- rescue UnauthorizedAccess => e\n- raise if retried || auth_type != :digest\n- @response_auth_header = e.response['WWW-Authenticate']\n- retried = true\n- retry\n- end\n-\n- def authorization_header(http_method, uri)\n- if @user || @password\n- if auth_type == :digest\n- { 'Authorization' => digest_auth_header(http_method, uri) }\n- else\n- { 'Authorization' => 'Basic ' + [\"#{@user}:#{@password}\"].pack('m').delete(\"\\r\\n\") }\n- end\n- else\n- {}\n- end\n- end\n-\n- def digest_auth_header(http_method, uri)\n- params = extract_params_from_response\n-\n- request_uri = uri.path\n- request_uri << \"?#{uri.query}\" if uri.query\n-\n- ha1 = Digest::MD5.hexdigest(\"#{@user}:#{params['realm']}:#{@password}\")\n- ha2 = Digest::MD5.hexdigest(\"#{http_method.to_s.upcase}:#{request_uri}\")\n-\n- params.merge!('cnonce' => client_nonce)\n- request_digest = Digest::MD5.hexdigest([ha1, params['nonce'], \"0\", params['cnonce'], params['qop'], ha2].join(\":\"))\n- \"Digest #{auth_attributes_for(uri, request_digest, params)}\"\n- end\n-\n- def client_nonce\n- Digest::MD5.hexdigest(\"%x\" % (Time.now.to_i + rand(65535)))\n- end\n-\n- def extract_params_from_response\n- params = {}\n- if response_auth_header =~ /^(\\w+) (.*)/\n- $2.gsub(/(\\w+)=\"(.*?)\"/) { params[$1] = $2 }\n- end\n- params\n- end\n-\n- def auth_attributes_for(uri, request_digest, params)\n- [\n- %Q(username=\"#{@user}\"),\n- %Q(realm=\"#{params['realm']}\"),\n- %Q(qop=\"#{params['qop']}\"),\n- %Q(uri=\"#{uri.path}\"),\n- %Q(nonce=\"#{params['nonce']}\"),\n- %Q(nc=\"0\"),\n- %Q(cnonce=\"#{params['cnonce']}\"),\n- %Q(opaque=\"#{params['opaque']}\"),\n- %Q(response=\"#{request_digest}\")].join(\", \")\n- end\n-\n- def http_format_header(http_method)\n- {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type}\n- end\n-\n- def legitimize_auth_type(auth_type)\n- return :basic if auth_type.nil?\n- auth_type = auth_type.to_sym\n- auth_type.in?([:basic, :digest]) ? auth_type : :basic\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "839dc79d502e47f58f4e425470a5332989427ff6",
filename = "activeresource/lib/active_resource/custom_methods.rb",
status = "removed", additions = 0L, deletions = 127L, changes = 127L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/custom_methods.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/custom_methods.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/custom_methods.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,127 +0,0 @@\n-require 'active_support/core_ext/object/blank'\n-\n-module ActiveResource\n- # A module to support custom REST methods and sub-resources, allowing you to break out\n- # of the \"default\" REST methods with your own custom resource requests. For example,\n- # say you use Rails to expose a REST service and configure your routes with:\n- #\n- # map.resources :people, :new => { :register => :post },\n- # :member => { :promote => :put, :deactivate => :delete }\n- # :collection => { :active => :get }\n- #\n- # This route set creates routes for the following HTTP requests:\n- #\n- # POST /people/new/register.json # PeopleController.register\n- # PATCH/PUT /people/1/promote.json # PeopleController.promote with :id => 1\n- # DELETE /people/1/deactivate.json # PeopleController.deactivate with :id => 1\n- # GET /people/active.json # PeopleController.active\n- #\n- # Using this module, Active Resource can use these custom REST methods just like the\n- # standard methods.\n- #\n- # class Person < ActiveResource::Base\n- # self.site = \"https://37s.sunrise.com\"\n- # end\n- #\n- # Person.new(:name => 'Ryan').post(:register) # POST /people/new/register.json\n- # # => { :id => 1, :name => 'Ryan' }\n- #\n- # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.json\n- # Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.json\n- #\n- # Person.get(:active) # GET /people/active.json\n- # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]\n- #\n- module CustomMethods\n- extend ActiveSupport::Concern\n-\n- included do\n- class << self\n- alias :orig_delete :delete\n-\n- # Invokes a GET to a given custom REST method. For example:\n- #\n- # Person.get(:active) # GET /people/active.json\n- # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]\n- #\n- # Person.get(:active, :awesome => true) # GET /people/active.json?awesome=true\n- # # => [{:id => 1, :name => 'Ryan'}]\n- #\n- # Note: the objects returned from this method are not automatically converted\n- # into ActiveResource::Base instances - they are ordinary Hashes. If you are expecting\n- # ActiveResource::Base instances, use the <tt>find</tt> class method with the\n- # <tt>:from</tt> option. For example:\n- #\n- # Person.find(:all, :from => :active)\n- def get(custom_method_name, options = {})\n- hashified = format.decode(connection.get(custom_method_collection_url(custom_method_name, options), headers).body)\n- derooted = Formats.remove_root(hashified)\n- derooted.is_a?(Array) ? derooted.map { |e| Formats.remove_root(e) } : derooted\n- end\n-\n- def post(custom_method_name, options = {}, body = '')\n- connection.post(custom_method_collection_url(custom_method_name, options), body, headers)\n- end\n-\n- def patch(custom_method_name, options = {}, body = '')\n- connection.patch(custom_method_collection_url(custom_method_name, options), body, headers)\n- end\n-\n- def put(custom_method_name, options = {}, body = '')\n- connection.put(custom_method_collection_url(custom_method_name, options), body, headers)\n- end\n-\n- def delete(custom_method_name, options = {})\n- # Need to jump through some hoops to retain the original class 'delete' method\n- if custom_method_name.is_a?(Symbol)\n- connection.delete(custom_method_collection_url(custom_method_name, options), headers)\n- else\n- orig_delete(custom_method_name, options)\n- end\n- end\n- end\n- end\n-\n- module ClassMethods\n- def custom_method_collection_url(method_name, options = {})\n- prefix_options, query_options = split_options(options)\n- \"#{prefix(prefix_options)}#{collection_name}/#{method_name}.#{format.extension}#{query_string(query_options)}\"\n- end\n- end\n-\n- def get(method_name, options = {})\n- self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body)\n- end\n-\n- def post(method_name, options = {}, body = nil)\n- request_body = body.blank? ? encode : body\n- if new?\n- connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)\n- else\n- connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers)\n- end\n- end\n-\n- def patch(method_name, options = {}, body = '')\n- connection.patch(custom_method_element_url(method_name, options), body, self.class.headers)\n- end\n-\n- def put(method_name, options = {}, body = '')\n- connection.put(custom_method_element_url(method_name, options), body, self.class.headers)\n- end\n-\n- def delete(method_name, options = {})\n- connection.delete(custom_method_element_url(method_name, options), self.class.headers)\n- end\n-\n-\n- private\n- def custom_method_element_url(method_name, options = {})\n- \"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}\"\n- end\n-\n- def custom_method_new_element_url(method_name, options = {})\n- \"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}\"\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "51bede3bd0f82ff25266c7be99f393c82a869c05",
filename = "activeresource/lib/active_resource/exceptions.rb",
status = "removed", additions = 0L, deletions = 82L, changes = 82L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/exceptions.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/exceptions.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/exceptions.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,82 +0,0 @@\n-module ActiveResource\n- class ConnectionError < StandardError # :nodoc:\n- attr_reader :response\n-\n- def initialize(response, message = nil)\n- @response = response\n- @message = message\n- end\n-\n- def to_s\n- message = \"Failed.\"\n- message << \" Response code = #{response.code}.\" if response.respond_to?(:code)\n- message << \" Response message = #{response.message}.\" if response.respond_to?(:message)\n- message\n- end\n- end\n-\n- # Raised when a Timeout::Error occurs.\n- class TimeoutError < ConnectionError\n- def initialize(message)\n- @message = message\n- end\n- def to_s; @message ;end\n- end\n-\n- # Raised when a OpenSSL::SSL::SSLError occurs.\n- class SSLError < ConnectionError\n- def initialize(message)\n- @message = message\n- end\n- def to_s; @message ;end\n- end\n-\n- # 3xx Redirection\n- class Redirection < ConnectionError # :nodoc:\n- def to_s\n- response['Location'] ? \"#{super} => #{response['Location']}\" : super\n- end\n- end\n-\n- class MissingPrefixParam < ArgumentError # :nodoc:\n- end\n-\n- # 4xx Client Error\n- class ClientError < ConnectionError # :nodoc:\n- end\n-\n- # 400 Bad Request\n- class BadRequest < ClientError # :nodoc:\n- end\n-\n- # 401 Unauthorized\n- class UnauthorizedAccess < ClientError # :nodoc:\n- end\n-\n- # 403 Forbidden\n- class ForbiddenAccess < ClientError # :nodoc:\n- end\n-\n- # 404 Not Found\n- class ResourceNotFound < ClientError # :nodoc:\n- end\n-\n- # 409 Conflict\n- class ResourceConflict < ClientError # :nodoc:\n- end\n-\n- # 410 Gone\n- class ResourceGone < ClientError # :nodoc:\n- end\n-\n- # 5xx Server Error\n- class ServerError < ConnectionError # :nodoc:\n- end\n-\n- # 405 Method Not Allowed\n- class MethodNotAllowed < ClientError # :nodoc:\n- def allowed_methods\n- @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "f7ad689cc5504e6192ab0a6db0a0aaeb8051c64f",
filename = "activeresource/lib/active_resource/formats.rb",
status = "removed", additions = 0L, deletions = 22L, changes = 22L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/formats.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,22 +0,0 @@\n-module ActiveResource\n- module Formats\n- autoload :XmlFormat, 'active_resource/formats/xml_format'\n- autoload :JsonFormat, 'active_resource/formats/json_format'\n-\n- # Lookup the format class from a mime type reference symbol. Example:\n- #\n- # ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat\n- # ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat\n- def self.[](mime_type_reference)\n- ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + \"Format\")\n- end\n-\n- def self.remove_root(data)\n- if data.is_a?(Hash) && data.keys.size == 1\n- data.values.first\n- else\n- data\n- end\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "827d1cc23a6a32cc780db5dbed3d32ec9cb58728",
filename = "activeresource/lib/active_resource/formats/json_format.rb",
status = "removed", additions = 0L, deletions = 25L, changes = 25L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats/json_format.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats/json_format.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/formats/json_format.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,25 +0,0 @@\n-require 'active_support/json'\n-\n-module ActiveResource\n- module Formats\n- module JsonFormat\n- extend self\n-\n- def extension\n- \"json\"\n- end\n-\n- def mime_type\n- \"application/json\"\n- end\n-\n- def encode(hash, options = nil)\n- ActiveSupport::JSON.encode(hash, options)\n- end\n-\n- def decode(json)\n- Formats.remove_root(ActiveSupport::JSON.decode(json))\n- end\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "49cb9aa1ac87720fcf223efe74c59b01a1aeb985",
filename = "activeresource/lib/active_resource/formats/xml_format.rb",
status = "removed", additions = 0L, deletions = 25L, changes = 25L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats/xml_format.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/formats/xml_format.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/formats/xml_format.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,25 +0,0 @@\n-require 'active_support/core_ext/hash/conversions'\n-\n-module ActiveResource\n- module Formats\n- module XmlFormat\n- extend self\n-\n- def extension\n- \"xml\"\n- end\n-\n- def mime_type\n- \"application/xml\"\n- end\n-\n- def encode(hash, options={})\n- hash.to_xml(options)\n- end\n-\n- def decode(xml)\n- Formats.remove_root(Hash.from_xml(xml))\n- end\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "9856f5872feb1248b87630ecb6968aef010b7dc0",
filename = "activeresource/lib/active_resource/http_mock.rb",
status = "removed", additions = 0L, deletions = 332L, changes = 332L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/http_mock.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/http_mock.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/http_mock.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,332 +0,0 @@\n-require 'active_support/core_ext/kernel/reporting'\n-require 'active_support/core_ext/object/inclusion'\n-\n-module ActiveResource\n- class InvalidRequestError < StandardError; end #:nodoc:\n-\n- # One thing that has always been a pain with remote web services is testing. The HttpMock\n- # class makes it easy to test your Active Resource models by creating a set of mock responses to specific\n- # requests.\n- #\n- # To test your Active Resource model, you simply call the ActiveResource::HttpMock.respond_to\n- # method with an attached block. The block declares a set of URIs with expected input, and the output\n- # each request should return. The passed in block has any number of entries in the following generalized\n- # format:\n- #\n- # mock.http_method(path, request_headers = {}, body = nil, status = 200, response_headers = {})\n- #\n- # * <tt>http_method</tt> - The HTTP method to listen for. This can be +get+, +post+, +patch+, +put+, +delete+ or\n- # +head+.\n- # * <tt>path</tt> - A string, starting with a \"/\", defining the URI that is expected to be\n- # called.\n- # * <tt>request_headers</tt> - Headers that are expected along with the request. This argument uses a\n- # hash format, such as <tt>{ \"Content-Type\" => \"application/json\" }</tt>. This mock will only trigger\n- # if your tests sends a request with identical headers.\n- # * <tt>body</tt> - The data to be returned. This should be a string of Active Resource parseable content,\n- # such as Json.\n- # * <tt>status</tt> - The HTTP response code, as an integer, to return with the response.\n- # * <tt>response_headers</tt> - Headers to be returned with the response. Uses the same hash format as\n- # <tt>request_headers</tt> listed above.\n- #\n- # In order for a mock to deliver its content, the incoming request must match by the <tt>http_method</tt>,\n- # +path+ and <tt>request_headers</tt>. If no match is found an +InvalidRequestError+ exception\n- # will be raised showing you what request it could not find a response for and also what requests and response\n- # pairs have been recorded so you can create a new mock for that request.\n- #\n- # ==== Example\n- # def setup\n- # @matz = { :person => { :id => 1, :name => \"Matz\" } }.to_json\n- # ActiveResource::HttpMock.respond_to do |mock|\n- # mock.post \"/people.json\", {}, @matz, 201, \"Location\" => \"/people/1.json\"\n- # mock.get \"/people/1.json\", {}, @matz\n- # mock.put \"/people/1.json\", {}, nil, 204\n- # mock.delete \"/people/1.json\", {}, nil, 200\n- # end\n- # end\n- #\n- # def test_get_matz\n- # person = Person.find(1)\n- # assert_equal \"Matz\", person.name\n- # end\n- #\n- class HttpMock\n- class Responder #:nodoc:\n- def initialize(responses)\n- @responses = responses\n- end\n-\n- [ :post, :patch, :put, :get, :delete, :head ].each do |method|\n- # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})\n- # @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || \"\", status, response_headers)\n- # end\n- module_eval <<-EOE, __FILE__, __LINE__ + 1\n- def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})\n- request = Request.new(:#{method}, path, nil, request_headers)\n- response = Response.new(body || \"\", status, response_headers)\n-\n- delete_duplicate_responses(request)\n-\n- @responses << [request, response]\n- end\n- EOE\n- end\n-\n- private\n-\n- def delete_duplicate_responses(request)\n- @responses.delete_if {|r| r[0] == request }\n- end\n- end\n-\n- class << self\n-\n- # Returns an array of all request objects that have been sent to the mock. You can use this to check\n- # if your model actually sent an HTTP request.\n- #\n- # ==== Example\n- # def setup\n- # @matz = { :person => { :id => 1, :name => \"Matz\" } }.to_json\n- # ActiveResource::HttpMock.respond_to do |mock|\n- # mock.get \"/people/1.json\", {}, @matz\n- # end\n- # end\n- #\n- # def test_should_request_remote_service\n- # person = Person.find(1) # Call the remote service\n- #\n- # # This request object has the same HTTP method and path as declared by the mock\n- # expected_request = ActiveResource::Request.new(:get, \"/people/1.json\")\n- #\n- # # Assert that the mock received, and responded to, the expected request from the model\n- # assert ActiveResource::HttpMock.requests.include?(expected_request)\n- # end\n- def requests\n- @@requests ||= []\n- end\n-\n- # Returns the list of requests and their mocked responses. Look up a\n- # response for a request using <tt>responses.assoc(request)</tt>.\n- def responses\n- @@responses ||= []\n- end\n-\n- # Accepts a block which declares a set of requests and responses for the HttpMock to respond to in\n- # the following format:\n- #\n- # mock.http_method(path, request_headers = {}, body = nil, status = 200, response_headers = {})\n- #\n- # === Example\n- #\n- # @matz = { :person => { :id => 1, :name => \"Matz\" } }.to_json\n- # ActiveResource::HttpMock.respond_to do |mock|\n- # mock.post \"/people.json\", {}, @matz, 201, \"Location\" => \"/people/1.json\"\n- # mock.get \"/people/1.json\", {}, @matz\n- # mock.put \"/people/1.json\", {}, nil, 204\n- # mock.delete \"/people/1.json\", {}, nil, 200\n- # end\n- #\n- # Alternatively, accepts a hash of <tt>{Request => Response}</tt> pairs allowing you to generate\n- # these the following format:\n- #\n- # ActiveResource::Request.new(method, path, body, request_headers)\n- # ActiveResource::Response.new(body, status, response_headers)\n- #\n- # === Example\n- #\n- # Request.new(:#{method}, path, nil, request_headers)\n- #\n- # @matz = { :person => { :id => 1, :name => \"Matz\" } }.to_json\n- #\n- # create_matz = ActiveResource::Request.new(:post, '/people.json', @matz, {})\n- # created_response = ActiveResource::Response.new(\"\", 201, {\"Location\" => \"/people/1.json\"})\n- # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)\n- # ok_response = ActiveResource::Response.new(\"\", 200, {})\n- #\n- # pairs = {create_matz => created_response, get_matz => ok_response}\n- #\n- # ActiveResource::HttpMock.respond_to(pairs)\n- #\n- # Note, by default, every time you call +respond_to+, any previous request and response pairs stored\n- # in HttpMock will be deleted giving you a clean slate to work on.\n- #\n- # If you want to override this behavior, pass in +false+ as the last argument to +respond_to+\n- #\n- # === Example\n- #\n- # ActiveResource::HttpMock.respond_to do |mock|\n- # mock.send(:get, \"/people/1\", {}, \"JSON1\")\n- # end\n- # ActiveResource::HttpMock.responses.length #=> 1\n- #\n- # ActiveResource::HttpMock.respond_to(false) do |mock|\n- # mock.send(:get, \"/people/2\", {}, \"JSON2\")\n- # end\n- # ActiveResource::HttpMock.responses.length #=> 2\n- #\n- # This also works with passing in generated pairs of requests and responses, again, just pass in false\n- # as the last argument:\n- #\n- # === Example\n- #\n- # ActiveResource::HttpMock.respond_to do |mock|\n- # mock.send(:get, \"/people/1\", {}, \"JSON1\")\n- # end\n- # ActiveResource::HttpMock.responses.length #=> 1\n- #\n- # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)\n- # ok_response = ActiveResource::Response.new(\"\", 200, {})\n- #\n- # pairs = {get_matz => ok_response}\n- #\n- # ActiveResource::HttpMock.respond_to(pairs, false)\n- # ActiveResource::HttpMock.responses.length #=> 2\n- #\n- # # If you add a response with an existing request, it will be replaced\n- #\n- # fail_response = ActiveResource::Response.new(\"\", 404, {})\n- # pairs = {get_matz => fail_response}\n- #\n- # ActiveResource::HttpMock.respond_to(pairs, false)\n- # ActiveResource::HttpMock.responses.length #=> 2\n- #\n- def respond_to(*args) #:yields: mock\n- pairs = args.first || {}\n- reset! if args.last.class != FalseClass\n-\n- if block_given?\n- yield Responder.new(responses)\n- else\n- delete_responses_to_replace pairs.to_a\n- responses.concat pairs.to_a\n- Responder.new(responses)\n- end\n- end\n-\n- def delete_responses_to_replace(new_responses)\n- new_responses.each{|nr|\n- request_to_remove = nr[0]\n- @@responses = responses.delete_if{|r| r[0] == request_to_remove}\n- }\n- end\n-\n- # Deletes all logged requests and responses.\n- def reset!\n- requests.clear\n- responses.clear\n- end\n- end\n-\n- # body? methods\n- { true => %w(post patch put),\n- false => %w(get delete head) }.each do |has_body, methods|\n- methods.each do |method|\n- # def post(path, body, headers)\n- # request = ActiveResource::Request.new(:post, path, body, headers)\n- # self.class.requests << request\n- # if response = self.class.responses.assoc(request)\n- # response[1]\n- # else\n- # raise InvalidRequestError.new(\"Could not find a response recorded for #{request.to_s} - Responses recorded are: - #{inspect_responses}\")\n- # end\n- # end\n- module_eval <<-EOE, __FILE__, __LINE__ + 1\n- def #{method}(path, #{'body, ' if has_body}headers)\n- request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers)\n- self.class.requests << request\n- if response = self.class.responses.assoc(request)\n- response[1]\n- else\n- raise InvalidRequestError.new(\"Could not find a response recorded for \\#{request.to_s} - Responses recorded are: \\#{inspect_responses}\")\n- end\n- end\n- EOE\n- end\n- end\n-\n- def initialize(site) #:nodoc:\n- @site = site\n- end\n-\n- def inspect_responses #:nodoc:\n- self.class.responses.map { |r| r[0].to_s }.inspect\n- end\n- end\n-\n- class Request\n- attr_accessor :path, :method, :body, :headers\n-\n- def initialize(method, path, body = nil, headers = {})\n- @method, @path, @body, @headers = method, path, body, headers\n- end\n-\n- def ==(req)\n- path == req.path && method == req.method && headers_match?(req)\n- end\n-\n- def to_s\n- \"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>\"\n- end\n-\n- private\n-\n- def headers_match?(req)\n- # Ignore format header on equality if it's not defined\n- format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]\n- if headers[format_header].present? || req.headers[format_header].blank?\n- headers == req.headers\n- else\n- headers.dup.merge(format_header => req.headers[format_header]) == req.headers\n- end\n- end\n- end\n-\n- class Response\n- attr_accessor :body, :message, :code, :headers\n-\n- def initialize(body, message = 200, headers = {})\n- @body, @message, @headers = body, message.to_s, headers\n- @code = @message[0,3].to_i\n-\n- resp_cls = Net::HTTPResponse::CODE_TO_OBJ[@code.to_s]\n- if resp_cls && !resp_cls.body_permitted?\n- @body = nil\n- end\n-\n- self['Content-Length'] = @body.nil? ? \"0\" : body.size.to_s\n-\n- end\n-\n- # Returns true if code is 2xx,\n- # false otherwise.\n- def success?\n- code.in?(200..299)\n- end\n-\n- def [](key)\n- headers[key]\n- end\n-\n- def []=(key, value)\n- headers[key] = value\n- end\n-\n- # Returns true if the other is a Response with an equal body, equal message\n- # and equal headers. Otherwise it returns false.\n- def ==(other)\n- if (other.is_a?(Response))\n- other.body == body && other.message == message && other.headers == headers\n- else\n- false\n- end\n- end\n- end\n-\n- class Connection\n- private\n- silence_warnings do\n- def http\n- @http ||= HttpMock.new(@site)\n- end\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "9e52baf36d55207f4387cca0e3face5200b51775",
filename = "activeresource/lib/active_resource/log_subscriber.rb",
status = "removed", additions = 0L, deletions = 15L, changes = 15L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/log_subscriber.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/log_subscriber.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/log_subscriber.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,15 +0,0 @@\n-module ActiveResource\n- class LogSubscriber < ActiveSupport::LogSubscriber\n- def request(event)\n- result = event.payload[:result]\n- info \"#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}\"\n- info \"--> %d %s %d (%.1fms)\" % [result.code, result.message, result.body.to_s.length, event.duration]\n- end\n-\n- def logger\n- ActiveResource::Base.logger\n- end\n- end\n-end\n-\n-ActiveResource::LogSubscriber.attach_to :active_resource\n\\ No newline at end of file"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "1bfceb8dc84b01af4d24b12e94581304aca247d0",
filename = "activeresource/lib/active_resource/observing.rb",
status = "removed", additions = 0L, deletions = 29L, changes = 29L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/observing.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/observing.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/observing.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,29 +0,0 @@\n-module ActiveResource\n- module Observing\n- extend ActiveSupport::Concern\n- include ActiveModel::Observing\n-\n- included do\n- %w( create save update destroy ).each do |method|\n- # def create_with_notifications(*args, &block)\n- # notify_observers(:before_create)\n- # if result = create_without_notifications(*args, &block)\n- # notify_observers(:after_create)\n- # end\n- # result\n- # end\n- # alias_method_chain(create, :notifications)\n- class_eval(<<-EOS, __FILE__, __LINE__ + 1)\n- def #{method}_with_notifications(*args, &block)\n- notify_observers(:before_#{method})\n- if result = #{method}_without_notifications(*args, &block)\n- notify_observers(:after_#{method})\n- end\n- result\n- end\n- EOS\n- alias_method_chain(method, :notifications)\n- end\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "60f6f88311c63023c7eb086606caca3a890a2d29",
filename = "activeresource/lib/active_resource/railtie.rb",
status = "removed", additions = 0L, deletions = 14L, changes = 14L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/railtie.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/railtie.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/railtie.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,14 +0,0 @@\n-require \"active_resource\"\n-require \"rails\"\n-\n-module ActiveResource\n- class Railtie < Rails::Railtie\n- config.active_resource = ActiveSupport::OrderedOptions.new\n-\n- initializer \"active_resource.set_configs\" do |app|\n- app.config.active_resource.each do |k,v|\n- ActiveResource::Base.send \"#{k}=\", v\n- end\n- end\n- end\n-end\n\\ No newline at end of file"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "5957969aa27724ef04fb8475ce27e3d3d1958eb9",
filename = "activeresource/lib/active_resource/schema.rb",
status = "removed", additions = 0L, deletions = 59L, changes = 59L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/schema.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/schema.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/schema.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,59 +0,0 @@\n-require 'active_resource/exceptions'\n-\n-module ActiveResource # :nodoc:\n- class Schema # :nodoc:\n- # attributes can be known to be one of these types. They are easy to\n- # cast to/from.\n- KNOWN_ATTRIBUTE_TYPES = %w( string text integer float decimal datetime timestamp time date binary boolean )\n-\n- # An array of attribute definitions, representing the attributes that\n- # have been defined.\n- attr_accessor :attrs\n-\n- # The internals of an Active Resource Schema are very simple -\n- # unlike an Active Record TableDefinition (on which it is based).\n- # It provides a set of convenience methods for people to define their\n- # schema using the syntax:\n- # schema do\n- # string :foo\n- # integer :bar\n- # end\n- #\n- # The schema stores the name and type of each attribute. That is then\n- # read out by the schema method to populate the schema of the actual\n- # resource.\n- def initialize\n- @attrs = {}\n- end\n-\n- def attribute(name, type, options = {})\n- raise ArgumentError, \"Unknown Attribute type: #{type.inspect} for key: #{name.inspect}\" unless type.nil? || Schema::KNOWN_ATTRIBUTE_TYPES.include?(type.to_s)\n-\n- the_type = type.to_s\n- # TODO: add defaults\n- #the_attr = [type.to_s]\n- #the_attr << options[:default] if options.has_key? :default\n- @attrs[name.to_s] = the_type\n- self\n- end\n-\n- # The following are the attribute types supported by Active Resource\n- # migrations.\n- KNOWN_ATTRIBUTE_TYPES.each do |attr_type|\n- # def string(*args)\n- # options = args.extract_options!\n- # attr_names = args\n- #\n- # attr_names.each { |name| attribute(name, 'string', options) }\n- # end\n- class_eval <<-EOV, __FILE__, __LINE__ + 1\n- def #{attr_type.to_s}(*args)\n- options = args.extract_options!\n- attr_names = args\n-\n- attr_names.each { |name| attribute(name, '#{attr_type}', options) }\n- end\n- EOV\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "028acb8bceaf8de87dcf84b9dbb579870c201915",
filename = "activeresource/lib/active_resource/validations.rb",
status = "removed", additions = 0L, deletions = 172L, changes = 172L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/validations.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/validations.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/validations.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,172 +0,0 @@\n-require 'active_support/core_ext/array/wrap'\n-require 'active_support/core_ext/object/blank'\n-\n-module ActiveResource\n- class ResourceInvalid < ClientError #:nodoc:\n- end\n-\n- # Active Resource validation is reported to and from this object, which is used by Base#save\n- # to determine whether the object in a valid state to be saved. See usage example in Validations.\n- class Errors < ActiveModel::Errors\n- # Grabs errors from an array of messages (like ActiveRecord::Validations).\n- # The second parameter directs the errors cache to be cleared (default)\n- # or not (by passing true).\n- def from_array(messages, save_cache = false)\n- clear unless save_cache\n- humanized_attributes = Hash[@base.attributes.keys.map { |attr_name| [attr_name.humanize, attr_name] }]\n- messages.each do |message|\n- attr_message = humanized_attributes.keys.detect do |attr_name|\n- if message[0, attr_name.size + 1] == \"#{attr_name} \"\n- add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]\n- end\n- end\n-\n- self[:base] << message if attr_message.nil?\n- end\n- end\n-\n- # Grabs errors from a hash of attribute => array of errors elements\n- # The second parameter directs the errors cache to be cleared (default)\n- # or not (by passing true)\n- #\n- # Unrecognized attribute names will be humanized and added to the record's\n- # base errors.\n- def from_hash(messages, save_cache = false)\n- clear unless save_cache\n-\n- messages.each do |(key,errors)|\n- errors.each do |error|\n- if @base.attributes.keys.include?(key)\n- add key, error\n- elsif key == 'base'\n- self[:base] << error\n- else\n- # reporting an error on an attribute not in attributes\n- # format and add them to base\n- self[:base] << \"#{key.humanize} #{error}\"\n- end\n- end\n- end\n- end\n-\n- # Grabs errors from a json response.\n- def from_json(json, save_cache = false)\n- decoded = ActiveSupport::JSON.decode(json) || {} rescue {}\n- if decoded.kind_of?(Hash) && (decoded.has_key?('errors') || decoded.empty?)\n- errors = decoded['errors'] || {}\n- if errors.kind_of?(Array)\n- # 3.2.1-style with array of strings\n- ActiveSupport::Deprecation.warn('Returning errors as an array of strings is deprecated.')\n- from_array errors, save_cache\n- else\n- # 3.2.2+ style\n- from_hash errors, save_cache\n- end\n- else\n- # <3.2-style respond_with - lacks 'errors' key\n- ActiveSupport::Deprecation.warn('Returning errors as a hash without a root \"errors\" key is deprecated.')\n- from_hash decoded, save_cache\n- end\n- end\n-\n- # Grabs errors from an XML response.\n- def from_xml(xml, save_cache = false)\n- array = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue []\n- from_array array, save_cache\n- end\n- end\n-\n- # Module to support validation and errors with Active Resource objects. The module overrides\n- # Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned\n- # in the web service response. The module also adds an +errors+ collection that mimics the interface\n- # of the errors provided by ActiveModel::Errors.\n- #\n- # ==== Example\n- #\n- # Consider a Person resource on the server requiring both a +first_name+ and a +last_name+ with a\n- # <tt>validates_presence_of :first_name, :last_name</tt> declaration in the model:\n- #\n- # person = Person.new(:first_name => \"Jim\", :last_name => \"\")\n- # person.save # => false (server returns an HTTP 422 status code and errors)\n- # person.valid? # => false\n- # person.errors.empty? # => false\n- # person.errors.count # => 1\n- # person.errors.full_messages # => [\"Last name can't be empty\"]\n- # person.errors[:last_name] # => [\"can't be empty\"]\n- # person.last_name = \"Halpert\"\n- # person.save # => true (and person is now saved to the remote service)\n- #\n- module Validations\n- extend ActiveSupport::Concern\n- include ActiveModel::Validations\n-\n- included do\n- alias_method_chain :save, :validation\n- end\n-\n- # Validate a resource and save (POST) it to the remote web service.\n- # If any local validations fail - the save (POST) will not be attempted.\n- def save_with_validation(options={})\n- perform_validation = options[:validate] != false\n-\n- # clear the remote validations so they don't interfere with the local\n- # ones. Otherwise we get an endless loop and can never change the\n- # fields so as to make the resource valid.\n- @remote_errors = nil\n- if perform_validation && valid? || !perform_validation\n- save_without_validation\n- true\n- else\n- false\n- end\n- rescue ResourceInvalid => error\n- # cache the remote errors because every call to <tt>valid?</tt> clears\n- # all errors. We must keep a copy to add these back after local\n- # validations.\n- @remote_errors = error\n- load_remote_errors(@remote_errors, true)\n- false\n- end\n-\n-\n- # Loads the set of remote errors into the object's Errors based on the\n- # content-type of the error-block received.\n- def load_remote_errors(remote_errors, save_cache = false ) #:nodoc:\n- case self.class.format\n- when ActiveResource::Formats[:xml]\n- errors.from_xml(remote_errors.response.body, save_cache)\n- when ActiveResource::Formats[:json]\n- errors.from_json(remote_errors.response.body, save_cache)\n- end\n- end\n-\n- # Checks for errors on an object (i.e., is resource.errors empty?).\n- #\n- # Runs all the specified local validations and returns true if no errors\n- # were added, otherwise false.\n- # Runs local validations (eg those on your Active Resource model), and\n- # also any errors returned from the remote system the last time we\n- # saved.\n- # Remote errors can only be cleared by trying to re-save the resource.\n- #\n- # ==== Examples\n- # my_person = Person.create(params[:person])\n- # my_person.valid?\n- # # => true\n- #\n- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''\n- # my_person.valid?\n- # # => false\n- #\n- def valid?\n- super\n- load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?\n- errors.empty?\n- end\n-\n- # Returns the Errors object that holds all information about attribute error messages.\n- def errors\n- @errors ||= Errors.new(self)\n- end\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "d02784bd5dfb8528b6adfc4913c3d878f8374c54",
filename = "activeresource/lib/active_resource/version.rb",
status = "removed", additions = 0L, deletions = 10L, changes = 10L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/version.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/lib/active_resource/version.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/lib/active_resource/version.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,10 +0,0 @@\n-module ActiveResource\n- module VERSION #:nodoc:\n- MAJOR = 4\n- MINOR = 0\n- TINY = 0\n- PRE = \"beta\"\n-\n- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "c68625df4f968c3270e716c7225f540d8c0d8891",
filename = "activeresource/test/abstract_unit.rb", status = "removed",
additions = 0L, deletions = 143L, changes = 143L, blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/abstract_unit.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/abstract_unit.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/test/abstract_unit.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,143 +0,0 @@\n-require File.expand_path('../../../load_paths', __FILE__)\n-\n-lib = File.expand_path(\"#{File.dirname(__FILE__)}/../lib\")\n-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)\n-\n-require 'minitest/autorun'\n-require 'active_resource'\n-require 'active_support'\n-require 'active_support/test_case'\n-require 'setter_trap'\n-require 'active_support/logger'\n-\n-ActiveResource::Base.logger = ActiveSupport::Logger.new(\"#{File.dirname(__FILE__)}/debug.log\")\n-\n-def setup_response\n- matz_hash = { 'person' => { :id => 1, :name => 'Matz' } }\n-\n- @default_request_headers = { 'Content-Type' => 'application/json' }\n- @matz = matz_hash.to_json\n- @matz_xml = matz_hash.to_xml\n- @david = { :person => { :id => 2, :name => 'David' } }.to_json\n- @greg = { :person => { :id => 3, :name => 'Greg' } }.to_json\n- @addy = { :address => { :id => 1, :street => '12345 Street', :country => 'Australia' } }.to_json\n- @rick = { :person => { :name => \"Rick\", :age => 25 } }.to_json\n- @joe = { :person => { :id => 6, :name => 'Joe', :likes_hats => true }}.to_json\n- @people = { :people => [ { :person => { :id => 1, :name => 'Matz' } }, { :person => { :id => 2, :name => 'David' } }] }.to_json\n- @people_david = { :people => [ { :person => { :id => 2, :name => 'David' } }] }.to_json\n- @addresses = { :addresses => [{ :address => { :id => 1, :street => '12345 Street', :country => 'Australia' } }] }.to_json\n-\n- # - deep nested resource -\n- # - Luis (Customer)\n- # - JK (Customer::Friend)\n- # - Mateo (Customer::Friend::Brother)\n- # - Edith (Customer::Friend::Brother::Child)\n- # - Martha (Customer::Friend::Brother::Child)\n- # - Felipe (Customer::Friend::Brother)\n- # - Bryan (Customer::Friend::Brother::Child)\n- # - Luke (Customer::Friend::Brother::Child)\n- # - Eduardo (Customer::Friend)\n- # - Sebas (Customer::Friend::Brother)\n- # - Andres (Customer::Friend::Brother::Child)\n- # - Jorge (Customer::Friend::Brother::Child)\n- # - Elsa (Customer::Friend::Brother)\n- # - Natacha (Customer::Friend::Brother::Child)\n- # - Milena (Customer::Friend::Brother)\n- #\n- @luis = {\n- :customer => {\n- :id => 1,\n- :name => 'Luis',\n- :friends => [{\n- :name => 'JK',\n- :brothers => [\n- {\n- :name => 'Mateo',\n- :children => [{ :name => 'Edith' },{ :name => 'Martha' }]\n- }, {\n- :name => 'Felipe',\n- :children => [{ :name => 'Bryan' },{ :name => 'Luke' }]\n- }\n- ]\n- }, {\n- :name => 'Eduardo',\n- :brothers => [\n- {\n- :name => 'Sebas',\n- :children => [{ :name => 'Andres' },{ :name => 'Jorge' }]\n- }, {\n- :name => 'Elsa',\n- :children => [{ :name => 'Natacha' }]\n- }, {\n- :name => 'Milena',\n- :children => []\n- }\n- ]\n- }]\n- }\n- }.to_json\n- # - resource with yaml array of strings; for ARs using serialize :bar, Array\n- @marty = <<-eof.strip\n- <?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\n- <person>\n- <id type=\\\"integer\\\">5</id>\n- <name>Marty</name>\n- <colors type=\\\"yaml\\\">---\n- - \\\"red\\\"\n- - \\\"green\\\"\n- - \\\"blue\\\"\n- </colors>\n- </person>\n- eof\n-\n- @startup_sound = {\n- :sound => {\n- :name => \"Mac Startup Sound\", :author => { :name => \"Jim Reekes\" }\n- }\n- }.to_json\n-\n- ActiveResource::HttpMock.respond_to do |mock|\n- mock.get \"/people/1.json\", {}, @matz\n- mock.get \"/people/1.xml\", {}, @matz_xml\n- mock.get \"/people/2.xml\", {}, @david\n- mock.get \"/people/5.xml\", {}, @marty\n- mock.get \"/people/Greg.json\", {}, @greg\n- mock.get \"/people/6.json\", {}, @joe\n- mock.get \"/people/4.json\", { 'key' => 'value' }, nil, 404\n- mock.put \"/people/1.json\", {}, nil, 204\n- mock.delete \"/people/1.json\", {}, nil, 200\n- mock.delete \"/people/2.xml\", {}, nil, 400\n- mock.get \"/people/99.json\", {}, nil, 404\n- mock.post \"/people.json\", {}, @rick, 201, 'Location' => '/people/5.xml'\n- mock.get \"/people.json\", {}, @people\n- mock.get \"/people/1/addresses.json\", {}, @addresses\n- mock.get \"/people/1/addresses/1.json\", {}, @addy\n- mock.get \"/people/1/addresses/2.xml\", {}, nil, 404\n- mock.get \"/people/2/addresses.json\", {}, nil, 404\n- mock.get \"/people/2/addresses/1.xml\", {}, nil, 404\n- mock.get \"/people/Greg/addresses/1.json\", {}, @addy\n- mock.put \"/people/1/addresses/1.json\", {}, nil, 204\n- mock.delete \"/people/1/addresses/1.json\", {}, nil, 200\n- mock.post \"/people/1/addresses.json\", {}, nil, 201, 'Location' => '/people/1/addresses/5'\n- mock.get \"/people/1/addresses/99.json\", {}, nil, 404\n- mock.get \"/people//addresses.xml\", {}, nil, 404\n- mock.get \"/people//addresses/1.xml\", {}, nil, 404\n- mock.put \"/people//addresses/1.xml\", {}, nil, 404\n- mock.delete \"/people//addresses/1.xml\", {}, nil, 404\n- mock.post \"/people//addresses.xml\", {}, nil, 404\n- mock.head \"/people/1.json\", {}, nil, 200\n- mock.head \"/people/Greg.json\", {}, nil, 200\n- mock.head \"/people/99.json\", {}, nil, 404\n- mock.head \"/people/1/addresses/1.json\", {}, nil, 200\n- mock.head \"/people/1/addresses/2.json\", {}, nil, 404\n- mock.head \"/people/2/addresses/1.json\", {}, nil, 404\n- mock.head \"/people/Greg/addresses/1.json\", {}, nil, 200\n- # customer\n- mock.get \"/customers/1.json\", {}, @luis\n- # sound\n- mock.get \"/sounds/1.json\", {}, @startup_sound\n- end\n-\n- Person.user = nil\n- Person.password = nil\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "fbfe086599777a5b18f0bf6cfc2ae555135abf43",
filename = "activeresource/test/cases/authorization_test.rb",
status = "removed", additions = 0L, deletions = 251L, changes = 251L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/authorization_test.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/authorization_test.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/test/cases/authorization_test.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,251 +0,0 @@\n-require 'abstract_unit'\n-\n-class AuthorizationTest < ActiveSupport::TestCase\n- Response = Struct.new(:code)\n-\n- def setup\n- @conn = ActiveResource::Connection.new('http://localhost')\n- @matz = { :person => { :id => 1, :name => 'Matz' } }.to_json\n- @david = { :person => { :id => 2, :name => 'David' } }.to_json\n- @authenticated_conn = ActiveResource::Connection.new(\"http://david:test123@localhost\")\n- @basic_authorization_request_header = { 'Authorization' => 'Basic ZGF2aWQ6dGVzdDEyMw==' }\n- end\n-\n- private\n- def decode(response)\n- @authenticated_conn.format.decode(response.body)\n- end\n-end\n-\n-class BasicAuthorizationTest < AuthorizationTest\n- def setup\n- super\n- @authenticated_conn.auth_type = :basic\n-\n- ActiveResource::HttpMock.respond_to do |mock|\n- mock.get \"/people/2.json\", @basic_authorization_request_header, @david\n- mock.get \"/people/1.json\", @basic_authorization_request_header, nil, 401, { 'WWW-Authenticate' => 'i_should_be_ignored' }\n- mock.put \"/people/2.json\", @basic_authorization_request_header, nil, 204\n- mock.delete \"/people/2.json\", @basic_authorization_request_header, nil, 200\n- mock.post \"/people/2/addresses.json\", @basic_authorization_request_header, nil, 201, 'Location' => '/people/1/addresses/5'\n- mock.head \"/people/2.json\", @basic_authorization_request_header, nil, 200\n- end\n- end\n-\n- def test_get\n- david = decode(@authenticated_conn.get(\"/people/2.json\"))\n- assert_equal \"David\", david[\"name\"]\n- end\n-\n- def test_post\n- response = @authenticated_conn.post(\"/people/2/addresses.json\")\n- assert_equal \"/people/1/addresses/5\", response[\"Location\"]\n- end\n-\n- def test_put\n- response = @authenticated_conn.put(\"/people/2.json\")\n- assert_equal 204, response.code\n- end\n-\n- def test_delete\n- response = @authenticated_conn.delete(\"/people/2.json\")\n- assert_equal 200, response.code\n- end\n-\n- def test_head\n- response = @authenticated_conn.head(\"/people/2.json\")\n- assert_equal 200, response.code\n- end\n-\n- def test_retry_on_401_doesnt_happen_with_basic_auth\n- assert_raise(ActiveResource::UnauthorizedAccess) { @authenticated_conn.get(\"/people/1.json\") }\n- assert_equal \"\", @authenticated_conn.send(:response_auth_header)\n- end\n-\n- def test_raises_invalid_request_on_unauthorized_requests\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.get(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.post(\"/people/2/addresses.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.put(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.delete(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.head(\"/people/2.json\") }\n- end\n-\n-\n- def test_authorization_header\n- authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization']\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"david\", \"test123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_with_username_but_no_password\n- @conn = ActiveResource::Connection.new(\"http://david:@localhost\")\n- authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"david\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_with_password_but_no_username\n- @conn = ActiveResource::Connection.new(\"http://:test123@localhost\")\n- authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"\", \"test123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_with_decoded_credentials_from_url\n- @conn = ActiveResource::Connection.new(\"http://my%40email.com:%31%32%33@localhost\")\n- authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"my@email.com\", \"123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_explicitly_setting_username_and_password\n- @authenticated_conn = ActiveResource::Connection.new(\"http://@localhost\")\n- @authenticated_conn.user = 'david'\n- @authenticated_conn.password = 'test123'\n- authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization']\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"david\", \"test123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_explicitly_setting_username_but_no_password\n- @conn = ActiveResource::Connection.new(\"http://@localhost\")\n- @conn.user = \"david\"\n- authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"david\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_explicitly_setting_password_but_no_username\n- @conn = ActiveResource::Connection.new(\"http://@localhost\")\n- @conn.password = \"test123\"\n- authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"\", \"test123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_authorization_header_if_credentials_supplied_and_auth_type_is_basic\n- authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization']\n- authorization = authorization_header[\"Authorization\"].to_s.split\n-\n- assert_equal \"Basic\", authorization[0]\n- assert_equal [\"david\", \"test123\"], ::Base64.decode64(authorization[1]).split(\":\")[0..1]\n- end\n-\n- def test_client_nonce_is_not_nil\n- assert_not_nil ActiveResource::Connection.new(\"http://david:test123@localhost\").send(:client_nonce)\n- end\n-end\n-\n-class DigestAuthorizationTest < AuthorizationTest\n- def setup\n- super\n- @authenticated_conn.auth_type = :digest\n-\n- # Make client nonce deterministic\n- def @authenticated_conn.client_nonce; 'i-am-a-client-nonce' end\n-\n- @nonce = \"MTI0OTUxMzc4NzpjYWI3NDM3NDNmY2JmODU4ZjQ2ZjcwNGZkMTJiMjE0NA==\"\n-\n- ActiveResource::HttpMock.respond_to do |mock|\n- mock.get \"/people/2.json\", { 'Authorization' => blank_digest_auth_header(\"/people/2.json\", \"fad396f6a34aeba28e28b9b96ddbb671\") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header }\n- mock.get \"/people/2.json\", { 'Authorization' => request_digest_auth_header(\"/people/2.json\", \"c064d5ba8891a25290c76c8c7d31fb7b\") }, @david, 200\n- mock.get \"/people/1.json\", { 'Authorization' => request_digest_auth_header(\"/people/1.json\", \"f9c0b594257bb8422af4abd429c5bb70\") }, @matz, 200\n-\n- mock.put \"/people/2.json\", { 'Authorization' => blank_digest_auth_header(\"/people/2.json\", \"50a685d814f94665b9d160fbbaa3958a\") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header }\n- mock.put \"/people/2.json\", { 'Authorization' => request_digest_auth_header(\"/people/2.json\", \"5a75cde841122d8e0f20f8fd1f98a743\") }, nil, 204\n-\n- mock.delete \"/people/2.json\", { 'Authorization' => blank_digest_auth_header(\"/people/2.json\", \"846f799107eab5ca4285b909ee299a33\") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header }\n- mock.delete \"/people/2.json\", { 'Authorization' => request_digest_auth_header(\"/people/2.json\", \"9f5b155224edbbb69fd99d8ce094681e\") }, nil, 200\n-\n- mock.post \"/people/2/addresses.json\", { 'Authorization' => blank_digest_auth_header(\"/people/2/addresses.json\", \"6984d405ff3d9ed07bbf747dcf16afb0\") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header }\n- mock.post \"/people/2/addresses.json\", { 'Authorization' => request_digest_auth_header(\"/people/2/addresses.json\", \"4bda6a28dbf930b5af9244073623bd04\") }, nil, 201, 'Location' => '/people/1/addresses/5'\n-\n- mock.head \"/people/2.json\", { 'Authorization' => blank_digest_auth_header(\"/people/2.json\", \"15e5ed84ba5c4cfcd5c98a36c2e4f421\") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header }\n- mock.head \"/people/2.json\", { 'Authorization' => request_digest_auth_header(\"/people/2.json\", \"d4c6d2bcc8717abb2e2ccb8c49ee6a91\") }, nil, 200\n- end\n- end\n-\n- def test_authorization_header_if_credentials_supplied_and_auth_type_is_digest\n- authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json'))\n- assert_equal blank_digest_auth_header(\"/people/2.json\", \"fad396f6a34aeba28e28b9b96ddbb671\"), authorization_header['Authorization']\n- end\n-\n- def test_authorization_header_with_query_string_if_auth_type_is_digest\n- authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json?only=name'))\n- assert_equal blank_digest_auth_header(\"/people/2.json?only=name\", \"f8457b0b5d21b6b80737a386217afb24\"), authorization_header['Authorization']\n- end\n-\n- def test_get_with_digest_auth_handles_initial_401_response_and_retries\n- response = @authenticated_conn.get(\"/people/2.json\")\n- assert_equal \"David\", decode(response)[\"name\"]\n- end\n-\n- def test_post_with_digest_auth_handles_initial_401_response_and_retries\n- response = @authenticated_conn.post(\"/people/2/addresses.json\")\n- assert_equal \"/people/1/addresses/5\", response[\"Location\"]\n- assert_equal 201, response.code\n- end\n-\n- def test_put_with_digest_auth_handles_initial_401_response_and_retries\n- response = @authenticated_conn.put(\"/people/2.json\")\n- assert_equal 204, response.code\n- end\n-\n- def test_delete_with_digest_auth_handles_initial_401_response_and_retries\n- response = @authenticated_conn.delete(\"/people/2.json\")\n- assert_equal 200, response.code\n- end\n-\n- def test_head_with_digest_auth_handles_initial_401_response_and_retries\n- response = @authenticated_conn.head(\"/people/2.json\")\n- assert_equal 200, response.code\n- end\n-\n- def test_get_with_digest_auth_caches_nonce\n- response = @authenticated_conn.get(\"/people/2.json\")\n- assert_equal \"David\", decode(response)[\"name\"]\n-\n- # There is no mock for this request with a non-cached nonce.\n- response = @authenticated_conn.get(\"/people/1.json\")\n- assert_equal \"Matz\", decode(response)[\"name\"]\n- end\n-\n- def test_raises_invalid_request_on_unauthorized_requests_with_digest_auth\n- @conn.auth_type = :digest\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.get(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.post(\"/people/2/addresses.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.put(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.delete(\"/people/2.json\") }\n- assert_raise(ActiveResource::InvalidRequestError) { @conn.head(\"/people/2.json\") }\n- end\n-\n- private\n- def blank_digest_auth_header(uri, response)\n- %Q(Digest username=\"david\", realm=\"\", qop=\"\", uri=\"#{uri}\", nonce=\"\", nc=\"0\", cnonce=\"i-am-a-client-nonce\", opaque=\"\", response=\"#{response}\")\n- end\n-\n- def request_digest_auth_header(uri, response)\n- %Q(Digest username=\"david\", realm=\"RailsTestApp\", qop=\"auth\", uri=\"#{uri}\", nonce=\"#{@nonce}\", nc=\"0\", cnonce=\"i-am-a-client-nonce\", opaque=\"ef6dfb078ba22298d366f99567814ffb\", response=\"#{response}\")\n- end\n-\n- def response_digest_auth_header\n- %Q(Digest realm=\"RailsTestApp\", qop=\"auth\", algorithm=MD5, nonce=\"#{@nonce}\", opaque=\"ef6dfb078ba22298d366f99567814ffb\")\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "f7aa7a4a0995466cbca8b31bbf3cf545d43af1f9",
filename = "activeresource/test/cases/base/custom_methods_test.rb",
status = "removed", additions = 0L, deletions = 101L, changes = 101L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/custom_methods_test.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/custom_methods_test.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/test/cases/base/custom_methods_test.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,101 +0,0 @@\n-require 'abstract_unit'\n-require 'fixtures/person'\n-require 'fixtures/street_address'\n-require 'active_support/core_ext/hash/conversions'\n-\n-class CustomMethodsTest < ActiveSupport::TestCase\n- def setup\n- @matz = { :person => { :id => 1, :name => 'Matz' } }.to_json\n- @matz_deep = { :person => { :id => 1, :name => 'Matz', :other => 'other' } }.to_json\n- @matz_array = { :people => [{ :person => { :id => 1, :name => 'Matz' } }] }.to_json\n- @ryan = { :person => { :name => 'Ryan' } }.to_json\n- @addy = { :address => { :id => 1, :street => '12345 Street' } }.to_json\n- @addy_deep = { :address => { :id => 1, :street => '12345 Street', :zip => \"27519\" } }.to_json\n-\n- ActiveResource::HttpMock.respond_to do |mock|\n- mock.get \"/people/1.json\", {}, @matz\n- mock.get \"/people/1/shallow.json\", {}, @matz\n- mock.get \"/people/1/deep.json\", {}, @matz_deep\n- mock.get \"/people/retrieve.json?name=Matz\", {}, @matz_array\n- mock.get \"/people/managers.json\", {}, @matz_array\n- mock.post \"/people/hire.json?name=Matz\", {}, nil, 201\n- mock.put \"/people/1/promote.json?position=Manager\", {}, nil, 204\n- mock.put \"/people/promote.json?name=Matz\", {}, nil, 204, {}\n- mock.put \"/people/sort.json?by=name\", {}, nil, 204\n- mock.delete \"/people/deactivate.json?name=Matz\", {}, nil, 200\n- mock.delete \"/people/1/deactivate.json\", {}, nil, 200\n- mock.post \"/people/new/register.json\", {}, @ryan, 201, 'Location' => '/people/5.json'\n- mock.post \"/people/1/register.json\", {}, @matz, 201\n- mock.get \"/people/1/addresses/1.json\", {}, @addy\n- mock.get \"/people/1/addresses/1/deep.json\", {}, @addy_deep\n- mock.put \"/people/1/addresses/1/normalize_phone.json?locale=US\", {}, nil, 204\n- mock.put \"/people/1/addresses/sort.json?by=name\", {}, nil, 204\n- mock.post \"/people/1/addresses/new/link.json\", {}, { :address => { :street => '12345 Street' } }.to_json, 201, 'Location' => '/people/1/addresses/2.json'\n- end\n-\n- Person.user = nil\n- Person.password = nil\n- end\n-\n- def teardown\n- ActiveResource::HttpMock.reset!\n- end\n-\n- def test_custom_collection_method\n- # GET\n- assert_equal([{ \"id\" => 1, \"name\" => 'Matz' }], Person.get(:retrieve, :name => 'Matz'))\n-\n- # POST\n- assert_equal(ActiveResource::Response.new(\"\", 201, {}), Person.post(:hire, :name => 'Matz'))\n-\n- # PUT\n- assert_equal ActiveResource::Response.new(\"\", 204, {}),\n- Person.put(:promote, {:name => 'Matz'}, 'atestbody')\n- assert_equal ActiveResource::Response.new(\"\", 204, {}), Person.put(:sort, :by => 'name')\n-\n- # DELETE\n- Person.delete :deactivate, :name => 'Matz'\n-\n- # Nested resource\n- assert_equal ActiveResource::Response.new(\"\", 204, {}), StreetAddress.put(:sort, :person_id => 1, :by => 'name')\n- end\n-\n- def test_custom_element_method\n- # Test GET against an element URL\n- assert_equal Person.find(1).get(:shallow), {\"id\" => 1, \"name\" => 'Matz'}\n- assert_equal Person.find(1).get(:deep), {\"id\" => 1, \"name\" => 'Matz', \"other\" => 'other'}\n-\n- # Test PUT against an element URL\n- assert_equal ActiveResource::Response.new(\"\", 204, {}), Person.find(1).put(:promote, {:position => 'Manager'}, 'body')\n-\n- # Test DELETE against an element URL\n- assert_equal ActiveResource::Response.new(\"\", 200, {}), Person.find(1).delete(:deactivate)\n-\n- # With nested resources\n- assert_equal StreetAddress.find(1, :params => { :person_id => 1 }).get(:deep),\n- { \"id\" => 1, \"street\" => '12345 Street', \"zip\" => \"27519\" }\n- assert_equal ActiveResource::Response.new(\"\", 204, {}),\n- StreetAddress.find(1, :params => { :person_id => 1 }).put(:normalize_phone, :locale => 'US')\n- end\n-\n- def test_custom_new_element_method\n- # Test POST against a new element URL\n- ryan = Person.new(:name => 'Ryan')\n- assert_equal ActiveResource::Response.new(@ryan, 201, { 'Location' => '/people/5.json' }), ryan.post(:register)\n- expected_request = ActiveResource::Request.new(:post, '/people/new/register.json', @ryan)\n- assert_equal expected_request.body, ActiveResource::HttpMock.requests.first.body\n-\n- # Test POST against a nested collection URL\n- addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1)\n- assert_equal ActiveResource::Response.new({ :address => { :street => '12345 Street' } }.to_json,\n- 201, { 'Location' => '/people/1/addresses/2.json' }),\n- addy.post(:link)\n-\n- matz = Person.find(1)\n- assert_equal ActiveResource::Response.new(@matz, 201), matz.post(:register)\n- end\n-\n- def test_find_custom_resources\n- assert_equal 'Matz', Person.find(:all, :from => :managers).first.name\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "fffd8b75c3a4f89a97b4e4c52a739c00e5c29f7b",
filename = "activeresource/test/cases/base/equality_test.rb",
status = "removed", additions = 0L, deletions = 52L, changes = 52L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/equality_test.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/equality_test.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/test/cases/base/equality_test.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,52 +0,0 @@\n-require 'abstract_unit'\n-require \"fixtures/person\"\n-require \"fixtures/street_address\"\n-\n-class BaseEqualityTest < ActiveSupport::TestCase\n- def setup\n- @new = Person.new\n- @one = Person.new(:id => 1)\n- @two = Person.new(:id => 2)\n- @street = StreetAddress.new(:id => 2)\n- end\n-\n- def test_should_equal_self\n- assert @new == @new, '@new == @new'\n- assert @one == @one, '@one == @one'\n- end\n-\n- def test_shouldnt_equal_new_resource\n- assert @new != @one, '@new != @one'\n- assert @one != @new, '@one != @new'\n- end\n-\n- def test_shouldnt_equal_different_class\n- assert @two != @street, 'person != street_address with same id'\n- assert @street != @two, 'street_address != person with same id'\n- end\n-\n- def test_eql_should_alias_equals_operator\n- assert_equal @new == @new, @new.eql?(@new)\n- assert_equal @new == @one, @new.eql?(@one)\n-\n- assert_equal @one == @one, @one.eql?(@one)\n- assert_equal @one == @new, @one.eql?(@new)\n-\n- assert_equal @one == @street, @one.eql?(@street)\n- end\n-\n- def test_hash_should_be_id_hash\n- [@new, @one, @two, @street].each do |resource|\n- assert_equal resource.id.hash, resource.hash\n- end\n- end\n-\n-\tdef test_with_prefix_options\n- assert_equal @one == @one, @one.eql?(@one)\n- assert_equal @one == @one.dup, @one.eql?(@one.dup)\n- new_one = @one.dup\n- new_one.prefix_options = {:foo => 'bar'}\n- assert_not_equal @one, new_one\n-\tend\n-\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch")), structure(list(sha = "f07e1ea16bbe09815da24e7b6e0f2f5c8c64985d",
filename = "activeresource/test/cases/base/load_test.rb",
status = "removed", additions = 0L, deletions = 199L, changes = 199L,
blob_url = "https://github.com/rails/rails/blob/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/load_test.rb",
raw_url = "https://github.com/rails/rails/raw/a85714a673d2e06b923bd4eba443a3849d332cce/activeresource/test/cases/base/load_test.rb",
contents_url = "https://api.github.com/repos/rails/rails/contents/activeresource/test/cases/base/load_test.rb?ref=a85714a673d2e06b923bd4eba443a3849d332cce",
patch = "@@ -1,199 +0,0 @@\n-require 'abstract_unit'\n-require \"fixtures/person\"\n-require \"fixtures/street_address\"\n-require 'active_support/core_ext/hash/conversions'\n-\n-module Highrise\n- class Note < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-\n- class Comment < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-\n- module Deeply\n- module Nested\n- class Note < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-\n- class Comment < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n-\n- module TestDifferentLevels\n- class Note < ActiveResource::Base\n- self.site = \"http://37s.sunrise.i:3000\"\n- end\n- end\n- end\n- end\n-end\n-\n-\n-class BaseLoadTest < ActiveSupport::TestCase\n- def setup\n- @matz = { :id => 1, :name => 'Matz' }\n-\n- @first_address = { :address => { :id => 1, :street => '12345 Street' } }\n- @addresses = [@first_address, { :address => { :id => 2, :street => '67890 Street' } }]\n- @addresses_from_json = { :street_addresses => @addresses }\n- @addresses_from_json_single = { :street_addresses => [ @first_address ] }\n-\n- @deep = { :id => 1, :street => {\n- :id => 1, :state => { :id => 1, :name => 'Oregon',\n- :notable_rivers => [\n- { :id => 1, :name => 'Willamette' },\n- { :id => 2, :name => 'Columbia', :rafted_by => @matz }],\n- :postal_codes => [ 97018, 1234567890 ],\n- :dates => [ Time.now ],\n- :votes => [ true, false, true ],\n- :places => [ \"Columbia City\", \"Unknown\" ]}}}\n-\n-\n- # List of books formated as [{timestamp_of_publication => name}, ...]\n- @books = {:books => [\n- {1009839600 => \"Ruby in a Nutshell\"},\n- {1199142000 => \"The Ruby Programming Language\"}\n- ]}\n-\n- @books_date = {:books => [\n- {Time.at(1009839600) => \"Ruby in a Nutshell\"},\n- {Time.at(1199142000) => \"The Ruby Programming Language\"}\n- ]}\n- @person = Person.new\n- end\n-\n- def test_load_hash_with_integers_as_keys\n- assert_nothing_raised{@person.load(@books)}\n- end\n-\n- def test_load_hash_with_dates_as_keys\n- assert_nothing_raised{@person.load(@books_date)}\n- end\n-\n- def test_load_expects_hash\n- assert_raise(ArgumentError) { @person.load nil }\n- assert_raise(ArgumentError) { @person.load '<person id=\"1\"/>' }\n- end\n-\n- def test_load_simple_hash\n- assert_equal Hash.new, @person.attributes\n- assert_equal @matz.stringify_keys, @person.load(@matz).attributes\n- end\n-\n- def test_after_load_attributes_are_accessible\n- assert_equal Hash.new, @person.attributes\n- assert_equal @matz.stringify_keys, @person.load(@matz).attributes\n- assert_equal @matz[:name], @person.attributes['name']\n- end\n-\n- def test_after_load_attributes_are_accessible_via_indifferent_access\n- assert_equal Hash.new, @person.attributes\n- assert_equal @matz.stringify_keys, @person.load(@matz).attributes\n- assert_equal @matz[:name], @person.attributes['name']\n- assert_equal @matz[:name], @person.attributes[:name]\n- end\n-\n- def test_load_one_with_existing_resource\n- address = @person.load(:street_address => @first_address.values.first).street_address\n- assert_kind_of StreetAddress, address\n- assert_equal @first_address.values.first.stringify_keys, address.attributes\n- end\n-\n- def test_load_one_with_unknown_resource\n- address = silence_warnings { @person.load(@first_address).address }\n- assert_kind_of Person::Address, address\n- assert_equal @first_address.values.first.stringify_keys, address.attributes\n- end\n-\n- def test_load_collection_with_existing_resource\n- addresses = @person.load(@addresses_from_json).street_addresses\n- assert_kind_of Array, addresses\n- addresses.each { |address| assert_kind_of StreetAddress, address }\n- assert_equal @addresses.map { |a| a[:address].stringify_keys }, addresses.map(&:attributes)\n- end\n-\n- def test_load_collection_with_unknown_resource\n- Person.__send__(:remove_const, :Address) if Person.const_defined?(:Address)\n- assert !Person.const_defined?(:Address), \"Address shouldn't exist until autocreated\"\n- addresses = silence_warnings { @person.load(:addresses => @addresses).addresses }\n- assert Person.const_defined?(:Address), \"Address should have been autocreated\"\n- addresses.each { |address| assert_kind_of Person::Address, address }\n- assert_equal @addresses.map { |a| a[:address].stringify_keys }, addresses.map(&:attributes)\n- end\n-\n- def test_load_collection_with_single_existing_resource\n- addresses = @person.load(@addresses_from_json_single).street_addresses\n- assert_kind_of Array, addresses\n- addresses.each { |address| assert_kind_of StreetAddress, address }\n- assert_equal [ @first_address.values.first ].map(&:stringify_keys), addresses.map(&:attributes)\n- end\n-\n- def test_load_collection_with_single_unknown_resource\n- Person.__send__(:remove_const, :Address) if Person.const_defined?(:Address)\n- assert !Person.const_defined?(:Address), \"Address shouldn't exist until autocreated\"\n- addresses = silence_warnings { @person.load(:addresses => [ @first_address ]).addresses }\n- assert Person.const_defined?(:Address), \"Address should have been autocreated\"\n- addresses.each { |address| assert_kind_of Person::Address, address }\n- assert_equal [ @first_address.values.first ].map(&:stringify_keys), addresses.map(&:attributes)\n- end\n-\n- def test_recursively_loaded_collections\n- person = @person.load(@deep)\n- assert_equal @deep[:id], person.id\n-\n- street = person.street\n- assert_kind_of Person::Street, street\n- assert_equal @deep[:street][:id], street.id\n-\n- state = street.state\n- assert_kind_of Person::Street::State, state\n- assert_equal @deep[:street][:state][:id], state.id\n-\n- rivers = state.notable_rivers\n- assert_kind_of Array, rivers\n- assert_kind_of Person::Street::State::NotableRiver, rivers.first\n- assert_equal @deep[:street][:state][:notable_rivers].first[:id], rivers.first.id\n- assert_equal @matz[:id], rivers.last.rafted_by.id\n-\n- postal_codes = state.postal_codes\n- assert_kind_of Array, postal_codes\n- assert_equal 2, postal_codes.size\n- assert_kind_of Fixnum, postal_codes.first\n- assert_equal @deep[:street][:state][:postal_codes].first, postal_codes.first\n- assert_kind_of Numeric, postal_codes.last\n- assert_equal @deep[:street][:state][:postal_codes].last, postal_codes.last\n-\n- places = state.places\n- assert_kind_of Array, places\n- assert_kind_of String, places.first\n- assert_equal @deep[:street][:state][:places].first, places.first\n-\n- dates = state.dates\n- assert_kind_of Array, dates\n- assert_kind_of Time, dates.first\n- assert_equal @deep[:street][:state][:dates].first, dates.first\n-\n- votes = state.votes\n- assert_kind_of Array, votes\n- assert_kind_of TrueClass, votes.first\n- assert_equal @deep[:street][:state][:votes].first, votes.first\n- end\n-\n- def test_nested_collections_within_the_same_namespace\n- n = Highrise::Note.new(:comments => [{ :comment => { :name => \"1\" } }])\n- assert_kind_of Highrise::Comment, n.comments.first\n- end\n-\n- def test_nested_collections_within_deeply_nested_namespace\n- n = Highrise::Deeply::Nested::Note.new(:comments => [{ :name => \"1\" }])\n- assert_kind_of Highrise::Deeply::Nested::Comment, n.comments.first\n- end\n-\n- def test_nested_collections_in_different_levels_of_namespaces\n- n = Highrise::Deeply::Nested::TestDifferentLevels::Note.new(:comments => [{ :name => \"1\" }])\n- assert_kind_of Highrise::Deeply::Nested::Comment, n.comments.first\n- end\n-end"), .Names = c("sha",
"filename", "status", "additions", "deletions", "changes", "blob_url",
"raw_url", "contents_url", "patch"))), headers = structure(list(
server = "GitHub.com", date = "Fri, 06 Feb 2015 15:04:14 GMT",
status = "304 Not Modified", `x-ratelimit-limit` = "5000",
`x-ratelimit-remaining` = "4727", `x-ratelimit-reset` = "1423238654",
`cache-control` = "private, max-age=60, s-maxage=60", `last-modified` = "Fri, 06 Feb 2015 05:12:30 GMT",
etag = "\"ca6a1fde3ed3852bc387862360e5a589\"", `x-xss-protection` = "1; mode=block",
`x-frame-options` = "deny", `content-security-policy` = "default-src 'none'",
`access-control-allow-credentials` = "true", `access-control-expose-headers` = "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
`access-control-allow-origin` = "*", `x-github-request-id` = "81160112:72CA:B921444:54D4D7ED",
`strict-transport-security` = "max-age=31536000; includeSubdomains; preload",
`x-content-type-options` = "nosniff", vary = "Accept-Encoding",
`x-served-by` = "318e55760cf7cdb40e61175a4d36cd32"), .Names = c("server",
"date", "status", "x-ratelimit-limit", "x-ratelimit-remaining",
"x-ratelimit-reset", "cache-control", "last-modified", "etag",
"x-xss-protection", "x-frame-options", "content-security-policy",
"access-control-allow-credentials", "access-control-expose-headers",
"access-control-allow-origin", "x-github-request-id", "strict-transport-security",
"x-content-type-options", "vary", "x-served-by"), class = c("insensitive",
"list")), code = 304L), .Names = c("ok", "content", "headers",
"code"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment