doc_raptor 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # DocRaptor Gem Changelog
2
2
 
3
+ ## 0.3.0 - 2012/03/29
4
+ * BUGFIX async create calls were incorrectly returning the status id
5
+ instead of the response object
6
+ * More test (fixture) refactoring
7
+ * A little production code cleanup
8
+
3
9
  ## 0.2.3 - 2012/03/15
4
10
  * major test refactor in preparation for bigger changes
5
11
  * use current gem packaging techniques
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doc_raptor (0.2.3)
4
+ doc_raptor (0.3.0)
5
5
  httparty (>= 0.4.3)
6
6
 
7
7
  GEM
data/doc_raptor.gemspec CHANGED
@@ -5,7 +5,7 @@ require "doc_raptor/version"
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "doc_raptor"
7
7
  gem.authors = ["Michael Kuehl", "Joel Meador", "Chris Moore"]
8
- gem.email = ["michael@expectedbehavior.com"]
8
+ gem.email = ["michael@expectedbehavior.com", "joel@expectedbehavior.com"]
9
9
  gem.description = %q{Provides a simple ruby wrapper around the DocRaptor API}
10
10
  gem.summary = %q{Provides a simple ruby wrapper around the DocRaptor API}
11
11
  gem.homepage = "http://docraptor.com"
data/lib/doc_raptor.rb CHANGED
@@ -39,11 +39,6 @@ class DocRaptor
39
39
  raise_exception_on_failure = options[:raise_exception_on_failure]
40
40
  options.delete :raise_exception_on_failure
41
41
 
42
- query = { }
43
- if options[:async]
44
- query[:output => 'json']
45
- end
46
-
47
42
  # HOTFIX
48
43
  # convert safebuffers to plain old strings so the gsub'ing that has to occur
49
44
  # for url encoding works
@@ -54,12 +49,16 @@ class DocRaptor
54
49
  end
55
50
  # /HOTFIX
56
51
 
57
- response = post("/docs", :body => {:doc => options}, :basic_auth => { :username => api_key }, :query => query)
52
+ response = post("/docs", :body => {:doc => options}, :basic_auth => {:username => api_key})
58
53
 
59
54
  if raise_exception_on_failure && !response.success?
60
55
  raise DocRaptorException::DocumentCreationFailure.new response.body, response.code
61
56
  end
62
57
 
58
+ if response.success? && options[:async]
59
+ self.status_id = response.parsed_response["status_id"]
60
+ end
61
+
63
62
  if block_given?
64
63
  ret_val = nil
65
64
  Tempfile.open("docraptor") do |f|
@@ -70,8 +69,6 @@ class DocRaptor
70
69
  ret_val = yield f, response
71
70
  end
72
71
  ret_val
73
- elsif options[:async]
74
- self.status_id = response.parsed_response["status_id"]
75
72
  else
76
73
  response
77
74
  end
@@ -97,6 +94,7 @@ class DocRaptor
97
94
  if raise_exception_on_failure && !response.success?
98
95
  raise DocRaptorException::DocumentListingFailure.new response.body, response.code
99
96
  end
97
+
100
98
  response
101
99
  end
102
100
 
@@ -1,3 +1,3 @@
1
1
  class DocRaptor
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -35,13 +35,13 @@ class CreateBangTest < MiniTest::Unit::TestCase
35
35
 
36
36
  it "should give me some error message if pass some invalid content" do
37
37
  invalid_html = "<herp"
38
- stub_http_response_with("invalid_pdf", :post, 422)
38
+ stub_http_response_with("invalid_pdf.xml", :post, 422)
39
39
  assert_raises(DocRaptorException::DocumentCreationFailure) {DocRaptor.create!(:document_content => invalid_html)}
40
40
  end
41
41
 
42
42
  it "should give me a valid response if I pass some valid content" do
43
- stub_http_response_with("simple_pdf", :post)
44
- assert_equal file_fixture("simple_pdf"), DocRaptor.create!(:document_content => @html_content).body
43
+ stub_http_response_with("simple_pdf.pdf", :post)
44
+ assert_equal file_fixture("simple_pdf.pdf"), DocRaptor.create!(:document_content => @html_content).body
45
45
  end
46
46
  end
47
47
  end
data/test/create_test.rb CHANGED
@@ -4,6 +4,7 @@ class CreateTest < MiniTest::Unit::TestCase
4
4
  describe "calling create" do
5
5
  before do
6
6
  DocRaptor.api_key "something something"
7
+ DocRaptor.status_id = nil
7
8
  end
8
9
 
