Code Monkey home page Code Monkey logo

glass's Introduction

Glass

This Gem is meant to help you quickly building application for Google Glass thanks to Ruby.

This gem is based on google/api-client.

Google/api-client is terrible to use. This gem aim to make it softer. It offer a simple interface to the Mirror API and manage Auth, credentials and tokens for you.

This gem is using Redis to store clients credentials and token.

Installation

Add this line to your application's Gemfile:

gem 'glass'

And then execute:

$ bundle

Or install it yourself as:

$ gem install glass

Usage

Setup Credential

require 'glass'
Glass::Mirror.client_id = ENV['GLASS_CLIENT_ID']
Glass::Mirror.client_secret = ENV['GLASS_CLIENT_SECRET']
Glass::Mirror.redirect_uri = ENV['GLASS_REDIRECT_URI']
Glass::Mirror.scopes = [ Add requested scopes]
    # Default is 'https://www.googleapis.com/auth/drive.file',
    #            'https://www.googleapis.com/auth/userinfo.profile',

You are a Glassware Explorer Now ! Get a way to get the authorization code from user app install. I don't know how for now. If you find let me know ! And do the OAuth trick

ok_glass = Glass::Mirror.build_with_code(authorization_code)

Token Persistence

As in OAuth2.0, Google API issue a Refresh_Token the first time you Authorize the client, so you can get new token later. You need to store this token. Out of the box Glass's Gem use Redis to do it.

Glass use a namespace on your redis. So don't bother about this (even if you can specify one too).

By default, Glass use local redis store (localhost:6379).

You can specify the Redis store this way :

For Heroku/RedisToGo users

Glass::Mirror.redis = ENV["REDISTOGO_URL"]

Overview

Timeline

Let's say you want to tell "Hi" to the user. Build it and send it.

item = Glass::TimelineItem.new()
item.text="Hi"
ok_glass.insert(item)

Subscriptions

Let's say you want to subscribe to location update. You need to provide a call_back_url, on wich Google will post the datas.

subscription = Glass::Subscription.new()
subscription.collection="location"
subscription.call_back_url="https://glassware.herokuapp.com/location_update"
ok_glass.insert(subscription)

Location

There is a quicker way to get Location update

Glass::Location.subscribe(ok_glass,call_back_url)

Going Further

As you are a Glassware Explorer you can explore yourself. Access the google/api-client Client this way :

ok_glass.client   # Get the discovered Google::API on wich you can make request

Have fun ! And please, show me any use. Just send me a tweet : @TheDamFr

Bypassing Redis

You can bypass Redis. I don't want to know why you would, but you can do it easily.

Just do :

Glass::Mirror.no_redis = true # Glass are so sad !

Now you need to handle the storage yourself !

credentials = Glass::Mirror.get_credentials(authorization_code)

# Store Credentials !

ok_glass = Glass::Mirror.build_client(credentials)

That's okay ! (for now)

Contributing

  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 new Pull Request

glass's People

Contributors

thedamfr avatar ericboehs avatar

Watchers

Libin Pan avatar James Cloos 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.