twitter_images 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twitter_images.rb +3 -0
- data/lib/twitter_images/authorizer.rb +55 -0
- data/lib/twitter_images/cli.rb +6 -1
- data/lib/twitter_images/configuration.rb +8 -9
- data/lib/twitter_images/consumer.rb +4 -0
- data/lib/twitter_images/downloader.rb +1 -1
- data/lib/twitter_images/requester.rb +4 -15
- data/lib/twitter_images/version.rb +1 -1
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 680f11ce26e7df87577faabdc26ad693666aab6a
|
4
|
+
data.tar.gz: cd696a0c46369e957d9090a248685ea950765caf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f95223c9dcf5183030b9573a4ace1356fb1e996885bb36b08a278f2a7b779d8d1375cef0b270298b16f1bb897032e30efeb6866ba136b8257fa341d3fb3d878c
|
7
|
+
data.tar.gz: a7008e590ab5b044b3a936e005641354adfac80ea4dc2a3e4aa90238a32bb47ef50af06f6e38dbf5f4bb0562d7ab8ef5efc374a83c98dba456f32f67d7b10f53
|
data/lib/twitter_images.rb
CHANGED
@@ -6,10 +6,13 @@ require "oauth"
|
|
6
6
|
require "ruby-progressbar"
|
7
7
|
require "typhoeus"
|
8
8
|
require "optparse"
|
9
|
+
require "launchy"
|
9
10
|
|
10
11
|
require "twitter_images/cli"
|
11
12
|
require "twitter_images/configuration"
|
13
|
+
require "twitter_images/authorizer"
|
12
14
|
require "twitter_images/requester"
|
13
15
|
require "twitter_images/parser"
|
14
16
|
require "twitter_images/downloader"
|
15
17
|
require "twitter_images/version"
|
18
|
+
require "twitter_images/consumer"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module TwitterImages
|
2
|
+
class Authorizer
|
3
|
+
attr_reader :oauth, :request_token, :pin, :access_token_object, :access_token, :access_secret
|
4
|
+
|
5
|
+
def authorize
|
6
|
+
get_request_token
|
7
|
+
visit_url
|
8
|
+
get_pin
|
9
|
+
authorize_with_pin
|
10
|
+
set_credentials
|
11
|
+
puts "Authorization successful. Credentials have been written to #{ENV['HOME']}/.twitter_imagesrc"
|
12
|
+
end
|
13
|
+
|
14
|
+
def access_token
|
15
|
+
if File.exist?(ENV["HOME"] + "/.twitter_imagesrc")
|
16
|
+
@access_token = IO.readlines(ENV["HOME"] + "/.twitter_imagesrc")[0].chomp
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_secret
|
21
|
+
if File.exist?(ENV["HOME"] + "/.twitter_imagesrc")
|
22
|
+
@access_secret = IO.readlines(ENV["HOME"] + "/.twitter_imagesrc")[1].chomp
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_request_token
|
29
|
+
@oauth = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "https://api.twitter.com")
|
30
|
+
@request_token = oauth.get_request_token
|
31
|
+
end
|
32
|
+
|
33
|
+
def visit_url
|
34
|
+
puts "Please visit this url in your browser: https://twitter.com/oauth/authorize?oauth_token=#{request_token.token}&oauth_callback=oob"
|
35
|
+
Launchy.open("https://twitter.com/oauth/authorize?oauth_token=#{request_token.token}&oauth_callback=oob")
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_pin
|
39
|
+
puts "Please enter your pin here: "
|
40
|
+
@pin = gets.chomp
|
41
|
+
end
|
42
|
+
|
43
|
+
def authorize_with_pin
|
44
|
+
@access_token_object = request_token.get_access_token(:oauth_verifier => @pin)
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_credentials
|
48
|
+
File.open(ENV["HOME"] + "/.twitter_imagesrc", "w") do |file|
|
49
|
+
file.puts(access_token_object.token)
|
50
|
+
file.puts(access_token_object.secret)
|
51
|
+
file.close
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/twitter_images/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TwitterImages
|
2
2
|
class CLI
|
3
|
-
attr_reader :configuration
|
3
|
+
attr_reader :configuration, :options
|
4
4
|
|
5
5
|
def initialize(argv)
|
6
6
|
@argv = argv
|
@@ -35,6 +35,11 @@ module TwitterImages
|
|
35
35
|
puts opts
|
36
36
|
exit
|
37
37
|
end
|
38
|
+
|
39
|
+
opts.on("-a", "--authorize", "Run this first to authorize the app with Twitter") do
|
40
|
+
Authorizer.new.authorize
|
41
|
+
exit
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
@@ -8,6 +8,7 @@ module TwitterImages
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def prepare(options)
|
11
|
+
check_auth
|
11
12
|
set_directory(options[:path])
|
12
13
|
get_search(options[:term])
|
13
14
|
get_amount(options[:amount])
|
@@ -16,17 +17,15 @@ module TwitterImages
|
|
16
17
|
|
17
18
|
private
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def directory_exists?
|
26
|
-
Dir.exist?(@directory)
|
20
|
+
def check_auth
|
21
|
+
unless File.exist?(ENV["HOME"] + "/.twitter_imagesrc")
|
22
|
+
raise StandardError, "No configuration file was found, please run `twitter_images -auth`"
|
23
|
+
end
|
27
24
|
end
|
28
25
|
|
29
|
-
def
|
26
|
+
def set_directory(dir)
|
27
|
+
@directory = File.expand_path(dir)
|
28
|
+
raise StandardError, "Directory doesn't exist" unless Dir.exist?(@directory)
|
30
29
|
Dir.chdir(@directory)
|
31
30
|
end
|
32
31
|
|
@@ -15,7 +15,7 @@ module TwitterImages
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def save_images(parsed_links)
|
18
|
-
progressbar = ProgressBar.create(:total => parsed_links.count)
|
18
|
+
progressbar = ProgressBar.create(:total => parsed_links.count, :format => "%a |%b>>%i| %p%% %t")
|
19
19
|
hydra = Typhoeus::Hydra.new
|
20
20
|
|
21
21
|
parsed_links.each do |src|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module TwitterImages
|
2
2
|
class Requester
|
3
|
-
attr_reader :consumer_key, :access_token, :downloader, :search, :parser
|
3
|
+
attr_reader :consumer_key, :access_token, :downloader, :search, :parser, :authorizer
|
4
4
|
attr_accessor :https, :address, :response
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@downloader = Downloader.new
|
8
8
|
@parser = Parser.new
|
9
|
+
@authorizer = Authorizer.new
|
9
10
|
end
|
10
11
|
|
11
12
|
def start(search, amount)
|
12
|
-
check_env
|
13
13
|
get_links(search, amount)
|
14
14
|
download
|
15
15
|
end
|
@@ -40,22 +40,11 @@ module TwitterImages
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def consumer_key
|
43
|
-
OAuth::Consumer.new(
|
43
|
+
OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET)
|
44
44
|
end
|
45
45
|
|
46
46
|
def access_token
|
47
|
-
OAuth::Token.new(
|
48
|
-
end
|
49
|
-
|
50
|
-
def check_env
|
51
|
-
if ENV.key?("CONSUMER_KEY") &&
|
52
|
-
ENV.key?("CONSUMER_SECRET") &&
|
53
|
-
ENV.key?("ACCESS_TOKEN") &&
|
54
|
-
ENV.key?("ACCESS_SECRET")
|
55
|
-
return true
|
56
|
-
else
|
57
|
-
puts "The credentials have not been correctly set up in your ENV"
|
58
|
-
end
|
47
|
+
OAuth::Token.new(authorizer.access_token, authorizer.access_secret)
|
59
48
|
end
|
60
49
|
|
61
50
|
def setup_https
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zabelin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|
@@ -98,6 +98,26 @@ dependencies:
|
|
98
98
|
- - "~>"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '1.0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: launchy
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '2.4'
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.4.3
|
111
|
+
type: :runtime
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.4'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.4.3
|
101
121
|
- !ruby/object:Gem::Dependency
|
102
122
|
name: bundler
|
103
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,8 +216,10 @@ extra_rdoc_files: []
|
|
196
216
|
files:
|
197
217
|
- bin/twitter_images
|
198
218
|
- lib/twitter_images.rb
|
219
|
+
- lib/twitter_images/authorizer.rb
|
199
220
|
- lib/twitter_images/cli.rb
|
200
221
|
- lib/twitter_images/configuration.rb
|
222
|
+
- lib/twitter_images/consumer.rb
|
201
223
|
- lib/twitter_images/downloader.rb
|
202
224
|
- lib/twitter_images/parser.rb
|
203
225
|
- lib/twitter_images/requester.rb
|