Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kuehl committed Oct 19, 2010
0 parents commit f1b6236
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
*~
\#*
.\#*
.DS_Store
*_flymake.*
*.LCK
Empty file added Changelog
Empty file.
Binary file added DocRaptor-0.1.0.gem
Binary file not shown.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2010 [Expected Behavior, LLC]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
@@ -0,0 +1,36 @@
DocRaptor
==========

This is a Ruby gem providing a simple wrapper around the DocRaptor API.


## Usage ######################################################################

The gem will look for your api key in the ENV variable "DOCRAPTOR_API_KEY". If it is
not there, you can set it directly by calling:

DocRaptor.api_key "My API Key Here"

Once an API key is set, you can create documents by calling

DocRaptor.create(:document_content => content, :document_type => "pdf", :test => false)

This will return an HTTParty respsonse object, the body of which will be the new file
(or errors, if the request was not valid). You can pass in "pdf" or "xls" as the
:document_type - default is pdf. This determines the type of file that DocRaptor will create.
You can pass in true or false for :test - default is false - and this turns on or off
test mode for DocRaptor. The only required parameter is :document_content, which should be a
string of html - this will be what DocRaptor turns into your document.

The create call can also take a block, like so:

DocRaptor.create(:document_content => content) do |file, response|
#file is a tempfile holding the response body
#reponse is the HTTParty response object
end

## Meta #######################################################################

Maintained by Expected Behavior

Released under the MIT license. http://github.com/expected-behavior/docraptor-gem
16 changes: 16 additions & 0 deletions doc_raptor.gemspec
@@ -0,0 +1,16 @@
Gem::Specification.new do |s|
s.name = %q{DocRaptor}
s.description = %q{Provides a simple wrapper around the DocRaptor API}
s.version = "0.1.0"
s.date = %q{2010-10-20}
s.authors = ["Michael Kuehl"]
s.email = %q{michael@expectedbehavior.com}
s.summary = %q{wrap up the api for DocRaptor nicely}
s.homepage = %q{http://docraptor.com}
s.files = [ "README.md", "MIT-LICENSE", "lib/doc_raptor.rb"]
[
["httparty", ">=0.6.1"],
].each do |gem_name, gem_version|
s.add_dependency gem_name, gem_version
end
end
42 changes: 42 additions & 0 deletions lib/doc_raptor.rb
@@ -0,0 +1,42 @@
require "httparty"
require "tempfile"

class DocRaptor
include HTTParty

def self.api_key(key = nil)
return default_options[:api_key] unless key
default_options[:api_key] = key
end

# when given a block, hands the block a TempFile of the resulting document
# otherwise, just returns the response
def self.create(options = { })
raise "must supply :document_content" if options[:document_content].blank?

default_options = {
:name => "default",
:document_type => "pdf",
:test => false,
}
options = default_options.merge(options)

response = post("/docs", :body => {:doc => options}, :basic_auth => { :username => api_key })

if block_given?
Tempfile.open("docraptor") do |f|
f.sync = true
f.write(response.body)
f.rewind

yield f, response
end
else
response
end
end

base_uri ENV["DOCRAPTOR_URL"] || "https://docraptor.com/"
api_key ENV["DOCRAPTOR_API_KEY"]

end

0 comments on commit f1b6236

Please sign in to comment.