Last active
August 29, 2015 14:01
-
-
Save justinribeiro/285831ed0f700ca5137a to your computer and use it in GitHub Desktop.
Really fast testing subscription for Glass w/Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'omniauth' | |
require 'google/omniauth' | |
require 'google/api_client/client_secrets' | |
CLIENT_SECRETS = Google::APIClient::ClientSecrets.load | |
client = Google::APIClient.new(:application_name => 'Ruby Mirror test', | |
:application_version => '1.0.0') | |
mirror = Google::APIClient.new.discovered_api('mirror', 'v1') | |
# Build an authorization object from the client secrets. | |
authorization = CLIENT_SECRETS.to_authorization | |
authorization.update_token!( | |
:access_token => "YOUR_TOKEN", | |
:refresh_token => "YOUR_REFRESH" | |
) | |
# Setup Subscription | |
subscription = mirror.subscriptions.insert.request_schema.new({ | |
'collection' => "timeline", | |
'userToken' => "AHappy2", | |
'verifyToken' => "meowmeowbeans", | |
'callbackUrl' => "https://SOMETHINGSEOMTHING.ngrok.com/rubyCallback" | |
}) | |
# Inject subscription | |
result_subscription = client.execute( | |
:api_method => mirror.subscriptions.insert, | |
:body_object => subscription, | |
:parameters => { 'id' => 'timeline' }, | |
:authorization => authorization) | |
# Setup menu items | |
menuItems = [] | |
menuItems << { action: 'CUSTOM', id: 'update', values: [ { displayName: "Update" } ]} | |
menuItems << { action: 'DELETE' } | |
#Create timeline card | |
timeline_item = mirror.timeline.insert.request_schema.new({ | |
'text' => "Test Notification Ping from Ruby", | |
'menuItems' => menuItems | |
}) | |
# inject to Glass | |
result_timelineitem = client.execute( | |
:api_method => mirror.timeline.insert, | |
:body_object => timeline_item, | |
:authorization => authorization) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment