Class: Mumukit::Bridge::Bibliotheca

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/bridge/bibliotheca.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/mumukit/bridge/bibliotheca.rb', line 4

def headers
  @headers
end

#urlObject

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

#booksObject



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

#guidesObject



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

#topicsObject



16
17
18
# File 'lib/mumukit/bridge/bibliotheca.rb', line 16

def topics
  get_collection 'topics'
end