Class: Almodovar::Resource

Inherits:
Object
  • Object
show all
Includes:
HttpAccessor
Defined in:
lib/almodovar/to_xml.rb,
lib/almodovar/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HttpAccessor

#check_errors, #http, #query_params, #xml

Constructor Details

#initialize(url, auth, xml = nil, options = {}) ⇒ Resource

Returns a new instance of Resource.



14
15
16
17
18
19
# File 'lib/almodovar/resource.rb', line 14

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



21
22
23
# File 'lib/almodovar/resource.rb', line 21

def method_missing(meth, *args, &blk)
  resource_object(meth).send(meth, *args, &blk)
end

Class Method Details

.from_xml(xml, auth = nil) ⇒ Object



10
11
12
# File 'lib/almodovar/resource.rb', line 10

def self.from_xml(xml, auth = nil)
  new(nil, auth, Nokogiri::XML.parse(xml).root)
end

Instance Method Details

#respond_to?(meth, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/almodovar/resource.rb', line 25

def respond_to?(meth, include_all=false)
  super || resource_object(meth).respond_to?(meth, include_all)
end

#to_xml(options = {}) ⇒ Object



12
13
14
# File 'lib/almodovar/to_xml.rb', line 12

def to_xml(options = {})
  options[:builder].tag!(:link, rel: options[:root], href: url)
end