siteleaf 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2dcab015e55d6e78bb8f1288441b05631455b87
4
- data.tar.gz: aa7ca707564c6aceec0493dc2e24a6c28924fe39
3
+ metadata.gz: b58e2191052b78089839ad0f0b413ffd3a621f96
4
+ data.tar.gz: 6da80855926d96b93ab727d976d76a6dc3c69056
5
5
  SHA512:
6
- metadata.gz: 4eb1f8dbda44ccf87e0becffb562444aaa8696ff56b92bd5076dc58effe0e6b8d1f6a8cdc88a8327d89f19f23ed5261503d148b8c192d634e2f3e9ad33250bc7
7
- data.tar.gz: f49b40a6d213e78bb04c118f8aeb96b49c450eab53c997efb6db3da264d12eb604b1ce41fd0a6d552725945f69c38db820ec27b06511b574702754d272e5e58a
6
+ metadata.gz: 0dd932d6d6f2c16e996ef39609914b906f9c3069838af7f37db3fa9eca8c3248d1c6848eb2281ae4f5de40d8917803460c9b567cc021adc0b59d8440bc25d8f3
7
+ data.tar.gz: 3818d0f20838566907748e7aab27d3bc9c80b2af7dada8a01759460b93421767d938e008e76c7aecee6dd062b0ed4cf1afd626bac160c685c43ac70b977c2d42
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'siteleaf'
4
+ require 'jekyll'
4
5
  require 'fileutils'
6
+ require 'pathutil'
5
7
  require 'open-uri'
6
8
  require 'tempfile'
7
9
  require 'yaml'
@@ -30,9 +32,9 @@ See https://github.com/siteleaf/siteleaf-gem for additional documentation.
30
32
  end
31
33
 
32
34
  def auth(re_auth = false)
33
- Siteleaf.load_settings if !re_auth && !Siteleaf.api_key
35
+ Siteleaf.load_settings if !re_auth && !(Siteleaf.api_key && Siteleaf.api_secret)
34
36
 
35
- if re_auth or !Siteleaf.api_key
37
+ if re_auth or !(Siteleaf.api_key && Siteleaf.api_secret)
36
38
  print 'Enter your Siteleaf email: '
37
39
  email = $stdin.gets.chomp
38
40
 
@@ -42,18 +44,17 @@ def auth(re_auth = false)
42
44
  system 'stty echo'
43
45
 
44
46
  puts "\nAuthorizing..."
45
-
46
- if (auth = Siteleaf::Client.auth(email, password)) && (auth.is_a?(Hash)) && (auth.has_key?('api_key'))
47
+
48
+ auth = Siteleaf::Client.auth(email, password)
49
+ if auth.is_a?(Hash) && auth.has_key?('api_key')
47
50
  Siteleaf.save_settings({api_key: auth['api_key'], api_secret: auth['api_secret']})
48
- puts "=> Gem authorized." if re_auth
51
+ Siteleaf.load_settings
52
+ puts "=> Account authorized." if re_auth
49
53
  return true
50
54
  else
51
- puts auth['error'] || "Could not authorize, check your email or password."
52
- return false
55
+ raise "Could not authorize, check your email or password."
53
56
  end
54
57
  end
55
- rescue Exception => e
56
- print "Error: #{e.message}\n"
57
58
  end
58
59
 
59
60
  def pull(site_id)
@@ -100,8 +101,6 @@ def pull(site_id)
100
101
  puts "=> #{missing_files.size} file(s) deleted.\n"
101
102
  end
102
103
  end
103
- rescue Exception => e
104
- print "Error: #{e.message}\n"
105
104
  end
106
105
 
107
106
  def push(site_id)
@@ -109,6 +108,7 @@ def push(site_id)
109
108
 
110
109
  # get all the things
111
110
  site = Siteleaf::Site.find(site_id)
111
+
112
112
  site_files = site.source_files('.', recursive: true)
113
113
  local_files = read_dir
114
114
  updated_count = 0
@@ -124,12 +124,11 @@ def push(site_id)
124
124
  changed_files.each do |path|
125
125
  print "Uploading #{path}..."
126
126
  response = Siteleaf::SourceFile.create(site_id: site_id, name: path, file: ::File.new(path))
127
- if error = !response || response.error || response.message
128
- print (error) ? "error: #{error}\n" : "error.\n"
129
- return
130
- else
131
- updated_count += 1
132
- print "complete.\n"
127
+ updated_count += 1
128
+ print "complete.\n"
129
+ if response.name && response.name != path
130
+ local_files.push(response.name)
131
+ puts "Warning: Remote filename has been normalized to `#{response.name}`."
133
132
  end
134
133
  end
135
134
 
@@ -155,8 +154,6 @@ def push(site_id)
155
154
  puts "=> #{missing_assets.size} file(s) deleted.\n"
