image_puller 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/image_puller.gemspec +1 -1
- data/lib/flickr/authenticator.rb +36 -31
- data/lib/strategies/flickr.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43694ba97ed29f91330b6e2396ff9013816b9fadb71ec2d2a00fe54fe5b7c43e
|
4
|
+
data.tar.gz: c703cdbbb9457de204130270dd367dfa8ff00dd438c87bec7d6986171d1a970b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3bdfe322a634d52c0ed34c725beda608b3ac83d3503e06e1a7185e4e907cff66ab213d63687c91be55036400a7d592d3ad3965ac670efcc99c8cdcd6d66c732
|
7
|
+
data.tar.gz: 2ffeb991a57bbdd511afe7d1e7b988c780af4034e7c082b3c12542bdac0e6ea265b9ce95a61026835ce7894dbb7619a02d13e70d20219a2055b6f6957fcd0c23
|
data/Gemfile.lock
CHANGED
data/image_puller.gemspec
CHANGED
data/lib/flickr/authenticator.rb
CHANGED
@@ -1,46 +1,51 @@
|
|
1
1
|
module Flickr
|
2
2
|
class Authenticator
|
3
3
|
|
4
|
-
|
5
|
-
@flickr ||= get_tokens
|
6
|
-
end
|
4
|
+
class << self
|
7
5
|
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
9
|
+
if File.exist? 'authkey.json'
|
10
|
+
auth_key = JSON.parse(File.read('authkey.json'))
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
29
|
-
token = flickr.get_request_token
|
30
|
-
auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
|
29
|
+
private
|
31
30
|
|
32
|
-
|
33
|
-
puts "Copy here the number given when you complete the process."
|
34
|
-
verify = gets.strip
|
31
|
+
def oauth(flickr)
|
35
32
|
|
36
|
-
|
37
|
-
flickr.
|
38
|
-
|
39
|
-
puts "
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
data/lib/strategies/flickr.rb
CHANGED
@@ -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.
|
12
|
-
downloader = ::Flickr::Downloader.new(auth
|
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.
|
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-
|
11
|
+
date: 2020-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|