Giter Club home page Giter Club logo

google_calendar's Introduction

Google Calendar

A fast lightweight and minimalist wrapper around the Google Calendar api.

<img src=“https://badge.fury.io/rb/google_calendar.svg” alt=“Gem Version” /> <img src=“https://travis-ci.org/northworld/google_calendar.png?branch=master” alt=“Build Status” /> <img src=“https://codeclimate.com/github/northworld/google_calendar/badges/gpa.svg” /> <img src=“https://codeclimate.com/github/northworld/google_calendar/badges/coverage.svg” />

Install

[sudo] gem install 'google_calendar'

Setup

Obtain a Client ID and Secret

  1. Go to the Google Developers Console.

  2. Select a project, or create a new one (at the top of the page).

  3. In the sidebar on the left, select Library.

  4. Type in ‘Google Calendar’ in the search box and click on ‘Google Calendar API’ in the results.

  5. Click on the ‘Enable’ link at the top of the page.

  6. In the sidebar on the left, select Credentials.

  7. If you haven’t done so already, create your ‘OAuth client ID’ by clicking Create Credentials’. Note: you need to set your ‘Product name show to users’ on the OAuth consent screen before you can create your client ID.

  8. Select the ‘Other’ option and click create.

Take note of the Client ID and Client Secret as you’ll need to add it to your code later.

Find your calendar ID

  1. Visit Google Calendar in your web browser.

  2. In the calendar list on the left, click the down-arrow button next to the appropriate calendar, then select Calendar settings.

  3. In the Calendar Address section, locate the Calendar ID listed next to the XML, ICAL and HTML buttons.

  4. Copy the Calendar ID.

Usage

require 'rubygems'
require 'google_calendar'

# Create an instance of the calendar.
cal = Google::Calendar.new(:client_id     => YOUR_CLIENT_ID,
                           :client_secret => YOUR_SECRET,
                           :calendar      => YOUR_CALENDAR_ID,
                           :redirect_url  => "urn:ietf:wg:oauth:2.0:oob" # this is what Google uses for 'applications'
                           )

puts "Do you already have a refresh token? (y/n)"
has_token = $stdin.gets.chomp

if has_token.downcase != 'y'

  # A user needs to approve access in order to work with their calendars.
  puts "Visit the following web page in your browser and approve access."
  puts cal.authorize_url
  puts "\nCopy the code that Google returned and paste it here:"

  # Pass the ONE TIME USE access code here to login and get a refresh token that you can use for access from now on.
  refresh_token = cal.login_with_auth_code( $stdin.gets.chomp )

  puts "\nMake sure you SAVE YOUR REFRESH TOKEN so you don't have to prompt the user to approve access again."
  puts "your refresh token is:\n\t#{refresh_token}\n"
  puts "Press return to continue"
  $stdin.gets.chomp

else

  puts "Enter your refresh token"
  refresh_token = $stdin.gets.chomp
  cal.login_with_refresh_token(refresh_token)

  # Note: You can also pass your refresh_token to the constructor and it will login at that time.

end

event = cal.create_event do |e|
  e.title = 'A Cool Event'
  e.start_time = Time.now
  e.end_time = Time.now + (60 * 60) # seconds * min
end

puts event

event = cal.find_or_create_event_by_id(event.id) do |e|
  e.title = 'An Updated Cool Event'
  e.end_time = Time.now + (60 * 60 * 2) # seconds * min * hours
end

puts event

# All events
puts cal.events

# Query events
puts cal.find_events('your search string')

This sample code is located in readme_code.rb in the root folder.

Ruby Support

The current google_calendar gem supports Ruby 2.1 and higher – because of the json gem dependency. We maintain support for Ruby 1.8.7, 1.9.3 and 2.0 on different branches.

Notes

  • This is not a complete implementation of the calendar api, it just includes the features we needed to support our internal calendar integration. Feel free to add additional features and we will happily integrate them.

  • Did you get an SSL exception? If so take a look at this: gist.github.com/fnichol/867550

Contributing to google_calendar

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Running Tests

The first time you run rake test Rake will copy over .env.test to .env for use by Dotenv. You can also use .env.default as your own starting point, just remember to copy it over to .env before running tests.

You can modify .env with your own credentials and don’t worry about accidentally committing to the repo as .env is in the .gitignore.

Copyright © 2010-2014 Steve Zich. See LICENSE.txt for further details.

google_calendar's People

Contributors

alfo avatar ayn avatar bfosberry avatar brendon9 avatar capncavedan avatar davidtoca avatar dependabot-support avatar edwinwills avatar hajder avatar harfangk avatar johnthepink avatar klarrimore avatar kristiankozak avatar liquidise avatar murtuzakz avatar nicolasbize avatar nicolasleger avatar omarskalli avatar onemanstartup avatar patricksrobertson avatar projectdelphai avatar pupca avatar sbounmy avatar szich avatar talyaniv avatar tkm-kj avatar tomav avatar vinh0604 avatar weilu avatar wstrinz avatar

Watchers

 avatar  avatar

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.