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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65cb29bf7a73956ef39edc253682ee24e454eccc
4
- data.tar.gz: 44b75859a26227cd9011faf9aad0947840d2b3f1
3
+ metadata.gz: 902d9d2293959bd5df82a0c202296dd1851e614e
4
+ data.tar.gz: 803781a9b845a3df4bebb627bc95679f67589f98
5
5
  SHA512:
6
- metadata.gz: 67bea4b73a68ffb7519537e14d966ac1e5c6067e2b1f82f2f67bf29632d680eed6e18388cf03269bf91744c1a73e0fd41011854d603381ae8e1ee051e7514f6c
7
- data.tar.gz: 855fa3c2221a59e88ae255dff3bdfff81176312840ad9d237f266a59a81c4b02f0e2ebcb3f513882ec3bcf39c5fd6f0011121ab77cbbddf4dab54ee415c49a34
6
+ metadata.gz: 0f60d06719719aa89926c3b2bf9d379b2dab036e7acbeb5a63eac56fda5d389962f18e5c8649d13ec2beaac0cae9c1a2ef1b73d310d02698deb56f1f205bdbf8
7
+ data.tar.gz: f85a92be6d8cb1f5628a70478898a4cff3a66d65d1623f6ea141d41cb27781e0dc5f85270b72a89ce3f6a30f30a3ac078cfa7fb6eda52dfe247fea316533f622
@@ -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 "do you want to create a configuration file? y/n"
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
- user = ask_for_user
65
- update_config_with_answer if user.nil? || user == ''
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(/username/, AutoPilot.configuration.user)
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.user = ask_for_user
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 = 1
85
- # config.date = { start: '2000-01-00', end: todays_date }
84
+ config.max_pages = 2
86
85
  end
87
86
  end
88
87
 
89
- # def todays_date
90
- # Time.now.to_s.split(' ').first
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 username, try again'
98
- ask_for_user
92
+ log.red '- invalid user id, try again'
93
+ ask_for_user_id
99
94
  else
100
- AutoPilot.configuration.user = answer
95
+ AutoPilot.configuration.user_id = answer
101
96
  end
102
97
  end
103
98
 
@@ -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
@@ -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.user, options = {})
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.user} via stackoverflow api"
14
+ Log.green "fetching information for id #{AutoPilot.configuration.user_id} via stackoverflow api"
15
15
  pages.each do |page|
16
- response = answer_response(page)
17
- answers << response.data.first.answers
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.user}"
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 username
5
- config.user = 'username'
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
@@ -1,3 +1,3 @@
1
1
  module AutoPilot
2
- VERSION = '0.4.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -18,8 +18,9 @@ unless ENV['DEBUG']
18
18
  module AutoPilot
19
19
  class Log
20
20
  class << self
21
- def colorize(*args); end
22
- def out(*args); end
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
- score: 1,
44
- answer_id: 123,
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(*args)
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
@@ -1,6 +1,6 @@
1
1
  def configure
2
2
  AutoPilot.configure do |config|
3
- config.user = 'foo'
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
@@ -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(:status => 200, :body => {}.to_s, :headers => {})
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, [{:answer_id=>123, :question_id=>123}]
24
+ assert_equal @subject.get_answers, [{ answer_id: 123, question_id: 123 }]
29
25
  end
30
26
  end
31
27
  end
@@ -1,7 +1,9 @@
1
1
  require_relative 'helper'
2
2
  require 'webmock/minitest'
3
3
  class TestAutoPilot < MiniTest::Test
4
- def setup; configure; end
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; [{ answer_id: 123, question_id: 123 }]; end
27
+ def get_answers
28
+ [{ answer_id: 123, question_id: 123 }]
29
+ end
26
30
  end
27
31
  before do
28
32
  configure
@@ -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.user, 'foo'
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.1
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-03-23 00:00:00.000000000 Z
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.4.5
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