pog 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/generators/active_record/active_record_migration_generator.rb +38 -0
- data/lib/generators/pog/USAGE +0 -0
- data/lib/generators/pog/install_generator.rb +28 -0
- data/lib/generators/pog/pog_model_generator.rb +21 -0
- data/lib/generators/pog/templates/pog_handler.rb +68 -0
- data/lib/pog.rb +5 -0
- data/lib/pog/version.rb +7 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b19ce6db104720c79bb2dab01a502b0a6617bbae
|
4
|
+
data.tar.gz: 484fd35607666b0cdaa6ab2b7765cca84acd8745
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c4d52afd88a7c8bb6c4d0eee33e7ada66426d4b9f25c00c0ec95baf4b235a8f7416e0378bed18ae791b517b7136661fc745803a22de8b1365d40b35cc908728
|
7
|
+
data.tar.gz: 477a4838131d0cb86ca338796b0ad045255465daf8852f4a1e366b2d066b8a94a74a71ced902b9ab3ee5e2fb15e0a3a0b0295b54f9beacea8815b91c14b02b53
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Generators
|
5
|
+
class ActiveRecordMigrationGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
# Invoke the active record migration generator
|
10
|
+
def create_pogs_migration
|
11
|
+
if Dir.glob("{db/migrate}/*_create_pogs.rb*").empty?
|
12
|
+
invoke "active_record:migration", ["create_pogs"]
|
13
|
+
insert_into_file Dir.glob("{db/migrate}/*create_pogs.rb*").last, migration_data, :after => "create_table :pogs do |t|\n"
|
14
|
+
else
|
15
|
+
puts "Migration for Pog already exists."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# code to be added to the migration
|
23
|
+
def migration_data
|
24
|
+
<<-RUBY
|
25
|
+
|
26
|
+
t.string :access_token
|
27
|
+
t.datetime :access_token_expiration_time
|
28
|
+
t.string :refresh_token
|
29
|
+
t.string :analytics_view_id
|
30
|
+
t.boolean :permission
|
31
|
+
|
32
|
+
t.timestamps
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/active_record/active_record_migration_generator'
|
3
|
+
require 'generators/pog/pog_model_generator'
|
4
|
+
|
5
|
+
module Pog
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
desc "This generator handles installation and setup"
|
12
|
+
|
13
|
+
# # requires a 'name' even though pog migration
|
14
|
+
# # does not require one, so we pass an empty string
|
15
|
+
def setup_migration
|
16
|
+
invoke "active_record:active_record_migration", [""]
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_model
|
20
|
+
invoke "pog:pog_model", [""]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module Pog
|
4
|
+
module Generators
|
5
|
+
class PogModelGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
# copy the pog file into app/models if it
|
10
|
+
# does not already exist
|
11
|
+
def create_pog_handler_model
|
12
|
+
if Dir.glob("app/models/pog.rb").empty?
|
13
|
+
copy_file "pog.rb", "app/models/pog.rb"
|
14
|
+
else
|
15
|
+
puts "Model for Pog already exists."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class Pog
|
2
|
+
|
3
|
+
# options expected to include client_id, client_secret, and redirect_uri
|
4
|
+
def initialize(options)
|
5
|
+
@client_id = options[:client_id]
|
6
|
+
@client_secret = options[:client_secret]
|
7
|
+
@redirect_uri = options[:redirect_uri]
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_permission?
|
11
|
+
self.permission
|
12
|
+
end
|
13
|
+
|
14
|
+
def access_token_expired?
|
15
|
+
self.access_token_expiration_time < Time.now
|
16
|
+
end
|
17
|
+
|
18
|
+
def retrieve_auth(options)
|
19
|
+
scope = create_uri_from_scopes(options)
|
20
|
+
@client = Signet::OAuth2::Client.new(
|
21
|
+
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
|
22
|
+
:token_endpoint_uri => 'https://accounts.google.com/o/oauth2/token',
|
23
|
+
:client_id => @client_id,
|
24
|
+
:client_secret => @client_secret,
|
25
|
+
:scope => scope,
|
26
|
+
:redirect_uri => @redirect_uri
|
27
|
+
)
|
28
|
+
@client.authorization_uri.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def create_uri_from_scope(options)
|
34
|
+
"https://www.googleapis.com/auth/#{options[:api]}.readonly" if options[:scope] == "read"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Takes an auth code provided when user consents to grant
|
38
|
+
# authorization.
|
39
|
+
def request_access_token(auth_code)
|
40
|
+
http = Net::HTTP.new('accounts.google.com', 443)
|
41
|
+
path = '/o/oauth2/token'
|
42
|
+
http.use_ssl = true
|
43
|
+
data = "code=#{auth_code}&client_id=#{@client_id}&client_secret=#{@client_secret}&redirect_uri=#{@redirect_uri}&grant_type=authorization_code"
|
44
|
+
response = http.post(path, data)
|
45
|
+
values = JSON.parse(response.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
def evaluate_response_code(code)
|
49
|
+
code = code.to_i
|
50
|
+
if code === 200
|
51
|
+
return true
|
52
|
+
else
|
53
|
+
revoke_permission if code === 403
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def grant_permission
|
59
|
+
self.has_permission = true
|
60
|
+
self.save!
|
61
|
+
end
|
62
|
+
|
63
|
+
def revoke_permission
|
64
|
+
self.has_permission = false
|
65
|
+
self.save!
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/lib/pog/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yaniv Savir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A wrapper for Google's Signet Gem to Allow for Persistent Data and Offline
|
14
|
+
Access
|
15
|
+
email: saviry@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/generators/active_record/active_record_migration_generator.rb
|
21
|
+
- lib/generators/pog/install_generator.rb
|
22
|
+
- lib/generators/pog/pog_model_generator.rb
|
23
|
+
- lib/generators/pog/templates/pog_handler.rb
|
24
|
+
- lib/generators/pog/USAGE
|
25
|
+
- lib/pog/version.rb
|
26
|
+
- lib/pog.rb
|
27
|
+
homepage: http://github.com/YSavir/pog
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.1.11
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Pog verion 0.0.1
|
51
|
+
test_files: []
|