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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -11
  3. data/bin/skypager +16 -10
  4. data/lib/skypager.rb +1 -69
  5. data/lib/skypager/cli.rb +14 -0
  6. data/lib/skypager/cli/01_extensions.rb +25 -0
  7. data/lib/skypager/cli/config.rb +41 -0
  8. data/lib/skypager/proxy.rb +0 -10
  9. data/lib/skypager/version.rb +1 -1
  10. data/skypager.gemspec +1 -15
  11. metadata +9 -216
  12. data/ARCHITECTURE.md +0 -34
  13. data/CONTRIBUTING.md +0 -7
  14. data/LICENSE.txt +0 -22
  15. data/bin/bootstrap.sh +0 -29
  16. data/examples/.gitignore +0 -4
  17. data/examples/blog-site/.gitignore +0 -18
  18. data/examples/blog-site/.pryrc +0 -4
  19. data/examples/blog-site/Gemfile +0 -8
  20. data/examples/blog-site/config.rb +0 -17
  21. data/examples/blog-site/data/dropbox.json +0 -1
  22. data/examples/blog-site/source/images/background.png +0 -0
  23. data/examples/blog-site/source/images/middleman.png +0 -0
  24. data/examples/blog-site/source/index.html.erb +0 -10
  25. data/examples/blog-site/source/javascripts/all.js +0 -1
  26. data/examples/blog-site/source/layouts/layout.erb +0 -19
  27. data/examples/blog-site/source/posts/introduction-to-skypager.html.md +0 -23
  28. data/examples/blog-site/source/posts/skypager-and-dnsimple-and-amazon-web-services-combo.html.md +0 -9
  29. data/examples/blog-site/source/stylesheets/all.css +0 -55
  30. data/examples/blog-site/source/stylesheets/normalize.css +0 -375
  31. data/examples/gallery-site/.gitignore +0 -18
  32. data/examples/gallery-site/.pryrc +0 -4
  33. data/examples/gallery-site/Gemfile +0 -11
  34. data/examples/gallery-site/config.rb +0 -38
  35. data/examples/gallery-site/data/dropbox.json +0 -1
  36. data/examples/gallery-site/data/galleries.json +0 -1
  37. data/examples/gallery-site/source/gallery.html.erb +0 -7
  38. data/examples/gallery-site/source/images/background.png +0 -0
  39. data/examples/gallery-site/source/images/galleries/cristian-gallery-1/001.jpg +0 -0
  40. data/examples/gallery-site/source/images/galleries/cristian-gallery-1/002.jpg +0 -0
  41. data/examples/gallery-site/source/images/galleries/cristian-gallery-1/003.jpg +0 -0
  42. data/examples/gallery-site/source/images/galleries/cristian-gallery-1/004.jpg +0 -0
  43. data/examples/gallery-site/source/images/galleries/luca-gallery-1/001.jpg +0 -0
  44. data/examples/gallery-site/source/images/galleries/luca-gallery-1/002.JPG +0 -0
  45. data/examples/gallery-site/source/images/galleries/luca-gallery-1/003.jpg +0 -0
  46. data/examples/gallery-site/source/images/galleries/luca-gallery-1/004.JPG +0 -0
  47. data/examples/gallery-site/source/images/middleman.png +0 -0
  48. data/examples/gallery-site/source/index.html.erb +0 -10
  49. data/examples/gallery-site/source/javascripts/all.js +0 -1
  50. data/examples/gallery-site/source/layouts/layout.erb +0 -20
  51. data/examples/gallery-site/source/stylesheets/all.css +0 -0
  52. data/examples/gallery-site/source/stylesheets/normalize.css +0 -375
  53. data/examples/gallery-site/source/tutorial.md +0 -151
  54. data/lib/skypager/builder.rb +0 -158
  55. data/lib/skypager/cli/commands/build.rb +0 -64
  56. data/lib/skypager/cli/commands/config.rb +0 -58
  57. data/lib/skypager/cli/commands/create.rb +0 -98
  58. data/lib/skypager/cli/commands/deploy.rb +0 -62
  59. data/lib/skypager/cli/commands/edit.rb +0 -32
  60. data/lib/skypager/cli/commands/list.rb +0 -12
  61. data/lib/skypager/cli/commands/setup.rb +0 -153
  62. data/lib/skypager/cli/commands/site.rb +0 -22
  63. data/lib/skypager/cli/commands/sync.rb +0 -20
  64. data/lib/skypager/data.rb +0 -8
  65. data/lib/skypager/data/excel_spreadsheet.rb +0 -8
  66. data/lib/skypager/data/google_spreadsheet.rb +0 -227
  67. data/lib/skypager/data/request.rb +0 -12
  68. data/lib/skypager/data/source.rb +0 -194
  69. data/lib/skypager/data/source_routes_proxy.rb +0 -30
  70. data/lib/skypager/dns.rb +0 -69
  71. data/lib/skypager/extension.rb +0 -271
  72. data/lib/skypager/middleman/commands/data.rb +0 -0
  73. data/lib/skypager/middleman/commands/deploy.rb +0 -0
  74. data/lib/skypager/middleman/commands/sync.rb +0 -0
  75. data/lib/skypager/sync.rb +0 -23
  76. data/lib/skypager/sync/amazon.rb +0 -181
  77. data/lib/skypager/sync/dropbox.rb +0 -173
  78. data/lib/skypager/sync/dropbox/delta.rb +0 -67
  79. data/lib/skypager/sync/folder.rb +0 -266
  80. data/lib/skypager/sync/github.rb +0 -55
  81. data/lib/skypager/sync/google.rb +0 -143
  82. data/spec/dummy/site-one/.gitignore +0 -18
  83. data/spec/dummy/site-one/Gemfile +0 -14
  84. data/spec/dummy/site-one/config.rb +0 -13
  85. data/spec/dummy/site-one/source/images/background.png +0 -0
  86. data/spec/dummy/site-one/source/images/middleman.png +0 -0
  87. data/spec/dummy/site-one/source/index.html.erb +0 -10
  88. data/spec/dummy/site-one/source/javascripts/all.js +0 -1
  89. data/spec/dummy/site-one/source/layouts/layout.erb +0 -19
  90. data/spec/dummy/site-one/source/stylesheets/all.css +0 -55
  91. data/spec/dummy/site-one/source/stylesheets/normalize.css +0 -375
  92. data/spec/lib/skypager/builder/server_spec.rb +0 -5
  93. data/spec/lib/skypager/configuration_spec.rb +0 -12
  94. data/spec/lib/skypager/data_spec.rb +0 -5
  95. data/spec/lib/skypager/site_spec.rb +0 -44
  96. data/spec/lib/skypager_spec.rb +0 -9
  97. data/spec/skypager-test-config.rb.example +0 -22
  98. data/spec/spec_helper.rb +0 -49
  99. data/spec/support/fixtures/cwd_config.json +0 -3
  100. data/spec/support/fixtures/home_config.json +0 -1
  101. data/spec/support/json_helper.rb +0 -7
