pdfthat-client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,117 @@
1
1
  = pdfthat-client
2
2
 
3
- Description goes here.
3
+ This gem allows you to play nicely with http://pdfth.at
4
4
 
5
+ == Overview
6
+
7
+ pdfTH.AT is a HTML to PDF rendering system that allows you to hand in HTML or a URL and have that rendered into a PDF. This can be done on a queue and posted back to your system, or rendered in real time and returned as base64 encoded data.
8
+
9
+ You'll need a free account from http://pdfth.at to play along, log in and get your token to access the system.
10
+
11
+ == Requirements
12
+
13
+ * HTTParty >= 0.5.2
14
+
15
+ == Installation
16
+
17
+ This library is intended to be installed as a Gem.
18
+
19
+ $ gem install pdfthat-client
20
+
21
+ You might need administrator privileges on your system to install it.
22
+
23
+ == Getting Started
24
+
25
+ You'll need an API token to use this gem, head over to http://pdfth.at to sign up for one, development accounts are free and can be used straight away.
26
+
27
+ Include the gem in your Gemfile, if you are running Rails
28
+
29
+ gem "pdfthat-client", :require => "pdfthat"
30
+
31
+ Include it like any other gem otherwise
32
+
33
+ require 'pdfthat'
34
+
35
+
36
+ If using rails, Initialise the library in a preinitializer
37
+
38
+ Pdfthat.configure do |pdf|
39
+ pdf.token = "<token goes here>"
40
+ end
41
+
42
+ Otherwise, initialise it before you use it.
43
+
44
+ By Default, the client will be talking to the pdfthat DEVELOPMENT api, to override this setting:
45
+
46
+ Pdfthat.configure do |pdf|
47
+ pdf.token = "<token goes here>"
48
+ pdf.production = true
49
+ end
50
+
51
+ == Usage
52
+
53
+ Using the pdfTHAT Queue for a URL
54
+
55
+ Pdfthat.create_document(:document => {:url => "http://google.com.au/"})
56
+
57
+ Using the pdfTHAT Queue for a URL with a postback
58
+
59
+ Pdfthat.create_document(:document => {:url => "http://google.com.au/", :postback_url => "http://exampl.com/documents/done"})
60
+
61
+ Using the pdfTHAT Queue for HTML
62
+
63
+ Pdfthat.create_document(:document => {:html_string => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>"})
64
+
65
+ Using the pdfTHAT Queue for HTML with a postback
66
+
67
+ Pdfthat.create_document(:document => {:html_string => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>", :postback_url => "http://exampl.com/documents/done"})
68
+
69
+ Using pdfTHAT in real-time for a URL
70
+
71
+ Pdfthat.create_document(:document => {:url => "http://google.com.au/",:wait_for_pdf => true})
72
+
73
+ Using pdfTHAT in real-time for HTML
74
+
75
+ Pdfthat.create_document(:document => {:url => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>",:wait_for_pdf => true})
76
+
77
+ The results of these calls will be similar to:
78
+
79
+ {"s3_bucket"=>"bucket",
80
+ "media_type"=>"screen",
81
+ "created_at"=>"Mon Feb 22 00:30:56 UTC 2010",
82
+ "upload_time"=>nil,
83
+ "upload_results"=>nil,
84
+ "error_messages"=>[],
85
+ "uuid"=>"76f93970-0177-012d-4131-0026b0d759a2",
86
+ "updated_at"=>"Mon Feb 22 00:30:56 UTC 2010",
87
+ "postback_url"=>nil,
88
+ "url"=>"http://google.com.au/",
89
+ "render_time"=>nil,
90
+ "storage_url"=>
91
+ "http://s3.amazonaws.com/bucket/76f93970-0177-012d-4131-0026b0d759a2.pdf",
92
+ "return_pdf"=>false,
93
+ "id"=>202,
94
+ "successful"=>true,
95
+ "user_id"=>1,
96
+ "styles"=>nil,
97
+ "render_results"=>nil,
98
+ "media"=>"screen",
99
+ "development"=>false,
100
+ "workflow_state"=>"new",
101
+ "wait_for_pdf"=>false,
102
+ "postback_time"=>nil,
103
+ "html_string"=>nil,
104
+ "postback_results"=>nil}
105
+
106
+
107
+ To query the document at a later date, use:
108
+
109
+ Pdfthat.get_document(:id => "76f93970-0177-012d-4131-0026b0d759a2")
110
+
111
+ It'll return the same result as the create_document method.
112
+
113
+ NOTE: If you are using the wait_for_pdf method, you will also get an attribute called "base64_pdf_data" that includes the PDF file encoded in base64. This is only available in the results of the create method, to access the document after that, use the storage_url attribute
114
+
5
115
  == Note on Patches/Pull Requests
6
116
 
7
117
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -3,6 +3,12 @@ class Pdfthat
3
3
  include HTTParty
4
4
  class << self
5
5
  attr :token,true
6
+ attr :production,true
7
+
8
+ def production(d)
9
+ @production = d
10
+ end
11
+
6
12
  def token(t)
7
13
  @token = t
8
14
  end
@@ -15,19 +21,23 @@ class Pdfthat
15
21
 
16
22
  def configure
17
23
  yield self
18
- end
24
+ end
25
+
26
+ def api_uri
27
+ dev_uri = @production == true ? "" : "/development"
28
+ "/api/v1#{dev_uri}"
29
+ end
19
30
 
20
31
  def create_document(options)
21
32
  return false unless @token
22
- results = post('/documents.json', :query => options.merge(:token => @token))
33
+ results = post(api_uri + "/documents.json", :query => options.merge(:token => @token))
23
34
  return results
24
35
  end
25
36
  def get_document(options)
26
37
  return false unless @token
27
- results = get("/documents/#{options[:id]}.json", :query => options.merge(:token => @token))
38
+ results = get(api_uri + "/documents/#{options[:id]}.json", :query => options.merge(:token => @token))
28
39
  return results
29
40
  end
30
-
31
41
  end
32
42
  end
33
43
  # Pdfthat.configure do |pdf|
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pdfthat-client}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["mattallen"]
12
+ s.date = %q{2010-02-22}
13
+ s.description = %q{Client to intereact with the pdfTH.AT services}
14
+ s.email = %q{matt@devlogic.com.au}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/pdfthat-client.rb",
27
+ "pdfthat-client.gemspec",
28
+ "spec/pdfthat-client_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/mattallen/pdfthat-client}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.6}
36
+ s.summary = %q{Client for http://pdfth.at}
37
+ s.test_files = [
38
+ "spec/pdfthat-client_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
+ s.add_development_dependency(%q<httparty>, [">= 0.5.2"])
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
56
+ end
57
+ end
58
+
@@ -1,40 +1,41 @@
1
- require 'httparty'
2
- class Pdfthat
3
- include HTTParty
4
- class << self
5
- attr :token,true
6
- def token(t)
7
- @token = t
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Pdfth.atRubyClient" do
4
+ context 'defaults' do
5
+ it "should set it's default URL" do
6
+ Pdfthat.base_uri.should == "http://pdfth.at"
8
7
  end
9
-
10
- def default_options
11
- @default_options[:timeout] ||= 10000
12
- @default_options[:base_uri] ||= "http://pdfth.at"
13
- super
8
+ it "should set the default timeout to 10 seconds" do
9
+ Pdfthat.default_options[:timeout].should == 10000
14
10
  end
15
-
16
- def configure
17
- yield self
18
- end
19
-
20
- def create_document(options)
21
- return false unless @token
22
- results = post('/documents.json', :query => options.merge(:token => @token))
23
- return results
11
+ it "should default to development" do
12
+ Pdfthat.api_uri.should == "/api/v1/development"
24
13
  end
25
- def get_document(options)
26
- return false unless @token
27
- results = get("/documents/#{options[:id]}.json", :query => options.merge(:token => @token))
28
- return results
14
+ it "should allow development to be over-written" do
15
+ Pdfthat.configure do |pdf|
16
+ pdf.production true
17
+ end
18
+ Pdfthat.api_uri.should == "/api/v1"
19
+ end
20
+ end
21
+ context '#get_document' do
22
+ it "should fail without a token" do
23
+ Pdfthat.get_document(:id => "abc").should == false
24
+ end
25
+ it "should pass with a token" do
26
+ Pdfthat.configure do |pdf|
27
+ pdf.token "629f29cb8d7c3de87fc248ea400b679688b3d5a128c01c981c"
28
+ pdf.base_uri "http://pdf.local"
29
+ end
30
+ Pdfthat.get_document(:id => "2f5321a0-0163-012d-412f-0026b0d759a2").should be_a(Hash)
31
+ end
32
+ end
33
+ context '#create_document' do
34
+ it "should fail without a token" do
35
+ Pdfthat.configure do |pdf|
36
+ pdf.token = nil
37
+ end
38
+ Pdfthat.create_document(:document => {:url => "http://google.com.au/"}).should == false
29
39
  end
30
-
31
40
  end
32
41
  end
33
- # Pdfthat.configure do |pdf|
34
- # pdf.token = "629f29cb8d7c3de87fc248ea400b679688b3d5a128c01c981c"
35
- # pdf.default_options = {:timeout => 1}
36
- # pdf.base_uri 'http://pdf.local'
37
- #
38
- # end
39
- # p = Pdfthat.new
40
- # puts p.get_document(:id => "2f5321a0-0163-012d-412f-0026b0d759a2")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - mattallen
@@ -62,6 +62,7 @@ files:
62
62
  - Rakefile
63
63
  - VERSION
64
64
  - lib/pdfthat-client.rb
65
+ - pdfthat-client.gemspec
65
66
  - spec/pdfthat-client_spec.rb
66
67
  - spec/spec.opts
67
68
  - spec/spec_helper.rb