form_api 0.1.3 → 0.1.4

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: c6439e9cb2b05efe66eca66fa5592116e9712a7a
4
- data.tar.gz: 6b5226c60049e966e413635cf409fb76ab88ec4b
3
+ metadata.gz: 1601d98e7510bd573bde97e48c4685cae8a72c4a
4
+ data.tar.gz: c6fcb19e49daa8ce6b590c2896f1af7d1b876ad1
5
5
  SHA512:
6
- metadata.gz: 19a12793aca87698c8a656592423b3422a8e5aa7e0591e5f8a633904e60c2325206de77a55b72ee018a072d1406e6ea5d0155a3ef27bbee9de8d120d7cedc559
7
- data.tar.gz: d2fa9c2058bbdbb40a01ca010fbbc77bad86beb23f6d81cc36b47ada2fda5e473d77b211b6b18d7b3988fe341226a1297f12f56117bbaf46a09aa3a581decb74
6
+ metadata.gz: ba61014b1f46f7f2100bb6c5a833dc90ee31a18ddf6001070fb5566734dd4ee78ab35d8ccfd853701a47895c6f81e91b73355bb67e7540d45bb243ba1e41a56c
7
+ data.tar.gz: 94191a22d051c41fa65c691106a8547d901c31b8aa49df3bd404e073baa9240edb88de98baa9987552d6f027c7601e21e424e3edf09f14db3d04a44b50c742d0
data/README.md CHANGED
@@ -24,7 +24,7 @@ bundle install
24
24
 
25
25
  ## Usage
26
26
 
27
- See [examples](examples/) for runnable examples.
27
+ See [examples](examples/) for some runnable examples.
28
28
 
