Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
  bin
  lib
  Gemfile
  README.md
  uoy-faculty-google.gemspec
Size: Mime:
  README.md

Google Gem

Useful functions for talking to google from our Ruby apps.

Installation

Add these lines to your application's Gemfile:

source 'https://gem.fury.io/universityofyork/' do
  gem 'uoy-faculty-google', '~> 0.1', require: 'faculty/google'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install uoy-faculty-google

Usage

Substitute your own API and scopes as appropriate:

@calendar = ::Google::Apis::CalendarV3::CalendarService.new
scopes = ['https://www.googleapis.com/auth/calendar']
@calendar.authorization = Faculty::Google::Auth::OAuth.new(scopes: scopes).authorization
p @calendar.list_calendar_lists

Local Dev OAuth setup

  • Create a new project at https://console.cloud.google.com/
  • Click 'APIs and Services' in the left-hand menu
    • Click 'Enable APIs and Services' at the top of the page
    • Search for the API(s) you wish to use, and click Enable
  • Visit https://console.cloud.google.com/apis/credentials
    • Click 'Create credentials; at the top of the page
    • Select OAuth client ID
    • Application Type should be Desktop app
      • this is for the behind-the-scenes connections like ExCircs
    • Give it a name and Create
    • In the row for the new OAuth Client, click the 'Download' button on the far-right
    • Save the file to your project as google-client-secrets.json

Initializing

If you're running ruby locally (e.g. in a gem), you can set up a rake task to call authorization directly::

desc 'Set up Google OAuth for local dev'
task :oauth do
  Faculty::Google::Auth::OAuth.new(scopes: FlexiLeave::Leave::GoogleCalendar::SCOPES).authorization
end

If you're running in a docker container, you'll need two parts; a file to run (e.g. oauth.rb):

# frozen_string_literal: true

require 'rubygems'
require 'bundler'

Bundler.require

require 'faculty/google'

Faculty::Google::Auth::OAuth.new(scopes: []).authorization

and a rake task to trigger this through the docker container:

desc 'Set up Google OAuth for local dev'
task :oauth do
  Faculty::Rake::DockerTasks.exec_in :app, 'ruby oauth.rb'
end

Development

Versioning

Your Gem's version is picked up automatically from lib/google.rb. When any changes are pushed to master, after the normal CI tasks the pipeline will push to gemfury automatically. The usual workflow is:

  • For minor changes, update VERSION and make the change in a single commit

  • For anything else, create a branch and set VERSION to the version you're aiming to release for. Make the changes; when the branch is merged, the gem will be uploaded.

Note that gemfury will never overwrite an existing gem version, even if the old one is yanked!

Running tests

Tests can be run via rake: bundle exec rake spec - this doesn't run performance tests; they can be run separately via bundle exec rake perf.

You can also run rspec normally e.g. bundle exec rspec -fd.

Identifying Performance Tests

If you have performance tests that take a while, tag the context / describe block like this:

context 'when foo is bar baz', :perf do
  ...
end

Contributing

Bug reports and pull requests are welcome at https://github.com/university-of-york/faculty-dev-google-gem