form_api 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16637dd3f1d35a14cb131ac8ebf6432498d67906
4
- data.tar.gz: c99c0ad76de1990a41656289284b2dc32c8faf43
3
+ metadata.gz: a43920ddce58d1e34829ae44d775d6f533a2bd62
4
+ data.tar.gz: 4aa5e61ffdf7c1426a55d104e679e4623495e2bf
5
5
  SHA512:
6
- metadata.gz: 0cfef6e030171349458ef9c01d50464e26354da4fe13ab60e2123e276bbbc01ff1b9bb0b9350e88a77d4bbbf816f45b72b85cf0bab88502690f54fa4ec55dba4
7
- data.tar.gz: 3bb5fc4eb9359d1077ee0e59e36cfec537a1386dd4aa48491619bb3c655b457c629c00dde923e9223fc1b0a9442862dc71459dee69fdec5c0dc4d5b5f434d6fd
6
+ metadata.gz: f281aa2c9f5a2dbfcb41cd3996c62bd20db86ae4ccd62c494bbfc80e4077a1f94860e20f2490e535ed96a7534223b310613bf964c6034c3638f9e79b2c291c27
7
+ data.tar.gz: 497aeb7db329614c0337da92b70241bd47b044d7e869055bcc1816cef3008a890b6cc7065447aaa49f548e092fb0b8f167342a22cbf87a5e0b62c94715ac99cb
data/README.md CHANGED
@@ -5,7 +5,11 @@ This is a Ruby gem for using [FormAPI](https://formapi.io) to generate PDF docum
5
5
 
6
6
  ## Installation
7
7
 
8
- Add the following to your `Gemfile`.
8
+ ```bash
9
+ gem install form_api
10
+ ```
11
+
12
+ Or add the following to your `Gemfile`.
9
13
 
10
14
  ```ruby
11
15
  gem "form_api"
@@ -20,25 +24,26 @@ bundle install
20
24
 
21
25
  ## Usage
22
26
 
23
- See [examples](examples/) for runnable examples with file output, error handling, etc.
27
+ See [examples](examples/) for runnable examples.
24
28
 
25
29
  ```ruby
26
30
  FormAPI.configure do |config|
27
- config.username = "YOUR_API_KEY_HERE"
28
- # config.debugging = true
31
+ config.username = "YOUR_API_TOKEN_ID"
32
+ config.password = "YOUR_API_TOKEN_SECRET"
29
33
  end
30
34
 
31
35
  formapi = FormAPI::Client.new
32
36
 
33
37
  response = formapi.generate_pdf(
34
- template_id: '<TEMPLATE_ID>', # ID of a template that you have configured
35
- test: true, # Test documents are free but watermarked
36
- template_data: { # Data to fill in the template
38
+ template_id: '<TEMPLATE_ID>', # ID of a template that you have configured
39
+ test: true, # Test documents are free but watermarked
40
+ template_data: { # Data to fill in the template
37
41
  name: "foo",
38
42
  number: 42
39
- },
40
- key: "<CUSTOM_KEY>", # Helps you find a PDF later
43
+ }
41
44
  )
45
+
46
+
42
47
  ```
43
48
 
44
49
  This submits a PDF request and waits for the job to finish.
@@ -46,14 +51,15 @@ This submits a PDF request and waits for the job to finish.
46
51
 
47
52
  ## More Help
48
53
 
49
- See the FormAPI documentation for more information.
54
+ See the [FormAPI documentation](https://formapi.io/docs) for more information.
50
55
 
51
- Please [email us](mailto:support@formapi.io) if you need help.
56
+ Please [email us](mailto:support@formapi.io) if you need any help.
52
57
 
53
58
 
54
59
  ## Development
55
60
 
56
- The majority of the code in this repo is generated using swagger-codegen on [formapi.yaml](formapi.yaml). You can modify this file and regenerate the client using `script/generate_language ruby`.
61
+ The majority of the code in this repo is generated using swagger-codegen.
62
+ You can modify this file and regenerate the client using `scripts/generate`.
57
63
 
58
64
 
59
65
  ## Release Process
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This example demonstrates generating a PDF from a preconfigured template,
4
+ # and downloading the PDF to a local file.
5
+ #
6
+ # You can run this example with: ./examples/generate_and_download_pdf.rb
7
+
8
+ require "bundler/setup"
9
+ Bundler.require
10
+
11
+ API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
+ API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
+ TEMPLATE_ID = '6zz3dYRYM67fxMXA'
14
+
15
+ PDF_FILENAME = '/tmp/formapi-test.pdf'
16
+
17
+ begin
18
+ FormAPI.configure do |c|
19
+ c.username = API_TOKEN_ID # Your API Token ID
20
+ c.password = API_TOKEN_SECRET # Your API Token Secret
21
+ # c.debugging = true
22
+ end
23
+
24
+ formapi = FormAPI::Client.new
25
+
26
+ puts "Downloading PDF to #{PDF_FILENAME}..."
27
+
28
+ formapi.generate_and_download_pdf(
29
+ template_id: '6zz3dYRYM67fxMXA',
30
+ filename: PDF_FILENAME,
31
+ data: {
32
+ first_name: 'John',
33
+ last_name: 'Smith',
34
+ favorite_color: 'Blue'
35
+ }
36
+ )
37
+
38
+ puts "PDF was downloaded to /tmp/formapi-test.pdf"
39
+
40
+ # Open the PDF on Mac or Linux.
41
+ `type xdg-open > /dev/null 2>&1 && xdg-open '#{PDF_FILENAME}' || open '#{PDF_FILENAME}'`
42
+
43
+ rescue FormAPI::ApiError => ex
44
+ puts "#{ex.class}: #{ex.message}"
45
+ puts ex.code # HTTP response code
46
+ puts ex.response_body # HTTP response body
47
+ puts ex.backtrace[0..3].join("\n")
48
+ end
@@ -1,28 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
+ #
2
3
  # This example demonstrates generating a PDF from a preconfigured template,
3
- # and downloading the PDF to a local file.
4
+ # and waiting for the PDF to be processed.
4
5
  #
5
6
  # You can run this example with: ./examples/generate_pdf.rb
6
7
 
7
8
  require "bundler/setup"
8
9
  Bundler.require
9
10
 
10
- PDF_FILENAME = '/tmp/formapi-test.pdf'
11
+ API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
+ API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
+ TEMPLATE_ID = '6zz3dYRYM67fxMXA'
14
+
11
15
 
12
16
  begin
13
17
  FormAPI.configure do |c|
14
- c.username = "yRaaR9JmTPtGX7EN" # Your API Token ID
15
- c.password = "IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec" # Your API Token Secret
18
+ c.username = API_TOKEN_ID # Your API Token ID
19
+ c.password = API_TOKEN_SECRET # Your API Token Secret
16
20
  # c.debugging = true
17
21
  end
18
22
 
19
23
  formapi = FormAPI::Client.new
20
24
 
21
- puts "Downloading PDF to /tmp/formapi-test.pdf..."
25
+ puts "Generating PDF and waiting until ready..."
22
26
 
23
- formapi.generate_and_download_pdf(
24
- template_id: '6zz3dYRYM67fxMXA',
25
- filename: PDF_FILENAME,
27
+ response = formapi.generate_pdf(
28
+ template_id: TEMPLATE_ID,
29
+ test: true,
26
30
  data: {
27
31
  first_name: 'John',
28
32
  last_name: 'Smith',
@@ -30,10 +34,8 @@ begin
30
34
  }
31
35
  )
32
36
 
33
- puts "PDF was downloaded to /tmp/formapi-test.pdf"
34
-
35
- # Open the PDF on Mac or Linux.
36
- `type xdg-open > /dev/null 2>&1 && xdg-open '#{PDF_FILENAME}' || open '#{PDF_FILENAME}'`
37
+ puts "PDF was generated:"
38
+ puts response
37
39
 
38
40
  rescue FormAPI::ApiError => ex
39
41
  puts "#{ex.class}: #{ex.message}"
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This example demonstrates generating a PDF from a preconfigured template,
4
+ # and NOT waiting for the PDF to be processed.
5
+ #
6
+ # You can run this example with: ./examples/generate_pdf.rb
7
+
8
+ require "bundler/setup"
9
+ Bundler.require
10
+
11
+ API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
+ API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
+ TEMPLATE_ID = '6zz3dYRYM67fxMXA'
14
+
15
+ begin
16
+ FormAPI.configure do |c|
17
+ c.username = API_TOKEN_ID # Your API Token ID
18
+ c.password = API_TOKEN_SECRET # Your API Token Secret
19
+ # c.debugging = true
20
+ end
21
+
22
+ formapi = FormAPI::Client.new
23
+
24
+ puts "Generating PDF, but not waiting for job to finish processing..."
25
+
26
+ response = formapi.generate_pdf(
27
+ template_id: TEMPLATE_ID,
28
+ wait: false,
29
+ data: {
30
+ first_name: 'John',
31
+ last_name: 'Smith',
32
+ favorite_color: 'Blue'
33
+ }
34
+ )
35
+
36
+ puts "PDF job was submitted:"
37
+ puts response
38
+
39
+ submission = response.submission
40
+ while submission.state == 'pending'
41
+ sleep 1
42
+ submission = formapi.get_submission(response.submission.id)
43
+ end
44
+
45
+ puts "PDF finished processing:"
46
+ puts submission
47
+
48
+
49
+ rescue FormAPI::ApiError => ex
50
+ puts "#{ex.class}: #{ex.message}"
51
+ puts ex.code # HTTP response code
52
+ puts ex.response_body # HTTP response body
53
+ puts ex.backtrace[0..3].join("\n")
54
+ end
@@ -10,22 +10,28 @@ module FormAPI
10
10
  class PollTimeoutError < ApiError; end
11
11
  class InvalidResponseError < ApiError; end
12
12
 
13
- def generate_pdf(template_id, opts = {})
13
+ def generate_pdf(opts = {})
14
14
  unless opts[:data].kind_of?(::Hash)
15
15
  raise InvalidDataError, ":data is required, and must be a Hash."
16
16
  end
17
17
 
18
+ # Wait for job to finish by default.
19
+ if !opts.has_key?(:wait)
20
+ opts[:wait] = true
21
+ end
22
+
18
23
  # FormAPI requires a nested :data object.
19
24
  opts[:data] = { data: opts.delete(:data) }
20
25
 
26
+ template_id = opts.delete :template_id
21
27
  response = super(template_id, opts)
28
+
22
29
  return response unless opts[:wait]
23
30
 
31
+ submission = response.submission
24
32
  timeout = opts[:timeout] || 60
25
33
  start_time = Time.now
26
34
 
27
- submission = response.submission
28
-
29
35
  # Wait for submission to be ready
30
36
  while submission.state != 'processed'
31
37
  sleep 1
@@ -43,17 +49,14 @@ module FormAPI
43
49
  end
44
50
 
45
51
  def generate_and_download_pdf(opts = {})
46
- template_id = opts.delete :template_id
47
52
  filename = opts.delete :filename
48
53
 
49
- response = generate_pdf(template_id, opts.merge(wait: true))
54
+ response = generate_pdf(opts.merge(wait: true))
50
55
  submission = response.submission
51
56
 
52
57
  pdf_response = Typhoeus.get(submission.download_url, followlocation: true)
53
58
 
54
- File.open(filename, 'wb') do |f|
55
- f.write pdf_response.body
56
- end
59
+ File.open(filename, 'wb') { |f| f.write pdf_response.body }
57
60
 
58
61
  response
59
62
  end
@@ -15,12 +15,15 @@ require 'date'
15
15
  module FormAPI
16
16
 
17
17
  class Data
18
+ attr_accessor :test
19
+
18
20
  attr_accessor :data
19
21
 
20
22
 
21
23
  # Attribute mapping from ruby-style variable name to JSON key.
22
24
  def self.attribute_map
23
25
  {
26
+ :'test' => :'test',
24
27
  :'data' => :'data'
25
28
  }
26
29
  end
@@ -28,6 +31,7 @@ module FormAPI
28
31
  # Attribute type mapping.
29
32
  def self.swagger_types
30
33
  {
34
+ :'test' => :'BOOLEAN',
31
35
  :'data' => :'Object'
32
36
  }
33
37
  end
@@ -40,6 +44,10 @@ module FormAPI
40
44
  # convert string to symbol for hash key
41
45
  attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
42
46
 
47
+ if attributes.has_key?(:'test')
48
+ self.test = attributes[:'test']
49
+ end
50
+
43
51
  if attributes.has_key?(:'data')
44
52
  self.data = attributes[:'data']
45
53
  end
@@ -69,6 +77,7 @@ module FormAPI
69
77
  def ==(o)
70
78
  return true if self.equal?(o)
71
79
  self.class == o.class &&
80
+ test == o.test &&
72
81
  data == o.data
73
82
  end
74
83
 
@@ -81,7 +90,7 @@ module FormAPI
81
90
  # Calculates hash code according to all attributes.
82
91
  # @return [Fixnum] Hash code
83
92
  def hash
84
- [data].hash
93
+ [test, data].hash
85
94
  end
86
95
 
87
96
  # Builds the object from hash
@@ -17,6 +17,8 @@ module FormAPI
17
17
  class InlineResponse201Submission
18
18
  attr_accessor :id
19
19
 
20
+ attr_accessor :test
21
+
20
22
  attr_accessor :state
21
23
 
22
24
  attr_accessor :download_url
@@ -47,6 +49,7 @@ module FormAPI
47
49
  def self.attribute_map
48
50
  {
49
51
  :'id' => :'id',
52
+ :'test' => :'test',
50
53
  :'state' => :'state',
51
54
  :'download_url' => :'download_url'
52
55
  }
@@ -56,6 +59,7 @@ module FormAPI
56
59
  def self.swagger_types
57
60
  {
58
61
  :'id' => :'String',
62
+ :'test' => :'BOOLEAN',
59
63
  :'state' => :'String',
60
64
  :'download_url' => :'String'
61
65
  }
@@ -73,6 +77,10 @@ module FormAPI
73
77
  self.id = attributes[:'id']
74
78
  end
75
79
 
80
+ if attributes.has_key?(:'test')
81
+ self.test = attributes[:'test']
82
+ end
83
+
76
84
  if attributes.has_key?(:'state')
77
85
  self.state = attributes[:'state']
78
86
  end
@@ -124,6 +132,7 @@ module FormAPI
124
132
  return true if self.equal?(o)
125
133
  self.class == o.class &&
126
134
  id == o.id &&
135
+ test == o.test &&
127
136
  state == o.state &&
128
137
  download_url == o.download_url
129
138
  end
@@ -137,7 +146,7 @@ module FormAPI
137
146
  # Calculates hash code according to all attributes.
138
147
  # @return [Fixnum] Hash code
139
148
  def hash
140
- [id, state, download_url].hash
149
+ [id, test, state, download_url].hash
141
150
  end
142
151
 
143
152
  # Builds the object from hash
@@ -11,5 +11,5 @@ Swagger Codegen version: 2.3.0-SNAPSHOT
11
11
  =end
12
12
 
13
13
  module FormAPI
14
- VERSION = "0.1.0"
14
+ VERSION = "0.1.1"
15
15
  end
File without changes
File without changes
data/scripts/generate ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "$(dirname "$0")/.."
4
+
5
+ LANGUAGE=ruby
6
+ CONFIG_FILE="swagger-config.json"
7
+
8
+ if [ ! -f "$CONFIG_FILE" ]; then
9
+ echo "Could not find $CONFIG_FILE"
10
+ ./scripts/swagger config-help -l "$LANGUAGE"
11
+ exit 1
12
+ fi
13
+
14
+ ./scripts/clean
15
+
16
+ ./scripts/swagger generate \
17
+ -i ../form_api/swagger/v1/swagger.json \
18
+ -l "$LANGUAGE" \
19
+ -c "$CONFIG_FILE"
20
+
21
+ # call a generator cleanup script
22
+ ./scripts/post_generate
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ echo "Removing trailing whitespace..."
6
+ find lib -name "*.rb" -type f -exec sed -E -i 's/[[:space:]]+$//g' {} +
7
+
8
+ echo "Fixing gemspec to work around swagger..."
9
+ ruby scripts/fix_gemspec.rb
10
+
11
+ echo "Injecting extensions..."
12
+ sed -i "s/require 'form_api\/api\/pdf_api'/\
13
+ require File.join(File.dirname(__FILE__), '..\/extensions\/lib\/form_api\/api\/client')/" \
14
+ lib/form_api.rb
File without changes
File without changes
data/swagger-config.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "gemName": "form_api",
3
3
  "moduleName": "FormAPI",
4
- "gemVersion": "0.1.0",
4
+ "gemVersion": "0.1.1",
5
5
  "gemAuthor": "Form Services Ltd.",
6
6
  "gemAuthorEmail": "support@formapi.io",
7
7
  "gemHomepage": "https://github.com/FormAPI/formapi-ruby",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Form Services Ltd.
@@ -247,7 +247,9 @@ files:
247
247
  - LICENSE
248
248
  - README.md
249
249
  - Rakefile
250
+ - examples/generate_and_download_pdf.rb
250
251
  - examples/generate_pdf.rb
252
+ - examples/generate_pdf_no_wait.rb
251
253
  - extensions/lib/form_api/api/client.rb
252
254
  - form_api.gemspec
253
255
  - lib/form_api.rb
@@ -261,12 +263,12 @@ files:
261
263
  - lib/form_api/models/inline_response_401.rb
262
264
  - lib/form_api/models/inline_response_422.rb
263
265
  - lib/form_api/version.rb
264
- - script/clean
265
- - script/fix_gemspec.rb
266
- - script/generate_language
267
- - script/post_generate_language
268
- - script/swagger
269
- - script/test
266
+ - scripts/clean
267
+ - scripts/fix_gemspec.rb
268
+ - scripts/generate
269
+ - scripts/post_generate
270
+ - scripts/swagger
271
+ - scripts/test
270
272
  - spec/api/pdf_api_spec.rb
271
273
  - spec/api_client_spec.rb
272
274
  - spec/configuration_spec.rb
@@ -1,35 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
- cd "$(dirname "$0")/.."
4
-
5
- LANGUAGE="$1"
6
- CONFIG_FILE="swagger-config.json"
7
-
8
- if [ "$LANGUAGE" = "" ]; then
9
- ./script/swagger # prints languages
10
- exit 1
11
- fi
12
-
13
- if [ ! -f "$CONFIG_FILE" ]; then
14
- echo "Could not find $CONFIG_FILE"
15
- ./script/swagger config-help -l "$LANGUAGE"
16
- exit 1
17
- fi
18
-
19
- ./script/clean
20
-
21
- ./script/swagger generate \
22
- -i ../form_api/swagger/v1/swagger.json \
23
- -l "$LANGUAGE" \
24
- -c "$CONFIG_FILE"
25
-
26
- # call a generator cleanup script
27
- if [ -f "script/post_generate_language" ]; then
28
- ./script/post_generate_language
29
- fi
30
-
31
-
32
- # Inject extensions
33
- sed -i "s/require 'form_api\/api\/pdf_api'/\
34
- require File.join(File.dirname(__FILE__), '..\/extensions\/lib\/form_api\/api\/client')/" \
35
- lib/form_api.rb
@@ -1,9 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
- cd "`dirname \"$0\"`/.."
4
-
5
- echo "Removing trailing whitespace..."
6
- find lib -name "*.rb" -type f -exec sed -E -i 's/[[:space:]]+$//g' {} +
7
-
8
- echo "Fixing gemspec to work around swagger..."
9
- ruby script/fix_gemspec.rb