doc_raptor 0.2.2 → 0.2.3

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.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *~
2
+ \#*
3
+ .\#*
4
+ .DS_Store
5
+ *_flymake.*
6
+ *.LCK
7
+ .bundle
8
+ vendor/bundle
9
+ bin
10
+ *.gem
11
+ *.rbc
12
+ .bundle
13
+ .config
14
+ .yardoc
15
+ _yardoc
16
+ coverage
17
+ pkg
18
+ rdoc
19
+ spec/reports
20
+ test/tmp
21
+ test/version_tmp
22
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@docraptor_gem --create
data/Changelog.md CHANGED
@@ -1,38 +1,45 @@
1
- # DocRaptor gem Change Log
2
-
3
- ## doc_raptor 0.2.2
4
- * bug: forgot a file in the gem
5
-
6
- ## doc_raptor 0.2.1
7
- * bug: there were certain envs where .blank? wasn't defined. So,
1
+ # DocRaptor Gem Changelog
2
+
3
+ ## 0.2.3 - 2012/03/15
4
+ * major test refactor in preparation for bigger changes
5
+ * use current gem packaging techniques
6
+ * add rake into the mix so all the tests can be run with `rake` instead of `bundle exec ruby whatever`
7
+ * readme cleanup
8
+ * changelog cleanup
9
+ * added dates for all the versions to the changelog
10
+ * package all the files from the repo instead of just a few
11
+
12
+ ## 0.2.2 - 2011/12/07
13
+ * BUG: forgot a file in the gem
14
+
15
+ ## 0.2.1 - 2011/12/07
16
+ * BUG: there were certain envs where .blank? wasn't defined. So,
8
17
  pulling in the core_ext from activesupport
9
18
 
10
- ## doc_raptor 0.2.0
11
- * tests!
19
+ ## 0.2.0 - 2011/09/01
20
+ * added behavioral tests!
12
21
  * added a create! method which will raise an exception when doc creation fails
13
22
  * added a list_docs! method which will raise an exception when doc listing fails
14
23
  * added a status! method which will raise an exception when getting an async status fails
15
24
  * added a download! method which will raise an exception when getting an async status fails
16
25
 
17
- ## doc_raptor 0.1.6
18
- * allow the gem to be used outside of places with activesupport
26
+ ## 0.1.6 - 2011/08/30
27
+ * allow the gem to be used outside without activesupport
19
28
 
20
- ## doc_raptor 0.1.5
21
- * fix bug caused by activesupport safebuffers in rails ~3.0.6 and up
29
+ ## 0.1.5 - 2011/08/29
30
+ * BUG: activesupport safebuffers in rails ~3.0.6 and up were screwing up downloads
22
31
 
23
- ## doc_raptor 0.1.4
32
+ ## 0.1.4 - 2011/06/24
24
33
  * add support for creating async jobs
25
34
 
26
- ## doc_raptor 0.1.3
35
+ ## 0.1.3 - 2011/01/29
27
36
  * if a block is given to "create", make the value the block returns be the
28
37
  value create returns
29
38
  * add list_doc method, for the new api call to list created documents
30
39
 
31
- ## doc_raptor 0.1.2
40
+ ## 0.1.2 - 2010/12/02
32
41
  * add support for the the document_url parameter to create
33
-
34
- ## doc_raptor 0.1.1
35
42
  * reduce httparty requirement to 0.4.3
36
43
 
37
- ## doc_raptor 0.1
38
- * Initial release
44
+ ## 0.1 - 2010/10/29
45
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ doc_raptor (0.2.3)
5
+ httparty (>= 0.4.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.2.7)
11
+ coderay (1.0.5)
12
+ crack (0.3.1)
13
+ httparty (0.8.1)
14
+ multi_json
15
+ multi_xml
16
+ method_source (0.7.1)
17
+ minitest (2.11.3)
18
+ multi_json (1.1.0)
19
+ multi_xml (0.4.2)
20
+ pry (0.9.8.4)
21
+ coderay (~> 1.0.5)
22
+ method_source (~> 0.7.1)
23
+ slop (>= 2.4.4, < 3)
24
+ rake (0.9.2.2)
25
+ slop (2.4.4)
26
+ webmock (1.8.2)
27
+ addressable (>= 2.2.7)
28
+ crack (>= 0.1.7)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ doc_raptor!
35
+ minitest
36
+ pry
37
+ rake
38
+ webmock
data/README.md CHANGED
@@ -1,21 +1,20 @@
1
- DocRaptor
2
- ==========
1
+ # DocRaptor
3
2
 
