image_puller 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4d6f8b3aa69adcf0996129eaf61997b38c572a8790a28b073b9b57ed443a4cf
4
- data.tar.gz: 89bc1c0fcacaf36278147e4a99500b89b318efc2b5103fc107ab05254f80e387
3
+ metadata.gz: 43694ba97ed29f91330b6e2396ff9013816b9fadb71ec2d2a00fe54fe5b7c43e
4
+ data.tar.gz: c703cdbbb9457de204130270dd367dfa8ff00dd438c87bec7d6986171d1a970b
5
5
  SHA512:
6
- metadata.gz: afabc83d0bd69cd3ca1ee343a792e94d3f968c4373efec8c754a1075a7521518b11ee4ed387ce690a0f72bf92a9bd0bc37ab171a3a2bb9053303f0cd5ead9236
7
- data.tar.gz: 7258cc5690096c4bab21ee6a76e087cf1ece5cc0874dbdf69d4d6a985e948a44621bcfac22143d1618a5ee0b408ef122f5fc7963fd8254d030cd50efab54b04e
6
+ metadata.gz: f3bdfe322a634d52c0ed34c725beda608b3ac83d3503e06e1a7185e4e907cff66ab213d63687c91be55036400a7d592d3ad3965ac670efcc99c8cdcd6d66c732
7
+ data.tar.gz: 2ffeb991a57bbdd511afe7d1e7b988c780af4034e7c082b3c12542bdac0e6ea265b9ce95a61026835ce7894dbb7619a02d13e70d20219a2055b6f6957fcd0c23
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- image_puller (0.2.2)
4
+ image_puller (0.2.3)
5
5
  activesupport (~> 5.2)
6
6
  flickraw
7
7
  ruby-progressbar (~> 1.10)
data/image_puller.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'image_puller'
3
- spec.version = '0.2.2'
3
+ spec.version = '0.2.3'
4
4
  spec.authors = ['Nick Longmore']
5
5
  spec.email = ['neeko99@gmail.com']
6
6
  spec.summary = 'Pulls all images from Flickr under photostreams '
@@ -1,46 +1,51 @@
1
1
  module Flickr
2
2
  class Authenticator
3
3
 
4
- def flickr
5
- @flickr ||= get_tokens
6
- end
4
+ class << self
7
5
 
8
- def get_tokens
9
- flickr = FlickRaw::Flickr.new(api_key: ENV['FLICKR_API_KEY'], shared_secret: ENV['FLICKR_SHARED_SECRET'])
6
+ def authenticate(should_retry = true)
7
+ flickr = FlickRaw::Flickr.new(api_key: ENV['FLICKR_API_KEY'], shared_secret: ENV['FLICKR_SHARED_SECRET'])
10
8
 
11
- if File.exist? 'authkey.json'
12
- auth_key = JSON.parse(File.read('authkey.json'))
9
+ if File.exist? 'authkey.json'
10
+ auth_key = JSON.parse(File.read('authkey.json'))
13
11
 
14
- flickr.access_token = auth_key['access_token']
15
- flickr.access_secret = auth_key['secret']
16
- end
12
+ flickr.access_token = auth_key['access_token']
13
+ flickr.access_secret = auth_key['secret']
14
+ end
15
+
16
+ begin
17
+ flickr.test.login
18
+ rescue StandardError => e
19
+ raise unless should_retry
20
+
21
+ oauth(flickr)
22
+ # retry
23
+ authenticate(false)
24
+ end
17
25
 
18
- begin
19
- flickr.test.login
20
26
  flickr
21
- rescue FlickRaw::FailedResponse => e
22
- authenticate
23
- # retry
24
- get_tokens
25
27
  end
26
- end
27
28
 
28
- def authenticate
29
- token = flickr.get_request_token
30
- auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
29
+ private
31
30
 
32
- puts "Open this url in your browser to complete the authentication process : #{auth_url}"
33
- puts "Copy here the number given when you complete the process."
34
- verify = gets.strip
31
+ def oauth(flickr)
35
32
 
36
- begin
37
- flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
38
- login = flickr.test.login
39
- puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}"
40
- File.write('authkey.json', { access_token: flickr.access_token, secret: flickr.access_secret }.to_json)
41
- flickr
42
- rescue FlickRaw::FailedResponse => e
43
- puts "Authentication failed : #{e.msg}"
33
+ token = flickr.get_request_token
34
+ auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
35
+
36
+ puts "Open this url in your browser to complete the authentication process : #{auth_url}"
37
+ puts 'Copy here the number given when you complete the process.'
38
+ verify = STDIN.gets.strip
39
+
40
+ begin
41
+ flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify)
42
+ login = flickr.test.login
43
+ puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}"
44
+ File.write('authkey.json', { access_token: flickr.access_token, secret: flickr.access_secret }.to_json)
45
+ flickr
46
+ rescue FlickRaw::FailedResponse => e
47
+ puts "Authentication failed : #{e.msg}"
48
+ end
44
49
  end
45
50
  end
46
51
  end
@@ -8,8 +8,8 @@ module Strategy
8
8
  def exec
9
9
  return puts 'Missing Requirements for Flickr Download please see documentation' unless has_requirements?
10
10
 
11
- auth = ::Flickr::Authenticator.new
12
- downloader = ::Flickr::Downloader.new(auth.flickr)
11
+ auth = ::Flickr::Authenticator.authenticate
12
+ downloader = ::Flickr::Downloader.new(auth)
13
13
 
14
14
  downloader.download
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_puller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Longmore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug