impostor 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +47 -0
  7. data/History.txt +8 -0
  8. data/Manifest.txt +87 -55
  9. data/README.txt +11 -11
  10. data/Rakefile +16 -20
  11. data/lib/impostor/auth.rb +103 -0
  12. data/lib/impostor/config.rb +171 -0
  13. data/lib/impostor/errors.rb +67 -0
  14. data/lib/impostor/phpbb2.rb +202 -0
  15. data/lib/impostor/phpbb3.rb +199 -0
  16. data/lib/impostor/post.rb +111 -0
  17. data/lib/impostor/topic.rb +115 -0
  18. data/lib/impostor/wwf79.rb +186 -0
  19. data/lib/impostor/wwf80.rb +190 -0
  20. data/lib/impostor.rb +108 -5
  21. data/spec/auth_spec.rb +148 -0
  22. data/spec/base_spec_helper.rb +12 -0
  23. data/{test/test_helper.rb → spec/caged_net_http.rb} +8 -17
  24. data/spec/config_spec.rb +136 -0
  25. data/spec/fixtures/junk.html +1 -0
  26. data/{test → spec}/fixtures/phpbb2-get-new_topic-form-good-response.html +0 -0
  27. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html +11 -11
  28. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html +0 -0
  29. data/{test → spec}/fixtures/phpbb2-index.html +0 -0
  30. data/{test → spec}/fixtures/phpbb2-logged-in.html +0 -0
  31. data/{test → spec}/fixtures/phpbb2-login.html +0 -0
  32. data/{test → spec}/fixtures/phpbb2-not-logged-in.html +0 -0
  33. data/{test → spec}/fixtures/phpbb2-post-new_topic-good-response.html +0 -0
  34. data/{test → spec}/fixtures/phpbb2-post-reply-good-response.html +0 -0
  35. data/{test → spec}/fixtures/phpbb2-post-reply-throttled-response.html +0 -0
  36. data/{test → spec}/fixtures/phpbb2-too-many-posts.html +0 -0
  37. data/{test → spec}/fixtures/phpbb3-get-new-topic-form-good-response.html +0 -0
  38. data/{test → spec}/fixtures/phpbb3-get-reply-form-good-response.html +0 -0
  39. data/{test → spec}/fixtures/phpbb3-logged-in.html +0 -0
  40. data/{test → spec}/fixtures/phpbb3-login.html +0 -0
  41. data/{test → spec}/fixtures/phpbb3-not-logged-in.html +0 -0
  42. data/{test → spec}/fixtures/phpbb3-post-new_topic-good-response.html +0 -0
  43. data/{test → spec}/fixtures/phpbb3-post-reply-good-response.html +0 -0
  44. data/spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml +1308 -0
  45. data/spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml +923 -0
  46. data/spec/fixtures/vcr_cassettes/phpbb2-should-login.yml +360 -0
  47. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml +497 -0
  48. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml +287 -0
  49. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml +497 -0
  50. data/spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml +1140 -0
  51. data/spec/fixtures/vcr_cassettes/phpbb2-should-post.yml +751 -0
  52. data/spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml +995 -0
  53. data/spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml +675 -0
  54. data/spec/fixtures/vcr_cassettes/phpbb3-should-login.yml +245 -0
  55. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml +350 -0
  56. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml +253 -0
  57. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml +350 -0
  58. data/spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml +1046 -0
  59. data/spec/fixtures/vcr_cassettes/phpbb3-should-post.yml +605 -0
  60. data/{test → spec}/fixtures/wwf79-forum_posts.html +0 -0
  61. data/{test → spec}/fixtures/wwf79-general-new-topic-error.html +0 -0
  62. data/{test → spec}/fixtures/wwf79-general-posting-error.html +0 -0
  63. data/{test → spec}/fixtures/wwf79-good-post-forum_posts.html +1 -1
  64. data/{test → spec}/fixtures/wwf79-index.html +0 -0
  65. data/{test → spec}/fixtures/wwf79-logged-in.html +0 -0
  66. data/{test → spec}/fixtures/wwf79-login.html +0 -0
  67. data/{test → spec}/fixtures/wwf79-new-topic-forum_posts-response.html +0 -0
  68. data/{test → spec}/fixtures/wwf79-new-topic-post_message_form.html +0 -0
  69. data/{test → spec}/fixtures/wwf79-not-logged-in.html +0 -0
  70. data/{test → spec}/fixtures/wwf79-too-many-posts.html +0 -0
  71. data/{test → spec}/fixtures/wwf79-too-many-topics.html +0 -0
  72. data/{test → spec}/fixtures/wwf80-general-posting-error.html +0 -0
  73. data/{test → spec}/fixtures/wwf80-get-new_topic-form-good-response.html +0 -0
  74. data/{test → spec}/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html +0 -0
  75. data/{test → spec}/fixtures/wwf80-index.html +0 -0
  76. data/{test → spec}/fixtures/wwf80-logged-in.html +0 -0
  77. data/{test → spec}/fixtures/wwf80-login.html +0 -0
  78. data/{test → spec}/fixtures/wwf80-new_reply_form.html +0 -0
  79. data/{test → spec}/fixtures/wwf80-not-logged-in.html +0 -0
  80. data/{test → spec}/fixtures/wwf80-post-new_topic-good-response.html +1 -1
  81. data/{test → spec}/fixtures/wwf80-post-reply-good-response.html +0 -0
  82. data/{test → spec}/fixtures/wwf80-too-many-posts.html +0 -0
  83. data/spec/impostor_spec_helper.rb +162 -0
  84. data/spec/integration/phpbb2_spec.rb +111 -0
  85. data/spec/integration/phpbb3_spec.rb +109 -0
  86. data/spec/integration_spec_helper.rb +7 -0
  87. data/spec/phpbb2_spec.rb +346 -0
  88. data/spec/phpbb3_spec.rb +332 -0
  89. data/spec/post_spec.rb +134 -0
  90. data/spec/spec_helper.rb +2 -0
  91. data/spec/test_impostor.rb +12 -0
  92. data/spec/topic_spec.rb +143 -0
  93. data/spec/wwf79_spec.rb +342 -0
  94. data/spec/wwf80_spec.rb +339 -0
  95. metadata +156 -87
  96. data/lib/www/impostor/phpbb2.rb +0 -258
  97. data/lib/www/impostor/phpbb3.rb +0 -236
  98. data/lib/www/impostor/wwf79.rb +0 -254
  99. data/lib/www/impostor/wwf80.rb +0 -264
  100. data/lib/www/impostor.rb +0 -269
  101. data/test/test_github.rb +0 -12
  102. data/test/test_www_impostor.rb +0 -165
  103. data/test/test_www_impostor_phpbb2.rb +0 -536
  104. data/test/test_www_impostor_phpbb3.rb +0 -483
  105. data/test/test_www_impostor_wwf79.rb +0 -535
  106. data/test/test_www_impostor_wwf80.rb +0 -535
  107. data/vendor/plugins/impostor/lib/autotest/discover.rb +0 -3
  108. data/vendor/plugins/impostor/lib/autotest/impostor.rb +0 -49
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  coverage/
3
3
  pkg/
