photo-helper 0.2.0 → 0.2.1

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: 74fe4a8df21965e6b330ce5f80b52602a26b447a
4
- data.tar.gz: f77f8d97e6e3019e948de0edb00bd61f58b8d92c
3
+ metadata.gz: 10936e1f4337f7ca26a766b16b69fe7a955b5e9d
4
+ data.tar.gz: 2b9a13e9b775b1974441c5933a9189299da634af
5
5
  SHA512:
6
- metadata.gz: 3aec807f26f222bf5764fc2213c5efa75f88168fe24fa67c59d4bd0bd6cc8663580bb3bb0d8ff1deb08842c3a604e3bac02c77c2943426682dcf758a72d0765c
7
- data.tar.gz: 0d8a2ec77bc0b2e5825cafa386bcc0a7b9ded76a538f3d21ef1065585270174001474cdf1bd6a918f9cf292ad3a33e4fe2cd574376c6791e8563a8367c2a12f5
6
+ metadata.gz: 8626562041251a2d8f867fea3579d14dda11114c36d9934db2e6569248e2ee13a6cce1b1e8ca213b760aa6b47e5db29e0e401549a564b339cbb969a9972377c3
7
+ data.tar.gz: 7117f97c2b55af7fa1469c2c16d641cc6e64730e2dc2011980aef39ac0454ebd9d4f5690f362eff21bb623e4b2ee75b22a5ba6a644408ea4d4b5e0cb94af7ef9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- photo-helper (0.2.0)
4
+ photo-helper (0.2.1)
5
5
  ejson
6
6
  mimemagic
7
7
  mini_magick
data/bin/photo-helper CHANGED
@@ -7,4 +7,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
7
 
8
8
  require 'photo_helper'
9
9
 
10
+ require 'byebug'
11
+
10
12
  PhotoHelper::CLI.start(ARGV)
@@ -5,7 +5,10 @@ require 'pathname'
5
5
  require 'json'
6
6
 
7
7
  class Secrets
8
+ attr_reader :ejson_config_file
9
+
8
10
  def initialize(config_file = nil, required = [])
11
+ @ejson_config_file = config_file
9
12
  @secrets = {}
10
13
  unless config_file.nil?
11
14
  load_from_ejson(config_file)
@@ -52,6 +55,10 @@ class Secrets
52
55
  required.each { |key| raise "required secrets not set: #{key}" if @secrets[key].nil? }
53
56
  end
54
57
 
58
+ def [](key)
59
+ @secrets[key.to_sym]
60
+ end
61
+
55
62
  def method_missing(key, *args)
56
63
  value = @secrets[key]
57
64
  return value unless value.nil?
@@ -12,12 +12,12 @@ class SmugmugAPI
12
12
  ACCESS_TOKEN_URL = '/services/oauth/1.0a/getAccessToken'.freeze
13
13
  AUTHORIZE_URL = '/services/oauth/1.0a/authorize'.freeze
14
14
  API_ENDPOINT = 'https://api.smugmug.com'.freeze
15
- UPLOAD_ENDPOINT = 'http://upload.smugmug.com/'.freeze
15
+ UPLOAD_ENDPOINT = 'https://upload.smugmug.com/'.freeze
16
16
 
17
17
  def initialize(ejson_file = '~/.photo_helper.ejson')
18
18
  ejson_file = File.expand_path(ejson_file)
19
19
  @secrets = Secrets.new(ejson_file, %i[api_key api_secret])
20
- get_access_token if !@secrets.access_token || !@secrets.access_secret
20
+ request_access_token if !@secrets["access_token"] || !@secrets["access_secret"]
21
21
 
22
22
  @http = get_access_token
23
23
  @uploader = get_access_token(UPLOAD_ENDPOINT)
@@ -54,7 +54,8 @@ class SmugmugAPI
54
54
  name: node['Name'],
55
55
  web_uri: node['WebUri'],
56
56
  node_uri: node['Uri'],
57
- id: File.basename(node['Uris']['Album']['Uri']))
57
+ id: File.basename(node['Uris']['Album']['Uri']),
58
+ type: 'node')
58
59
  end
59
60
  end
60
61
  album_list
@@ -102,10 +103,10 @@ class SmugmugAPI
102
103
  resp = post(url, Name: album_name,
103
104
  UrlName: album_url.tr(' ', '-').capitalize,
104
105
  Privacy: 'Unlisted',
105
- SmugSearchable: "No",
106
- SortMethod: "Date Taken",
107
- LargestSize: "X4Large",
108
- SortDirection: "Ascending",
106
+ SmugSearchable: 'No',
107
+ SortMethod: 'Date Taken',
108
+ LargestSize: 'X4Large',
109
+ SortDirection: 'Ascending',
109
110
  WorldSearchable: false,
110
111
  EXIF: false,
111
112
  Printable: false,
@@ -210,12 +211,38 @@ class SmugmugAPI
210
211
  end
211
212
  end
212
213
 
213
- private
214
-
215
214
  def request_access_token
216
- raise 'Not Implemented'
215
+ @consumer = OAuth::Consumer.new(@secrets.api_key, @secrets.api_secret,
216
+ site: OAUTH_ORIGIN,
217
+ name: 'photo-helper',
218
+ request_token_path: REQUEST_TOKEN_URL,
219
+ authorize_path: AUTHORIZE_URL,
220
+ access_token_path: ACCESS_TOKEN_URL)
221
+
222
+ # Generate request token
223
+ @request_token = @consumer.get_request_token
224
+
225
+ # Get authorize URL
226
+ @request_token.authorize_url
227
+
228
+ url = add_auth_params(@request_token.authorize_url, 'Access' => 'Full', 'Permissions' => 'Modify')
229
+
230
+ puts "Go to #{url} and enter shown 6 digit number:"
231
+ verifier = STDIN.gets.strip
232
+
233
+ # Now go to that url and when you're done authorization you can run the
234
+ # following command where you put in the value for oauth_verifier that you got
235
+ # from completely the above URL request:
236
+ access_token = @request_token.get_access_token(oauth_verifier: verifier)
237
+
238
+ puts "Add the following to your ejson file #{@secrets.ejson_config_file}:"
239
+ puts "\"access_token\": \"#{access_token.token}\","
240
+ puts "\"access_secret\": \"#{access_token.secret}\""
241
+ exit 0
217
242
  end
218
243
 
244
+ private
245
+
219
246
  def http_raw(method, url, headers = {}, _body = nil)
220
247
  url.tr!(' ', '-')
221
248
  headers['Accept'] = 'application/json'
@@ -265,4 +292,12 @@ class SmugmugAPI
265
292
  type: 'image'
266
293
  }
