Google API wrapper
3.4.0 Latest release released
19 3

Crystal CI


Provides ability to interact with google services. Feel free to follow our guide on how to configure API access.

Currently supports following:

  • OAuth Token Generation
    • By providing credentials via argument
    • By providing absolute path to client_auth.json file
  • Directory API
    • List
    • Single user fetch
  • Calendar
    • CalendarList
    • Listing calendar events
    • Single calendar event fetch
    • Create calendar event
    • Delete calendar event
    • Update calendar event
    • Move calendar event
    • Availability
  • Drive
    • Listing Files in drive
    • Single file fetch
    • Create file
    • Delete file
  • Translate
    • List available languages
    • Detect source language
    • Translate one language to another
  • Gmail
    • send an email


  1. Add the dependency to your shard.yml:

        github: PlaceOS/google
  2. Run shards install


require "google"


There are three authentication options

Google::Auth "", signing_key: PRIVATE_KEY, scopes: "", sub: "")

Google::FileAuth = "/absolute_path/client_auth.json", scopes: "", sub: "")

Access token


For instance 3-legged OAuth2 where a user token has been provided. i.e.



# auth variable below can be instance of Google::Auth or Google::FileAuth
directory = auth, domain: "")

# To fetch all users

# Fetch single user


# auth variable below can be instance of Google::Auth or Google::FileAuth
calendar = auth)

# To fetch calendar list

# To fetch all calendar events

# To fetch single calendar event by id

# To create calendar event
calendar.create(event_start: Time.utc, event_end: Time.utc + 1.hour, attendees: [""], summary: "ACA test event", description: "test description", attachments: ["file_id", "file_url in google drive")])

# To update single calendar event by id
calendar.update("event_id", summary: "updated summary")

# To delete single calendar event by id

# To move single calendar event by id
calendar.move(event_id: "event_id", calendar_id: "original_calendar_id", destination_id: "destination_calendar_id")

# To fetch availability (free/busy) for a set of mailboxes
calendar.availability(mailboxes: ["", ""], starts_at: Time.utc, ends_at: Time.utc + 1.hour)


# auth variable below can be instance of Google::Auth or Google::FileAuth
drive_files = auth)

# To fetch files list

# To fetch single file by id

# To create file
drive_files.create(name: "test.txt", content_bytes: "Hello world!", content_type: "text/plain")

# To delete single file by id


# auth variable below can be instance of Google::Auth or Google::FileAuth
translate = auth)

# To fetch available languages

# To fetch available languages as localized values
translate.languages("de") # Where "de" is a language code

# To detect the language of a given string (or strings)
translate.detect_language("Some text to detect")

# To translate a string into a target language (auto detecting the source)
translate.translate("Some text to translate", to: "de")

# To translate a string into a target language (with a manual source)
translate.translate("Some text to translate", to: "de", from: "en")

Pay Passes

Currently only allows TicketClass and TicketObject creation

Output is google pay pass url that can be emailed or shared so that user can save in their google pay app

# Current use case is to create meetings as TicketClass and an attendee pass as TicketObject
# `execute` does this in one swoop and creates TicketClass/TicketObject remotely using google api
# jwt payload is then encoded/signed and shared as url

# file_auth variable below is an instance of Google::FileAuth file_auth,
  issuer_id: "YOUR ISSUER ID",
  serial_number: "Unique identifier for the ticket",
  issuer_name: "ISSUER NAME",
  event_name: "TEST EVENT",
  ticket_holder_name: "John Smith",
  location: {"lat": 37.424299996, "lon": -122.0925956000001},
  event_details: {header: "some header", body: "Some other body"},
  date_time: {start: "2023-04-12T11:20:50.52Z", end: "2023-04-12T16:20:50.52Z"},
  logo_image: {uri: "", description: "Baconrista stadium logo"},
  event_image: {uri: "", description: "Coffee beans"},
  venue: {name: "JK Stadium", address: "123 FYI Str"},
  origins: ["", ""],
  qr_code_value: "Data encoded in qr_code",
  qr_code_alternate_text: "User Friendly alternate text"

# Result


Currently using RAW RFC 2822 to send emails, versus the optional custom message JSON. To generate the message you can use the email shard

# auth needs a scope like
messages = auth)

user_id = "steve@place.os"

email =
email.from user_id ""
email.subject "subject"
email.message "hello gmail"

messages.send(user_id, email.to_s)
# returns an unparsed response body text currently


To run specs crystal spec


  1. Fork it (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
  github: PlaceOS/google
  version: ~> 3.4.0
License MIT
Crystal >= 0.36.1

Dependencies 2

  • connect-proxy ~> 2.0
    {'github' => 'spider-gazelle/connect-proxy', 'version' => '~> 2.0'}
  • jwt ~> 1.4
    {'github' => 'crystal-community/jwt', 'version' => '~> 1.4'}

Development Dependencies 3

  • ameba
    {'github' => 'veelenga/ameba'}
  • email
    {'github' => 'arcage/crystal-email'}
  • webmock
    {'github' => 'manastech/'}

Dependents 0

Last synced .
search fire star recently