4
+ coverage.info
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use impostor
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # -*- ruby -*-
2
+
3
+ source :gemcutter
4
+
5
+ gem "hoe", ">=2.8.0"
6
+ gem "mechanize", ">=1.0.0"
7
+ gem "nokogiri", ">=1.4.4"
8
+
9
+ group :development, :test do
10
+ gem "mongrel", ">=1.1.5"
11
+ gem "rspec", ">= 2.3.0"
12
+ gem "redgreen", ">=1.2.2"
13
+ gem "vcr", ">=1.5.1"
14
+ gem "webmock", ">=1.6.2"
15
+ end
16
+
17
+ # vim: syntax=ruby
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.4)
5
+ cgi_multipart_eof_fix (2.5.0)
6
+ crack (0.1.8)
7
+ daemons (1.1.0)
8
+ diff-lcs (1.1.2)
9
+ fastthread (1.0.7)
10
+ gem_plugin (0.2.3)
11
+ hoe (2.9.0)
12
+ rake (>= 0.8.7)
13
+ mechanize (1.0.0)
14
+ nokogiri (>= 1.2.1)
15
+ mongrel (1.1.5)
16
+ cgi_multipart_eof_fix (>= 2.4)
17
+ daemons (>= 1.0.3)
18
+ fastthread (>= 1.0.1)
19
+ gem_plugin (>= 0.2.3)
20
+ nokogiri (1.4.4)
21
+ rake (0.8.7)
22
+ redgreen (1.2.2)
23
+ rspec (2.4.0)
24
+ rspec-core (~> 2.4.0)
25
+ rspec-expectations (~> 2.4.0)
26
+ rspec-mocks (~> 2.4.0)
27
+ rspec-core (2.4.0)
28
+ rspec-expectations (2.4.0)
29
+ diff-lcs (~> 1.1.2)
30
+ rspec-mocks (2.4.0)
31
+ vcr (1.5.1)
32
+ webmock (1.6.2)
33
+ addressable (>= 2.2.2)
34
+ crack (>= 0.1.7)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ hoe (>= 2.8.0)
41
+ mechanize (>= 1.0.0)
42
+ mongrel (>= 1.1.5)
43
+ nokogiri (>= 1.4.4)
44
+ redgreen (>= 1.2.2)
45
+ rspec (>= 2.3.0)
46
+ vcr (>= 1.5.1)
47
+ webmock (>= 1.6.2)
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ ### 1.0.0 / 2011-02-XX (move over bacon there's something leaner)
2
+
3
+ * 2 major enhancements
4
+ * refactored to a modularized architecture with base classes Config, Auth,
5
+ Post, and Topic using mixins to specify behavior specific to each forum by
6
+ implementing defined template methods from the base classes
7
+ * rspec and vcr used for specifying unit and integration behavior
8
+
1
9
  ### 0.2.1 / 2008-09-24 (to screen scrape is to love the internets)
