Class: Mumukit::Bridge::Bibliotheca
- Inherits:
-
Object
- Object
- Mumukit::Bridge::Bibliotheca
- Defined in:
- lib/mumukit/bridge/bibliotheca.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #book(slug) ⇒ Object
- #books ⇒ Object
- #get(path) ⇒ Object
- #get_collection(name) ⇒ Object
- #get_element(name, slug) ⇒ Object
- #guide(slug) ⇒ Object
- #guides ⇒ Object
-
#initialize(url, timeout = 10, headers = {}) ⇒ Bibliotheca
constructor
A new instance of Bibliotheca.
- #topic(slug) ⇒ Object
- #topics ⇒ Object
Constructor Details
#initialize(url, timeout = 10, headers = {}) ⇒ Bibliotheca
Returns a new instance of Bibliotheca.
6 7 8 9 10 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 6 def initialize(url, timeout=10, headers={}) @url = url @timeout = timeout @headers = headers end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 4 def headers @headers end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 4 def url @url end |
Instance Method Details
#book(slug) ⇒ Object
32 33 34 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 32 def book(slug) get_element 'books', slug end |
#books ⇒ Object
20 21 22 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 20 def books get_collection 'books' end |
#get(path) ⇒ Object
44 45 46 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 44 def get(path) JSON.parse RestClient.get("#{url}/#{path}", self.headers) end |
#get_collection(name) ⇒ Object
36 37 38 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 36 def get_collection(name) get(name)[name] end |
#get_element(name, slug) ⇒ Object
40 41 42 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 40 def get_element(name, slug) get "#{name}/#{slug}" end |
#guide(slug) ⇒ Object
24 25 26 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 24 def guide(slug) get_element 'guides', slug end |
#guides ⇒ Object
12 13 14 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 12 def guides get_collection 'guides' end |
#topic(slug) ⇒ Object
28 29 30 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 28 def topic(slug) get_element 'topics', slug end |
#topics ⇒ Object
16 17 18 |
# File 'lib/mumukit/bridge/bibliotheca.rb', line 16 def topics get_collection 'topics' end |