267
294
  end
295
+
296
+ def add_auth_params(url, params)
297
+ uri = URI.parse(url)
298
+ new_query_ar = URI.decode_www_form(uri.query || '')
299
+ params.to_a.each { |el| new_query_ar << el }
300
+ uri.query = URI.encode_www_form(new_query_ar)
301
+ uri.to_s
302
+ end
268
303
  end
@@ -22,9 +22,9 @@ module PhotoHelper
22
22
 
23
23
  files =
24
24
  if options[:recursive]
25
- Dir["#{search_path}/**/*.#{JPEG_EXTENSION}"]
25
+ Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(",")}}"]
26
26
  else
27
- Dir["#{search_path}/*.#{JPEG_EXTENSION}"]
27
+ Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(",")}}"]
28
28
  end
29
29
 
30
30
  files.each do |file|
@@ -22,9 +22,9 @@ module PhotoHelper
22
22
 
23
23
  files =
24
24
  if options[:recursive]
25
- Dir["#{search_path}/**/*.#{JPEG_EXTENSION}"]
25
+ Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(",")}}"]
26
26
  else
27
- Dir["#{search_path}/*.#{JPEG_EXTENSION}"]
27
+ Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(",")}}"]
28
28
  end
29
29
 
30
30
  files.each do |file|
@@ -33,9 +33,9 @@ module PhotoHelper
33
33
  puts "Using album: #{album_name}"
34
34
 
35
35
  @smugmug = SmugmugAPI.new
36
- album = @smugmug.get_or_create_album(album_name, album_url: location.downcase)
36
+ album = @smugmug.get_or_create_album(album_name, album_url: location&.downcase)
37
37
  puts "#{album[:web_uri]}\n"
38
- pictures = Dir["#{search_path}/**/*.JPG"]
38
+ pictures = Dir["#{search_path}/**/*.{#{IMAGE_EXTENSIONS.join(",")}}"]
39
39
 
40
40
  # remove uploaded pictures
41
41
  uploaded = @smugmug.image_list(album[:id])
@@ -44,5 +44,32 @@ module PhotoHelper
44
44
 
45
45
  @smugmug.upload_images(pictures, album[:id], workers: 8)
46
46
  end
47
+
48
+ desc 'oauth', "fetch oauth credentials"
49
+ def oauth()
50
+ SmugmugAPI.new.request_access_token
51
+ end
52
+
53
+ desc 'albums', "list albums with their weburl"
54
+ method_option :folder, aliases: '-f', type: :string, default: '.'
55
+ def albums(folder = nil, album_name = nil)
56
+ @smugmug = SmugmugAPI.new
57
+ albums = @smugmug.albums_long
58
+
59
+ current_month = albums.first[:path].split("/")[1]
60
+ output = ["# Photos", "## #{current_month}"]
61
+
62
+ albums.each do |a|
63
+ month = a[:path].split("/")[1]
64
+ next unless month
65
+ if month != current_month
66
+ current_month = month
67
+ output.push("## #{current_month}")
68
+ end
69
+ output.push("[#{a[:name]}](#{a[:web_uri].gsub('http://', 'https://')})")
70
+ end
71
+
72
+ puts output.join("\n\n")
73
+ end
47
74
  end
48
75
  end
@@ -1,3 +1,3 @@
1
1
  module KubeDeploy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/photo_helper.rb CHANGED
@@ -14,6 +14,8 @@ require 'photo-helper/smugmug'
14
14
  # RAW_EXTENSION = "ORF"
15
15
  RAW_EXTENSION = "dng"
16
16
  JPEG_EXTENSION = "JPG"
17
+ JPEG_EXTENSIONS = ["JPG", "jpg", "jpeg"]
18
+ IMAGE_EXTENSIONS = JPEG_EXTENSIONS.merge([])
17
19
  PHOTOS_ROOT = "/Users/benjamincaldwell/Pictures/Pictures"
18
20
  JPEG_ROOT ="/Users/benjamincaldwell/Pictures/jpegs"
19
21
  IGNORE_FOLDERS = ["instagram", "exported", "edited"]
@@ -25,7 +27,7 @@ module PhotoHelper
25
27
 
26
28
  desc "version", "displays installed version"
27
29
  def version
28
- puts KubeDeploy::VERSION
30
+ puts PhotoHelper::VERSION
29
31
  end
30
32
 
31
33
  register PhotoHelper::Generate, :generate, "generate", "Do something else"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photo-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Caldwell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-11 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler