Class: RestClient::Resource

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#passwordObject (readonly)

Returns the value of attribute password.



16
17
18
# File 'lib/resource.rb', line 16

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/resource.rb', line 16

def url
  @url
end

#userObject (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

#post(payload, headers = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/resource.rb', line 32

def post(payload, headers={})
	Request.execute(:method => :post,
		:url => url,
		:payload => payload,
		:user => user,
		:password => password,
		:headers => headers)
end

#put(payload, headers = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/resource.rb', line 41

def put(payload, headers={})
	Request.execute(:method => :put,
		:url => url,
		:payload => payload,
		:user => user,
		:password => password,
		:headers => headers)
end