2
10
 
3
11
  * 1 minor enhancement:
data/Manifest.txt CHANGED
@@ -1,4 +1,8 @@
1
1
  .gitignore
2
+ .rspec
3
+ .rvmrc
4
+ Gemfile
5
+ Gemfile.lock
2
6
  History.txt
3
7
  Manifest.txt
4
8
  README.txt
@@ -6,58 +10,86 @@ Rakefile
6
10
  dev_tools/github.rb
7
11
  impostor.gemspec
8
12
  lib/impostor.rb
9
- lib/www/impostor.rb
10
- lib/www/impostor/phpbb2.rb
11
- lib/www/impostor/phpbb3.rb
12
- lib/www/impostor/wwf79.rb
13
- lib/www/impostor/wwf80.rb
14
- test/fixtures/phpbb2-get-new_topic-form-good-response.html
15
- test/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html
16
- test/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html
17
- test/fixtures/phpbb2-index.html
18
- test/fixtures/phpbb2-logged-in.html
19
- test/fixtures/phpbb2-login.html
20
- test/fixtures/phpbb2-not-logged-in.html
21
- test/fixtures/phpbb2-post-new_topic-good-response.html
22
- test/fixtures/phpbb2-post-reply-good-response.html
23
- test/fixtures/phpbb2-post-reply-throttled-response.html
24
- test/fixtures/phpbb2-too-many-posts.html
25
- test/fixtures/phpbb3-get-new-topic-form-good-response.html
26
- test/fixtures/phpbb3-get-reply-form-good-response.html
27
- test/fixtures/phpbb3-logged-in.html
28
- test/fixtures/phpbb3-login.html
29
- test/fixtures/phpbb3-not-logged-in.html
30
- test/fixtures/phpbb3-post-new_topic-good-response.html
31
- test/fixtures/phpbb3-post-reply-good-response.html
32
- test/fixtures/wwf79-forum_posts.html
33
- test/fixtures/wwf79-general-new-topic-error.html
34
- test/fixtures/wwf79-general-posting-error.html
35
- test/fixtures/wwf79-good-post-forum_posts.html
36
- test/fixtures/wwf79-index.html
37
- test/fixtures/wwf79-logged-in.html
38
- test/fixtures/wwf79-login.html
39
- test/fixtures/wwf79-new-topic-forum_posts-response.html
40
- test/fixtures/wwf79-new-topic-post_message_form.html
41
- test/fixtures/wwf79-not-logged-in.html
42
- test/fixtures/wwf79-too-many-posts.html
43
- test/fixtures/wwf79-too-many-topics.html
44
- test/fixtures/wwf80-general-posting-error.html
45
- test/fixtures/wwf80-get-new_topic-form-good-response.html
46
- test/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html
47
- test/fixtures/wwf80-index.html
48
- test/fixtures/wwf80-logged-in.html
49
- test/fixtures/wwf80-login.html
50
- test/fixtures/wwf80-new_reply_form.html
51
- test/fixtures/wwf80-not-logged-in.html
52
- test/fixtures/wwf80-post-new_topic-good-response.html
53
- test/fixtures/wwf80-post-reply-good-response.html
54
- test/fixtures/wwf80-too-many-posts.html
55
- test/test_github.rb
56
- test/test_helper.rb
57
- test/test_www_impostor.rb
58
- test/test_www_impostor_phpbb2.rb
59
- test/test_www_impostor_phpbb3.rb
60
- test/test_www_impostor_wwf79.rb
61
- test/test_www_impostor_wwf80.rb
62
- vendor/plugins/impostor/lib/autotest/discover.rb
63
- vendor/plugins/impostor/lib/autotest/impostor.rb
13
+ lib/impostor/auth.rb
14
+ lib/impostor/config.rb
15
+ lib/impostor/errors.rb
16
+ lib/impostor/phpbb2.rb
17
+ lib/impostor/phpbb3.rb
18
+ lib/impostor/post.rb
19
+ lib/impostor/topic.rb
20
+ lib/impostor/wwf79.rb
21
+ lib/impostor/wwf80.rb
22
+ spec/auth_spec.rb
23
+ spec/base_spec_helper.rb
24
+ spec/caged_net_http.rb
25
+ spec/config_spec.rb
26
+ spec/fixtures/junk.html
27
+ spec/fixtures/phpbb2-get-new_topic-form-good-response.html
28
+ spec/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html
29
+ spec/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html
30
+ spec/fixtures/phpbb2-index.html
31
+ spec/fixtures/phpbb2-logged-in.html
32
+ spec/fixtures/phpbb2-login.html
33
+ spec/fixtures/phpbb2-not-logged-in.html
34
+ spec/fixtures/phpbb2-post-new_topic-good-response.html
35
+ spec/fixtures/phpbb2-post-reply-good-response.html
36
+ spec/fixtures/phpbb2-post-reply-throttled-response.html
37
+ spec/fixtures/phpbb2-too-many-posts.html
38
+ spec/fixtures/phpbb3-get-new-topic-form-good-response.html
39
+ spec/fixtures/phpbb3-get-reply-form-good-response.html
40
+ spec/fixtures/phpbb3-logged-in.html
41
+ spec/fixtures/phpbb3-login.html
42
+ spec/fixtures/phpbb3-not-logged-in.html
43
+ spec/fixtures/phpbb3-post-new_topic-good-response.html
44
+ spec/fixtures/phpbb3-post-reply-good-response.html
45
+ spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml
46
+ spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml
47
+ spec/fixtures/vcr_cassettes/phpbb2-should-login.yml
48
+ spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml
49
+ spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml
50
+ spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml
51
+ spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml
52
+ spec/fixtures/vcr_cassettes/phpbb2-should-post.yml
53
+ spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml
54
+ spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml
55
+ spec/fixtures/vcr_cassettes/phpbb3-should-login.yml
56
+ spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml
57
+ spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml
58
+ spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml
59
+ spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml
60
+ spec/fixtures/vcr_cassettes/phpbb3-should-post.yml
61
+ spec/fixtures/wwf79-forum_posts.html
62
+ spec/fixtures/wwf79-general-new-topic-error.html
63
+ spec/fixtures/wwf79-general-posting-error.html
64
+ spec/fixtures/wwf79-good-post-forum_posts.html
65
+ spec/fixtures/wwf79-index.html
66
+ spec/fixtures/wwf79-logged-in.html
67
+ spec/fixtures/wwf79-login.html
68
+ spec/fixtures/wwf79-new-topic-forum_posts-response.html
69
+ spec/fixtures/wwf79-new-topic-post_message_form.html
70
+ spec/fixtures/wwf79-not-logged-in.html
71
+ spec/fixtures/wwf79-too-many-posts.html
72
+ spec/fixtures/wwf79-too-many-topics.html
73
+ spec/fixtures/wwf80-general-posting-error.html
74
+ spec/fixtures/wwf80-get-new_topic-form-good-response.html
75
+ spec/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html
76
+ spec/fixtures/wwf80-index.html
77
+ spec/fixtures/wwf80-logged-in.html
78
+ spec/fixtures/wwf80-login.html
79
+ spec/fixtures/wwf80-new_reply_form.html
80
+ spec/fixtures/wwf80-not-logged-in.html
81
+ spec/fixtures/wwf80-post-new_topic-good-response.html
82
+ spec/fixtures/wwf80-post-reply-good-response.html
83
+ spec/fixtures/wwf80-too-many-posts.html
84
+ spec/impostor_spec_helper.rb
85
+ spec/integration/phpbb2_spec.rb
86
+ spec/integration/phpbb3_spec.rb
87
+ spec/integration_spec_helper.rb
88
+ spec/phpbb2_spec.rb
89
+ spec/phpbb3_spec.rb
90
+ spec/post_spec.rb
91
+ spec/spec_helper.rb
92
+ spec/test_impostor.rb
93
+ spec/topic_spec.rb
94
+ spec/wwf79_spec.rb
95
+ spec/wwf80_spec.rb
data/README.txt CHANGED
@@ -1,9 +1,10 @@
1
1
  impostor
