form_api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a43920ddce58d1e34829ae44d775d6f533a2bd62
4
- data.tar.gz: 4aa5e61ffdf7c1426a55d104e679e4623495e2bf
3
+ metadata.gz: b369e863ec1ebe4a6916db2835f07fbb1579e318
4
+ data.tar.gz: ea11624eee27b90f5dd8c2ba6fb9d7a93fc4b1dd
5
5
  SHA512:
6
- metadata.gz: f281aa2c9f5a2dbfcb41cd3996c62bd20db86ae4ccd62c494bbfc80e4077a1f94860e20f2490e535ed96a7534223b310613bf964c6034c3638f9e79b2c291c27
7
- data.tar.gz: 497aeb7db329614c0337da92b70241bd47b044d7e869055bcc1816cef3008a890b6cc7065447aaa49f548e092fb0b8f167342a22cbf87a5e0b62c94715ac99cb
6
+ metadata.gz: e0cf854c6b6090954b76e42e2b1597b5be490c65aa2f55a53415735737b1a435b60568d343d72cd161cc906a395d8a004e29035347b1412995816ebec406f721
7
+ data.tar.gz: a3d25bbbd7c00de727675666beee16314867f9d3607cdd03fe3ef42650d5ed8b9359042a010900309a759dc3ea7d95a4b90a9460b6bad513c2909d915bd8e8c3
data/README.md CHANGED
@@ -35,15 +35,24 @@ end
35
35
  formapi = FormAPI::Client.new
36
36
 
37
37
  response = formapi.generate_pdf(
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
38
+ template_id: 'YOUR_TEMPLATE_ID', # ID of a template that you have configured
39
+ test: true, # Test documents are free but watermarked
40
+ wait: true, # Wait for the PDF to be processed (default: true)
41
+ data: { # Data to render in the template
41
42
  name: "foo",
42
43
  number: 42
43
44
  }
44
45
  )
45
46
 
