Class: RestClient::Resource
- Inherits:
-
Object
- Object
- RestClient::Resource
- Defined in:
- lib/resource.rb
Overview
A class that can be instantiated for access to a RESTful resource, including authentication.
Example:
resource = RestClient::Resource.new('http://some/resource')
jpg = resource.get(:accept => 'image/jpg')
With HTTP basic authentication:
resource = RestClient::Resource.new('http://protected/resource', 'user', 'pass')
resource.delete
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #delete(headers = {}) ⇒ Object
- #get(headers = {}) ⇒ Object
-
#initialize(url, user = nil, password = nil) ⇒ Resource
constructor
A new instance of Resource.
- #post(payload, headers = {}) ⇒ Object
- #put(payload, headers = {}) ⇒ Object
Constructor Details
#initialize(url, user = nil, password = nil) ⇒ Resource
Returns a new instance of Resource.
18 19 20 21 22 |
# File 'lib/resource.rb', line 18 def initialize(url, user=nil, password=nil) @url = url @user = user @password = password end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
16 17 18 |
# File 'lib/resource.rb', line 16 def password @password end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/resource.rb', line 16 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
16 17 18 |
# File 'lib/resource.rb', line 16 def user @user end |
Instance Method Details
#delete(headers = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/resource.rb', line 50 def delete(headers={}) Request.execute(:method => :delete, :url => url, :user => user, :password => password, :headers => headers) end |
#get(headers = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/resource.rb', line 24 def get(headers={}) Request.execute(:method => :get, :url => url, :user => user, :password => password, :headers => headers) end |