2
2
  by Mike Mondragon
3
+ https://github.com/monde/impostor
3
4
  http://impostor.rubyforge.org/
4
5
 
5
6
  == DESCRIPTION:
6
-
7
+
7
8
  imPOSTor posts messages to forums
8
9
 
9
10
  == FEATURES/PROBLEMS:
@@ -12,45 +13,44 @@ Makes automated posts to the following forum applications:
12
13
 
13
14
  * Web Wiz Forums (WWF) 7.9
14
15
  * Web Wiz Forums (WWF) 8.0
15
- * PHP Bullitin Board (phpBB) 2.0 (2.0.22)
16
+ * PHP Bullitin Board (phpBB) 2.2
16
17
  * PHP Bullitin Board (phpBB) 3.0
17
18
 
18
19
  == SYNOPSIS:
19
20
 
20
21
  # config yaml has options specific to wwf79, phpbb2, etc.
21
- # Read the impostor docs for configuration options for the kind of forum to
22
+ # Read the impostor docs for configuration options for the kind of forum to
22
23
  # be accessed.
23
24
  # config can be keyed by symbols or strings
24
25
  config = YAML::load_file('conf/impostor.yml')
25
- post = WWW::Impostor.new(config)
26
+ impostor = Impostor.new(config)
26
27
  message = %q{hello world is to application
27
28
  programmers as tea pots are to graphics programmers}