9
10
  describe "with bogus arguments" do
@@ -35,15 +36,54 @@ class CreateTest < MiniTest::Unit::TestCase
35
36
 
36
37
  it "should give me some error message if pass some invalid content" do
37
38
  invalid_html = "<herp"
38
- stub_http_response_with("invalid_pdf", :post, 422)
39
+ stub_http_response_with("invalid_pdf.xml", :post, 422)
39
40
  response = DocRaptor.create(:document_content => invalid_html)
40
- assert_equal file_fixture("invalid_pdf"), response.body
41
+ assert_equal file_fixture("invalid_pdf.xml"), response.body
41
42
  assert_equal 422, response.code
42
43
  end
43
44
 
44
45
  it "should give me a valid response if I pass some valid content" do
45
- stub_http_response_with("simple_pdf", :post)
46
- assert_equal file_fixture("simple_pdf"), DocRaptor.create(:document_content => @html_content).body
46
+ stub_http_response_with("simple_pdf.pdf", :post)
47
+ assert_equal file_fixture("simple_pdf.pdf"), DocRaptor.create(:document_content => @html_content).body
48
+ end
49
+ end
50
+
51
+
52
+ describe "with async" do
53
+ it "should give me a response object on successful enqueue" do
54
+ stub_http_response_with("simple_enqueue.json", :post, 200)
55
+ response = DocRaptor.create(:document_url => "http://example.com",
56
+ :async => true)
57
+ # HTTParty parties all over kind_of?/is_a?, so we can't use
58
+ # them here.
59
+ assert_equal HTTParty::Response, response.class
60
+ assert_equal response.code, 200
61
+ end
62
+
63
+ it "should set the status_id on successful enqueue" do
64
+ stub_http_response_with("simple_enqueue.json", :post,
65
+ 200, 'Content-Type' => "application/json")
66
+ response = DocRaptor.create(:document_url => "http://example.com",
67
+ :async => true)
68
+
69
+ expected_status_id = JSON.parse(file_fixture("simple_enqueue.json"))["status_id"]
70
+ assert_equal expected_status_id, DocRaptor.status_id
71
+ end
72
+
73
+ it "should give me a response object on failure to enqueue" do
74
+ stub_http_response_with("invalid_enqueue.xml", :post, 422)
75
+ response = DocRaptor.create(:document_url => "http://example.com",
76
+ :async => true)
77
+ # HTTParty parties all over kind_of?/is_a?, so we can't use
78
+ # them here.
79
+ assert_equal HTTParty::Response, response.class
80
+ end
81
+
82
+ it "should not set the status_id on failure to enqueue" do
83
+ stub_http_response_with("invalid_enqueue.xml", :post, 422)
84
+ response = DocRaptor.create(:document_url => "http://example.com",
85
+ :async => true)
86
+ assert DocRaptor.status_id.nil?, DocRaptor.status_id
47
87
  end
48
88
  end
49
89
  end
@@ -8,14 +8,14 @@ class DownloadBangTest < MiniTest::Unit::TestCase
8
8
 
9
9
  describe "with good arguments" do
10
10
  it "should give me a valid response" do
11
- stub_http_response_with("simple_download", :get)
11
+ stub_http_response_with("simple_download.pdf", :get)
12
12
  DocRaptor.download!("test-id")
13
13
  end
14
14
  end
15
15
 
16
16
  describe "with invalid arguments" do
17
17
  it "should raise an exception" do
18
- stub_http_response_with("invalid_download", :get, 400)
18
+ stub_http_response_with("invalid_download.xml", :get, 400)
19
19
  assert_raises(DocRaptorException::DocumentDownloadFailure) {DocRaptor.download!("test-id")}
20
20
  end
21
21
  end
@@ -8,7 +8,7 @@ class DownloadTest < MiniTest::Unit::TestCase
8
8
 
9
9
  describe "with good arguments" do
10
10
  it "should give me a valid response" do
11
- stub_http_response_with("simple_download", :get)
11
+ stub_http_response_with("simple_download.pdf", :get)
12
12
  DocRaptor.download("test-id")
13
13
  end
14
14
  end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors>
3
+ <error>[Document Queueing Error] There was an error queueing your document.</error>
4
+ </errors>
File without changes
@@ -0,0 +1,3 @@
1
+ {
2
+ "status_id":"28a1d7a050fe012f4f92723c91dfe57c"
3
+ }
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <docs type="array">
3
+ <doc>
4
+ <created-at type="datetime">2011-09-01T19:22:42Z</created-at>
5
+ <document-type>pdf</document-type>
6
+ <ip-address>192.168.0.1</ip-address>
7
+ <javascript type="boolean">false</javascript>
8
+ <name>try_it_now_doc</name>
9
+ <tag nil="true"></tag>
10
+ <test type="boolean">true</test>
11
+ </doc>
12
+ </docs>
File without changes
File without changes
@@ -15,12 +15,12 @@ describe "list_docs!" do
15
15
 
