Class: RestMan::Resource
- Inherits:
-
Object
- Object
- RestMan::Resource
- Defined in:
- lib/restman/resource.rb
Overview
:include: _doc/lib/restman/resource.rdoc
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#[](suburl, &new_block) ⇒ Object
:include: _doc/lib/restman/resource/[].rdoc.
-
#concat_urls(url, suburl) ⇒ Object
:nodoc:.
- #delete(additional_headers = {}, &block) ⇒ Object
- #get(additional_headers = {}, &block) ⇒ Object
- #head(additional_headers = {}, &block) ⇒ Object
- #headers ⇒ Object
-
#initialize(url, options = {}, backwards_compatibility = nil, &block) ⇒ Resource
constructor
A new instance of Resource.
- #log ⇒ Object
- #open_timeout ⇒ Object
- #password ⇒ Object
- #patch(payload, additional_headers = {}, &block) ⇒ Object
- #post(payload, additional_headers = {}, &block) ⇒ Object
- #put(payload, additional_headers = {}, &block) ⇒ Object
- #read_timeout ⇒ Object
- #to_s ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(url, options = {}, backwards_compatibility = nil, &block) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 12 13 14 |
# File 'lib/restman/resource.rb', line 6 def initialize(url, ={}, backwards_compatibility=nil, &block) @url = url @block = block if .class == Hash @options = else # compatibility with previous versions @options = { :user => , :password => backwards_compatibility } end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/restman/resource.rb', line 4 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/restman/resource.rb', line 4 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/restman/resource.rb', line 4 def url @url end |
Instance Method Details
#[](suburl, &new_block) ⇒ Object
:include: _doc/lib/restman/resource/[].rdoc
102 103 104 105 106 107 108 |
# File 'lib/restman/resource.rb', line 102 def [](suburl, &new_block) case when block_given? then self.class.new(concat_urls(url, suburl), , &new_block) when block then self.class.new(concat_urls(url, suburl), , &block) else self.class.new(concat_urls(url, suburl), ) end end |
#concat_urls(url, suburl) ⇒ Object
:nodoc:
110 111 112 113 114 115 116 117 118 |
# File 'lib/restman/resource.rb', line 110 def concat_urls(url, suburl) # :nodoc: url = url.to_s suburl = suburl.to_s if url.slice(-1, 1) == '/' or suburl.slice(0, 1) == '/' url + suburl else "#{url}/#{suburl}" end end |
#delete(additional_headers = {}, &block) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/restman/resource.rb', line 64 def delete(additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :delete, :url => url, :headers => headers, :log => log), &(block || @block)) end |
#get(additional_headers = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/restman/resource.rb', line 16 def get(additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :get, :url => url, :headers => headers, :log => log), &(block || @block)) end |
#head(additional_headers = {}, &block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/restman/resource.rb', line 25 def head(additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :head, :url => url, :headers => headers, :log => log), &(block || @block)) end |
#headers ⇒ Object
85 86 87 |
# File 'lib/restman/resource.rb', line 85 def headers [:headers] || {} end |
#open_timeout ⇒ Object
93 94 95 |
# File 'lib/restman/resource.rb', line 93 def open_timeout [:open_timeout] end |
#password ⇒ Object
81 82 83 |
# File 'lib/restman/resource.rb', line 81 def password [:password] end |
#patch(payload, additional_headers = {}, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/restman/resource.rb', line 54 def patch(payload, additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :patch, :url => url, :payload => payload, :headers => headers, :log => log), &(block || @block)) end |
#post(payload, additional_headers = {}, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/restman/resource.rb', line 34 def post(payload, additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :post, :url => url, :payload => payload, :headers => headers, :log => log), &(block || @block)) end |
#put(payload, additional_headers = {}, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/restman/resource.rb', line 44 def put(payload, additional_headers={}, &block) headers = ([:headers] || {}).merge(additional_headers) Request.execute(.merge( :method => :put, :url => url, :payload => payload, :headers => headers, :log => log), &(block || @block)) end |
#read_timeout ⇒ Object
89 90 91 |
# File 'lib/restman/resource.rb', line 89 def read_timeout [:read_timeout] end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/restman/resource.rb', line 73 def to_s url end |
#user ⇒ Object
77 78 79 |
# File 'lib/restman/resource.rb', line 77 def user [:user] end |