28
29
  # your application stores forum and topic ids
29
- post.post(forum=5,topic=10,message)
30
+ impostor.post(forum=5,topic=10,message)
30
31
  # make a new topic
31
32
  subject = "about programmers..."
32
- post.new_topic(forum=7,subject,message)
33
- post.logout
33
+ impostor.new_topic(forum=7,subject,message)
34
34
 
35
35
  == REQUIREMENTS:
36
36
 
37
+ * hoe
37
38
  * mechanize
38
- * hpricot
39
+ * nokogiri
39
40
 
40
41
  == SOURCE
41
42
 
42
43
  git clone git://github.com/monde/impostor.git
43
- svn co svn://rubyforge.org/var/svn/impostor/trunk impostor
44
44
 
45
45
  == INSTALL:
46
46
 
47
- * sudo gem install impostor
47
+ * gem install impostor
48
48
 
49
49
  == LICENSE:
50
50
 
51
51
  (The MIT License)
52
52
 
53
- Copyright (c) 2008 Mike Mondragon
53
+ Copyright (c) 2008-2011 Mike Mondragon
54
54
 
55
55
  Permission is hereby granted, free of charge, to any person obtaining
56
56
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,40 +1,36 @@
1
1
  # -*- ruby -*-
2
2
 
3
- require 'rubygems'
4
- require 'hoe'
5
3
  begin
