Class: LibraryThing::Resource
- Inherits:
-
Object
- Object
- LibraryThing::Resource
- Includes:
- HTTParty
- Defined in:
- lib/librarything/resource.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#item_node ⇒ Object
readonly
Returns the value of attribute item_node.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(xml) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(xml) ⇒ Resource
Returns a new instance of Resource.
56 57 58 59 60 |
# File 'lib/librarything/resource.rb', line 56 def initialize(xml) @xml = xml @document = self.parse_response(@xml) @item_node = self.find_item_node(@document) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
53 54 55 |
# File 'lib/librarything/resource.rb', line 53 def document @document end |
#item_node ⇒ Object (readonly)
Returns the value of attribute item_node.
54 55 56 |
# File 'lib/librarything/resource.rb', line 54 def item_node @item_node end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
52 53 54 |
# File 'lib/librarything/resource.rb', line 52 def xml @xml end |
Class Method Details
.get(query) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/librarything/resource.rb', line 108 def get(query) raise LibraryThing::Error.new("Missing developer key. Please define LibraryThing::DEVELOPER_KEY") unless defined?(LibraryThing::DEVELOPER_KEY) all_params = { :apikey => LibraryThing::DEVELOPER_KEY, :method => self.get_method }.merge(query) response = super('', :query => all_params) self.new(response.body) end |
.get_method(method_name = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/librarything/resource.rb', line 98 def get_method(method_name = nil) if method_name @get_method = method_name elsif @get_method @get_method else raise LibraryThing::Error.new('Cannot get a generic resource. Try LibraryThing::Work.get or LibraryThing::Author.get') end end |
Instance Method Details
#[](name) ⇒ Object
62 63 64 |
# File 'lib/librarything/resource.rb', line 62 def [](name) @item_node[name] end |