doc_raptor 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8279d25ef018cd3b58f8c7f350f4da05ca82c473
4
- data.tar.gz: 4507a790ea7e62c4f344006d77ec0ac2e8805b36
3
+ metadata.gz: cd186909844dde268bbdbaf15bb0fb18407b1ad8
4
+ data.tar.gz: 3229f86f07ae00958e0ae96c4b7bf76905a4de18
5
5
  SHA512:
6
- metadata.gz: b1b2a4186acbf8a2549349c7a1ef63ca4af0fc5555a38e72cfcf3b4d4044533dbe4e0f8222c07f6b54fd2bf18dc1d93e657eea448ae0f47d804b190119a95cfc
7
- data.tar.gz: ded0a40ad621bfb035203c7cc9591a515ca5f74d7b09e3fb61b8c0cc3387ba7adad02a53016148c542266a87b0615aefad9818b3398f50f99117c6d3f831ae1d
6
+ metadata.gz: a07ab4b5ec5e953ee283a7f06275b1e69a41a9afbd01ae20a914a23046a6cd004eb948e712445d0065268f75a4282cb9727ada62eee418e5c59e3f5dd787f681
7
+ data.tar.gz: 0105f46cd76ddb7faac77c0a7a26214bcedb59e805cff136275f37989440570f99d8068b9e255a0977c178ef75517fbf1f4261f71d4d0f75e0cbaad519fe5e36
@@ -1,5 +1,10 @@
1
1
  # DocRaptor Gem Changelog
2
2
 
3
+ ## 0.5.0 - 2015/08/07
4
+ * Add a new method for getting doc logs: `DocRaptor.list_doc_logs`/`DocRaptor.list_doc_logs!`
5
+ * Add a new option to `DocRaptor.list_docs`, `DocRaptor.list_docs!`, `DocRaptor.list_doc_logs`, `DocRaptor.list_doc_logs!`: `output_format`.
6
+ Options should be one of `xml` or `json`.
7
+
3
8
  ## 0.4.0 - 2015/06/24
4
9
  * Add user agent for calls `expectedbehavior_doc_raptor_gem/<gem version> <ruby platform>/<version>`
5
10
  * Update development dependencies to be more modern and not have as many warnings when generating new gems
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # DocRaptor
2
2
 
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).
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).
4
4
 
5
5
 
6
6
  ## Usage
7
7
 
8
- 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
9
9
  not there, you can set it directly by calling:
10
10
 
11
11
  ```
@@ -27,7 +27,7 @@ You might want to set other options in that hash:
27
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
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
- * `:callback_url` - a url that we will hit with a status once the asynchronous document has been fully processed
30
+ * `:callback_url` - a url that we will hit with a status once the asynchronous document has been fully processed
31
31
 
32
32
  The only required parameter is one of `:document_content` or `:document_url`.
33
33
 
@@ -58,9 +58,9 @@ DocRaptor.status
58
58
  DocRaptor.status(status_id)
59
59
  ```
60
60
 
61
- `status_id` is the value returned from `DocRaptor.create` when `:async` is true. If you have
61
+ `status_id` is the value returned from `DocRaptor.create` when `:async` is true. If you have
62
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
63
+ This will return a hash containing, at the very least, a key of `status` with a value of
64
64
  one of the following: `{"completed", "failed", "killed", "queued", "working"}`.
65
65
 
66
66
  * If the status is `queued`, no other information will be available.
@@ -69,7 +69,7 @@ one of the following: `{"completed", "failed", "killed", "queued", "working"}`.
69
69
 
70
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
71
 
72
- To download an async document, you can visit the URL (`download_url`) provided via the `status`
72
+ To download an async document, you can visit the URL (`download_url`) provided via the `status`
73
73
  function or you can call:
74
74
 