6
- require 'rcov/rcovtask'
4
+ require 'hoe'
7
5
  rescue LoadError
6
+ require 'rubygems'
7
+ require 'hoe'
8
8
  end
9
- require 'mechanize'
9
+ require 'rspec/core/rake_task'
10
+
10
11
  $LOAD_PATH.unshift 'lib'
11
12
  require 'impostor'
12
13
 
13
- Hoe.new('impostor', WWW::Impostor::VERSION) do |p|
14
+ Hoe.plugin :bundler, :git
15
+ Hoe.spec('impostor') do |p|
16
+ p.version = Impostor::VERSION
14
17
  p.rubyforge_name = 'impostor'
15
18
  p.author = 'Mike Mondragon'
16
19
  p.email = 'mikemondragon@gmail.com'
17
20
  p.summary = 'imPOSTor posts messages to non-RESTful forums and blogs'
18
21
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
19
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
22
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/).map{ |line| line.strip }[2]
23
+ p.readme_file = "README.txt"
24
+ p.history_file = "History.txt"
20
25
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
21
- p.extra_deps << ['hpricot', '>= 0.5.0']
22
- p.extra_deps << ['mechanize', '>= 0.7.0']
26
+ p.extra_deps << ['nokogiri', '>= 1.4.4']
27
+ p.extra_deps << ['mechanize', '>= 1.0.0']
23
28
  p.clean_globs << 'coverage'
29
+ p.testlib = :rspec
24
30
  end
25
31
 
26
- begin
27
- Rcov::RcovTask.new do |t|
28
- t.test_files = FileList['test/test_www_impostor*.rb']
29
- t.verbose = true
30
- end
31
- rescue NameError
32
- end
32
+ RSpec::Core::RakeTask.new(:spec)
33
33
 
34
- Rake::TestTask.new do |t|
35
- t.libs << "test"
36
- t.test_files = FileList['test/test_www_impostor*.rb']
37
- t.verbose = true
38
- end
34
+ task :default => :spec
39
35
 
40
36
  # vim: syntax=Ruby
