Class: Nestful::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/nestful/endpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Endpoint

Returns a new instance of Endpoint.



9
10
11
12
# File 'lib/nestful/endpoint.rb', line 9

def initialize(url, options = {})
  @url     = url
  @options = options
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/nestful/endpoint.rb', line 7

def url
  @url
end

Class Method Details

.[](url) ⇒ Object



3
4
5
# File 'lib/nestful/endpoint.rb', line 3

def self.[](url)
  self.new(url)
end

Instance Method Details

#[](suburl) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/nestful/endpoint.rb', line 14

def [](suburl)
  return self if suburl.nil?
  suburl = suburl.to_s
  base   = url
  base  += "/" unless base =~ /\/$/
  self.class.new(URI.join(base, suburl).to_s, @options)
end

#delete(params = {}, options = {}) ⇒ Object



34
35
36
# File 'lib/nestful/endpoint.rb', line 34

def delete(params = {}, options = {})
  request(options.merge(:method => :delete, :params => params))
end

#get(params = {}, options = {}) ⇒ Object



22
23
24
# File 'lib/nestful/endpoint.rb', line 22

def get(params = {}, options = {})
  request(options.merge(:method => :get, :params => params))
end

#post(params = {}, options = {}) ⇒ Object



30
31
32
# File 'lib/nestful/endpoint.rb', line 30

def post(params = {}, options = {})
  request(options.merge(:method => :post, :params => params))
end

#put(params = {}, options = {}) ⇒ Object



26
27
28
# File 'lib/nestful/endpoint.rb', line 26

def put(params = {}, options = {})
  request(options.merge(:method => :put, :params => params))
end

#request(options = {}) ⇒ Object



38
39
40
# File 'lib/nestful/endpoint.rb', line 38

def request(options = {})
  Request.new(url, options.merge(@options)).execute
end