@@ -1,266 +0,0 @@
1
- module Skypager
2
- module Sync
3
- class Folder
4
- attr_accessor :options,
5
- :cursor,
6
- :app
7
-
8
- def initialize(options={})
9
- @options = options
10
- @cursor = options.fetch(:cursor, nil)
11
- @app = options[:app]
12
- end
13
-
14
- def type
15
- options[:type]
16
- end
17
-
18
- # Used to generate the config line in the
19
- # middleman config.rb
20
- def config_line
21
- if dropbox?
22
- "dropbox_sync('#{ relative_local_path }','#{ remote_path }')"
23
- end
24
- end
25
-
26
- # Gets the reference to the dropbox folder settings for the app
27
- # which allows us to persist info about the sync state of the folder
28
- def folder_settings
29
- data = app.data.dropbox
30
- data[:folders][options[:folder]].tap {|h| h && h.symbolize_keys! }
31
- end
32
-
33
- def cursor= value
34
- folder_settings[:cursor] = value
35
- save_folder_settings
36
- end
37
-
38
- def save_folder_settings
39
- data = app.data.dropbox.dup
40
-
41
- Pathname(app.data_dir).join("dropbox.json").open('w+') do |fh|
42
- fh.write(data.to_json)
43
- end
44
- end
45
-
46
- def auto_prefix
47
- options[:site_name]
48
- end
49
-
50
- def dropbox?
51
- options[:type] == "dropbox"
52
- end
53
-
54
- def google?
55
- options[:type] == "google"
56
- end
57
-
58
- def sync(push=false)
59
- if dropbox?
60
- dropbox_pull
61
- dropbox_push_sync if push
62
- elsif google?
63
- google_sync
64
- end
65
- end
66
-
67
- def dropbox_pull
68
- delta = dropbox_delta
69
-
70
- delta.entries.each do |entry|
71
- local = matching_local_path_for(entry.path)
72
-
73
- if entry.is_deleted
74
- puts "== Removing #{ local }"
75
- local.rmtree if local.exist?
76
- elsif entry.is_dir == true
77
- unless local.exist?
78
- puts "== Creating #{ local } directory"
79
- local.mkdir
80
- end
81
- elsif entry.is_dir == false || entry.is_dir == nil
82
- puts "== Downloading #{ local }"
83
- local.open('wb+') do |fh|
84
- fh.write(entry.download)
85
- end
86
- end
87
- end
88
-
89
- self.cursor = delta.cursor
90
- end
91
-
92
- def google_sync
93
- # TODO
94
- # Implement google drive folder cloning
95
- end
96
-
97
- def files_map
98
- remotes = all_remote_files
99
-
100
- fmap = {}
101
-
102
- if dropbox?
103
- all_local_files.each do |e|
104
- remote = remotes.find do |x|
105
- "#{x[:path]}".match(/#{ e[:path] }$/)
106
- end
107
-
108
- fmap[e[:path]] = {local: e, remote: remote}
109
- end
110
- end
111
-
112
- fmap
113
- end
114
-
115
- def newer_local_files
116
- remotes = all_remote_files
117
-
118
- if dropbox?
119
- all_local_files.select do |e|
120
- remote = remotes.find do |x|
121
- "#{x[:path]}".match(/#{ e[:path] }$/)
122
- end
123
-
124
- remote.nil? || (remote[:mtime] < e[:mtime])
125
- end
126
- end
127
- end
128
-
129
- def all_dropbox_files
130
- h = lambda do |node|
131
- base = [{
132
- path: node.path,
133
- mtime: DateTime.parse(node.modified).to_i
134
- }]
135
-
136
- base += node.ls.map(&h) if node.is_dir
137
-
138
- base
139
- end
140
-
141
- dropbox_folder_files.map(&h).flatten
142
- end
143
-
144
- def dropbox_folder_files
145
- Array((dropbox_folder rescue nil).try(:ls))
146
- end
147
-
148
- def matching_local_path_for(remote)
149
- if sandboxed?
150
- parts = remote.to_s.split("/")
151
- parts.shift
152
- part = parts.join("/")
153
- local_path.join(part)
154
- else
155
- sanitized = remote.with_leading_slash.gsub(/^#{remote_path.to_s.with_leading_slash}/, '').without_leading_slash
156
- local_path.join sanitized
157
- end
158
- end
159
-
160
- def root
161
- Pathname(options[:root] || Dir.pwd)
162
- end
163
-
164
- def all_local_files
165
- h = lambda do |path|
166
- base = [{
167
- path: path.relative_path_from(local_path).to_s,
168
- realpath: path,
169
- mtime: path.mtime.to_i
170
- }]
171
-
172
- base += path.children.map(&h) if path.directory?
173
-
174
- base
175
- end
176
-
177
- local_path.children.map(&h).flatten
178
- end
179
-
180
- def all_remote_files
181
- if dropbox?
182
- all_dropbox_files
183
- else
184
-
185
- end
186
- end
187
-
188
- def relative_local_path
189
- local_path.relative_path_from(root).to_s
190
- end
191
-
192
- def local_path
193
- root.join(options[:local_path]).tap do |folder|
194
- folder.mkdir unless folder.exist?
195
- end
196
- end
197
-
198
- def synced
199
- push_sync
200
- self
201
- end
202
-
203
- def push_sync
204
- return dropbox_push_sync if dropbox?
205
- return google_push_sync if google?
206
- end
207
-
208
- def dropbox_push_sync
209
- api = Skypager.dropbox.api
210
-
211
- newer_local_files.each do |entry|
212
- target = "#{ path_prefix }/#{ entry[:path] }"
213
- target = target.gsub(/^\//,'')
214
-
215
- puts "== Attempting to sync #{ entry[:realpath] } to #{ target }"
216
-
217
- if entry[:realpath].file?
218
- api.upload(target, entry[:realpath].read, overwrite: true)
219
- end
220
- end
221
- end
222
-
223
- def google_push_sync
224
-
225
- end
226
-
227
- def dropbox_folder
228
- Skypager.dropbox.find(path_prefix)
229
- end
230
-
231
- def remote_path
232
- options[:remote_path].to_s
233
- end
234
-
235
- def sandboxed?
236
- Skypager.config.dropbox_app_type == "sandbox"
237
- end
238
-
239
- # Which path do we scope our delta calls to?
240
- def path_prefix
241
- if sandboxed?
242
- if remote_path.match(/^\/#{ options[:site_name] }/)
243
- remote_path
244
- else
245
- "/#{ options[:site_name] }/#{ remote_path.gsub(/^\//,'') }"
246
- end
247
- else
248
- unless remote_path.match(/^\//)
249
- return "/#{ remote_path }"
250
- end
251
-
252
- remote_path
253
- end
254
- end
255
-
256
- def has_remote_changes?
257
- dropbox_delta.entries.length > 0
258
- end
259
-
260
- def dropbox_delta
261
- @dropbox_delta ||= Skypager.dropbox.delta(cursor, path_prefix: path_prefix)
262
- end
263
-
264
- end
265
- end
266
- end
@@ -1,55 +0,0 @@
1
- module Skypager
2
- module Sync
3
- class Github
4
- include Singleton
5
-
6
- def self.method_missing(meth, *args, &block)
7
- if client.respond_to?(meth)
8
- return client.send(meth, *args, &block)
9
- end
10
-
11
- super
12
- end
13
-
14
- def self.client(options={})
15
- @client ||= begin
16
- instance.with_options(options)
17
- end
18
- end
19
-
20
- def options
21
- @options ||= {}
22
- end
23
-
24
- def with_options(opts={})
25
- options.merge!(opts)
26
- self
27
- end
28
-
29
- def api
30
- @api ||= begin
31
- Octokit::Client.new(access_token: Skypager.config.github_access_token)
32
- end
33
- end
34
-
35
- def setup(options={})
36
- access_token = options[:github_access_token] || Skypager.config.github_access_token
37
-
38
- unless access_token.to_s.length == 40
39
- puts "You should generate an access token to use with the Github client."
40
- puts "Access tokens allow you to revoke and/or limit access if needed."
41
- puts "To learn more about access tokens, and how to generate them, visit: https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
42
-
43
- access_token = ask("Enter a 40 character access token when you have one", String)
44
- end
45
-
46
- unless access_token.to_s.length == 40
47
- puts "Can not proceed without a valid access token: error code #{ access_token.length }"
48
- return
49
- end
50
-
51
- Skypager.config.set(:github_access_token, access_token)
52
- end
53
- end
54
- end
55
- end
@@ -1,143 +0,0 @@
1
- module Skypager
2
- module Sync
3
- class Google
4
- include Singleton
5
-
6
- def self.method_missing(meth, *args, &block)
7
- if client.respond_to?(meth)
8
- return client.send(meth, *args, &block)
9
- end
10
-
11
- super
12
- end
13
-
14
- def self.client(options={})
15
- @client ||= begin
16
- instance.with_options(options)
17
- end
18
- end
19
-
20
- def refreshable?
21
- has_application_keys? && has_refresh_token?
22
- end
23
-
24
- # Runs through an interactive session where we get the
25
- # necessary tokens needed to integrate with google drive.
26
- def setup(options={})
27
- get_application_keys unless has_application_keys?
28
-
29
- if options[:client_id]
30
- Skypager.config.set "google_client_id", options[:client_id]
31
- end
32
-
33
- if options[:client_secret]
34
- Skypager.config.set "google_client_secret", options[:client_secret]
35
- end
36
-
37
- if has_refresh_token?
38
- refresh_access_token!
39
- else
40
- Launchy.open(auth_client.authorization_uri)
41
- say("\n1. Open this page:\n%s\n\n" % auth_client.authorization_uri)
42
- auth_client.code = ask("2. Enter the authorization code shown in the page: ", String)
43
- auth_client.fetch_access_token!
44
- Skypager.config.set "google_refresh_token", auth_client.refresh_token
45
- Skypager.config.set "google_access_token", auth_client.access_token
46
- end
47
- end
48
-
49
- def session
50
- api
51
- end
52
-
53
- def api
54
- @api ||= begin
55
- refresh_access_token!
56
- GoogleDrive.login_with_oauth(Skypager.config.google_access_token)
57
- end
58
- end
59
-
60
- def method_missing meth, *args, &block
61
- if api.respond_to?(meth)
62
- return api.send(meth, *args, &block)
63
- end
64
-
65
- super
66
- end
67
-
68
- def authorize(token, secret)
69
- @api = nil if @api
70
- options[:token] = token
71
- options[:secret] = secret
72
- self
73
- end
74
-
75
- def options
76
- @options ||= {}
77
- end
78
-
79
- def with_options(opts={})
80
- options.merge!(opts)
81
- self
82
- end
83
-
84
- def has_application_keys?
85
- (Skypager.config.google_client_id.to_s.length > 0 && Skypager.config.google_client_secret.to_s.length > 0)
86
- end
87
-
88
- def get_application_keys
89
- unless Skypager.config.google_client_id.to_s.length > 0
90
- google_client_id = ask("What is the Google Client ID?", String)
91
- Skypager.config.set "google_client_id", google_client_id
92
- end
93
-
94
- unless Skypager.config.google_client_secret.to_s.length > 0
95
- google_client_secret = ask("What is the Google Client Secret?", String)
96
- Skypager.config.set "google_client_secret", google_client_secret
97
- end
98
- end
99
-
100
- def auth_client
101
- return @auth_client if @auth_client
102
-
103
- client = ::Google::APIClient.new(
104
- :application_name => "google_drive Ruby library",
105
- :application_version => "0.3.11"
106
- )
107
-
108
- client_id = "452925651630-egr1f18o96acjjvphpbbd1qlsevkho1d.apps.googleusercontent.com"
109
- client_secret = "1U3-Krii5x1oLPrwD5zgn-ry"
110
-
111
- @auth_client = auth = client.authorization
112
- auth.client_id = client_id #Skypager.config.google_client_id
113
- auth.client_secret = client_secret #Skypager.config.google_client_secret
114
- auth.scope =
115
- "https://www.googleapis.com/auth/drive " +
116
- "https://spreadsheets.google.com/feeds/ " +
117
- "https://docs.google.com/feeds/ " +
118
- "https://docs.googleusercontent.com/"
119
-
120
- auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
121
-
122
- auth
123
- end
124
-
125
- def refresh_token
126
- Skypager.config.google_refresh_token.to_s
127
- end
128
-
129
- def has_refresh_token?
130
- refresh_token.length > 0
131
- end
132
-
133
- def refresh_access_token!
134
- if has_refresh_token?
135
- auth_client.refresh_token = refresh_token
136
- auth_client.fetch_access_token!
137
- Skypager.config.set "google_access_token", auth_client.access_token
138
- end
139
- end
140
-
141
- end
142
- end
143
- end