Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit f1b623616a354b0bcb4d49dff56196e27efffed5 Michael Kuehl committed Oct 19, 2010
Showing with 120 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. 0 Changelog
  3. BIN DocRaptor-0.1.0.gem
  4. +20 −0 MIT-LICENSE
  5. +36 −0 README.md
  6. +16 −0 doc_raptor.gemspec
  7. +42 −0 lib/doc_raptor.rb
@@ -0,0 +1,6 @@
+*~
+\#*
+.\#*
+.DS_Store
+*_flymake.*
+*.LCK
No changes.
Binary file not shown.
@@ -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.
@@ -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
@@ -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
@@ -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.