16
16
  describe "with good arguments" do
17
17
  it "should give me a valid response" do
18
- stub_http_response_with("simple_list_docs", :get)
19
- assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs!.body
18
+ stub_http_response_with("simple_list_docs.xml", :get)
19
+ assert_equal file_fixture("simple_list_docs.xml"), DocRaptor.list_docs!.body
20
20
  end
21
21
 
22
22
  it "raise an exception when the list get fails" do
23
- stub_http_response_with("invalid_list_docs", :get, 422)
23
+ stub_http_response_with("invalid_list_docs.xml", :get, 422)
24
24
  assert_raises(DocRaptorException::DocumentListingFailure) {DocRaptor.list_docs!}
25
25
  end
26
26
  end
@@ -15,8 +15,8 @@ class ListDocsTest < MiniTest::Unit::TestCase
15
15
 
16
16
  describe "with good arguments" do
17
17
  it "should give me a valid response" do
18
- stub_http_response_with("simple_list_docs", :get)
19
- assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs.body
18
+ stub_http_response_with("simple_list_docs.xml", :get)
19
+ assert_equal file_fixture("simple_list_docs.xml"), DocRaptor.list_docs.body
20
20
  end
21
21
  end
22
22
  end
@@ -8,14 +8,14 @@ class StatusBangTest < MiniTest::Unit::TestCase
8
8
 
9
9
  describe "with good arguments" do
10
10
  it "should give me a valid response" do
11
- stub_http_response_with("simple_status", :get)
11
+ stub_http_response_with("simple_status.json", :get)
12
12
  DocRaptor.status!("test-id")
13
13
  end
14
14
  end
15
15
 
16
16
  describe "with invalid arguments" do
17
17
  it "should raise an exception" do
18
- stub_http_response_with("invalid_status", :get, 403)
18
+ stub_http_response_with("invalid_status.xml", :get, 403)
19
19
  assert_raises(DocRaptorException::DocumentStatusFailure) {DocRaptor.status!("test-id")}
20
20
  end
21
21
  end
data/test/status_test.rb CHANGED
@@ -8,7 +8,7 @@ class StatusTest < MiniTest::Unit::TestCase
8
8
 
9
9
  describe "with good arguments" do
10
10
  it "should give me a valid response" do
11
- stub_http_response_with("simple_status", :get)
11
+ stub_http_response_with("simple_status.json", :get)
12
12
  DocRaptor.status("test-id")
13
13
  end
14
14
  end
data/test/test_helper.rb CHANGED
@@ -1,24 +1,22 @@
1
1
  require 'rubygems'
2
2
 
3
- # minitest setup
4
3
  gem 'minitest'
5
4
  require 'minitest/autorun'
6
5
  require 'minitest/spec'
7
6
  require 'minitest/mock'
8
7
  require 'webmock/minitest'
9
-
10
- # pull in the docraptor code
11
- require File.expand_path(File.dirname(__FILE__) + "/../lib/doc_raptor")
8
+ require 'pry'
9
+ require "doc_raptor"
12
10
 
13
11
  class MiniTest::Unit::TestCase
14
- def stub_http_response_with(filename, method = :any, status = 200)
12
+ def stub_http_response_with(filename, method = :any, status = 200, headers = nil)
15
13
  format = filename.split('.').last.intern
16
14
  data = file_fixture(filename)
17
15
 
18
- stub_request(method, /docraptor\.com/).to_return(:body => data, :status => status)
16
+ stub_request(method, /docraptor\.com/).to_return(:body => data, :status => status, :headers => headers)
19
17
  end
20
18
 
21
19
  def file_fixture(filename)
22
- open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
20
+ open(File.join(File.dirname(__FILE__), "fixtures", "#{filename.to_s}")).read.strip
23
21
  end
