# TimeTree APIs client [![Test](https://github.com/koshilife/timetree-api-ruby-client/workflows/Test/badge.svg)](https://github.com/koshilife/timetree-api-ruby-client/actions?query=workflow%3ATest) [![codecov](https://codecov.io/gh/koshilife/timetree-api-ruby-client/branch/master/graph/badge.svg)](https://codecov.io/gh/koshilife/timetree-api-ruby-client) [![Gem Version](https://badge.fury.io/rb/timetree.svg)](http://badge.fury.io/rb/timetree) [![license](https://img.shields.io/github/license/koshilife/timetree-api-ruby-client)](https://github.com/koshilife/timetree-api-ruby-client/blob/master/LICENSE.txt) ## About These client libraries are created for [TimeTree APIs](https://developers.timetreeapp.com/en). ## Installation Add this line to your application's Gemfile: ```ruby gem 'timetree' ``` And then execute: $ bundle Or install it yourself as: $ gem install timetree ## Usage for Calendar App The APIs client for Calendar App needs installation_id, application_id and private key. ```ruby # set token by TimeTree.configure methods. TimeTree.configure do |config| config.calendar_app_application_id = '' config.calendar_app_private_key = File.read('') end client = TimeTree::CalendarApp::Client.new('') # set token by TimeTree::CalendarApp::Client initializer. client = TimeTree::CalendarApp::Client.new('', '', '') # get connected calendar's information. cal = client.calendar # => # # get upcoming events on the calendar. evs = cal.upcoming_events # => [#, #, ...] ev = evs.first.title # => "Event Title" ``` ## Usage for OAuth App The APIs client for OAuth App needs access token. ```ruby # set token by TimeTree.configure methods. TimeTree.configure do |config| config.oauth_app_token = '' end client = TimeTree::OAuthApp::Client.new # set token by TimeTree::OAuthApp::Client initializer. client = TimeTree::OAuthApp::Client.new('') # get a current user's information. user = client.current_user # => # user.name # => "USER Name" # get current user's calendars. cals = client.calendars # => [#, #, ...] cal = cals.first cal.name # => "Calendar Name" # get upcoming events on the calendar. evs = cal.upcoming_events # => [#, #, ...] ev = evs.first ev.title # => "Event Title" # updates an event. ev.title += ' Updated' ev.start_at = Time.parse('2020-06-20 09:00 +09:00') ev.end_at = Time.parse('2020-06-20 10:00 +09:00') ev.update # => # # creates an event. copy_ev = ev.dup new_ev = copy_ev.create # => # # deletes an event. ev.delete # => true # creates a comment to an event. ev.create_comment 'Hi there!' # => # # handles APIs error. begin ev.delete ev.delete # 404 Error occured. rescue TimeTree::ApiError => e e => # e.response => # end ``` ## Logging ```ruby # if the log level set :debug, you can get the request/response information. TimeTree.configuration.logger.level = :debug => # >> client.event 'cal_id_001', 'event_id_001_not_found' I, [2020-06-24T10:05:07.294807] INFO -- : GET https://timetreeapis.com/calendars/cal_id_001/events/event_id_001_not_found?include=creator%2Clabel%2Cattendees D, [2020-06-24T10:05:07.562038] DEBUG -- : Response status:404, body:{:type=>"https://developers.timetreeapp.com/en/docs/api#client-failure", :title=>"Not Found", :status=>404, :errors=>"Event not found"} ``` More in-depth method documentation can be found at [RubyDoc.info](https://www.rubydoc.info/gems/timetree/). ## Contributing Bug reports and pull requests are welcome on [GitHub](https://github.com/koshilife/timetree-api-ruby-client). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the TimeTree Api Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/koshilife/timetree-api-ruby-client/blob/master/CODE_OF_CONDUCT.md).