4
- This is a Ruby gem providing a simple wrapper around the DocRaptor API. DocRaptor is a web service that allows you to convert [html to pdf](http://docraptor.com) or html to xls.
3
+ This is a Ruby gem providing a simple wrapper around the DocRaptor API. DocRaptor is a web service that allows you to convert [html to pdf](http://docraptor.com) or [html to xls](http://docraptor.com).
5
4
 
6
5
 
7
- ## Usage ######################################################################
6
+ ## Usage
8
7
 
9
- The gem will look for your api key in the ENV variable "DOCRAPTOR_API_KEY". If it is
8
+ The gem will look for your api key in the `ENV` variable `DOCRAPTOR_API_KEY`. If it is
10
9
  not there, you can set it directly by calling:
11
10
 
12
- ```ruby
11
+ ```
13
12
  DocRaptor.api_key "My API Key Here"
14
13
  ```
15
14
 
16
15
  Once an API key is set, you can create a PDF document by calling:
17
16
 
18
- ```ruby
17
+ ```
19
18
  DocRaptor.create(:document_content => content)
20
19
  ```
21
20
 
@@ -26,13 +25,13 @@ You might want to set other options in that hash:
26
25
  * `:document_type` - "pdf" or "xls"; controls the type of document generated; default is "pdf"
27
26
  * `:name` - an identifier you can use for the document; shows up in doc logs; default is "default"
28
27
  * `:test` - test mode flag; set to true to while doing testing so the docs won't count against your monthly count; default is false
28
+ * `:prince_options` - see [http://docraptor.com/documentation#pdf_options](http://docraptor.com/documentation#pdf_options) (PDFs only)
29
29
  * `:async` - create the document asynchonously; default is false
30
30
  * `:callback_url` - a url that we will hit with a status once the asynchronous document has been fully processed
31
- * `:prince_options` - see http://docraptor.com/documentation#pdf_options (PDFs only)
32
31
 
33
32
  The only required parameter is one of `:document_content` or `:document_url`.
34
33
 
35
- `create` will return an HTTParty response object, the body of which will be the new file (or errors, if the request was not valid).
34
+ `create` will return an [HTTParty](https://github.com/jnunemaker/httparty) response object, the body of which will be the new file (or errors, if the request was not valid).
36
35
 
37
36
  `create!` will raise an exception instead of return errors if there is a failure of any sort in the document generation process. It otherwise works in the same way as `create`.
38
37
 
@@ -40,56 +39,137 @@ If the document is processed asynchronously, a status id will be returned as opp
40
39
 
41
40
  The `create` call can also take a block, like so:
42
41
 
43
- ```ruby
42
+ ```
44
43
  DocRaptor.create(:document_content => content) do |file, response|
45
44
  #file is a tempfile holding the response body
46
45
  #reponse is the HTTParty response object
47
- end
46
+ end
48
47
  ```
49
48
 
49
+ ### Async Doc Creation
50
50
  To get the status of an async request, you can call:
51
51
 
52
- ```ruby
52
+ ```
53
53
  # uses the id of the most recently created async job
54
54
  DocRaptor.status
55
+ ```
56
+ ```
55
57
  # query some other async job and make it the "active" async job for the DocRaptor class
56
58
  DocRaptor.status(status_id)
57
59
  ```
58
60
 
59
61
  `status_id` is the value returned from `DocRaptor.create` when `:async` is true. If you have
60
- just created a document, status_id defaults to the last status_id received from DocRaptor.
61
- This will return a hash containing, at the very least, a key of "status" with a value of
62
- one of the following: { "completed", "failed", "killed", "queued", "working" }. If the
63
- status is "queued", no other information will be available. If the status is "working",
64
- there will be a human readable message contained in "message" that gives further details
65
- as to the state of the document. If the status is "complete" there will be a key of
66
- "download_url" that will contain a 2 time use URL that, when visited, will provide your
67
- document. There will also be a key of "download_key" that can be given to the
68
- DocRaptor.download function to obtain your document. If the status is "killed", it means
69
- the system had to abort your document generation process for an unknown reason, most
70
- likely it was taking too long to generate. If the status is "failed" you can check the
71
- "messages" value for a message and the "validation_errors" value for a more detailed reason
72
- for the failure to generate your document.
73
-
74
- To download an async document, you can visit the URL (download_url) provided via the status
62
+ just created a document, `status_id` defaults to the last `status_id` received from DocRaptor.
63
+ This will return a hash containing, at the very least, a key of `status` with a value of
64
+ one of the following: `{"completed", "failed", "killed", "queued", "working"}`.
65
+
66
+ * If the status is `queued`, no other information will be available.
67
+ * If the status is `working`, there will be a human readable message contained in "message" that gives further details as to the state of the document.
68
+ * If the status is `complete` there will be a key of "download_url" that will contain a 2 time use URL that, when visited, will provide your document.
69
+
70
+ There will also be a key of `download_key` that can be given to the `DocRaptor.download` function to obtain your document. If the status is `killed`, it means the system had to abort your document generation process for an unknown reason, most likely it was taking too long to generate. If the status is `failed` you can check the `messages` value for a message and the `validation_errors` value for a more detailed reason for the failure to generate your document.
71
+
72
+ To download an async document, you can visit the URL (`download_url`) provided via the `status`
75
73
  function or you can call:
76
74
 
77
- ```ruby
75
+ ```
78
76
  # uses the key of the most recently checked async job which is complete
79
77
  DocRaptor.download
78
+ ```
79
+ ```
80
80
  # use some other complete doc's download key
81
81
  DocRaptor.download(download_key)
82
82
  ```
83
83
 
84
- `download_key` is the value from the status hash of a call to DocRaptor.status of a completed job. If you have just checked the status of a document and it is completed, `download_key` defaults to that of the document you just checked. The download function works like DocRaptor.create in that you get back either an HTTParty response object or you can give it a block.
84
+ `download_key` is the value from the status hash of a call to `DocRaptor.status` of a completed job.
85
85
 
86
- ## Examples ###################################################################
87
- Check the examples directory for some simple examples. To make them work, you will need to have the docraptor gem installed (via bundler or gem install).
86
+ * If you have just checked the status of a document and it is completed, `download_key` defaults to that of the document you just checked.
88
87
 
89
- For more examples including a full rails example, check https://github.com/expectedbehavior/doc_raptor_examples.
88
+ The `download` function works like `DocRaptor.create` in that you get back either an HTTParty response object or you can give it a block.
90
89
 
91
- ## Meta #######################################################################
90
+ ## Examples
92
91
 
93
- Maintained by Expected Behavior
92
+ Check the examples directory for some simple examples. To make them work, you will need to have the docraptor gem installed (via bundler or gem install).
94
93
 
95
- Released under the MIT license. http://github.com/expected-behavior/docraptor-gem
94
+ For more examples including a full rails example, check [https://github.com/expectedbehavior/doc_raptor_examples](https://github.com/expectedbehavior/doc_raptor_examples).
95
+
96
+ ## Meta
97
+
98
+ Maintained by [Expected Behavior](http://expectedbehavior.com)
99
+
100
+ Released under the MIT license. [http://github.com/expected-behavior/docraptor-gem](http://github.com/expected-behavior/docraptor-gem)
101
+
102
+ ## Obligatory Raptor
103
+
104
+ ''
105
+ -'
106
+ .-
107
+ .:'
108
+ :-
109
+ -s-
110
+ 'sy.
111
+ .so'
112
+ -/-
113
+ '::.
114
+ .+o'
115
+ '+hs
116
+ .yh+
117
+ :ys-
118
+ :+/'
119
+ '/+:
120
+ :sy:
121
+ 'shh.
122
+ -yyo
123
+ -//-
124
+ ':/:'
125
+ :+o/
126
+ 'syy:
127
+ ' :yyy.
128
+ '':+- '/oo+
129
+ '..-++o++//-' .///.
130
+ ./++oooooooso+oo+. '/++/'
131
+ -oosssoosydddhhsosy+- :yyh+
132
+ .sssyssshddyhddhhhsyso' -yhhh-
133
+ -syyyyddmmmhyddhyhysyy/ '+shho'
134
+ -syyydmmmddmddhhyyyysyhy- '-//+o-
135
+ ./yyhhmmddddhhhyysssyyyydhy. '/ooo+:
136
+ :syyydmhdddddhyyyssyyyyhhhhho .+hddhs.
137
+ '/ossyhhhhhddhhhhhhdhhyhhhhhhhh: ''....'' .+shddd/
138
+ :syosyhhhyyyyhdmddhyyyyyyyhhdhhh-''.-:/++++oooo+/:. ':+ooooso'
139
+ .+ysoosyyyyyydNmmdyyyyyoosyhdddddho//+osooooosyhyooyoooyhhys+.
140
+ -oo+++sssyyhmNmmdyyyo-'-/osyhhdddddhssssyyyssyyhhhsyhhysshhy:
141
+ ':+++oossyhdNNmmhyy+. -/+osyhhddddddhhhhhyyyhdddhhdmhhyyho'
142
+ '''.:yydNmmdhyy+. ./+syyhhddddmddhdhhyyhdmmdddmmhhys.
143
+ /yydmmhyys: .:+osyhdddddddddhhhhdmmddhyyddyy+
144
+ '+syhyssyo. .+/+oshhdddddddhhhhhdNmhyysoohyyo'
145
+ '/+sooss/' /oo+ooshddddhhhhyhhdmmhysyhdsshyo-
146
+ -/o++:' /++osssyhhhhyyyyyyhdddhhhhmNyohys:
147
+ ' :o+++osssyyyyyyssyyhdmmddmmmmhohhs+
148
+ .oo++oosssyyyysyssyhmNNmmmmdhyooddyo'
149
+ :/+ssysssyyysyyyyyhdmNNNmyyhyooshhys'
150
+ ':/sddddhysyssyyyyhhhdmNNysosoooshhyy'
151
+ ./oyddmmmmmhhyyyyssoosyhdy+ososyshhh+
152
+ -+yhdddmNmNNmNNmmo/+oyyhhs+osshyshhh/
153
+ :+hdhhddmmmmmmmNd' '-syhyoshhhsyyyyo'
154
+ .:odmddddmNmmdddmm+ ./ssoshdhsyysss/
155
+ ./ohmmmy:smmddhhdmh' ''-oshhysssyys'
156
+ ./+hdmNd-:mmddhhddo .osydhhyyhho'
157
+ ./+ydmNMmydmmdddhh: .ssyhddyyhh/
158
+ odsydmNMNydmmddhh- .ossyhdhyyy.
159
+ ./'-sdmNN+/dmmddd: +hyssysyyh-
160
+ 'oyh/.'odddmm/ ohysoossyho'
161
+ ':hd:'/hhhdmo '.-/+ooosys'
162
+ '-+osyhhdmy' '/+osy/
163
+ .syyhhh. '/+osy.
164
+ 'osssys' -+ooss.
165
+ '/ooos+' '/oosss.
166
+ :oo+o+' -shhhyyy/
167
+ '+ss+oy. .yNmmmdhys.
168
+ smNdshd: -ydmdhyys/'
169
+ .mNNdydms :yhyyhy++/.
170
+ '+ddyyhdy: -sddddo++s+'
171
+ '.-/ohdmNdyyy' 'odmyss+odd/
172
+ -+oyhhhhdmmmmdhy+ ':- '.:.
173
+ 'sMmoosshmmNdmmh/.
174
+ -oo+---/ddmMhho'
175
+ :++:-'
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ desc "Default: run unit tests."
6
+ task :default => :test
7
+
8
+ desc "Test the eb-patches gem"
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push(File.expand_path "../lib", __FILE__)
3
+ require "doc_raptor/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "doc_raptor"
7
+ gem.authors = ["Michael Kuehl", "Joel Meador", "Chris Moore"]
8
+ gem.email = ["michael@expectedbehavior.com"]
9
+ gem.description = %q{Provides a simple ruby wrapper around the DocRaptor API}
10
+ gem.summary = %q{Provides a simple ruby wrapper around the DocRaptor API}
11
+ gem.homepage = "http://docraptor.com"
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DocRaptor::VERSION
17
+
18
+ gem.add_dependency "httparty", ">=0.4.3"
19
+
20
+ gem.add_development_dependency "minitest"
21
+ gem.add_development_dependency "pry"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "webmock"
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'doc_raptor'
3
+
4
+ TEN_SECONDS = 10
5
+ FIVE_MINUTES = 300
6
+
7
+ DocRaptor.api_key "YOUR_API_KEY_HERE"
8
+
9
+ pdf_html = '<html><body>I am an asynchronously-created doc.</body></html>'
10
+
11
+ def pretty_time; Time.now.strftime("%I:%M:%S %p"); end
12
+ def print_status(status = {}); puts "#{pretty_time} - Status: #{status['status']}";end
13
+
14
+ status_id = DocRaptor.create(:document_content => pdf_html,
15
+ :name => "docraptor_sample.pdf",
16
+ :document_type => "pdf",
17
+ :test => true,
18
+ :async => true)
19
+
20
+ # This timeout is 5 minutes.
21
+ # If there is no load on the background processors, this test should take (far) less than 20s. It's possible production will be backed up with real jobs, hence the timeout.
22
+ timeout_time = Time.now + FIVE_MINUTES
23
+
24
+ status = {'status' => 'queued'}
25
+
26
+ print_status(status)
27
+ while !(['completed','failed'].include? status['status']) && Time.now <= timeout_time
28
+ sleep TEN_SECONDS
29
+ status = DocRaptor.status
30
+ print_status(status)
31
+ end
32
+
33
+ if status['status'] == 'completed'
34
+ file = DocRaptor.download
35
+ File.open("docraptor_sample.pdf", "w+b") do |f|
36
+ f.write file.response.body
37
+ end
38
+ puts "#{pretty_time} - File downloaded to docraptor_sample.pdf"
39
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'doc_raptor'
3
+
4
+ DocRaptor.api_key "YOUR_API_KEY_HERE"
5
+
6
+ xls_html = "<table><tr><td>I am a test cell.</td><td>So am I</td></tr></table>"
7
+ File.open("docraptor_sample.xls", "w+") do |f|
8
+ f.write DocRaptor.create(:document_content => xls_html,
9
+ :name => "docraptor_sample.xls",
10
+ :document_type => "xls",
11
+ :test => true)
12
+ end
13
+
14
+ pdf_html = '<html><body>I am a test doc!</body></html>'
15
+ File.open("docraptor_sample.pdf", "w+") do |f|
16
+ f.write DocRaptor.create(:document_content => pdf_html,
17
+ :name => "docraptor_sample.pdf",
18
+ :document_type => "pdf",
19
+ :test => true)
20
+ end
data/lib/doc_raptor.rb CHANGED
@@ -1,34 +1,10 @@
1
1
  require "httparty"
2
2
  require "tempfile"
3
- require File.expand_path(File.dirname(__FILE__) + "/core_ext/object/blank")
4
3
 
5
- module DocRaptorError
6
- class NoApiKeyProvidedError < RuntimeError; end
7
- class NoContentError < ArgumentError; end
8
- end
9
-
10
- module DocRaptorException
11
- class DocRaptorRequestException < StandardError
12
- attr_accessor :status_code
13
- attr_accessor :message
14
- def initialize(message, status_code)
15
- self.message = message
16
- self.status_code = status_code
17
- super message
18
- end
19
-
20
- def to_s
21
- "#{self.class.name}\nHTTP Status: #{status_code}\nReturned: #{message}"
22
- end
23
-
24
- def inspect
25
- self.to_s
26
- end
27
- end
28
- class DocumentCreationFailure < DocRaptorRequestException; end
29
- class DocumentListingFailure < DocRaptorRequestException; end
30
- class DocumentStatusFailure < DocRaptorRequestException; end
31
- class DocumentDownloadFailure < DocRaptorRequestException; end
4
+ ["/core_ext/object/blank",
5
+ "/doc_raptor/error",
6
+ "/doc_raptor/exception"].each do |filename|
7
+ require File.expand_path(File.dirname(__FILE__) + filename)
32
8
  end
33
9
 
34
10
  class DocRaptor
@@ -0,0 +1,4 @@
1
+ module DocRaptorError
2
+ class NoApiKeyProvidedError < RuntimeError; end
3
+ class NoContentError < ArgumentError; end
4
+ end
@@ -0,0 +1,23 @@
1
+ module DocRaptorException
2
+ class DocRaptorRequestException < StandardError
3
+ attr_accessor :status_code
4
+ attr_accessor :message
5
+ def initialize(message, status_code)
6
+ self.message = message
7
+ self.status_code = status_code
8
+ super message
9
+ end
10
+
11
+ def to_s
12
+ "#{self.class.name}\nHTTP Status: #{status_code}\nReturned: #{message}"
13
+ end
14
+
15
+ def inspect
16
+ self.to_s
17
+ end
18
+ end
19
+ class DocumentCreationFailure < DocRaptorRequestException; end
20
+ class DocumentListingFailure < DocRaptorRequestException; end
21
+ class DocumentStatusFailure < DocRaptorRequestException; end
22
+ class DocumentDownloadFailure < DocRaptorRequestException; end
23
+ end
@@ -0,0 +1,3 @@
1
+ class DocRaptor
2
+ VERSION = "0.2.3"
3
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class ApiKeyTest < MiniTest::Unit::TestCase
4
+ describe "test API keys" do
5
+ before do
6
+ DocRaptor.default_options.delete :api_key
7
+ ENV.delete "DOCRAPTOR_API_KEY"
8
+ @test_key = "Test Key!"
9
+ end
10
+
11
+ it "should throw an error if no api key is provided via a key, set in the environment, or already set on the DocRaptor class object" do
12
+ assert_raises(DocRaptorError::NoApiKeyProvidedError) {DocRaptor.api_key}
13
+ end
14
+
15
+ it "should read the api key from the ENV" do
16
+ ENV["DOCRAPTOR_API_KEY"] = @test_key
17
+ assert_equal @test_key, DocRaptor.api_key
18
+ end
19
+
20
+ it "changes to the ENV variable shouldn't be implicitly picked up" do
21
+ ENV["DOCRAPTOR_API_KEY"] = @test_key
22
+ DocRaptor.api_key
23
+
24
+ ENV["DOCRAPTOR_API_KEY"] = "some other key"
25
+ assert_equal @test_key, DocRaptor.api_key
26
+ end
27
+
28
+ it "should use the passed in key" do
29
+ assert_equal @test_key, DocRaptor.api_key(@test_key)
30
+ end
31
+
32
+ it "should persist the passed in key on subsequent calls" do
33
+ DocRaptor.api_key(@test_key)
34
+ assert_equal @test_key, DocRaptor.api_key
35
+ end
36
+
37
+ it "should override keys when passed in explicitly" do
38
+ other_key = "some other key"
39
+ DocRaptor.api_key(@test_key)
40
+ assert_equal other_key, DocRaptor.api_key(other_key)
41
+ end
42
+
43
+ it "should persist overridden keys" do
44
+ other_key = "some other key"
45
+ DocRaptor.api_key(@test_key)
46
+ DocRaptor.api_key(other_key)
47
+ assert_equal other_key, DocRaptor.api_key
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class CreateBangTest < MiniTest::Unit::TestCase
4
+ describe "calling create!" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with bogus arguments" do
10
+ it "should raise an error if something other than an options hash is passed in" do
11
+ assert_raises(ArgumentError) {DocRaptor.create!(true)}
12
+ assert_raises(ArgumentError) {DocRaptor.create!(nil)}
13
+ end
14
+
15
+ it "should raise an error if document_content and document_url are both unset" do
16
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!}
17
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!({:herped => :the_derp})}
18
+ end
19
+
20
+ it "should raise an error if document_content is passed by is blank" do
21
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => nil)}
22
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => "")}
23
+ end
24
+
25
+ it "should raise an error if document_url is passed by is blank" do
26
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => nil)}
27
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => "")}
28
+ end
29
+ end
30
+
31
+ describe "with document_content" do
32
+ before do
33
+ @html_content = "<html><body>Hey</body></html>"
34
+ end
35
+
36
+ it "should give me some error message if pass some invalid content" do
37
+ invalid_html = "<herp"
38
+ stub_http_response_with("invalid_pdf", :post, 422)
39
+ assert_raises(DocRaptorException::DocumentCreationFailure) {DocRaptor.create!(:document_content => invalid_html)}
40
+ end
41
+
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
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class CreateTest < MiniTest::Unit::TestCase
4
+ describe "calling create" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with bogus arguments" do
10
+ it "should raise an error if something other than an options hash is passed in" do
11
+ assert_raises(ArgumentError) {DocRaptor.create(true)}
12
+ assert_raises(ArgumentError) {DocRaptor.create(nil)}
13
+ end
14
+
15
+ it "should raise an error if document_content and document_url are both unset" do
16
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create}
17
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create({:herped => :the_derp})}
18
+ end
19
+
20
+ it "should raise an error if document_content is passed by is blank" do
21
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => nil)}
22
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => "")}
23
+ end
24
+
25
+ it "should raise an error if document_url is passed by is blank" do
26
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => nil)}
27
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => "")}
28
+ end
29
+ end
30
+
31
+ describe "with document_content" do
32
+ before do
33
+ @html_content = "<html><body>Hey</body></html>"
34
+ end
35
+
36
+ it "should give me some error message if pass some invalid content" do
37
+ invalid_html = "<herp"
38
+ stub_http_response_with("invalid_pdf", :post, 422)
39
+ response = DocRaptor.create(:document_content => invalid_html)
40
+ assert_equal file_fixture("invalid_pdf"), response.body
41
+ assert_equal 422, response.code
42
+ end
43
+
44
+ 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
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class DocRaptorTest < MiniTest::Unit::TestCase
4
+ describe "the public interface" do
5
+ methods = [:api_key,
6
+ :create,
7
+ :create!,
8
+ :list_docs,
9
+ :list_docs!,
10
+ :status,
11
+ :status!,
12
+ :download,
13
+ :download!].each do |method_name|
14
+ it "should respond to #{method_name}" do
15
+ assert DocRaptor.respond_to?(method_name)
16
+ end
17
+ end
18
+ end
19
+
20
+ # TODO basic tests of the various exception/error classes beyond
21
+ # what is used in the gem functionality tests
22
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class DownloadBangTest < MiniTest::Unit::TestCase
4
+ describe "download!" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with good arguments" do
10
+ it "should give me a valid response" do
11
+ stub_http_response_with("simple_download", :get)
12
+ DocRaptor.download!("test-id")
13
+ end
14
+ end
15
+
16
+ describe "with invalid arguments" do
17
+ it "should raise an exception" do
18
+ stub_http_response_with("invalid_download", :get, 400)
19
+ assert_raises(DocRaptorException::DocumentDownloadFailure) {DocRaptor.download!("test-id")}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class DownloadTest < MiniTest::Unit::TestCase
4
+ describe "download" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with good arguments" do
10
+ it "should give me a valid response" do
11
+ stub_http_response_with("simple_download", :get)
12
+ DocRaptor.download("test-id")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>
2
+ <errors>
3
+ <error>[Download Key Error] The supplied download key is not valid.</error>
4
+ </errors>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors>
3
+ <error>Something went horribly awry!</error>
4
+ </errors>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors>
3
+ <error>Document Malformed: Tag herp invalid</error>
4
+ <error>Document Malformed: Couldn't find end of Start Tag herp</error>
5
+ </errors>
@@ -0,0 +1,4 @@
1
+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>
2
+ <errors>
3
+ <error>[Authentication Error] You do not have permission to view the status of this document.</error>
4
+ </errors>
Binary file
@@ -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>
Binary file
@@ -0,0 +1,6 @@
1
+ {
2
+ "status":"completed",
3
+ "message":"Completed at Thu Sep 01 20:02:52 +0000 2011",
4
+ "download_url":"http://docraptor.com/download/ffffffffffd74b4a993fcae917699ed7",
5
+ "number_of_pages":1
6
+ }
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class ListDocsBangTest < MiniTest::Unit::TestCase
4
+ describe "list_docs!" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with bogus arguments" do
10
+ it "should raise an error if something other than an options hash is passed in" do
11
+ assert_raises(ArgumentError) {DocRaptor.list_docs!(true)}
12
+ assert_raises(ArgumentError) {DocRaptor.list_docs!(nil)}
13
+ end
14
+ end
15
+
16
+ describe "with good arguments" do
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
20
+ end
21
+
22
+ it "raise an exception when the list get fails" do
23
+ stub_http_response_with("invalid_list_docs", :get, 422)
24
+ assert_raises(DocRaptorException::DocumentListingFailure) {DocRaptor.list_docs!}
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class ListDocsTest < MiniTest::Unit::TestCase
4
+ describe "list_docs" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with bogus arguments" do
10
+ it "should raise an error if something other than an options hash is passed in" do
11
+ assert_raises(ArgumentError) {DocRaptor.list_docs(true)}
12
+ assert_raises(ArgumentError) {DocRaptor.list_docs(nil)}
13
+ end
14
+ end
15
+
16
+ describe "with good arguments" do
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
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class StatusBangTest < MiniTest::Unit::TestCase
4
+ describe "status!" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with good arguments" do
10
+ it "should give me a valid response" do
11
+ stub_http_response_with("simple_status", :get)
12
+ DocRaptor.status!("test-id")
13
+ end
14
+ end
15
+
16
+ describe "with invalid arguments" do
17
+ it "should raise an exception" do
18
+ stub_http_response_with("invalid_status", :get, 403)
19
+ assert_raises(DocRaptorException::DocumentStatusFailure) {DocRaptor.status!("test-id")}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class StatusTest < MiniTest::Unit::TestCase
4
+ describe "status" do
5
+ before do
6
+ DocRaptor.api_key "something something"
7
+ end
8
+
9
+ describe "with good arguments" do
10
+ it "should give me a valid response" do
11
+ stub_http_response_with("simple_status", :get)
12
+ DocRaptor.status("test-id")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+
3
+ # minitest setup
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest/spec'
7
+ require 'minitest/mock'
8
+ require 'webmock/minitest'
9
+
10
+ # pull in the docraptor code
11
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/doc_raptor")
12
+
13
+ class MiniTest::Unit::TestCase
14
+ def stub_http_response_with(filename, method = :any, status = 200)
15
+ format = filename.split('.').last.intern
16
+ data = file_fixture(filename)
17
+
18
+ stub_request(method, /docraptor\.com/).to_return(:body => data, :status => status)
19
+ end
20
+
21
+ def file_fixture(filename)
22
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
23
+ end
24
+ end
metadata CHANGED
@@ -1,88 +1,162 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: doc_raptor
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Kuehl
14
9
  - Joel Meador
15
10
  - Chris Moore
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2011-08-29 00:00:00 -04:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
14
+ date: 2012-03-15 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
24
17
  name: httparty
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &70205221784680 !ruby/object:Gem::Requirement
27
19
  none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 9
32
- segments:
33
- - 0
34
- - 4
35
- - 3
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
36
23
  version: 0.4.3
37
24
  type: :runtime
38
- version_requirements: *id001
25
+ prerelease: false
26
+ version_requirements: *70205221784680
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: &70205221784260 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *70205221784260
38
+ - !ruby/object:Gem::Dependency
39
+ name: pry
40
+ requirement: &70205221783620 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70205221783620
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: &70205221783000 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70205221783000
60
+ - !ruby/object:Gem::Dependency
61
+ name: webmock
62
+ requirement: &70205221782340 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70205221782340
39
71
  description: Provides a simple ruby wrapper around the DocRaptor API
40
- email: michael@expectedbehavior.com
72
+ email:
73
+ - michael@expectedbehavior.com
41
74
  executables: []
42
-
43
75
  extensions: []
44
-
45
76
  extra_rdoc_files: []
46
-
47
- files:
77
+ files:
78
+ - .gitignore
79
+ - .rvmrc
48
80
  - Changelog.md
49
- - README.md
81
+ - Gemfile
82
+ - Gemfile.lock
50
83
  - MIT-LICENSE
51
- - lib/doc_raptor.rb
84
+ - README.md
85
+ - Rakefile
86
+ - doc_raptor.gemspec
87
+ - examples/async_ruby_example.rb
88
+ - examples/docraptor_gem_example.rb
52
89
  - lib/core_ext/object/blank.rb
53
- has_rdoc: true
90
+ - lib/doc_raptor.rb
91
+ - lib/doc_raptor/error.rb
92
+ - lib/doc_raptor/exception.rb
93
+ - lib/doc_raptor/version.rb
94
+ - test/api_key_test.rb
95
+ - test/create_bang_test.rb
96
+ - test/create_test.rb
97
+ - test/doc_raptor_test.rb
98
+ - test/download_bang_test.rb
99
+ - 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
108
+ - test/list_docs_bang_test.rb
109
+ - test/list_docs_test.rb
110
+ - test/status_bang_test.rb
111
+ - test/status_test.rb
112
+ - test/test_helper.rb
54
113
  homepage: http://docraptor.com
55
114
  licenses: []
56
-
57
115
  post_install_message:
58
116
  rdoc_options: []
59
-
60
- require_paths:
117
+ require_paths:
61
118
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
119
+ required_ruby_version: !ruby/object:Gem::Requirement
63
120
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
69
126
  - 0
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
127
+ hash: 1035474426871719147
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
129
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
78
135
  - 0
79
- version: "0"
136
+ hash: 1035474426871719147
80
137
  requirements: []
81
-
82
138
  rubyforge_project:
83
- rubygems_version: 1.6.0
139
+ rubygems_version: 1.8.17
84
140
  signing_key:
85
141
  specification_version: 3
86
- summary: wrap up the api for DocRaptor nicely
87
- test_files: []
88
-
142
+ summary: Provides a simple ruby wrapper around the DocRaptor API
143
+ test_files:
144
+ - test/api_key_test.rb
145
+ - test/create_bang_test.rb
146
+ - test/create_test.rb
147
+ - test/doc_raptor_test.rb
148
+ - test/download_bang_test.rb
149
+ - 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
158
+ - test/list_docs_bang_test.rb
159
+ - test/list_docs_test.rb
160
+ - test/status_bang_test.rb
161
+ - test/status_test.rb
162
+ - test/test_helper.rb