pdfcrowd 1.9.0 → 2.0.0
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/lib/pdfcrowd.rb +36 -49
- metadata +5 -5
data/lib/pdfcrowd.rb
CHANGED
@@ -49,6 +49,7 @@ module Pdfcrowd
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def to_s()
|
52
|
+
|
52
53
|
@http_code ? "#{@http_code} - #{@error}" : @error
|
53
54
|
end
|
54
55
|
end
|
@@ -69,7 +70,9 @@ module Pdfcrowd
|
|
69
70
|
useSSL(false)
|
70
71
|
@fields = {
|
71
72
|
'username' => username,
|
72
|
-
'key' => apikey
|
73
|
+
'key' => apikey,
|
74
|
+
'html_zoom' => 200,
|
75
|
+
'pdf_scaling_factor' => 1
|
73
76
|
}
|
74
77
|
end
|
75
78
|
|
@@ -81,7 +84,7 @@ module Pdfcrowd
|
|
81
84
|
# return value is a string containing the PDF.
|
82
85
|
#
|
83
86
|
def convertURI(uri, outstream=nil)
|
84
|
-
return
|
87
|
+
return call_api_urlencoded('/api/pdf/convert/uri/', uri, outstream)
|
85
88
|
end
|
86
89
|
|
87
90
|
#
|
@@ -92,7 +95,7 @@ module Pdfcrowd
|
|
92
95
|
# return value is a string containing the PDF.
|
93
96
|
#
|
94
97
|
def convertHtml(content, outstream=nil)
|
95
|
-
return
|
98
|
+
return call_api_urlencoded('/api/pdf/convert/html/', content, outstream)
|
96
99
|
end
|
97
100
|
|
98
101
|
#
|
@@ -110,9 +113,8 @@ module Pdfcrowd
|
|
110
113
|
# Returns the number of available conversion tokens.
|
111
114
|
#
|
112
115
|
def numTokens()
|
113
|
-
uri =
|
114
|
-
|
115
|
-
return Integer(response)
|
116
|
+
uri = '/api/user/%s/tokens/' % @fields['username']
|
117
|
+
return Integer(call_api_urlencoded(uri))
|
116
118
|
end
|
117
119
|
|
118
120
|
def useSSL(use_ssl)
|
@@ -273,36 +275,38 @@ module Pdfcrowd
|
|
273
275
|
return http
|
274
276
|
end
|
275
277
|
|
276
|
-
def
|
277
|
-
|
278
|
-
|
278
|
+
def call_api_urlencoded(path, src=nil, out_stream=nil)
|
279
|
+
request = Net::HTTP::Post.new(path)
|
280
|
+
request.set_form_data(rename_post_data({'src' => src}))
|
281
|
+
return call_api(request, out_stream)
|
279
282
|
end
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
url = URI.parse(uri)
|
284
|
-
req = Net::HTTP::Post.new(url.path)
|
285
|
-
req.set_form_data(data)
|
283
|
+
|
284
|
+
|
285
|
+
def call_api(request, out_stream)
|
286
286
|
http = create_http_obj()
|
287
287
|
begin
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
288
|
+
http.start {|conn|
|
289
|
+
conn.request(request) {|response|
|
290
|
+
case response
|
291
|
+
when Net::HTTPSuccess
|
292
|
+
if out_stream
|
293
|
+
response.read_body do |chunk|
|
294
|
+
out_stream.write(chunk)
|
295
|
+
end
|
296
|
+
else
|
297
|
+
return response.body
|
298
|
+
end
|
299
|
+
else
|
300
|
+
raise Error.new(response.body, response.code)
|
301
|
+
end
|
302
|
+
}
|
303
|
+
}
|
300
304
|
rescue SystemCallError => why
|
301
305
|
raise Error.new("#{why}\n")
|
302
306
|
end
|
303
307
|
end
|
304
|
-
|
305
|
-
def
|
308
|
+
|
309
|
+
def rename_post_data(extra_data={})
|
306
310
|
result = extra_data.clone()
|
307
311
|
@fields.each { |key, val| result[key] = val if val }
|
308
312
|
result
|
@@ -330,26 +334,9 @@ module Pdfcrowd
|
|
330
334
|
end
|
331
335
|
|
332
336
|
def post_multipart(fpath, out_stream)
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
begin
|
337
|
-
res = http.start {|connection| connection.post(API_SELECTOR_BASE + 'pdf/convert/html/', body, headers) }
|
338
|
-
case res
|
339
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
340
|
-
if out_stream
|
341
|
-
out_stream.write(res.body)
|
342
|
-
return out_stream
|
343
|
-
else
|
344
|
-
return res.body
|
345
|
-
end
|
346
|
-
else
|
347
|
-
raise Error.new(res.body, res.code)
|
348
|
-
end
|
349
|
-
rescue SystemCallError => why
|
350
|
-
raise Error.new("#{why}\n")
|
351
|
-
end
|
352
|
-
return
|
337
|
+
req = Net::HTTP::Post.new('/api/pdf/convert/html/')
|
338
|
+
req.content_type, req.body = encode_multipart_post_data(fpath)
|
339
|
+
return call_api(req, out_stream)
|
353
340
|
end
|
354
341
|
end
|
355
342
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfcrowd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
- 9
|
7
|
+
- 2
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pdfcrowd Team
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-22 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: It lets you easily convert web pages and raw HTML code to PDF in your Ruby applications.
|