auto_pilot 0.4.1 → 1.0.0
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 +4 -4
- data/bin/autopilot +11 -16
- data/lib/auto_pilot.rb +0 -12
- data/lib/auto_pilot/api.rb +13 -23
- data/lib/auto_pilot/templates/auto_pilot_config.rb +2 -2
- data/lib/auto_pilot/util/version.rb +1 -1
- data/test/helper.rb +8 -13
- data/test/support/common.rb +1 -2
- data/test/test_api.rb +3 -7
- data/test/test_autopilot.rb +6 -2
- data/test/test_configure.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 902d9d2293959bd5df82a0c202296dd1851e614e
|
4
|
+
data.tar.gz: 803781a9b845a3df4bebb627bc95679f67589f98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f60d06719719aa89926c3b2bf9d379b2dab036e7acbeb5a63eac56fda5d389962f18e5c8649d13ec2beaac0cae9c1a2ef1b73d310d02698deb56f1f205bdbf8
|
7
|
+
data.tar.gz: f85a92be6d8cb1f5628a70478898a4cff3a66d65d1623f6ea141d41cb27781e0dc5f85270b72a89ce3f6a30f30a3ac078cfa7fb6eda52dfe247fea316533f622
|
data/bin/autopilot
CHANGED
@@ -37,7 +37,7 @@ class Application
|
|
37
37
|
log.out "found existing configuration at #{Dir.pwd}/#{CONF_TEMPLATE}"
|
38
38
|
load_configuration
|
39
39
|
else
|
40
|
-
log.out
|
40
|
+
log.out 'do you want to create a configuration file? y/n'
|
41
41
|
answer = $stdin.gets.chomp
|
42
42
|
if answer == 'y'
|
43
43
|
add_configuration_file
|
@@ -61,11 +61,11 @@ class Application
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def update_config_with_user
|
64
|
-
|
65
|
-
update_config_with_answer if
|
64
|
+
id = ask_for_user_id
|
65
|
+
update_config_with_answer if id.nil? || id == ''
|
66
66
|
template = "#{Dir.pwd}/#{CONF_TEMPLATE}"
|
67
67
|
text = File.read(template)
|
68
|
-
new_contents = text.gsub(/
|
68
|
+
new_contents = text.gsub(/userid/, AutoPilot.configuration.user_id)
|
69
69
|
File.open(template, 'w') { |file| file.puts new_contents }
|
70
70
|
reload_config
|
71
71
|
end
|
@@ -77,27 +77,22 @@ class Application
|
|
77
77
|
|
78
78
|
def use_default_configuration
|
79
79
|
AutoPilot.configure do |config|
|
80
|
-
config.
|
80
|
+
config.user_id = ask_for_user_id
|
81
81
|
config.format = [:md]
|
82
82
|
config.folder = "#{Dir.pwd}/stackoverflow"
|
83
83
|
config.disable_front_matter = false
|
84
|
-
config.max_pages =
|
85
|
-
# config.date = { start: '2000-01-00', end: todays_date }
|
84
|
+
config.max_pages = 2
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
# end
|
92
|
-
|
93
|
-
def ask_for_user
|
94
|
-
log.out "enter a stackoverflow username:"
|
88
|
+
def ask_for_user_id
|
89
|
+
log.out 'enter a stackoverflow id (can be found in your profile url):'
|
95
90
|
answer = $stdin.gets.chomp
|
96
91
|
if answer.nil? or answer == ''
|
97
|
-
log.red '- invalid
|
98
|
-
|
92
|
+
log.red '- invalid user id, try again'
|
93
|
+
ask_for_user_id
|
99
94
|
else
|
100
|
-
AutoPilot.configuration.
|
95
|
+
AutoPilot.configuration.user_id = answer
|
101
96
|
end
|
102
97
|
end
|
103
98
|
|
data/lib/auto_pilot.rb
CHANGED
@@ -10,18 +10,6 @@ module AutoPilot
|
|
10
10
|
class << self
|
11
11
|
BASE_URL = 'http://stackoverflow.com/questions'
|
12
12
|
|
13
|
-
# def get_answers(_user = '', _options = {})
|
14
|
-
# # TODO: id stubs, replace with API
|
15
|
-
# question_ids = [19_348_076]
|
16
|
-
# answer_ids = [25_536_701]
|
17
|
-
# parsed_documents = []
|
18
|
-
# question_ids.each do |id|
|
19
|
-
# doc = Request.fetch page_with_my_answer(id)
|
20
|
-
# parsed_documents << DocumentParser.new(doc, id, answer_ids.first)
|
21
|
-
# end
|
22
|
-
# parsed_documents
|
23
|
-
# end
|
24
|
-
|
25
13
|
def get_api_answers
|
26
14
|
parsed_documents = []
|
27
15
|
answers = AutoPilot::API.new.get_answers
|
data/lib/auto_pilot/api.rb
CHANGED
@@ -3,7 +3,7 @@ module AutoPilot
|
|
3
3
|
class API
|
4
4
|
attr_reader :user, :options, :answers
|
5
5
|
|
6
|
-
def initialize(user = AutoPilot.configuration.
|
6
|
+
def initialize(user = AutoPilot.configuration.user_id, options = {})
|
7
7
|
@user = user
|
8
8
|
@options = options
|
9
9
|
@answers = []
|
@@ -11,10 +11,17 @@ module AutoPilot
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_answers
|
14
|
-
Log.green "fetching information for #{AutoPilot.configuration.
|
14
|
+
Log.green "fetching information for id #{AutoPilot.configuration.user_id} via stackoverflow api"
|
15
15
|
pages.each do |page|
|
16
|
-
|
17
|
-
|
16
|
+
begin
|
17
|
+
Log.green "fetching answers for page #{page}"
|
18
|
+
response = answer_response(page)
|
19
|
+
answers << response.data.first.answers
|
20
|
+
rescue => e
|
21
|
+
Log.red "An error occured: #{e}"
|
22
|
+
Log.red '- AutoPilot will continue downloading your answers'
|
23
|
+
break
|
24
|
+
end
|
18
25
|
break unless response.has_more
|
19
26
|
end
|
20
27
|
filtered(answers)
|
@@ -34,7 +41,7 @@ module AutoPilot
|
|
34
41
|
private
|
35
42
|
|
36
43
|
def answer_response(page)
|
37
|
-
throttle { RubyStackoverflow.users_with_answers([user_id], 'page' => page) }
|
44
|
+
throttle { RubyStackoverflow.users_with_answers([AutoPilot.configuration.user_id], 'page' => page) }
|
38
45
|
end
|
39
46
|
|
40
47
|
def add_config_client_key
|
@@ -45,23 +52,6 @@ module AutoPilot
|
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
48
|
-
def user_id
|
49
|
-
throttle
|
50
|
-
if user_response.data.length
|
51
|
-
user_response.data.first.user_id
|
52
|
-
else
|
53
|
-
if error = user_response.error
|
54
|
-
fail "#{error.error_message} | #{error.error_name} | #{error.error_code}"
|
55
|
-
else
|
56
|
-
fail "could not find user data for #{AutoPilot.configuration.user}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def user_response
|
62
|
-
@response ||= RubyStackoverflow.users(name: user)
|
63
|
-
end
|
64
|
-
|
65
55
|
def filtered(answers)
|
66
56
|
if answers.length > 0
|
67
57
|
filtered_answers = answers.flatten.uniq.select { |answer| answer.score > (AutoPilot.configuration.score_threshold || 0) }
|
@@ -71,7 +61,7 @@ module AutoPilot
|
|
71
61
|
end
|
72
62
|
end
|
73
63
|
else
|
74
|
-
fail "could not find answers for #{AutoPilot.configuration.
|
64
|
+
fail "could not find answers for id #{AutoPilot.configuration.user_id}"
|
75
65
|
end
|
76
66
|
end
|
77
67
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
AutoPilot.configure do |config|
|
2
2
|
# string or nil - your application key (optional, allows for more requests)
|
3
3
|
config.key = nil
|
4
|
-
# string - a stackoverflow
|
5
|
-
config.
|
4
|
+
# string - a valid stackoverflow id eg '4727792', can be found on your profile url
|
5
|
+
config.user_id = 'userid'
|
6
6
|
# integer - score must be greater than threshold in order to qualify for download
|
7
7
|
config.score_threshold = -1
|
8
8
|
# string - where to put markdown or html files
|
data/test/helper.rb
CHANGED
@@ -18,8 +18,9 @@ unless ENV['DEBUG']
|
|
18
18
|
module AutoPilot
|
19
19
|
class Log
|
20
20
|
class << self
|
21
|
-
def colorize(*
|
22
|
-
|
21
|
+
def colorize(*_args); end
|
22
|
+
|
23
|
+
def out(*_args); end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -39,20 +40,14 @@ end
|
|
39
40
|
module AutoPilot
|
40
41
|
class API
|
41
42
|
def answer_double
|
42
|
-
OpenStruct.new(
|
43
|
-
|
44
|
-
|
45
|
-
question_id: 123
|
46
|
-
})
|
43
|
+
OpenStruct.new(score: 1,
|
44
|
+
answer_id: 123,
|
45
|
+
question_id: 123)
|
47
46
|
end
|
48
47
|
|
49
|
-
def answer_response(*
|
48
|
+
def answer_response(*_args)
|
50
49
|
# [{:answer_id=>123, :question_id=>123}]
|
51
|
-
OpenStruct.new(
|
52
|
-
data: [ OpenStruct.new({
|
53
|
-
answers: [answer_double]
|
54
|
-
})]
|
55
|
-
})
|
50
|
+
OpenStruct.new(data: [OpenStruct.new(answers: [answer_double])])
|
56
51
|
end
|
57
52
|
end
|
58
53
|
end
|
data/test/support/common.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
def configure
|
2
2
|
AutoPilot.configure do |config|
|
3
|
-
config.
|
3
|
+
config.user_id = '4727792'
|
4
4
|
config.format = [:md, :html]
|
5
5
|
config.folder = 'test/stackoverflow'
|
6
6
|
config.disable_front_matter = false
|
@@ -19,7 +19,6 @@ def load_fixture_and_parse
|
|
19
19
|
[parsed_doc]
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
22
|
def load_html_fixture
|
24
23
|
@fixture ||= File.read(File.open("#{Dir.pwd}/test/fixtures/so_page.html", 'r'))
|
25
24
|
end
|
data/test/test_api.rb
CHANGED
@@ -6,11 +6,7 @@ class TestAPI < MiniTest::Test
|
|
6
6
|
configure
|
7
7
|
AutoPilot.configuration.key = 'some_key'
|
8
8
|
@subject = AutoPilot::API.new
|
9
|
-
stub_request(:get, /api.stackexchange.com/i).to_return(:
|
10
|
-
end
|
11
|
-
|
12
|
-
it '#user' do
|
13
|
-
assert_equal @subject.user, 'foo'
|
9
|
+
stub_request(:get, /api.stackexchange.com/i).to_return(status: 200, body: {}.to_s, headers: {})
|
14
10
|
end
|
15
11
|
it '#options' do
|
16
12
|
assert_equal @subject.options, {}
|
@@ -22,10 +18,10 @@ class TestAPI < MiniTest::Test
|
|
22
18
|
assert_equal @subject.throttle, nil
|
23
19
|
end
|
24
20
|
it '#pages' do
|
25
|
-
assert_equal @subject.pages, [1,2,3]
|
21
|
+
assert_equal @subject.pages, [1, 2, 3]
|
26
22
|
end
|
27
23
|
it '#get_answers' do
|
28
|
-
assert_equal @subject.get_answers, [{:
|
24
|
+
assert_equal @subject.get_answers, [{ answer_id: 123, question_id: 123 }]
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
data/test/test_autopilot.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
require 'webmock/minitest'
|
3
3
|
class TestAutoPilot < MiniTest::Test
|
4
|
-
def setup
|
4
|
+
def setup
|
5
|
+
configure
|
6
|
+
end
|
5
7
|
|
6
8
|
describe '.page_with_my_answer' do
|
7
9
|
it 'returns url' do
|
@@ -22,7 +24,9 @@ class TestAutoPilot < MiniTest::Test
|
|
22
24
|
|
23
25
|
describe '.get_api_answers' do
|
24
26
|
class AutoPilot::API
|
25
|
-
def get_answers
|
27
|
+
def get_answers
|
28
|
+
[{ answer_id: 123, question_id: 123 }]
|
29
|
+
end
|
26
30
|
end
|
27
31
|
before do
|
28
32
|
configure
|
data/test/test_configure.rb
CHANGED
@@ -12,7 +12,7 @@ class TestConfigure < MiniTest::Test
|
|
12
12
|
end
|
13
13
|
assert_equal @subject.configuration.foo, 'bar'
|
14
14
|
|
15
|
-
assert_equal @subject.configuration.
|
15
|
+
assert_equal @subject.configuration.user_id, '4727792'
|
16
16
|
assert_equal @subject.configuration.format, [:md, :html]
|
17
17
|
assert_equal @subject.configuration.folder, 'test/stackoverflow'
|
18
18
|
assert_equal @subject.configuration.disable_front_matter, false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_pilot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Fender
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.2.2
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: convert your stackoverflow to a github blog
|