Giter VIP home page Giter VIP logo

kosapi_client.rb's Introduction

KOSapi Client

Gem Version Build Status Inline docs

A simple Ruby client library for KOSapi RESTful service.

Installation

Add this line to your application's Gemfile:

gem 'kosapi_client', github: 'cvut/kosapi_client.rb'

And then execute:

$ bundle

Basic usage

# Creates a new instance of client with OAuth2 credentials
client = KOSapiClient.new({ client_id: OAUTH_CLIENT_ID, client_secret: OAUTH_SECRET })

# Retrieves first page of all course events
course_events_page = client.course_events
course_events_page.each { |event| do_stuff_with_event(event) }

# Fetches page of parallels according to API parameters
parallels_page = client.parallels.offset(0).limit(50).query('course.department' => '18*')

# Finds all parallels related to parallel with id = 42
client.parallels.find(42).related

Configuration

KOSapiClient can be created and configured in two ways. The simple way is to call KOSapiClient.new, which returns an ApiClient instance.

client = KOSapiClient.new({ client_id: OAUTH_CLIENT_ID, client_secret: OAUTH_SECRET })
client.parallels.find(42)

The other way is to configure client using KOSapiClient.configure and setting options inside a block. In addition to returning the client instance from configure, the client is also stored in KOSapiClient singleton property and its methods can be accessed by calling them on KOSapiClient directly. This approach is more suitable for configuring client inside an initializer.

KOSapiClient.configure do |c|
  c.client_id = ENV['KOSAPI_OAUTH_CLIENT_ID']
  c.client_secret = ENV['KOSAPI_OAUTH_CLIENT_SECRET']
end

KOSapiClient.parallels.find(42)

Development

Run bin/setup script to setup dependencies and create .env file. You will need to obtain access to KOSapi.

OAuth Credentials

You will need a KOSapi OAuth credentials from the Apps Manager to run integration specs.

OAuth credentials need to be exposed as environment variables KOSAPI_OAUTH_CLIENT_ID and KOSAPI_OAUTH_CLIENT_SECRET. If you put them into .env file, the test suite will load them for you automatically:

KOSAPI_OAUTH_CLIENT_ID=xxx-xxxx-xxxx
KOSAPI_OAUTH_CLIENT_SECRET=yyyyyyyyy

Contributing

Bug reports and pull requests are welcome on GitHub at cvut/kosapi_client.rb. 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.

License

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

kosapi_client.rb's People

Contributors

deric avatar flexik avatar jirutka avatar jnv avatar pidekjunior avatar rrrene avatar simacektomas avatar tszolar avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kosapi_client.rb's Issues

Unable to configure / 504 from spec

No matter how I try to configure it...

  • /bin/setup creates .env, rake spec stuck and then returns 504 Bad Gateway
  • KOSapiClient.new() expects hash, not OAUTH_CLIENT_ID, OAUTH_SECRET (what are the keys?)
  • KOSapiClient.configure does not make configuration accessible to the client

Please change README :)

Implement follow support for all API Links

Currently only links that work with the auto/manual follow are pagination links in ResultPage. Other parsed links don't get a HTTP client injected.

Will have to pass HTTPClient instance into ResponseConverter and inject it to entities that are interested in it.

Add global options support

It needs to be implemented so it can be accessed from everywhere and the options are correctly retrieved for current client instance.

Will be helpful for implementing options like:

  • DEFAULT_PAGE_SIZE
  • DEFAULT_LANG
  • DISABLE_AUTOPAGINATION
  • ...

Add support for more KOSapi resources

Working resources so far:

  • Branches
  • CourseEvents
  • Courses
  • CoursesGroups
  • Divisions
  • Exams
  • Parallels
  • Pathways
  • People
  • Programmes
  • Rooms
  • Semesters
  • Students
  • StudyPlans
  • Teachers
  • Theses
  • ThesesDrafts

Publish gem on RubyGems

We are planning some other gems which will depend on KOSapi, so it would be awesome to publish this thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.