29
29
  ```ruby
30
30
  FormAPI.configure do |config|
@@ -41,6 +41,9 @@ response = formapi.generate_pdf(
41
41
  data: { # Data to render in the template
42
42
  name: "foo",
43
43
  number: 42
44
+ },
45
+ metadata: { # Custom data to include in the request, for your own purposes
46
+ user_id: 123
44
47
  }
45
48
  )
46
49
 
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This example demonstrates merging multiple generated PDFs into a single PDF.
4
+ #
5
+
6
+ require "bundler/setup"
7
+ Bundler.require
8
+
9
+ begin
10
+ FormAPI.configure do |c|
11
+ c.username = ENV['FORM_API_TOKEN_ID']
12
+ c.password = ENV['FORM_API_TOKEN_SECRET']
13
+ end
14
+
15
+ formapi = FormAPI::Client.new
16
+
17
+ response = formapi.combine_submissions(
18
+ submission_ids: ["SUBMISSION_1_ID", "SUBMISSION_2_ID", ... ],
19
+ metadata: {
20
+ user_id: 123
21
+ }
22
+ )
23
+
24
+ puts "Download your combined PDF at: #{response.combined_submission.download_url}"
25
+
26
+ rescue FormAPI::ApiError => ex
27
+ puts "#{ex.class}: #{ex.message}"
28
+ puts ex.code # HTTP response code
29
+ puts ex.response_body # HTTP response body
30
+ puts ex.backtrace[0..3].join("\n")
31
+ end
@@ -12,7 +12,7 @@ module FormAPI
12
12
 
13
13
  def generate_pdf(opts = {})
14
14
  unless opts[:data].kind_of?(::Hash)
15
- raise InvalidDataError, ":data is required, and must be a Hash."
15
+ raise InvalidDataError, "data is required, and must be a Hash."
16
16
  end
17
17
 
18
18
  # Wait for job to finish by default.
@@ -36,7 +36,7 @@ module FormAPI
36
36
  start_time = Time.now
37
37
 
38
38
  # Wait for submission to be ready
39
- while submission.state != 'processed'
39
+ while submission.state == 'pending'
40
40
  sleep 1
41
41
  submission = get_submission(submission.id)
42
42
 
@@ -45,10 +45,54 @@ module FormAPI
45
45
  end
46
46
  end
47
47
 
48
- return InlineResponse201.new(
48
+ return InlineResponse2011.new(
49
49
  status: submission.state == 'processed' ? 'success' : 'error',
50
50
  submission: submission
51
51
  )
52
52
  end
53
+
54
+
55
+ def combine_submissions(opts = {})
56
+ unless opts[:submission_ids].kind_of?(::Array)
57
+ raise InvalidDataError, "submission_ids is required, and must be an Array."
58
+ end
59
+
60
+ # Wait for job to finish by default.
61
+ if !opts.has_key?(:wait)
62
+ opts[:wait] = true
63
+ end
64
+
65
+ # FormAPI requires a nested :data object.
66
+ opts[:data] = { submission_ids: opts.delete(:submission_ids) }
67
+ if opts[:metadata]
68
+ opts[:data][:metadata] = opts.delete(:metadata)
69
+ end
70
+ if opts[:expire_in]
71
+ opts[:data][:expire_in] = opts.delete(:expire_in)
72
+ end
73
+
74
+ response = super(opts)
75
+
76
+ return response unless opts[:wait]
77
+
78
+ combined_submission = response.combined_submission
79
+ timeout = opts[:timeout] || 60
80
+ start_time = Time.now
81
+
82
+ # Wait for submission to be ready
83
+ while combined_submission.state == 'pending'
84
+ sleep 1
85
+ combined_submission = get_combined_submission(combined_submission.id)
86
+
87
+ if Time.now - start_time > timeout
88
+ raise PollTimeoutError, "Merged PDF was not ready after #{timeout} seconds!"
89
+ end
90
+ end
91
+
92
+ return InlineResponse201.new(
93
+ status: combined_submission.state == 'processed' ? 'success' : 'error',
94
+ combined_submission: combined_submission
95
+ )
96
+ end
53
97
  end
54
98
  end
@@ -18,9 +18,13 @@ require 'form_api/configuration'
18
18
 
19
19
  # Models
20
20
  require 'form_api/models/data'
21
+ require 'form_api/models/data_1'
21
22
  require 'form_api/models/inline_response_201'
22
- require 'form_api/models/inline_response_201_submission'
23
+ require 'form_api/models/inline_response_201_1'
24
+ require 'form_api/models/inline_response_201_1_submission'
25
+ require 'form_api/models/inline_response_201_combined_submission'
23
26
  require 'form_api/models/inline_response_400'
27
+ require 'form_api/models/inline_response_401'
24
28
  require 'form_api/models/inline_response_422'
25
29
 
26
30
  # APIs
@@ -20,11 +20,115 @@ module FormAPI
20
20
  @api_client = api_client
21
21
  end
22
22
 
23
+ # Merge generated PDFs together
24
+ #
25
+ # @param [Hash] opts the optional parameters
26
+ # @option opts [Data] :data
27
+ # @return [InlineResponse201]
28
+ def combine_submissions(opts = {})
29
+ data, _status_code, _headers = combine_submissions_with_http_info(opts)
30
+ return data
31
+ end
32
+
33
+ # Merge generated PDFs together
34
+ #
35
+ # @param [Hash] opts the optional parameters
36
+ # @option opts [Data] :data
37
+ # @return [Array<(InlineResponse201, Fixnum, Hash)>] InlineResponse201 data, response status code and response headers
38
+ def combine_submissions_with_http_info(opts = {})
39
+ if @api_client.config.debugging
40
+ @api_client.config.logger.debug "Calling API: PDFApi.combine_submissions ..."
41
+ end
42
+ # resource path
43
+ local_var_path = "/combined_submissions"
44
+
45
+ # query parameters
46
+ query_params = {}
47
+
48
+ # header parameters
49
+ header_params = {}
50
+ # HTTP header 'Accept' (if needed)
51
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
52
+ # HTTP header 'Content-Type'
53
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
54
+
55
+ # form parameters
56
+ form_params = {}
57
+
58
+ # http body (model)
59
+ post_body = @api_client.object_to_http_body(opts[:'data'])
60
+ auth_names = ['basic']
61
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path,
62
+ :header_params => header_params,
63
+ :query_params => query_params,
64
+ :form_params => form_params,
65
+ :body => post_body,
66
+ :auth_names => auth_names,
67
+ :return_type => 'InlineResponse201')
68
+ if @api_client.config.debugging
69
+ @api_client.config.logger.debug "API called: PDFApi#combine_submissions\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
70
+ end
71
+ return data, status_code, headers
72
+ end
73
+
74
+ # Expire a combined submission
75
+ #
76
+ # @param combined_submission_id
77
+ # @param [Hash] opts the optional parameters
78
+ # @return [InlineResponse201CombinedSubmission]
79
+ def expire_combined_submission(combined_submission_id, opts = {})
80
+ data, _status_code, _headers = expire_combined_submission_with_http_info(combined_submission_id, opts)
81
+ return data
82
+ end
83
+
84
+ # Expire a combined submission
85
+ #
86
+ # @param combined_submission_id
87
+ # @param [Hash] opts the optional parameters
88
+ # @return [Array<(InlineResponse201CombinedSubmission, Fixnum, Hash)>] InlineResponse201CombinedSubmission data, response status code and response headers
89
+ def expire_combined_submission_with_http_info(combined_submission_id, opts = {})
90
+ if @api_client.config.debugging
91
+ @api_client.config.logger.debug "Calling API: PDFApi.expire_combined_submission ..."
92
+ end
93
+ # verify the required parameter 'combined_submission_id' is set
94
+ if @api_client.config.client_side_validation && combined_submission_id.nil?
95
+ fail ArgumentError, "Missing the required parameter 'combined_submission_id' when calling PDFApi.expire_combined_submission"
96
+ end
97
+ # resource path
98
+ local_var_path = "/combined_submissions/{combined_submission_id}".sub('{' + 'combined_submission_id' + '}', combined_submission_id.to_s)
99
+
100
+ # query parameters
101
+ query_params = {}
102
+
103
+ # header parameters
104
+ header_params = {}
105
+ # HTTP header 'Accept' (if needed)
106
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
107
+
108
+ # form parameters
109
+ form_params = {}
110
+
111
+ # http body (model)
112
+ post_body = nil
113
+ auth_names = ['basic']
114
+ data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
115
+ :header_params => header_params,
116
+ :query_params => query_params,
117
+ :form_params => form_params,
118
+ :body => post_body,
119
+ :auth_names => auth_names,
120
+ :return_type => 'InlineResponse201CombinedSubmission')
121
+ if @api_client.config.debugging
122
+ @api_client.config.logger.debug "API called: PDFApi#expire_combined_submission\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
123
+ end
124
+ return data, status_code, headers
125
+ end
126
+
23
127
  # Expire a PDF submission
24
128
  #
25
129
  # @param submission_id
26
130
  # @param [Hash] opts the optional parameters
27
- # @return [InlineResponse201Submission]
131
+ # @return [InlineResponse2011Submission]
28
132
  def expire_submission(submission_id, opts = {})
29
133
  data, _status_code, _headers = expire_submission_with_http_info(submission_id, opts)
30
134
  return data
@@ -34,7 +138,7 @@ module FormAPI
34
138
  #
35
139
  # @param submission_id
36
140
  # @param [Hash] opts the optional parameters
37
- # @return [Array<(InlineResponse201Submission, Fixnum, Hash)>] InlineResponse201Submission data, response status code and response headers
141
+ # @return [Array<(InlineResponse2011Submission, Fixnum, Hash)>] InlineResponse2011Submission data, response status code and response headers
38
142
  def expire_submission_with_http_info(submission_id, opts = {})
39
143
  if @api_client.config.debugging
40
144
  @api_client.config.logger.debug "Calling API: PDFApi.expire_submission ..."
@@ -66,7 +170,7 @@ module FormAPI
66
170
  :form_params => form_params,
67
171
  :body => post_body,
68
172
  :auth_names => auth_names,
69
- :return_type => 'InlineResponse201Submission')
173
+ :return_type => 'InlineResponse2011Submission')
70
174
  if @api_client.config.debugging
71
175
  @api_client.config.logger.debug "API called: PDFApi#expire_submission\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
72
176
  end
@@ -77,8 +181,8 @@ module FormAPI
77
181
  #
78
182
  # @param template_id
79
183
  # @param [Hash] opts the optional parameters
80
- # @option opts [Data] :data
81
- # @return [InlineResponse201]
184
+ # @option opts [Data1] :data
185
+ # @return [InlineResponse2011]
82
186
  def generate_pdf(template_id, opts = {})
83
187
  data, _status_code, _headers = generate_pdf_with_http_info(template_id, opts)
84
188
  return data
@@ -88,8 +192,8 @@ module FormAPI
88
192
  #
89
193
  # @param template_id
90
194
  # @param [Hash] opts the optional parameters
91
- # @option opts [Data] :data
92
- # @return [Array<(InlineResponse201, Fixnum, Hash)>] InlineResponse201 data, response status code and response headers
195
+ # @option opts [Data1] :data
196
+ # @return [Array<(InlineResponse2011, Fixnum, Hash)>] InlineResponse2011 data, response status code and response headers
93
197
  def generate_pdf_with_http_info(template_id, opts = {})
94
198
  if @api_client.config.debugging
95
199
  @api_client.config.logger.debug "Calling API: PDFApi.generate_pdf ..."
@@ -123,18 +227,71 @@ module FormAPI
123
227
  :form_params => form_params,
124
228
  :body => post_body,
125
229
  :auth_names => auth_names,
126
- :return_type => 'InlineResponse201')
230
+ :return_type => 'InlineResponse2011')
127
231
  if @api_client.config.debugging
128
232
  @api_client.config.logger.debug "API called: PDFApi#generate_pdf\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
129
233
  end
130
234
  return data, status_code, headers
131
235
  end
132
236
 
237
+ # Check the status of a combined submission (merged PDFs)
238
+ #
239
+ # @param combined_submission_id
240
+ # @param [Hash] opts the optional parameters
241
+ # @return [InlineResponse201CombinedSubmission]
242
+ def get_combined_submission(combined_submission_id, opts = {})
243
+ data, _status_code, _headers = get_combined_submission_with_http_info(combined_submission_id, opts)
244
+ return data
245
+ end
246
+
247
+ # Check the status of a combined submission (merged PDFs)
248
+ #
249
+ # @param combined_submission_id
250
+ # @param [Hash] opts the optional parameters
251
+ # @return [Array<(InlineResponse201CombinedSubmission, Fixnum, Hash)>] InlineResponse201CombinedSubmission data, response status code and response headers
252
+ def get_combined_submission_with_http_info(combined_submission_id, opts = {})
253
+ if @api_client.config.debugging
254
+ @api_client.config.logger.debug "Calling API: PDFApi.get_combined_submission ..."
255
+ end
256
+ # verify the required parameter 'combined_submission_id' is set
257
+ if @api_client.config.client_side_validation && combined_submission_id.nil?
258
+ fail ArgumentError, "Missing the required parameter 'combined_submission_id' when calling PDFApi.get_combined_submission"
259
+ end
260
+ # resource path
261
+ local_var_path = "/combined_submissions/{combined_submission_id}".sub('{' + 'combined_submission_id' + '}', combined_submission_id.to_s)
262
+
263
+ # query parameters
264
+ query_params = {}
265
+
266
+ # header parameters
267
+ header_params = {}
268
+ # HTTP header 'Accept' (if needed)
269
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
270
+
271
+ # form parameters
272
+ form_params = {}
273
+
274
+ # http body (model)
275
+ post_body = nil
276
+ auth_names = ['basic']
277
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
278
+ :header_params => header_params,
279
+ :query_params => query_params,
280
+ :form_params => form_params,
281
+ :body => post_body,
282
+ :auth_names => auth_names,
283
+ :return_type => 'InlineResponse201CombinedSubmission')
284
+ if @api_client.config.debugging
285
+ @api_client.config.logger.debug "API called: PDFApi#get_combined_submission\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
286
+ end
287
+ return data, status_code, headers
288
+ end
289
+
133
290
  # Check the status of a PDF
134
291
  #
135
292
  # @param submission_id
136
293
  # @param [Hash] opts the optional parameters
137
- # @return [InlineResponse201Submission]
294
+ # @return [InlineResponse2011Submission]
138
295
  def get_submission(submission_id, opts = {})
139
296
  data, _status_code, _headers = get_submission_with_http_info(submission_id, opts)
140
297
  return data
@@ -144,7 +301,7 @@ module FormAPI
144
301
  #
145
302
  # @param submission_id
146
303
  # @param [Hash] opts the optional parameters
147
- # @return [Array<(InlineResponse201Submission, Fixnum, Hash)>] InlineResponse201Submission data, response status code and response headers
304
+ # @return [Array<(InlineResponse2011Submission, Fixnum, Hash)>] InlineResponse2011Submission data, response status code and response headers
148
305
  def get_submission_with_http_info(submission_id, opts = {})
149
306
  if @api_client.config.debugging
150
307
  @api_client.config.logger.debug "Calling API: PDFApi.get_submission ..."
@@ -176,7 +333,7 @@ module FormAPI
176
333
  :form_params => form_params,
177
334
  :body => post_body,
178
335
  :auth_names => auth_names,
179
- :return_type => 'InlineResponse201Submission')
336
+ :return_type => 'InlineResponse2011Submission')
180
337
  if @api_client.config.debugging
181
338
  @api_client.config.logger.debug "API called: PDFApi#get_submission\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
182
339
  end
@@ -17,17 +17,20 @@ module FormAPI
17
17
  class Data
18
18
  attr_accessor :test
19
19
 
20
- attr_accessor :data
20
+ attr_accessor :submission_ids
21
21
 
22
22
  attr_accessor :metadata
23
23
 
24
+ attr_accessor :expires_in
25
+
24
26
 
25
27
  # Attribute mapping from ruby-style variable name to JSON key.
26
28
  def self.attribute_map
27
29
  {
28
30
  :'test' => :'test',
29
- :'data' => :'data',
30
- :'metadata' => :'metadata'
31
+ :'submission_ids' => :'submission_ids',
32
+ :'metadata' => :'metadata',
33
+ :'expires_in' => :'expires_in'
31
34
  }
32
35
  end
33
36
 
@@ -35,8 +38,9 @@ module FormAPI
35
38
  def self.swagger_types
36
39
  {
37
40
  :'test' => :'BOOLEAN',
38
- :'data' => :'Object',
39
- :'metadata' => :'Object'
41
+ :'submission_ids' => :'Array<String>',
42
+ :'metadata' => :'Object',
43
+ :'expires_in' => :'Float'
40
44
  }
41
45
  end
42
46
 
@@ -52,22 +56,28 @@ module FormAPI
52
56
  self.test = attributes[:'test']
53
57
  end
54
58
 
55
- if attributes.has_key?(:'data')
56
- self.data = attributes[:'data']
59
+ if attributes.has_key?(:'submission_ids')
60
+ if (value = attributes[:'submission_ids']).is_a?(Array)
61
+ self.submission_ids = value
62
+ end
57
63
  end
58
64
 
59
65
  if attributes.has_key?(:'metadata')
60
66
  self.metadata = attributes[:'metadata']
61
67
  end
62
68
 
69
+ if attributes.has_key?(:'expires_in')
70
+ self.expires_in = attributes[:'expires_in']
71
+ end
72
+
63
73
  end
64
74
 
65
75
  # Show invalid properties with the reasons. Usually used together with valid?
66
76
  # @return Array for valid properies with the reasons
67
77
  def list_invalid_properties
68
78
  invalid_properties = Array.new
69
- if @data.nil?
70
- invalid_properties.push("invalid value for 'data', data cannot be nil.")
79
+ if @submission_ids.nil?
80
+ invalid_properties.push("invalid value for 'submission_ids', submission_ids cannot be nil.")
71
81
  end
72
82
 
73
83
  return invalid_properties
@@ -76,7 +86,7 @@ module FormAPI
76
86
  # Check to see if the all the properties in the model are valid
77
87
  # @return true if the model is valid
78
88
  def valid?
79
- return false if @data.nil?
89
+ return false if @submission_ids.nil?
80
90
  return true
81
91
  end
82
92
 
@@ -86,8 +96,9 @@ module FormAPI
86
96
  return true if self.equal?(o)
87
97
  self.class == o.class &&
88
98
  test == o.test &&
89
- data == o.data &&
90
- metadata == o.metadata
99
+ submission_ids == o.submission_ids &&
100
+ metadata == o.metadata &&
101
+ expires_in == o.expires_in
91
102
  end
92
103
 
93
104
  # @see the `==` method
@@ -99,7 +110,7 @@ module FormAPI
99
110
  # Calculates hash code according to all attributes.
100
111
  # @return [Fixnum] Hash code
101
112
  def hash
102
- [test, data, metadata].hash
113
+ [test, submission_ids, metadata, expires_in].hash
103
114
  end
104
115
 
105
116
  # Builds the object from hash