@@ -0,0 +1,103 @@
1
+ class Impostor::Auth
2
+
3
+ attr_reader :config
4
+ attr_reader :authenticated
5
+ alias :authenticated? :authenticated
6
+
7
+ ##
8
+ # Auth is initialized with the config of the impostor
9
+
10
+ def initialize(config)
11
+ @config = config
12
+ self.extend eval("Impostor::#{config.type.to_s.capitalize}::Auth")
13
+ end
14
+
15
+ ##
16
+ # Login to the impostor's forum. #login is comprised of the following
17
+ # template methods to allow implementation for specific forum applications:
18
+ #
19
+ # * fetch_login_page
20
+ # * logged_in?(page)
21
+ # * get_login_form(page)
22
+ # * set_username_and_password(form)
23
+ # * post_login(form)
24
+
25
+ def login
26
+ return true if self.authenticated?
27
+
28
+ page = self.fetch_login_page
29
+ return true if self.logged_in?(page)
30
+
31
+ form = self.get_login_form(page)
32
+ self.set_username_and_password(form)
33
+ page = self.post_login(form)
34
+
35
+ @authenticated = self.logged_in?(page)
36
+ end
37
+
38
+ def login_with_raises
39
+ return true if self.login
40
+
41
+ raise Impostor::LoginError.new("not logged in")
42
+ end
43
+
44
+ ##
45
+ # logot of the impostor's forum
46
+
47
+ def logout
48
+ return false unless self.authenticated?
49
+
50
+ self.config.save_topics
51
+ self.config.save_cookie_jar
52
+
53
+ @authenticated = false
54
+
55
+ not self.authenticated?
56
+ end
57
+
58
+ ##
59
+ # given the state of the page, are we logged in to the forum?
60
+
61
+ def logged_in?(page)
62
+ raise Impostor::MissingTemplateMethodError.new("logged_in? must be implemented")
63
+ end
64
+
65
+ ##
66
+ # get the page for logging in
67
+
68
+ def fetch_login_page
69
+ begin
70
+ self.config.agent.get(self.config.login_page)
71
+ rescue StandardError => err
72
+ raise Impostor::LoginError.new(err)
73
+ end
74
+ end
75
+
76
+ ##
77
+ # returns the login form from the login page
78
+
79
+ def get_login_form(page)
80
+ raise Impostor::MissingTemplateMethodError.new("get_login_form must be implemented")
81
+ end
82
+
83
+ ##
84
+ # Sets the user name and pass word on the loing form.
85
+
86
+ def set_username_and_password(form)
87
+ raise Impostor::MissingTemplateMethodError.new("set_username_and_password must be implemented")
88
+ end
89
+
90
+ ##
91
+ # does the work of posting the login form
92
+
93
+ def post_login(form)
94
+ begin
95
+ config.sleep_before_post
96
+ page = form.submit
97
+ rescue StandardError => err
98
+ raise Impostor::LoginError.new(err)
99
+ end
100
+ end
101
+
102
+
103
+ end
@@ -0,0 +1,171 @@
1
+ class Impostor::Config
2
+
3
+ attr_reader :agent
4
+ attr_reader :topics
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ validate_keys(:type, :username, :password, :app_root, :login_page)
9
+ setup_agent
10
+ load_topics
11
+ end
12
+
13
+ ##
14
+ # Validates expected keys are in the config
15
+
16
+ def validate_keys(*keys)
17
+ keys.each do |key|
18
+ val = self.config(key)
19
+ raise Impostor::ConfigError.new("Missing key '#{key}' in configuration") unless val
20
+ end
21
+ end
22
+
23
+ ##
24
+ # Access the current config and key it without regard for symbols or strings
25
+
26
+ def config(key)
27
+ @config[key.to_sym] || @config[key.to_s]
28
+ end
29
+
30
+ ##
31
+ # Sets up the mechanize agent initialized with cookie jar file specified by
32
+ # the :cookie_jar configuration parameter if it exists
33
+
34
+ def setup_agent
35
+ @agent = Mechanize.new do |mechanize|
36
+ if logger = self.config(:logger)
37
+ if File.exist?(logger.to_s)
38
+ mechanize.log = Logger.new(logger.to_s)
39
+ elsif logger == "STDOUT"
40
+ mechanize.log = Logger.new(STDOUT)
41
+ else
42
+ mechanize.log = logger
43
+ end
44
+ end
45
+ end
46
+ @agent.user_agent_alias = self.user_agent if self.user_agent
47
+ # jar is a yaml file
48
+ @agent.cookie_jar.load(cookie_jar) if cookie_jar && File.exist?(cookie_jar)
49
+ end
50
+
51
+ ##
52
+ # Load the topics that the impostor already knows about
53
+
54
+ def load_topics
55
+ cache = self.topics_cache || ""
56
+ if File::exist?(cache)
57
+ @topics = YAML::load_file(cache)
58
+ else
59
+ @topics = Hash.new
60
+ end
61
+ end
62
+
63
+ ##
64
+ # Add subject to topics hash
65
+
66
+ def add_subject(forum, topic, name)
67
+ forum = forum.to_s
68
+ topic = topic.to_s
69
+ if self.topics[forum].nil?
70
+ self.topics[forum] = {topic, name}
71
+ else
72
+ self.topics[forum][topic] = name
73
+ end
74
+ end
75
+
76
+ ##
77
+ # Get the topic name (subject) based on forum and topic ids
78
+
79
+ def get_subject(forum, topic)
80
+ forum = forum.to_s
81
+ topic = topic.to_s
82
+ self.topics[forum] ? self.topics[forum][topic] : nil
83
+ end
84
+
85
+ ##
86
+ # Save the topics
87
+
88
+ def save_topics
89
+ cache = self.topics_cache || ""
90
+ if File::exist?(cache)
91
+ File.open(cache, 'w') do |out|
92
+ YAML.dump(self.topics, out)
93
+ end
94
+ end
95
+ end
96
+
97
+ ##
98
+ # Save the cookie jar
99
+
100
+ def save_cookie_jar
101
+ self.agent.cookie_jar.save_as(self.cookie_jar) if self.cookie_jar
102
+ end
103
+
104
+ ##
105
+ # Gets the application root of the application such as
106
+ # http://example.com/phpbb or http://example.com/forums
107
+
108
+ def app_root
109
+ self.config(:app_root)
110
+ end
111
+
112
+ ##
113
+ # Get the topics cache
114
+
115
+ def topics_cache
116
+ self.config(:topics_cache)
117
+ end
118
+
119
+ ##
120
+ # Get the login page for the application
121
+
122
+ def login_page
123
+ URI.join(app_root, self.config(:login_page))
124
+ end
125
+
126
+ ##
127
+ # Get the username for the application
128
+
129
+ def username
130
+ self.config(:username)
131
+ end
132
+
133
+ ##
134
+ # Get the password for the application
135
+
136
+ def password
137
+ self.config(:password)
138
+ end
139
+
140
+ ##
141
+ # A Mechanize user agent name, see the mechanize documentation
142
+ # 'Linux Mozilla', 'Mac Safari', 'Windows IE 7', etc.
143
+
144
+ def user_agent
145
+ self.config(:user_agent) || 'Mechanize'
146
+ end
147
+
148
+ ##
149
+ # is a yaml file for Mechanize::CookieJar
150
+
151
+ def cookie_jar
152
+ self.config(:cookie_jar)
153
+ end
154
+
155
+ ##
156
+ # The impostor type, as specified in the config
157
+
158
+ def type
159
+ self.config(:type)
160
+ end
161
+
162
+ ##
163
+ # Some forums require a bit of delay before posting to not have the post be
164
+ # considered coming from a bot.
165
+
166
+ def sleep_before_post
167
+ sleep self.config(:sleep_before_post).to_i
168
+ end
169
+
170
+ end
171
+