Skip to content
This repository
Newer
Older
100644 100 lines (79 sloc) 3.124 kb
d3bbeea7 »
2011-11-17 initial commit, working on the README
1 require "bundler/gem_tasks"
033001eb »
2013-01-24 make rspec the default rake task
2 require 'rspec/core/rake_task'
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
3
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
4 require 'oauth'
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
5 require 'oauth2'
6
033001eb »
2013-01-24 make rspec the default rake task
7 RSpec::Core::RakeTask.new(:spec)
8
9 task :default => :spec
10
3a1a3eff » Tony Pitale
2012-01-20 added some notes on getting oauth2 token with device id
11 # get oauth2 via device code, unimplemented as of now
12 # curl -d "client_id={{client_id}}&scope=https://www.googleapis.com/auth/analytics.readonly" https://accounts.google.com/o/oauth2/device/code
13 # { "device_code" : "4/8O1xUKWzOdJESG7ednnulZPsbyNt", "user_code" : "3tywhirg", "verification_url" : "http://www.google.com/device", "expires_in" : 1800, "interval" : 5 }
14 # curl -d "client_id={{client_id}}&client_secret={{client_secret}}&code=4/8O1xUKWzOdJESG7ednnulZPsbyNt&grant_type=http://oauth.net/grant_type/device/1.0" https://accounts.google.com/o/oauth2/token
15 # { "access_token" : "ERspXATXoblahblahblah", "token_type" : "Bearer", "expires_in" : 3600, "refresh_token" : "1/balhaajsdfklasfdjs;df" }
16
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
17 module OAuth2Helpers
18 def build_client(id, secret)
3fa7abde »
2012-01-12 update rakefile; move oauth info into wiki; update query and profile …
19 # This is my test client account for Legato.
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
20 opts = {
3fa7abde »
2012-01-12 update rakefile; move oauth info into wiki; update query and profile …
21 :authorize_url => 'https://accounts.google.com/o/oauth2/auth',
22 :token_url => 'https://accounts.google.com/o/oauth2/token'
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
23 }
24
25 OAuth2::Client.new(id, secret, opts)
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
26 end
27
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
28 def auth_url(client)
3fa7abde »
2012-01-12 update rakefile; move oauth info into wiki; update query and profile …
29 client.auth_code.authorize_url({
30 :scope => 'https://www.googleapis.com/auth/analytics.readonly',
31 :redirect_uri => 'http://localhost'
32 })
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
33 end
34
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
35 extend self
36 end
37
38 namespace :oauth2 do
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
39 desc "Get a new OAuth2 Token"
40 task :token do
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
41 puts 'Get your OAuth2 id and secret from the API Console: https://code.google.com/apis/console#access'
42
43 puts
44 print 'Your OAuth2 id: '
45 oauth_id = $stdin.gets.strip
46 print 'Your OAuth2 secret: '
47 oauth_secret = $stdin.gets.strip
48
49 client = OAuth2Helpers.build_client(oauth_id, oauth_secret)
50
51 puts
52 puts "Opening the OAuth2 auth url: #{OAuth2Helpers.auth_url(client)} ..."
53 `open "#{OAuth2Helpers.auth_url(client)}"`
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
54
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
55 puts
56 print 'OAuth2 Code (in the url): '
57 code = $stdin.gets.strip
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
58
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
59 access_token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost')
60
61 puts
62 puts "Here's your access token: "
08cb02c9 »
2011-11-27 completed integration testing the management api with vcr, added clas…
63 puts access_token.token
64 end
3fa7abde »
2012-01-12 update rakefile; move oauth info into wiki; update query and profile …
65 end
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
66
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
67 # namespace :oauth do
68 # def consumer(id, secret)
69 # OAuth::Consumer.new('779170787975.apps.googleusercontent.com', 'mbCISoZiSwyVQIDEbLj4EeEc', {
70 # :site => "https://www.google.com",
71 # :request_token_path => "/accounts/OAuthGetRequestToken",
72 # :access_token_path => "/accounts/OAuthGetAccessToken",
73 # :authorize_path => "/accounts/OAuthAuthorizeToken"
74 # })
75 # end
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
76
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
77 # def request_token
78 # @request_token ||= consumer.get_request_token({}, {:scope => "https://www.googleapis.com/auth/analytics.readonly"})
79 # end
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
80
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
81 # def auth_url
82 # request_token.authorize_url
83 # end
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
84
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
85 # def access_token
86 # @access_token ||= begin
87 # print 'OAuth Code: '
88 # code = $stdin.gets.strip
89 # request_token.get_access_token(:oauth_verifier => code)
90 # end
91 # end
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
92
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
93 # desc "Get a new OAuth Token"
94 # task :token do
95 # `open "#{auth_url}"`
b9b7d8b6 » Tony Pitale
2012-01-20 spiked out oauth 1 support, with api key, fixes for 1.8.*
96
03753bcc »
2013-01-02 fix rake oauth2:token task; change it to require user to set their oa…
97 # puts "Token: #{access_token.token}"
98 # puts "Secret: #{access_token.secret}"
99 # end
100 # end
Something went wrong with that request. Please try again.