Class: Coursera::Course
- Inherits:
-
Base
- Object
- Base
- Coursera::Course
show all
- Defined in:
- lib/coursera/course.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
batch_request, get_elements, #initialize, prepare_attributes
Constructor Details
This class inherits a constructor from Coursera::Base
Class Method Details
.all(attrs = {}) ⇒ Object
> Coursera::Course.all(limit: 10)
5
6
7
|
# File 'lib/coursera/course.rb', line 5
def self.all(attrs = {})
Coursera::Course.batch_request("/courses.v1", self.prepare_attributes(attrs))
end
|
.find(id, attrs = {}) ⇒ Object
> Coursera::Course.find(“Gtv4Xb1-EeS-ViIACwYKVQ”)
10
11
12
13
14
15
|
# File 'lib/coursera/course.rb', line 10
def self.find(id, attrs = {})
attrs = self.prepare_attributes(attrs)
elems = self.get_elements("/courses.v1/#{id}", {query: attrs})
Coursera::Course.new elems[0] if (elems ||= []).size > 0
end
|
.find_by_slug(input, attrs = {}) ⇒ Object
> Coursera::Course.find_by_slug(“machine-learning”)
26
27
28
29
30
31
|
# File 'lib/coursera/course.rb', line 26
def self.find_by_slug(input, attrs = {})
attrs = self.prepare_attributes(attrs)
elems = self.get_elements("/courses.v1?q=slug&slug=#{input}", {query: attrs})
Coursera::Course.new elems[0] if (elems ||= []).size > 0
end
|
.find_many(input, attrs = {}) ⇒ Object
> Coursera::Course.find_many([“Gtv4Xb1-EeS-ViIACwYKVQ”, “zfksZy_FEeWWqBIFfWmDPQ”])
18
19
20
21
22
23
|
# File 'lib/coursera/course.rb', line 18
def self.find_many(input, attrs = {})
attrs = self.prepare_attributes(attrs)
route = "/courses.v1?ids=".concat(input.map(&:to_s).join(","))
Coursera::Course.batch_request(route, attrs)
end
|
Instance Method Details
#start_date ⇒ Object
33
34
35
|
# File 'lib/coursera/course.rb', line 33
def start_date
Time.at(self.startDate / 1000) unless self.startDate.nil?
end
|