skypager 0.1.2 → 0.2.0
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 +4 -4
- data/Rakefile +0 -11
- data/bin/skypager +16 -10
- data/lib/skypager.rb +1 -69
- data/lib/skypager/cli.rb +14 -0
- data/lib/skypager/cli/01_extensions.rb +25 -0
- data/lib/skypager/cli/config.rb +41 -0
- data/lib/skypager/proxy.rb +0 -10
- data/lib/skypager/version.rb +1 -1
- data/skypager.gemspec +1 -15
- metadata +9 -216
- data/ARCHITECTURE.md +0 -34
- data/CONTRIBUTING.md +0 -7
- data/LICENSE.txt +0 -22
- data/bin/bootstrap.sh +0 -29
- data/examples/.gitignore +0 -4
- data/examples/blog-site/.gitignore +0 -18
- data/examples/blog-site/.pryrc +0 -4
- data/examples/blog-site/Gemfile +0 -8
- data/examples/blog-site/config.rb +0 -17
- data/examples/blog-site/data/dropbox.json +0 -1
- data/examples/blog-site/source/images/background.png +0 -0
- data/examples/blog-site/source/images/middleman.png +0 -0
- data/examples/blog-site/source/index.html.erb +0 -10
- data/examples/blog-site/source/javascripts/all.js +0 -1
- data/examples/blog-site/source/layouts/layout.erb +0 -19
- data/examples/blog-site/source/posts/introduction-to-skypager.html.md +0 -23
- data/examples/blog-site/source/posts/skypager-and-dnsimple-and-amazon-web-services-combo.html.md +0 -9
- data/examples/blog-site/source/stylesheets/all.css +0 -55
- data/examples/blog-site/source/stylesheets/normalize.css +0 -375
- data/examples/gallery-site/.gitignore +0 -18
- data/examples/gallery-site/.pryrc +0 -4
- data/examples/gallery-site/Gemfile +0 -11
- data/examples/gallery-site/config.rb +0 -38
- data/examples/gallery-site/data/dropbox.json +0 -1
- data/examples/gallery-site/data/galleries.json +0 -1
- data/examples/gallery-site/source/gallery.html.erb +0 -7
- data/examples/gallery-site/source/images/background.png +0 -0
- data/examples/gallery-site/source/images/galleries/cristian-gallery-1/001.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/cristian-gallery-1/002.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/cristian-gallery-1/003.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/cristian-gallery-1/004.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/luca-gallery-1/001.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/luca-gallery-1/002.JPG +0 -0
- data/examples/gallery-site/source/images/galleries/luca-gallery-1/003.jpg +0 -0
- data/examples/gallery-site/source/images/galleries/luca-gallery-1/004.JPG +0 -0
- data/examples/gallery-site/source/images/middleman.png +0 -0
- data/examples/gallery-site/source/index.html.erb +0 -10
- data/examples/gallery-site/source/javascripts/all.js +0 -1
- data/examples/gallery-site/source/layouts/layout.erb +0 -20
- data/examples/gallery-site/source/stylesheets/all.css +0 -0
- data/examples/gallery-site/source/stylesheets/normalize.css +0 -375
- data/examples/gallery-site/source/tutorial.md +0 -151
- data/lib/skypager/builder.rb +0 -158
- data/lib/skypager/cli/commands/build.rb +0 -64
- data/lib/skypager/cli/commands/config.rb +0 -58
- data/lib/skypager/cli/commands/create.rb +0 -98
- data/lib/skypager/cli/commands/deploy.rb +0 -62
- data/lib/skypager/cli/commands/edit.rb +0 -32
- data/lib/skypager/cli/commands/list.rb +0 -12
- data/lib/skypager/cli/commands/setup.rb +0 -153
- data/lib/skypager/cli/commands/site.rb +0 -22
- data/lib/skypager/cli/commands/sync.rb +0 -20
- data/lib/skypager/data.rb +0 -8
- data/lib/skypager/data/excel_spreadsheet.rb +0 -8
- data/lib/skypager/data/google_spreadsheet.rb +0 -227
- data/lib/skypager/data/request.rb +0 -12
- data/lib/skypager/data/source.rb +0 -194
- data/lib/skypager/data/source_routes_proxy.rb +0 -30
- data/lib/skypager/dns.rb +0 -69
- data/lib/skypager/extension.rb +0 -271
- data/lib/skypager/middleman/commands/data.rb +0 -0
- data/lib/skypager/middleman/commands/deploy.rb +0 -0
- data/lib/skypager/middleman/commands/sync.rb +0 -0
- data/lib/skypager/sync.rb +0 -23
- data/lib/skypager/sync/amazon.rb +0 -181
- data/lib/skypager/sync/dropbox.rb +0 -173
- data/lib/skypager/sync/dropbox/delta.rb +0 -67
- data/lib/skypager/sync/folder.rb +0 -266
- data/lib/skypager/sync/github.rb +0 -55
- data/lib/skypager/sync/google.rb +0 -143
- data/spec/dummy/site-one/.gitignore +0 -18
- data/spec/dummy/site-one/Gemfile +0 -14
- data/spec/dummy/site-one/config.rb +0 -13
- data/spec/dummy/site-one/source/images/background.png +0 -0
- data/spec/dummy/site-one/source/images/middleman.png +0 -0
- data/spec/dummy/site-one/source/index.html.erb +0 -10
- data/spec/dummy/site-one/source/javascripts/all.js +0 -1
- data/spec/dummy/site-one/source/layouts/layout.erb +0 -19
- data/spec/dummy/site-one/source/stylesheets/all.css +0 -55
- data/spec/dummy/site-one/source/stylesheets/normalize.css +0 -375
- data/spec/lib/skypager/builder/server_spec.rb +0 -5
- data/spec/lib/skypager/configuration_spec.rb +0 -12
- data/spec/lib/skypager/data_spec.rb +0 -5
- data/spec/lib/skypager/site_spec.rb +0 -44
- data/spec/lib/skypager_spec.rb +0 -9
- data/spec/skypager-test-config.rb.example +0 -22
- data/spec/spec_helper.rb +0 -49
- data/spec/support/fixtures/cwd_config.json +0 -3
- data/spec/support/fixtures/home_config.json +0 -1
- data/spec/support/json_helper.rb +0 -7
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
command 'show deploy info' do |c|
|
|
2
|
-
c.syntax = 'skypager show deploy info'
|
|
3
|
-
c.description = 'display info about where this site will be deployed'
|
|
4
|
-
|
|
5
|
-
c.option '--verbose', nil, 'Display verbose status information'
|
|
6
|
-
c.option '--full', nil, 'Ignore the build manifest, deploy everything'
|
|
7
|
-
|
|
8
|
-
c.action do |args, options|
|
|
9
|
-
app = Skypager.app
|
|
10
|
-
site = app.site
|
|
11
|
-
|
|
12
|
-
puts "== Site Info:"
|
|
13
|
-
puts "==== Bucket Name: #{ site.bucket_name }"
|
|
14
|
-
puts "==== Bucket URL: #{ site.bucket_url }"
|
|
15
|
-
puts "==== CDN URL: #{ site.cname_value }" if site.has_cdn?
|
|
16
|
-
puts "==== Custom Domain: #{ site.custom_domain }" if site.custom_domain?
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
command 'deploy' do |c|
|
|
21
|
-
c.syntax = 'skypager deploy [options]'
|
|
22
|
-
c.description = 'deploy this site'
|
|
23
|
-
|
|
24
|
-
c.option '--verbose', nil, 'Display verbose status information'
|
|
25
|
-
c.option '--full', nil, 'Ignore the build manifest, deploy everything'
|
|
26
|
-
|
|
27
|
-
c.action do |args, options|
|
|
28
|
-
app = Skypager.app
|
|
29
|
-
site = app.site
|
|
30
|
-
|
|
31
|
-
if options.full.present?
|
|
32
|
-
site.remove_build_manifest
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
site.deploy(app.build_path)
|
|
36
|
-
|
|
37
|
-
if site.use_cdn?
|
|
38
|
-
cdn = site.cdn
|
|
39
|
-
|
|
40
|
-
paths = app.sitemap.resources.map do |resource|
|
|
41
|
-
"/#{ resource.request_path }"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
paths << "/"
|
|
45
|
-
|
|
46
|
-
paths.uniq!
|
|
47
|
-
|
|
48
|
-
begin
|
|
49
|
-
service = cdn.service
|
|
50
|
-
|
|
51
|
-
puts "== Posting CDN Invalidations"
|
|
52
|
-
paths.each do |path|
|
|
53
|
-
puts "==== #{ path }"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
service.post_invalidation cdn.id, paths
|
|
57
|
-
rescue => e
|
|
58
|
-
puts "Error invalidating the CDN: #{ e.message }"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
edit_spreadsheet_command = lambda do |c|
|
|
2
|
-
c.syntax = "skypager edit datasource NAME"
|
|
3
|
-
c.description = "Open up the data source editor"
|
|
4
|
-
|
|
5
|
-
c.action do |args, options|
|
|
6
|
-
require 'launchy'
|
|
7
|
-
require 'middleman-core'
|
|
8
|
-
|
|
9
|
-
name = args.first
|
|
10
|
-
|
|
11
|
-
if defined?(::Middleman)
|
|
12
|
-
app = ::Middleman::Application.server.inst do
|
|
13
|
-
set :environment, 'development'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
if !name
|
|
17
|
-
names = app.data_sources.keys.map(&:to_s)
|
|
18
|
-
name = choose("Which data source?", *names)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
source = app.data_sources[name.to_sym]
|
|
22
|
-
|
|
23
|
-
if source
|
|
24
|
-
Launchy.open(source.edit_url)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
command "edit data source" do |c|
|
|
31
|
-
edit_spreadsheet_command.call(c)
|
|
32
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
command 'list spreadsheets' do |c|
|
|
2
|
-
c.syntax = 'skypager list:spreadsheets [options]'
|
|
3
|
-
c.description = 'list available spreadsheets to use with skypager '
|
|
4
|
-
|
|
5
|
-
c.action do |_args, _options|
|
|
6
|
-
|
|
7
|
-
Skypager::Sync::Google.setup
|
|
8
|
-
Skypager::Sync.google.spreadsheets.map {|s| puts [s.key,s.title].join("\t\t") }
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
command 'setup' do |c|
|
|
2
|
-
c.syntax = 'skypager setup [options]'
|
|
3
|
-
c.description = 'setup the integrations for skypager to work'
|
|
4
|
-
|
|
5
|
-
c.option '--skip-dropbox', nil, 'Skip dropbox setup'
|
|
6
|
-
c.option '--skip-google', nil, 'Skip google setup'
|
|
7
|
-
c.option '--skip-amazon', nil, 'Skip amazon setup'
|
|
8
|
-
c.option '--skip-dns', nil, 'Skip dns setup'
|
|
9
|
-
|
|
10
|
-
c.action do |args, options|
|
|
11
|
-
Skypager::Sync::Dropbox.setup unless options.skip_dropbox || Skypager.config.dropbox_setup?
|
|
12
|
-
Skypager::Sync::Google.setup unless options.skip_google || Skypager.config.google_setup?
|
|
13
|
-
Skypager::Sync::Amazon.setup unless options.skip_amazon || Skypager.config.amazon_setup?
|
|
14
|
-
|
|
15
|
-
require 'dnsimple'
|
|
16
|
-
Skypager.dns.setup unless options.skip_dns || Skypager.config.dnsimple_setup?
|
|
17
|
-
|
|
18
|
-
want_to_setup_deployment = agree("Want to setup deployment right now? This will make your site available in the clouds. type yes/no")
|
|
19
|
-
|
|
20
|
-
if want_to_setup_deployment
|
|
21
|
-
puts "== This might take a minute."
|
|
22
|
-
Skypager::DeploymentSetup.run(options)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
command 'setup amazon' do |c|
|
|
28
|
-
c.syntax = 'skypager setup amazon [options]'
|
|
29
|
-
c.description = 'Setup amazon integration'
|
|
30
|
-
|
|
31
|
-
c.option '--access-key-id STRING', String, 'What is the AWS access key id?'
|
|
32
|
-
c.option '--secret-access-key STRING', String, 'What is the AWS secret access key?'
|
|
33
|
-
c.option '--create-bucket STRING', String, 'What is the bucket name?'
|
|
34
|
-
|
|
35
|
-
c.action do |args, options|
|
|
36
|
-
Skypager::Sync::Amazon.setup(access_key_id: options.access_key_id,
|
|
37
|
-
secret_access_key: options.secret_access_key)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
command 'setup deployment' do |c|
|
|
43
|
-
c.syntax = 'skypager setup deployment [options]'
|
|
44
|
-
c.description = 'Setup AWS deployment / hosting'
|
|
45
|
-
|
|
46
|
-
c.option '--access-key-id STRING', String, 'What is the AWS access key id?'
|
|
47
|
-
c.option '--secret-access-key STRING', String, 'What is the AWS secret access key?'
|
|
48
|
-
c.option '--create-bucket STRING', String, 'What is the bucket name?'
|
|
49
|
-
|
|
50
|
-
c.action do |args, options|
|
|
51
|
-
Skypager::Sync::Amazon.setup(access_key_id: options.access_key_id,
|
|
52
|
-
secret_access_key: options.secret_access_key)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Skypager::DeploymentSetup.run(options)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
command 'setup dropbox' do |c|
|
|
60
|
-
c.syntax = 'skypager setup dropbox [options]'
|
|
61
|
-
c.description = 'Setup dropbox sync'
|
|
62
|
-
|
|
63
|
-
c.option '--app-key STRING', String, 'What is the dropbox app key?'
|
|
64
|
-
c.option '--app-secret STRING', String, 'What is the dropbox app secret?'
|
|
65
|
-
|
|
66
|
-
c.action do |args, options|
|
|
67
|
-
Skypager::Sync::Dropbox.setup(dropbox_app_key: options.app_key,
|
|
68
|
-
dropbox_app_secret: options.app_secret)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
command 'setup google' do |c|
|
|
73
|
-
c.syntax = 'skypager setup google [options]'
|
|
74
|
-
c.description = 'Setup google sync'
|
|
75
|
-
|
|
76
|
-
c.option '--client-id STRING', String, 'What is the google app client id?'
|
|
77
|
-
c.option '--client-secret STRING', String, 'What is the google app client secret?'
|
|
78
|
-
|
|
79
|
-
c.action do |args, options|
|
|
80
|
-
Skypager::Sync::Google.setup(client_id: options.client_id,
|
|
81
|
-
client_secret: options.client_secret)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
command 'setup github' do |c|
|
|
86
|
-
c.syntax = 'skypager setup github [options]'
|
|
87
|
-
c.description = 'Setup github syncing'
|
|
88
|
-
|
|
89
|
-
c.option '--github-access-token STRING', String, 'What is the Github access token?'
|
|
90
|
-
|
|
91
|
-
c.action do |args, options|
|
|
92
|
-
Skypager::Sync::Github.setup(github_access_token: options.github_access_token)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
module Skypager
|
|
98
|
-
class DeploymentSetup
|
|
99
|
-
def self.run(options)
|
|
100
|
-
app = Skypager.app
|
|
101
|
-
|
|
102
|
-
if !Skypager.config.dnsimple_setup?
|
|
103
|
-
if agree("Do you want to setup DNSimple integration?")
|
|
104
|
-
Skypager.dns.setup()
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
custom_domain = app.deploy_options[:custom_domain] || options.custom_domain || ask("Enter a custom domain name to deploy to. Leave blank if you don't want to use this.")
|
|
109
|
-
|
|
110
|
-
if custom_domain.to_s.length > 0
|
|
111
|
-
app.site.set :custom_domain, custom_domain
|
|
112
|
-
app.site.set :use_cdn, true
|
|
113
|
-
@custom_domain = custom_domain
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
unless @custom_domain || app.deploy_options[:use_cdn] == true
|
|
117
|
-
if agree("Do you want to use a CDN? Answer yes if you want to use a custom domain, or SSL for this site")
|
|
118
|
-
app.site.set :use_cdn, true
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
bucket_name = app.deploy_options[:bucket_name] || options.create_bucket || ask("Enter a name for this bucket. Leave blank to use #{ app.site.name }.#{ Skypager.config.domain}")
|
|
123
|
-
bucket_name = app.site_name + "." + Skypager.config.domain if bucket_name.to_s.length == 0
|
|
124
|
-
|
|
125
|
-
if bucket_name
|
|
126
|
-
if bucket = Skypager.amazon.find_or_create_bucket(bucket_name)
|
|
127
|
-
app.site.set :bucket_key, bucket.key
|
|
128
|
-
app.site.set :bucket_name, bucket.key
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
config_path = Pathname(app.root).join("config.rb")
|
|
133
|
-
config_text = config_path.read rescue ""
|
|
134
|
-
|
|
135
|
-
app.site.after_setup
|
|
136
|
-
|
|
137
|
-
unless config_text.match(/deploy_to\(\:amazon/)
|
|
138
|
-
puts "Adding the following to your config.rb:\n\n\t#{ line = app.site.deploy_options_config_string }"
|
|
139
|
-
config_path.open("a+") {|fh| fh.write(line) }
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
site = app.site
|
|
143
|
-
|
|
144
|
-
puts "Site Info:"
|
|
145
|
-
puts "Bucket Name: #{ site.bucket_name }"
|
|
146
|
-
puts "Bucket URL: #{ site.bucket_url }"
|
|
147
|
-
puts "CDN URL: #{ site.cname_value }" if site.has_cdn?
|
|
148
|
-
puts "Custom Domain: #{ site.custom_domain }" if site.custom_domain?
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
command 'promote site' do |c|
|
|
2
|
-
c.syntax = 'skypager promote site'
|
|
3
|
-
c.description = 'Promotes this current folder to be the main folder for this site in the build server'
|
|
4
|
-
|
|
5
|
-
c.action do
|
|
6
|
-
app = Skypager.app
|
|
7
|
-
site = app.site
|
|
8
|
-
site.set(:root, app.root_path)
|
|
9
|
-
app.save_site_config
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
command 'list build queue' do |c|
|
|
14
|
-
c.syntax = "skypager list build queue"
|
|
15
|
-
c.description = "lists the sites in the build queue"
|
|
16
|
-
|
|
17
|
-
c.action do
|
|
18
|
-
Skypager::Site.requiring_build.each do |site|
|
|
19
|
-
puts "== site #{ site.name } at #{ site.root } requires a build"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
command 'sync' do |c|
|
|
2
|
-
c.action do |args, options|
|
|
3
|
-
$enable_skypager_sync_from_command = true
|
|
4
|
-
|
|
5
|
-
app = ::Middleman::Application.server.inst do
|
|
6
|
-
set :environment, 'development'
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
app.synced_folders.each do |name, folder|
|
|
10
|
-
puts "== Syncing #{ name }"
|
|
11
|
-
folder.sync()
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
app.data_sources.each do |name, source|
|
|
15
|
-
source.refresh
|
|
16
|
-
source.save_to_disk unless source.persisted?
|
|
17
|
-
app.data.callbacks(name, -> { source.data })
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/skypager/data.rb
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
module Skypager
|
|
2
|
-
module Data
|
|
3
|
-
class GoogleSpreadsheet < Source
|
|
4
|
-
|
|
5
|
-
requires :key
|
|
6
|
-
|
|
7
|
-
attr_accessor :key,
|
|
8
|
-
:session,
|
|
9
|
-
:name
|
|
10
|
-
|
|
11
|
-
def initialize name, options={}
|
|
12
|
-
@options = options
|
|
13
|
-
|
|
14
|
-
if name.is_a?(GoogleDrive::Spreadsheet)
|
|
15
|
-
@spreadsheet = name
|
|
16
|
-
@name = @spreadsheet.title
|
|
17
|
-
@key = @spreadsheet.key
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
@key ||= options[:key]
|
|
21
|
-
@session ||= options.fetch(:session) { Skypager::Sync.google.api }
|
|
22
|
-
|
|
23
|
-
ensure_valid_options!
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def self.create_from_file(path, title)
|
|
27
|
-
if find_by_title(title)
|
|
28
|
-
raise 'Spreadsheet with this title already exists'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
session.upload_from_file(path, title, :content_type => "text/csv")
|
|
32
|
-
|
|
33
|
-
find_by_title(title)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.[](key_or_title)
|
|
37
|
-
find_by_key(key_or_title) || find_by_title(key_or_title)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.find_by_key(key)
|
|
41
|
-
sheet = session_spreadsheets.detect do |spreadsheet|
|
|
42
|
-
spreadsheet.key == key
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
sheet && new(sheet, session: Skypager.google.session)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def self.find_by_title title
|
|
49
|
-
sheet = session_spreadsheets.detect do |spreadsheet|
|
|
50
|
-
spreadsheet.title.match(title)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
sheet && new(sheet, session: Skypager.google.session)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.session_spreadsheets
|
|
57
|
-
@session_spreadsheets ||= Skypager.google.api.spreadsheets
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.create_from_data(data, options={})
|
|
61
|
-
require 'csv'
|
|
62
|
-
|
|
63
|
-
headers = Array(options[:headers]).map(&:to_s)
|
|
64
|
-
|
|
65
|
-
tmpfile = "tmp-csv.csv"
|
|
66
|
-
|
|
67
|
-
CSV.open(tmpfile, "wb") do |csv|
|
|
68
|
-
csv << headers
|
|
69
|
-
|
|
70
|
-
data.each do |row|
|
|
71
|
-
csv << headers.map do |header|
|
|
72
|
-
row = row.stringify_keys
|
|
73
|
-
row[header.to_s]
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
spreadsheet = Skypager::Sync.google.api.upload_from_file(tmpfile, options[:title], :content_type => "text/csv")
|
|
79
|
-
|
|
80
|
-
if options[:skypager_config_info]
|
|
81
|
-
config_line = "data_source :#{ spreadsheet.title.to_s.downcase.underscore }, :type => 'google', :key => '#{ spreadsheet.key }'\n"
|
|
82
|
-
|
|
83
|
-
puts "Adding the following line to your config.rb: \n #{config_line}"
|
|
84
|
-
|
|
85
|
-
File.open("config.rb", "a+") do |fh|
|
|
86
|
-
fh.write("\n")
|
|
87
|
-
fh.write(config_line)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
new(spreadsheet.title, key: spreadsheet.key)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def title
|
|
96
|
-
@name ||= spreadsheet.try(:title)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def edit_url
|
|
100
|
-
spreadsheet.human_url
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def share_write_access_with *emails
|
|
104
|
-
acl = spreadsheet.acl
|
|
105
|
-
|
|
106
|
-
Array(emails).flatten.each do |email|
|
|
107
|
-
acl.push scope_type: "user",
|
|
108
|
-
with_key: false,
|
|
109
|
-
role: "writer",
|
|
110
|
-
scope: email
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def share_read_access_with *emails
|
|
115
|
-
acl = spreadsheet.acl
|
|
116
|
-
|
|
117
|
-
Array(emails).flatten.each do |email|
|
|
118
|
-
acl.push scope_type: "user",
|
|
119
|
-
with_key: false,
|
|
120
|
-
role: "reader",
|
|
121
|
-
scope: email
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def add_to_collection collection_title
|
|
126
|
-
collection = if collection_title.is_a?(GoogleDrive::Collection)
|
|
127
|
-
collection_title
|
|
128
|
-
else
|
|
129
|
-
session.collections.find do |c|
|
|
130
|
-
c.title == collection_title
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
if !collection
|
|
135
|
-
collection_names = session.collections.map(&:title)
|
|
136
|
-
raise 'Could not find collection in Google drive. Maybe you mean: ' + collection_names.join(', ')
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def spreadsheet_key
|
|
141
|
-
key
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def stale?
|
|
145
|
-
(!need_to_refresh? && (age > max_age)) || fresh_on_server?
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def fresh_on_server?
|
|
149
|
-
refreshed_at.to_i > 0 && (last_updated_at > refreshed_at)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def last_updated_at
|
|
153
|
-
if value = spreadsheet.document_feed_entry_internal.css('updated').try(:text) rescue nil
|
|
154
|
-
DateTime.parse(value).to_i
|
|
155
|
-
else
|
|
156
|
-
Time.now.to_i
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def fetch
|
|
161
|
-
self.raw = process_worksheets
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def preprocess
|
|
165
|
-
single? ? raw.values.flatten : raw
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
protected
|
|
169
|
-
|
|
170
|
-
def process_worksheets
|
|
171
|
-
worksheets.inject({}.to_mash) do |memo, parts|
|
|
172
|
-
k, ws = parts
|
|
173
|
-
header_row = Array(ws.rows[0])
|
|
174
|
-
column_names = header_row.map {|cell| "#{ cell }".parameterize.underscore }
|
|
175
|
-
rows = ws.rows.slice(1, ws.rows.length)
|
|
176
|
-
|
|
177
|
-
row_index = 1
|
|
178
|
-
memo[k] = rows.map do |row|
|
|
179
|
-
col_index = 0
|
|
180
|
-
|
|
181
|
-
_record = column_names.inject({}) do |record, field|
|
|
182
|
-
record[field] = "#{ row[col_index] }".strip
|
|
183
|
-
record["_id"] = row_index
|
|
184
|
-
col_index += 1
|
|
185
|
-
record
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
row_index += 1
|
|
189
|
-
|
|
190
|
-
_record
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
memo
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def single?
|
|
198
|
-
worksheets.length == 1
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def header_rows_for_worksheet key
|
|
202
|
-
if key.is_a?(Fixnum)
|
|
203
|
-
_worksheets[key]
|
|
204
|
-
else
|
|
205
|
-
worksheets.fetch(key)
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
def worksheets
|
|
210
|
-
@worksheets ||= _worksheets.inject({}.to_mash) do |memo,ws|
|
|
211
|
-
key = ws.title.strip.downcase.underscore.gsub(/\s+/,'_')
|
|
212
|
-
memo[key] = ws
|
|
213
|
-
memo
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def _worksheets
|
|
218
|
-
@_worksheets ||= spreadsheet.worksheets
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def spreadsheet
|
|
222
|
-
@spreadsheet ||= session.spreadsheet_by_key(spreadsheet_key)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
end
|