156
155
  end
157
156
  end
158
- rescue Exception => e
159
- print "Error: #{e.message}\n"
160
157
  end
161
158
 
162
159
  def import(file, quiet = true)
@@ -174,8 +171,6 @@ def import(file, quiet = true)
174
171
  end
175
172
  puts "=> Import completed.\n"
176
173
  end
177
- rescue Exception => e
178
- print "Error: #{e.message}\n"
179
174
  end
180
175
 
181
176
  def publish(site_id, quiet = true)
@@ -194,8 +189,6 @@ def publish(site_id, quiet = true)
194
189
  end
195
190
  puts "=> Publish completed.\n"
196
191
  end
197
- rescue Exception => e
198
- print "Error: #{e.message}\n"
199
192
  end
200
193
 
201
194
  def config(site)
@@ -217,94 +210,98 @@ def get_site_id
217
210
  end
218
211
 
219
212
  def read_dir
220
- jekyll_config = ::File.exist?('_config.yml') ? YAML::load(::File.read('_config.yml')) : {}
213
+ jekyll_site = Jekyll::Site.new(Jekyll.configuration(quiet: true))
221
214
 
222
215
  ignore_paths = ['config.ru', '.*', '_site/*', 'Gemfile', 'Gemfile.lock']
223
216
  ignore_paths += ::File.read('.siteleafignore').split(/\r?\n/) if ::File.exists?('.siteleafignore')
224
- ignore_paths += jekyll_config['exclude'] if jekyll_config['exclude'].is_a? Array
217
+ ignore_paths += jekyll_site.exclude
218
+
219
+ entry_filter = Jekyll::EntryFilter.new(jekyll_site)
225
220
 
226
221
  Dir.glob("**/*").reject do |path|
227
- ::File.directory?(path) ||
228
- ignore_paths.any? {|i| ::File.fnmatch?(i, path, File::FNM_CASEFOLD) || ::File.fnmatch?(i, ::File.basename(path), File::FNM_CASEFOLD) }
222
+ ::File.directory?(path) || entry_filter.glob_include?(ignore_paths, path)
229
223
  end
230
224
  end
231
225
 
232
- case ARGV[0]
233
- when '-v', '--version', 'version'
234
- puts Siteleaf::VERSION
235
- when '-h', '--help', 'help'
236
- puts help
237
- when 'auth'
238
- auth true
239
- when 'c', 'config', 'setup'
240
- if auth != false
241
- if site = Siteleaf::Site.find_by_domain(ARGV[1])
242
- config site
243
- else
244
- puts "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n"
226
+ begin
227
+ case ARGV[0]
228
+ when '-v', '--version', 'version'
229
+ puts Siteleaf::VERSION
230
+ when '-h', '--help', 'help'
231
+ puts help
232
+ when 'auth'
233
+ auth true
234
+ when 'c', 'config', 'setup'
235
+ if auth != false
236
+ if site = Siteleaf::Site.find_by_domain(ARGV[1])
237
+ config site
238
+ else
239
+ raise "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n"
240
+ end
245
241
  end
246
- end
247
- when 'n', 'new'
248
- if auth != false
249
- if (site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])) && (!site.error)
242
+ when 'n', 'new'
243
+ if auth != false
244
+ site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])
250
245
  dir = ARGV.size >= 3 ? ARGV[2] : ARGV[1]
251
246
  Dir.mkdir(dir) unless ::File.directory?(dir)
252
247
  Dir.chdir(dir)
253
248
  config site
249
+ end
250
+ when 'pull'
251
+ if ARGV.size == 1
252
+ site_id = get_site_id
253
+ if auth != false
254
+ if site_id
255
+ pull(site_id)
256
+ else
257
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
258
+ end
259
+ end
254
260
  else
255
- puts "Could not create site `#{ARGV[1]}`.\n"
261
+ raise "`#{ARGV.join(' ')}` command not found.\n"
256
262
  end
257
- end
258
- when 'pull'
259
- if ARGV.size == 1
263
+ when 'push'
264
+ if ARGV.size == 1
265
+ site_id = get_site_id
266
+ if auth != false
267
+ if site_id
268
+ push(site_id)
269
+ else
270
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
271
+ end
272
+ end
273
+ else
274
+ raise "`#{ARGV.join(' ')}` command not found.\n"
275
+ end
276
+ when 'publish'
260
277
  site_id = get_site_id
261
278
  if auth != false
279
+ quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
262
280
  if site_id
263
- pull(site_id)
281
+ publish(site_id, quiet)
264
282
  else
265
- puts "Site not configured, run `siteleaf config yoursite.com`.\n"
283
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
266
284
  end
267
285
  end