24
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doc_raptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-03-15 00:00:00.000000000Z
14
+ date: 2012-03-30 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
18
- requirement: &70205221784680 !ruby/object:Gem::Requirement
18
+ requirement: &70165480596960 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 0.4.3
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70205221784680
26
+ version_requirements: *70165480596960
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &70205221784260 !ruby/object:Gem::Requirement
29
+ requirement: &70165480595860 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70205221784260
37
+ version_requirements: *70165480595860
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: pry
40
- requirement: &70205221783620 !ruby/object:Gem::Requirement
40
+ requirement: &70165480594760 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70205221783620
48
+ version_requirements: *70165480594760
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &70205221783000 !ruby/object:Gem::Requirement
51
+ requirement: &70165480593840 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70205221783000
59
+ version_requirements: *70165480593840
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: webmock
62
- requirement: &70205221782340 !ruby/object:Gem::Requirement
62
+ requirement: &70165480592920 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,11 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70205221782340
70
+ version_requirements: *70165480592920
71
71
  description: Provides a simple ruby wrapper around the DocRaptor API
72
72
  email:
73
73
  - michael@expectedbehavior.com
74
+ - joel@expectedbehavior.com
74
75
  executables: []
75
76
  extensions: []
76
77
  extra_rdoc_files: []
@@ -97,14 +98,16 @@ files:
97
98
  - test/doc_raptor_test.rb
98
99
  - test/download_bang_test.rb
99
100
  - test/download_test.rb
100
- - test/fixtures/invalid_download
101
- - test/fixtures/invalid_list_docs
102
- - test/fixtures/invalid_pdf
103
- - test/fixtures/invalid_status
104
- - test/fixtures/simple_download
105
- - test/fixtures/simple_list_docs
106
- - test/fixtures/simple_pdf
107
- - test/fixtures/simple_status
101
+ - test/fixtures/invalid_download.xml
102
+ - test/fixtures/invalid_enqueue.xml
103
+ - test/fixtures/invalid_list_docs.xml
104
+ - test/fixtures/invalid_pdf.xml
105
+ - test/fixtures/invalid_status.xml
106
+ - test/fixtures/simple_download.pdf
107
+ - test/fixtures/simple_enqueue.json
108
+ - test/fixtures/simple_list_docs.xml
109
+ - test/fixtures/simple_pdf.pdf
110
+ - test/fixtures/simple_status.json
108
111
  - test/list_docs_bang_test.rb
109
112
  - test/list_docs_test.rb
110
113
  - test/status_bang_test.rb
@@ -124,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
127
  version: '0'
125
128
  segments:
126
129
  - 0
127
- hash: 1035474426871719147
130
+ hash: -2661456971242108702
128
131
  required_rubygems_version: !ruby/object:Gem::Requirement
129
132
  none: false
130
133
  requirements:
@@ -133,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
136
  version: '0'
134
137
  segments:
135
138
  - 0
136
- hash: 1035474426871719147
139
+ hash: -2661456971242108702
137
140
  requirements: []
138
141
  rubyforge_project:
139
142
  rubygems_version: 1.8.17
@@ -147,14 +150,16 @@ test_files:
147
150
  - test/doc_raptor_test.rb
148
151
  - test/download_bang_test.rb
149
152
  - test/download_test.rb
150
- - test/fixtures/invalid_download
151
- - test/fixtures/invalid_list_docs
152
- - test/fixtures/invalid_pdf
153
- - test/fixtures/invalid_status
154
- - test/fixtures/simple_download
155
- - test/fixtures/simple_list_docs
156
- - test/fixtures/simple_pdf
157
- - test/fixtures/simple_status
153
+ - test/fixtures/invalid_download.xml
154
+ - test/fixtures/invalid_enqueue.xml
155
+ - test/fixtures/invalid_list_docs.xml
156
+ - test/fixtures/invalid_pdf.xml
157
+ - test/fixtures/invalid_status.xml
158
+ - test/fixtures/simple_download.pdf
159
+ - test/fixtures/simple_enqueue.json
160
+ - test/fixtures/simple_list_docs.xml
161
+ - test/fixtures/simple_pdf.pdf
162
+ - test/fixtures/simple_status.json
158
163
  - test/list_docs_bang_test.rb
159
164
  - test/list_docs_test.rb
160
165
  - test/status_bang_test.rb
@@ -1,12 +0,0 @@
1
- <?xml version=\"1.0\" encoding=\"UTF-8\"?>
2
- <docs type=\"array\">
3
- <doc>
4
- <created-at type=\"datetime\">2011-09-01T19:22:42Z</created-at>
5
- <document-type>pdf</document-type>
6
- <ip-address>192.168.0.1</ip-address>
7
- <javascript type=\"boolean\">false</javascript>
8
- <name>try_it_now_doc</name>
9
- <tag nil=\"true\"></tag>
10
- <test type=\"boolean\">true</test>
11
- </doc>
12
- </docs>