75
75
  ```
@@ -82,21 +82,48 @@ class DocRaptor
82
82
 
83
83
  def self.list_docs!(options = { })
84
84
  raise ArgumentError.new "please pass in an options hash" unless options.is_a? Hash
85
- self.list_docs(options.merge({:raise_exception_on_failure => true}))
85
+ self.list_docs(options.merge(:raise_exception_on_failure => true))
86
86
  end
87
87
 
88
88
  def self.list_docs(options = { })
89
89
  raise ArgumentError.new "please pass in an options hash" unless options.is_a? Hash
90
90
  default_options = {
91
- :page => 1,
92
- :per_page => 100,
93
- :raise_exception_on_failure => false
91
+ :page => 1,
92
+ :per_page => 100,
93
+ :raise_exception_on_failure => false,
94
+ :output_format => "xml",
94
95
  }
95
96
  options = default_options.merge(options)
96
- raise_exception_on_failure = options[:raise_exception_on_failure]
97
- options.delete :raise_exception_on_failure
97
+ output_format = options.delete(:output_format)
98
+ raise_exception_on_failure = options.delete(:raise_exception_on_failure)
99
+
100
+ response = get("/docs.#{output_format}", :query => options, :basic_auth => { :username => api_key })
101
+ if raise_exception_on_failure && !response.success?
102
+ raise DocRaptorException::DocumentListingFailure.new response.body, response.code
103
+ end
104
+
105
+ response
106
+ end
107
+
108
+ def self.list_doc_logs!(options = { })
109
+ raise ArgumentError.new "please pass in an options hash" unless options.is_a? Hash
110
+ self.list_doc_logs(options.merge(:raise_exception_on_failure => true))
111
+ end
112
+
113
+ def self.list_doc_logs(options = { })
114
+ raise ArgumentError.new "please pass in an options hash" unless options.is_a? Hash
115
+ default_options = {
116
+ :page => 1,
117
+ :per_page => 100,
118
+ :raise_exception_on_failure => false,
119
+ :output_format => "xml",
120
+ }
121
+
122
+ options = default_options.merge(options)
123
+ output_format = options.delete(:output_format)
124
+ raise_exception_on_failure = options.delete(:raise_exception_on_failure)
98
125
 
99
- response = get("/docs", :query => options, :basic_auth => { :username => api_key })
126
+ response = get("/doc_logs.#{output_format}", :query => options, :basic_auth => { :username => api_key })
100
127
  if raise_exception_on_failure && !response.success?
101
128
  raise DocRaptorException::DocumentListingFailure.new response.body, response.code
102
129
  end
@@ -1,3 +1,3 @@
1
1
  class DocRaptor
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,74 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <doc-logs type="array">
3
+ <doc-log>
4
+ <name>8v8weck7.pdf</name>
5
+ <document-type>pdf</document-type>
6
+ <document-url>http://example.com</document-url>
7
+ <test type="boolean">true</test>
8
+ <tag nil="true"/>
9
+ <success type="boolean">true</success>
10
+ <javascript type="boolean">true</javascript>
11
+ <async type="boolean">false</async>
12
+ <strict>none</strict>
13
+ <ip-address>127.0.0.1</ip-address>
14
+ <created-at type="datetime">2015-01-06T16:53:06Z</created-at>
15
+ <generation-time type="float">4.0</generation-time>
16
+ <input-size type="integer">1294</input-size>
17
+ <output-size type="integer">24227</output-size>
18
+ <prince-options>
19
+ <baseurl>http://example.com</baseurl>
20
+ </prince-options>
21
+ <validation-errors></validation-errors>
22
+ <generation-log>dat|total_page_count|1sta|Loading document...
23
+ msg|inf||loading HTML5 input: -
24
+ sta|Running scripts...
25
+ msg|inf||loading script: /Users/joel/projects/docraptor/lib/princess.js
26
+ sta|Applying style sheets...
27
+ msg|inf||loading style sheet: /Users/joel/projects/docraptor/lib/prince_test_mode.css
28
+ sta|Preparing document...
29
+ sta|Converting document...
30
+ prg|0
31
+ msg|inf||used font: Open Sans, Bold
32
+ msg|inf||used font: Open Sans, Regular
33
+ msg|inf||used font: Times New Roman, Regular
34
+ prg|100
35
+ dat|total_page_count|1
36
+ fin|success
37
+ Tue Jan 06 12:53:09 2015: ---- begin
38
+ Tue Jan 06 12:53:09 2015: Loading document...
39
+ Tue Jan 06 12:53:09 2015: loading HTML5 input: -
40
+ Tue Jan 06 12:53:09 2015: Running scripts...
41
+ Tue Jan 06 12:53:09 2015: loading script: /Users/joel/projects/docraptor/lib/princess.js
42
+ Tue Jan 06 12:53:09 2015: Applying style sheets...
43
+ Tue Jan 06 12:53:09 2015: loading style sheet: /Users/joel/projects/docraptor/lib/prince_test_mode.css
44
+ Tue Jan 06 12:53:09 2015: Preparing document...
45
+ Tue Jan 06 12:53:09 2015: Converting document...
46
+ Tue Jan 06 12:53:10 2015: used font: Open Sans, Bold
47
+ Tue Jan 06 12:53:10 2015: used font: Open Sans, Regular
48
+ Tue Jan 06 12:53:10 2015: used font: Times New Roman, Regular
49
+ Tue Jan 06 12:53:10 2015: stats: total_page_count: 1
50
+ Tue Jan 06 12:53:10 2015: finished: success
51
+ Tue Jan 06 12:53:10 2015: ---- end
52
+ </generation-log>
53
+ </doc-log>
54
+ <doc-log>
55
+ <name>5jbvvph0.pdf</name>
56
+ <document-type>pdf</document-type>
57
+ <document-url>http://example.com</document-url>
58
+ <test type="boolean">false</test>
59
+ <tag nil="true"/>
60
+ <success type="boolean">false</success>
61
+ <javascript type="boolean">true</javascript>
62
+ <async type="boolean">false</async>
63
+ <strict>none</strict>
64
+ <ip-address>127.0.0.1</ip-address>
65
+ <created-at type="datetime">2015-01-05T16:52:39Z</created-at>
66
+ <generation-time type="float">1.0</generation-time>
67
+ <input-size type="integer">0</input-size>
68
+ <output-size type="integer">0</output-size>
69
+ <prince-options>
70
+ </prince-options>
71
+ <validation-errors>Over document limit. Please upgrade your account.</validation-errors>
72
+ <generation-log nil="true"/>
73
+ </doc-log>
74
+ </doc-logs>
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class ListDocLogsBangTest < MiniTest::Test
4
+ describe "doc_logs!" 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_doc_logs!(true) }
12
+ assert_raises(ArgumentError) { DocRaptor.list_doc_logs!(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_doc_logs.xml", :get)
19
+ assert_equal file_fixture("simple_doc_logs.xml"), DocRaptor.list_doc_logs!.body
20
+ end
21
+
22
+ it "raise an exception when the list get fails" do
23
+ stub_http_response_with("invalid_list_docs.xml", :get, 422)
24
+ assert_raises(DocRaptorException::DocumentListingFailure) { DocRaptor.list_doc_logs! }
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 ListDocLogsTest < MiniTest::Test
4
+ describe "doc_logs" 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_doc_logs(true) }
12
+ assert_raises(ArgumentError) { DocRaptor.list_doc_logs(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_doc_logs.xml", :get)
19
+ assert_equal file_fixture("simple_doc_logs.xml"), DocRaptor.list_doc_logs.body
20
+ end
21
+ end
22
+ end
23
+ 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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kuehl
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-24 00:00:00.000000000 Z
13
+ date: 2015-08-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -119,11 +119,14 @@ files:
119
119
  - test/fixtures/invalid_pdf.xml
120
120
  - test/fixtures/invalid_status.xml
121
121
  - test/fixtures/moby_dick.txt
122
+ - test/fixtures/simple_doc_logs.xml
122
123
  - test/fixtures/simple_download.pdf
123
124
  - test/fixtures/simple_enqueue.json
124
125
  - test/fixtures/simple_list_docs.xml
125
126
  - test/fixtures/simple_pdf.pdf
126
127
  - test/fixtures/simple_status.json
128
+ - test/list_doc_logs_bang_test.rb
129
+ - test/list_doc_logs_test.rb
127
130
  - test/list_docs_bang_test.rb
128
131
  - test/list_docs_test.rb
129
132
  - test/status_bang_test.rb
@@ -167,11 +170,14 @@ test_files:
167
170
  - test/fixtures/invalid_pdf.xml
168
171
  - test/fixtures/invalid_status.xml
169
172
  - test/fixtures/moby_dick.txt
173
+ - test/fixtures/simple_doc_logs.xml
170
174
  - test/fixtures/simple_download.pdf
171
175
  - test/fixtures/simple_enqueue.json
172
176
  - test/fixtures/simple_list_docs.xml
173
177
  - test/fixtures/simple_pdf.pdf
174
178
  - test/fixtures/simple_status.json
179
+ - test/list_doc_logs_bang_test.rb
180
+ - test/list_doc_logs_test.rb
175
181
  - test/list_docs_bang_test.rb
176
182
  - test/list_docs_test.rb
177
183
  - test/status_bang_test.rb