46
-
47
+ # {
48
+ # status: "success",
49
+ # submission: {
50
+ # id: "bymRSZYTKDnd6jfY",
51
+ # test: true,
52
+ # state: "processed",
53
+ # download_url: "https://..."
54
+ # }
55
+ # }
47
56
  ```
48
57
 
49
58
  This submits a PDF request and waits for the job to finish.
@@ -8,10 +8,11 @@
8
8
  require "bundler/setup"
9
9
  Bundler.require
10
10
 
11
+ # This is a real test API token and template on formapi.io
12
+ # -------------------------------------------------------------
11
13
  API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
14
  API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
15
  TEMPLATE_ID = '6zz3dYRYM67fxMXA'
14
-
15
16
  PDF_FILENAME = '/tmp/formapi-test.pdf'
16
17
 
17
18
  begin
@@ -23,10 +24,10 @@ begin
23
24
 
24
25
  formapi = FormAPI::Client.new
25
26
 
26
- puts "Downloading PDF to #{PDF_FILENAME}..."
27
+ puts "Generating PDF..."
27
28
 
28
- formapi.generate_and_download_pdf(
29
- template_id: '6zz3dYRYM67fxMXA',
29
+ response = formapi.generate_pdf(
30
+ template_id: TEMPLATE_ID,
30
31
  filename: PDF_FILENAME,
31
32
  data: {
32
33
  first_name: 'John',
@@ -35,10 +36,22 @@ begin
35
36
  }
36
37
  )
37
38
 
38
- puts "PDF was downloaded to /tmp/formapi-test.pdf"
39
+ puts "Downloading PDF to #{PDF_FILENAME}..."
39
40
 
40
- # Open the PDF on Mac or Linux.
41
- `type xdg-open > /dev/null 2>&1 && xdg-open '#{PDF_FILENAME}' || open '#{PDF_FILENAME}'`
41
+ # Note: This example uses the Typhoeus library to download the file as a stream.
42
+ # This is a good way to download files, since the whole file is not loaded into memory.
43
+ # (The form_api gem includes Typhoeus as a dependency.)
44
+ downloaded_file = File.open PDF_FILENAME, 'wb'
45
+ request = Typhoeus::Request.new(response.submission.download_url)
46
+ request.on_body { |chunk| downloaded_file.write(chunk) }
47
+ request.on_complete do |response|
48
+ downloaded_file.close
49
+
50
+ puts "PDF was downloaded!"
51
+ # Open the downloaded PDF on Mac or Linux.
52
+ `type xdg-open > /dev/null 2>&1 && xdg-open '#{PDF_FILENAME}' || open '#{PDF_FILENAME}'`
53
+ end
54
+ request.run
42
55
 
43
56
  rescue FormAPI::ApiError => ex
44
57
  puts "#{ex.class}: #{ex.message}"
@@ -8,6 +8,8 @@
8
8
  require "bundler/setup"
9
9
  Bundler.require
10
10
 
11
+ # This is a real test API token and template on formapi.io
12
+ # -------------------------------------------------------------
11
13
  API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
14
  API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
15
  TEMPLATE_ID = '6zz3dYRYM67fxMXA'
@@ -8,10 +8,13 @@
8
8
  require "bundler/setup"
9
9
  Bundler.require
10
10
 
11
+ # This is a real test API token and template on formapi.io
12
+ # -------------------------------------------------------------
11
13
  API_TOKEN_ID = 'yRaaR9JmTPtGX7EN'
12
14
  API_TOKEN_SECRET = 'IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec'
13
15
  TEMPLATE_ID = '6zz3dYRYM67fxMXA'
14
16
 
17
+
15
18
  begin
16
19
  FormAPI.configure do |c|
17
20
  c.username = API_TOKEN_ID # Your API Token ID
@@ -22,6 +22,9 @@ module FormAPI
22
22
 
23
23
  # FormAPI requires a nested :data object.
24
24
  opts[:data] = { data: opts.delete(:data) }
25
+ if opts[:metadata]
26
+ opts[:data][:metadata] = opts.delete(:metadata)
27
+ end
25
28
 
26
29
  template_id = opts.delete :template_id
27
30
  response = super(template_id, opts)
@@ -47,18 +50,5 @@ module FormAPI
47
50
  submission: submission
48
51
  )
49
52
  end
50
-
51
- def generate_and_download_pdf(opts = {})
52
- filename = opts.delete :filename
53
-
54
- response = generate_pdf(opts.merge(wait: true))
55
- submission = response.submission
56
-
57
- pdf_response = Typhoeus.get(submission.download_url, followlocation: true)
58
-
59
- File.open(filename, 'wb') { |f| f.write pdf_response.body }
60
-
61
- response
62
- end
63
53
  end
64
54
  end
data/lib/form_api.rb CHANGED
@@ -20,7 +20,7 @@ require 'form_api/configuration'
20
20
  require 'form_api/models/data'
21
21
  require 'form_api/models/inline_response_201'
22
22
  require 'form_api/models/inline_response_201_submission'
23
- require 'form_api/models/inline_response_401'
23
+ require 'form_api/models/inline_response_400'
24
24
  require 'form_api/models/inline_response_422'
25
25
 
26
26
  # APIs
@@ -20,6 +20,59 @@ module FormAPI
20
20
  @api_client = api_client
21
21
  end
22
22
 
23
+ # Expire a PDF submission
24
+ #
25
+ # @param submission_id
26
+ # @param [Hash] opts the optional parameters
27
+ # @return [InlineResponse201Submission]
28
+ def expire_submission(submission_id, opts = {})
29
+ data, _status_code, _headers = expire_submission_with_http_info(submission_id, opts)
30
+ return data
31
+ end
32
+
33
+ # Expire a PDF submission
34
+ #
35
+ # @param submission_id
36
+ # @param [Hash] opts the optional parameters
37
+ # @return [Array<(InlineResponse201Submission, Fixnum, Hash)>] InlineResponse201Submission data, response status code and response headers
38
+ def expire_submission_with_http_info(submission_id, opts = {})
39
+ if @api_client.config.debugging
40
+ @api_client.config.logger.debug "Calling API: PDFApi.expire_submission ..."
41
+ end
42
+ # verify the required parameter 'submission_id' is set
43
+ if @api_client.config.client_side_validation && submission_id.nil?
44
+ fail ArgumentError, "Missing the required parameter 'submission_id' when calling PDFApi.expire_submission"
45
+ end
46
+ # resource path
47
+ local_var_path = "/submissions/{submission_id}".sub('{' + 'submission_id' + '}', submission_id.to_s)
48
+
49
+ # query parameters
50
+ query_params = {}
51
+
52
+ # header parameters
53
+ header_params = {}
54
+ # HTTP header 'Accept' (if needed)
55
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
56
+
57
+ # form parameters
58
+ form_params = {}
59
+
60
+ # http body (model)
61
+ post_body = nil
62
+ auth_names = ['basic']
63
+ data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
64
+ :header_params => header_params,
65
+ :query_params => query_params,
66
+ :form_params => form_params,
67
+ :body => post_body,
68
+ :auth_names => auth_names,
69
+ :return_type => 'InlineResponse201Submission')
70
+ if @api_client.config.debugging
71
+ @api_client.config.logger.debug "API called: PDFApi#expire_submission\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
72
+ end
73
+ return data, status_code, headers
74
+ end
75
+
23
76
  # Generates a new PDF
24
77
  #
25
78
  # @param template_id
@@ -19,12 +19,15 @@ module FormAPI
19
19
 
20
20
  attr_accessor :data
21
21
 
22
+ attr_accessor :metadata
23
+
22
24
 
23
25
  # Attribute mapping from ruby-style variable name to JSON key.
24
26
  def self.attribute_map
25
27
  {
26
28
  :'test' => :'test',
27
- :'data' => :'data'
29
+ :'data' => :'data',
30
+ :'metadata' => :'metadata'
28
31
  }
29
32
  end
30
33
 
@@ -32,7 +35,8 @@ module FormAPI
32
35
  def self.swagger_types
33
36
  {
34
37
  :'test' => :'BOOLEAN',
35
- :'data' => :'Object'
38
+ :'data' => :'Object',
39
+ :'metadata' => :'Object'
36
40
  }
37
41
  end
38
42
 
@@ -52,6 +56,10 @@ module FormAPI
52
56
  self.data = attributes[:'data']
53
57
  end
54
58
 
59
+ if attributes.has_key?(:'metadata')
60
+ self.metadata = attributes[:'metadata']
61
+ end
62
+
55
63
  end
56
64
 
57
65
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -78,7 +86,8 @@ module FormAPI
78
86
  return true if self.equal?(o)
79
87
  self.class == o.class &&
80
88
  test == o.test &&
81
- data == o.data
89
+ data == o.data &&
90
+ metadata == o.metadata
82
91
  end
83
92
 
84
93
  # @see the `==` method
@@ -90,7 +99,7 @@ module FormAPI
90
99
  # Calculates hash code according to all attributes.
91
100
  # @return [Fixnum] Hash code
92
101
  def hash
93
- [test, data].hash
102
+ [test, data, metadata].hash
94
103
  end
95
104
 
96
105
  # Builds the object from hash
@@ -19,8 +19,14 @@ module FormAPI
19
19
 
20
20
  attr_accessor :test
21
21
 
22
+ attr_accessor :expired
23
+
24
+ attr_accessor :expires_at
25
+
22
26
  attr_accessor :state
23
27
 
28
+ attr_accessor :metadata
29
+
24
30
  attr_accessor :download_url
25
31
 
26
32
  class EnumAttributeValidator
@@ -50,7 +56,10 @@ module FormAPI
50
56
  {
51
57
  :'id' => :'id',
52
58
  :'test' => :'test',
59
+ :'expired' => :'expired',
60
+ :'expires_at' => :'expires_at',
53
61
  :'state' => :'state',
62
+ :'metadata' => :'metadata',
54
63
  :'download_url' => :'download_url'
55
64
  }
56
65
  end
@@ -60,7 +69,10 @@ module FormAPI
60
69
  {
61
70
  :'id' => :'String',
62
71
  :'test' => :'BOOLEAN',
72
+ :'expired' => :'BOOLEAN',
73
+ :'expires_at' => :'String',
63
74
  :'state' => :'String',
75
+ :'metadata' => :'Object',
64
76
  :'download_url' => :'String'
65
77
  }
66
78
  end
@@ -81,10 +93,22 @@ module FormAPI
81
93
  self.test = attributes[:'test']
82
94
  end
83
95
 
96
+ if attributes.has_key?(:'expired')
97
+ self.expired = attributes[:'expired']
98
+ end
99
+
100
+ if attributes.has_key?(:'expires_at')
101
+ self.expires_at = attributes[:'expires_at']
102
+ end
103
+
84
104
  if attributes.has_key?(:'state')
85
105
  self.state = attributes[:'state']
86
106
  end
87
107
 
108
+ if attributes.has_key?(:'metadata')
109
+ self.metadata = attributes[:'metadata']
110
+ end
111
+
88
112
  if attributes.has_key?(:'download_url')
89
113
  self.download_url = attributes[:'download_url']
90
114
  end
@@ -99,6 +123,18 @@ module FormAPI
99
123
  invalid_properties.push("invalid value for 'id', id cannot be nil.")
100
124
  end
101
125
 
126
+ if @test.nil?
127
+ invalid_properties.push("invalid value for 'test', test cannot be nil.")
128
+ end
129
+
130
+ if @expired.nil?
131
+ invalid_properties.push("invalid value for 'expired', expired cannot be nil.")
132
+ end
133
+
134
+ if @expires_at.nil?
135
+ invalid_properties.push("invalid value for 'expires_at', expires_at cannot be nil.")
136
+ end
137
+
102
138
  if @state.nil?
103
139
  invalid_properties.push("invalid value for 'state', state cannot be nil.")
104
140
  end
@@ -110,6 +146,9 @@ module FormAPI
110
146
  # @return true if the model is valid
111
147
  def valid?
112
148
  return false if @id.nil?
149
+ return false if @test.nil?
150
+ return false if @expired.nil?
151
+ return false if @expires_at.nil?
113
152
  return false if @state.nil?
114
153
  state_validator = EnumAttributeValidator.new('String', ["pending", "processed", "invalid_data", "error", "image_download_failed", "image_processing_failed"])
115
154
  return false unless state_validator.valid?(@state)
@@ -133,7 +172,10 @@ module FormAPI
133
172
  self.class == o.class &&
134
173
  id == o.id &&
135
174
  test == o.test &&
175
+ expired == o.expired &&
176
+ expires_at == o.expires_at &&
136
177
  state == o.state &&
178
+ metadata == o.metadata &&
137
179
  download_url == o.download_url
138
180
  end
139
181
 
@@ -146,7 +188,7 @@ module FormAPI
146
188
  # Calculates hash code according to all attributes.
147
189
  # @return [Fixnum] Hash code
148
190
  def hash
149
- [id, test, state, download_url].hash
191
+ [id, test, expired, expires_at, state, metadata, download_url].hash
150
192
  end
151
193
 
152
194
  # Builds the object from hash
@@ -14,7 +14,7 @@ require 'date'
14
14
 
15
15
  module FormAPI
16
16
 
17
- class InlineResponse401
17
+ class InlineResponse400
18
18
  attr_accessor :status
19
19
 
20
20
  attr_accessor :error
@@ -11,5 +11,5 @@ Swagger Codegen version: 2.3.0-SNAPSHOT
11
11
  =end
12
12
 
13
13
  module FormAPI
14
- VERSION = "0.1.1"
14
+ VERSION = "0.1.2"
15
15
  end
@@ -8,6 +8,14 @@ find lib -name "*.rb" -type f -exec sed -E -i 's/[[:space:]]+$//g' {} +
8
8
  echo "Fixing gemspec to work around swagger..."
9
9
  ruby scripts/fix_gemspec.rb
10
10
 
11
+
12
+ # This is not needed anymore.
13
+ # echo "Adding ':followlocation => true'..."
14
+ # sed -i "s/req_opts = {/\
15
+ # req_opts = {\n :followlocation => true,/" \
16
+ # lib/form_api/api_client.rb
17
+
18
+
11
19
  echo "Injecting extensions..."
12
20
  sed -i "s/require 'form_api\/api\/pdf_api'/\
13
21
  require File.join(File.dirname(__FILE__), '..\/extensions\/lib\/form_api\/api\/client')/" \
data/scripts/release ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ ./scripts/generate
5
+ rm form_api-*.gem
6
+ gem build form_api.gemspec
7
+ gem push form_api-*.gem
@@ -0,0 +1,42 @@
1
+ =begin
2
+ #API V1
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+ require 'date'
16
+
17
+ # Unit tests for FormAPI::InlineResponse302
18
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
19
+ # Please update as you see appropriate
20
+ describe 'InlineResponse302' do
21
+ before do
22
+ # run before each test
23
+ @instance = FormAPI::InlineResponse302.new
24
+ end
25
+
26
+ after do
27
+ # run after each test
28
+ end
29
+
30
+ describe 'test an instance of InlineResponse302' do
31
+ it 'should create an instance of InlineResponse302' do
32
+ expect(@instance).to be_instance_of(FormAPI::InlineResponse302)
33
+ end
34
+ end
35
+ describe 'test attribute "url"' do
36
+ it 'should work' do
37
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,52 @@
1
+ =begin
2
+ #API V1
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+ require 'date'
16
+
17
+ # Unit tests for FormAPI::InlineResponse400
18
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
19
+ # Please update as you see appropriate
20
+ describe 'InlineResponse400' do
21
+ before do
22
+ # run before each test
23
+ @instance = FormAPI::InlineResponse400.new
24
+ end
25
+
26
+ after do
27
+ # run after each test
28
+ end
29
+
30
+ describe 'test an instance of InlineResponse400' do
31
+ it 'should create an instance of InlineResponse400' do
32
+ expect(@instance).to be_instance_of(FormAPI::InlineResponse400)
33
+ end
34
+ end
35
+ describe 'test attribute "status"' do
36
+ it 'should work' do
37
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
38
+ #validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["error"])
39
+ #validator.allowable_values.each do |value|
40
+ # expect { @instance.status = value }.not_to raise_error
41
+ #end
42
+ end
43
+ end
44
+
45
+ describe 'test attribute "error"' do
46
+ it 'should work' do
47
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
48
+ end
49
+ end
50
+
51
+ end
52
+
data/swagger-config.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "gemName": "form_api",
3
3
  "moduleName": "FormAPI",
4
- "gemVersion": "0.1.1",
4
+ "gemVersion": "0.1.2",
5
5
  "gemAuthor": "Form Services Ltd.",
6
6
  "gemAuthorEmail": "support@formapi.io",
7
7
  "gemHomepage": "https://github.com/FormAPI/formapi-ruby",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Form Services Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -260,13 +260,14 @@ files:
260
260
  - lib/form_api/models/data.rb
261
261
  - lib/form_api/models/inline_response_201.rb
262
262
  - lib/form_api/models/inline_response_201_submission.rb
263
- - lib/form_api/models/inline_response_401.rb
263
+ - lib/form_api/models/inline_response_400.rb
264
264
  - lib/form_api/models/inline_response_422.rb
265
265
  - lib/form_api/version.rb
266
266
  - scripts/clean
267
267
  - scripts/fix_gemspec.rb
268
268
  - scripts/generate
269
269
  - scripts/post_generate
270
+ - scripts/release
270
271
  - scripts/swagger
271
272
  - scripts/test
272
273
  - spec/api/pdf_api_spec.rb
@@ -275,6 +276,8 @@ files:
275
276
  - spec/models/data_spec.rb
276
277
  - spec/models/inline_response_201_spec.rb
277
278
  - spec/models/inline_response_201_submission_spec.rb
279
+ - spec/models/inline_response_302_spec.rb
280
+ - spec/models/inline_response_400_spec.rb
278
281
  - spec/models/inline_response_401_spec.rb
279
282
  - spec/models/inline_response_422_spec.rb
280
283
  - spec/spec_helper.rb
@@ -310,6 +313,8 @@ test_files:
310
313
  - spec/models/data_spec.rb
311
314
  - spec/models/inline_response_201_spec.rb
312
315
  - spec/models/inline_response_201_submission_spec.rb
316
+ - spec/models/inline_response_302_spec.rb
317
+ - spec/models/inline_response_400_spec.rb
313
318
  - spec/models/inline_response_401_spec.rb
314
319
  - spec/models/inline_response_422_spec.rb
315
320
  - spec/spec_helper.rb