268
- else
269
- puts "`#{ARGV.join(' ')}` command not found.\n"
270
- end
271
- when 'push'
272
- if ARGV.size == 1
286
+ when 'import'
273
287
  site_id = get_site_id
274
288
  if auth != false
275
- if site_id
276
- push(site_id)
289
+ file = ARGV[1]
290
+ if File.extname(file) != '.zip'
291
+ raise "Import file must be ZIP format.\n"
292
+ elsif !File.exist?(file)
293
+ raise "Import file not found.\n"
277
294
  else
278
- puts "Site not configured, run `siteleaf config yoursite.com`.\n"
295
+ quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
296
+ import(file, quiet)
279
297
  end
280
298
  end
281
299
  else
282
- puts "`#{ARGV.join(' ')}` command not found.\n"
283
- end
284
- when 'publish'
285
- site_id = get_site_id
286
- if auth != false
287
- quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
288
- if site_id
289
- publish(site_id, quiet)
290
- else
291
- puts "Site not configured, run `siteleaf config yoursite.com`.\n"
292
- end
300
+ puts "Error: `#{ARGV[0]}` command not found.\n"
301
+ puts help
302
+ exit(1)
293
303
  end
294
- when 'import'
295
- site_id = get_site_id
296
- if auth != false
297
- file = ARGV[1]
298
- if File.extname(file) != '.zip'
299
- puts "Import file must be ZIP format.\n"
300
- elsif !File.exist?(file)
301
- puts "Import file not found.\n"
302
- else
303
- quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
304
- import(file, quiet)
305
- end
306
- end
307
- else
308
- puts "`#{ARGV[0]}` command not found.\n"
309
- puts help
304
+ rescue Exception => e
305
+ puts "Error: #{e.message}\n"
306
+ exit(1)
310
307
  end
@@ -1,17 +1,17 @@
1
- require 'httmultiparty'
1
+ require 'httparty'
2
2
 
3
3
  module Siteleaf
4
4
  class Client
5
5
  def self.auth(email, password)
6
- begin
7
- request = HTTParty.post(Siteleaf.api_url('auth'), {
8
- :basic_auth => {:username => email, :password => password},
9
- :headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"}
10
- })
11
- return request.parsed_response # parse JSON
12
- rescue => e
13
- return 'error' => e.message # error
6
+ request = HTTParty.post(Siteleaf.api_url('auth'), {
7
+ :basic_auth => {:username => email, :password => password},
8
+ :headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"}
9
+ })
10
+ response = request.parsed_response
11
+ if response.is_a?(Hash) && error = response['message'] || response['error']
12
+ raise error
14
13
  end
14
+ response
15
15
  end
16
16
 
17
17
  def self.get(path, params = {})
@@ -33,33 +33,28 @@ module Siteleaf
33
33
 
34
34
  def self.execute(method, path, params = nil)
35
35
  Siteleaf.load_settings if !Siteleaf.api_key
36
- begin
37
- if (method == :post || method == :put) && !params.has_key?('file') && !params.has_key?(:file)
38
- request = HTTParty.send(method, Siteleaf.api_url(path), {
39
- :body => params.to_json,
40
- :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
41
- :headers => {
42
- "Content-Type" => "application/json",
43
- "User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"
44
- },
45
- :timeout => 300
46
- })
47
- else
48
- request = HTTMultiParty.send(method, Siteleaf.api_url(path), {
49
- :query => params,
50
- :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
51
- :headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"},
52
- :timeout => 300
53
- })
54
- end
55
- if request.respond_to?('parsed_response')
56
- return request.parsed_response # parse JSON
57
- else
58
- return request # raw
59
- end
60
- rescue => e
61
- return 'error' => e.message # error
36
+
37
+ options = {
38
+ :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
39
+ :headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"},
40
+ :timeout => 300
41
+ }
42
+
43
+ if method == :get || method == :delete
44
+ options[:query] = params
45
+ elsif params.has_key?('file') || params.has_key?(:file)
46
+ options[:body] = params
47
+ else
48
+ options[:body] = params.to_json
49
+ options[:headers]["Content-Type"] = "application/json"
62
50
  end
51
+
52
+ request = HTTParty.send(method, Siteleaf.api_url(path), options)
53
+ response = request.parsed_response
54
+ if response.is_a?(Hash) && error = response['message'] || response['error']
55
+ raise error
56
+ end
57
+ response
63
58
  end
64
59
  end
65
60
  end
@@ -22,12 +22,12 @@ module Siteleaf
22
22
 
23
23
  def documents
24
24
  result = Client.get "#{entity_endpoint}/documents"
25
- result.map { |r| Document.new(r) } if result.parsed_response.is_a? Array
25
+ result.map { |r| Document.new(r) } if result.is_a? Array
26
26
  end
