scruwys / coursera-ruby

Thin Ruby wrapper for Coursera API

Home Page:https://tech.coursera.org/app-platform/catalog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coursera API

This is an unofficial Ruby library for the Catalog APIs provided by Coursera.

Disclaimer: According to Coursera, these APIs are still in beta and can change in backwards-incompatible ways without warning. Therefore, beware when using this gem in production.

Installation

In your Gemfile:

gem 'coursera'

Or install it yourself as:

$ gem install coursera

Usage

There are three primary endpoints for the Coursera API: Courses, Partners, and Instructors. Due to the experimental nature of the API, I have decided to only include support for the Courses endpoint. The other two endpoints could be accessed in a similar nature, so feel free to read the code and contribute as you see fit.

Course

You can search for a course if you know the ID:

course = Coursera::Course.find("Gtv4Xb1-EeS-ViIACwYKVQ")
#=> #<Coursera::Course id="Gtv4Xb1-EeS-ViIACwYKVQ" ...>

Or if you know the slug you are interested in:

course = Coursera::Course.find_by_slug("machine-learning")
#=> #<Coursera::Course id="Gtv4Xb1-EeS-ViIACwYKVQ" ...>

You can then access course attributes like this :

course.name
#=> "Machine Learning"

course.slug
#=> "machine-learning"

You can add additional fields via a hash parameter:

course = Coursera::Course.find("Gtv4Xb1-EeS-ViIACwYKVQ", {fields: [:startDate, :description]})
#=> #<Coursera::Course id="Gtv4Xb1-EeS-ViIACwYKVQ", description="Machine learning is ...>

Query the entire course catalog via the .all method:

courses = Coursera::Course.all(limit: 30) # pass optional limit parameter to cap results
#=> [#<Coursera::Course ...>, #<Coursera::Course ...>]

Search functionality is also included:

client = Coursera::Client.new

client.search_courses("data analytics", { fields: [:name, :photo], limit: 5 })
#=> [#<Coursera::Course ...>, #<Coursera::Course ...>]

Note in this last example, we initialize a client rather than call a class method. This was included for future development purposes, i.e., in case Coursera begins to require authorization tokens.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/scruwys/coursera-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Note: Test suite is minimal due to the experimental nature of this API. Contributions are appreciated.

License

The gem is available as open source under the terms of the MIT License.

About

Thin Ruby wrapper for Coursera API

https://tech.coursera.org/app-platform/catalog/

License:MIT License


Languages

Language:Ruby 98.8%Language:Shell 1.2%