27
27
 
28
28
  def files
29
29
  result = Client.get "#{entity_endpoint}/files"
30
- result.map { |r| File.new(r) } if result.parsed_response.is_a? Array
30
+ result.map { |r| File.new(r) } if result.is_a? Array
31
31
  end
32
32
 
33
33
  def output?
@@ -39,4 +39,4 @@ module Siteleaf
39
39
  end
40
40
 
41
41
  end
42
- end
42
+ end
@@ -9,7 +9,7 @@ module Siteleaf
9
9
 
10
10
  def self.all
11
11
  result = Client.get endpoint
12
- result.map { |r| new(r) } if result.parsed_response.is_a? Array
12
+ result.map { |r| new(r) } if result.is_a? Array
13
13
  end
14
14
 
15
15
  def self.find(identifier)
@@ -31,9 +31,11 @@ module Siteleaf
31
31
  else
32
32
  result = Client.post create_endpoint, attributes
33
33
  end
34
- if result
34
+ if result.is_a?(Hash)
35
35
  self.attributes = result
36
36
  return self
37
+ else
38
+ raise 'Invalid response'
37
39
  end
38
40
  end
39
41
 
@@ -17,17 +17,17 @@ module Siteleaf
17
17
 
18
18
  def source_files(dir = '.', opts = {})
19
19
  result = Client.get ::File.join(entity_endpoint, "source", dir), opts
20
- result.map { |r| SourceFile.new(r.merge('site_id' => id)) } if result.parsed_response.is_a? Array
20
+ result.map { |r| SourceFile.new(r.merge('site_id' => id)) } if result.is_a? Array
21
21
  end
22
22
 
23
23
  def pages
24
24
  result = Client.get "#{entity_endpoint}/pages"
25
- result.map { |r| Page.new(r) } if result.parsed_response.is_a? Array
25
+ result.map { |r| Page.new(r) } if result.is_a? Array
26
26
  end
27
27
 
28
28
  def collections
29
29
  result = Client.get "#{entity_endpoint}/collections"
30
- result.map { |r| Collection.new(r) } if result.parsed_response.is_a? Array
30
+ result.map { |r| Collection.new(r) } if result.is_a? Array
31
31
  end
32
32
 
33
33
  def posts
@@ -56,4 +56,4 @@ module Siteleaf
56
56
  end
57
57
 
58
58
  end
59
- end
59
+ end
@@ -17,10 +17,8 @@ module Siteleaf
17
17
  end
18
18
 
19
19
  def to_file
20
- response = Client.get(::File.join("sites", site_id, "source", "#{URI.escape(identifier)}?download"))
21
- raise response['message'] if response.parsed_response.is_a?(Hash) && response['message'] # indicates API error
22
- response.body
20
+ Client.get(::File.join("sites", site_id, "source", "#{URI.escape(identifier)}?download"))
23
21
  end
24
22
 
25
23
  end
26
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Siteleaf
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -11,13 +11,13 @@ Gem::Specification.new do |gem|
11
11
  gem.email = ["api@siteleaf.com"]
12
12
  gem.description = %q{A Ruby interface and command line utility for the Siteleaf API.}
13
13
  gem.summary = "Siteleaf Ruby interface"
14
- gem.homepage = "http://siteleaf.com"
14
+ gem.homepage = "https://www.siteleaf.com"
15
15
 
16
16
  gem.required_ruby_version = '>= 1.9.3'
17
17
 
18
- gem.add_dependency 'httparty', '~> 0.14.0'
19
- gem.add_dependency 'httmultiparty', '~> 0.3.13'
20
- gem.add_dependency 'psych', '>= 2.0.17'
18
+ gem.add_dependency 'httparty', '>= 0.16.0'
19
+ gem.add_dependency 'psych', '>= 2.1.0'
20
+ gem.add_dependency 'jekyll', '>= 1.4.1'
21
21
  gem.add_dependency 'rack'
22
22
 
23
23
  gem.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: siteleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siteleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-01 00:00:00.000000000 Z
11
+ date: 2018-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.0
19
+ version: 0.16.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.14.0
26
+ version: 0.16.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: httmultiparty
28
+ name: psych
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.13
33
+ version: 2.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.13
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: psych
42
+ name: jekyll
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.17
47
+ version: 1.4.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.17
54
+ version: 1.4.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ files:
96
96
  - lib/siteleaf/user.rb
97
97
  - lib/siteleaf/version.rb
98
98
  - siteleaf.gemspec
99
- homepage: http://siteleaf.com
99
+ homepage: https://www.siteleaf.com
100
100
  licenses:
101
101
  - MIT
102
102
  metadata: {}
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.5.1
119
+ rubygems_version: 2.6.13
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Siteleaf Ruby interface