form_api 0.1.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +2 -0
  4. data/.swagger-codegen-ignore +31 -0
  5. data/.swagger-codegen/VERSION +1 -0
  6. data/.swagger-revision +1 -0
  7. data/CHANGELOG.md +2 -0
  8. data/Gemfile +7 -0
  9. data/LICENSE +7 -0
  10. data/README.md +76 -0
  11. data/Rakefile +11 -0
  12. data/examples/generate_pdf.rb +43 -0
  13. data/extensions/lib/form_api/api/client.rb +61 -0
  14. data/form_api.gemspec +51 -0
  15. data/lib/form_api.rb +45 -0
  16. data/lib/form_api/api/pdf_api.rb +133 -0
  17. data/lib/form_api/api_client.rb +389 -0
  18. data/lib/form_api/api_error.rb +38 -0
  19. data/lib/form_api/configuration.rb +209 -0
  20. data/lib/form_api/models/data.rb +193 -0
  21. data/lib/form_api/models/inline_response_201.rb +235 -0
  22. data/lib/form_api/models/inline_response_201_submission.rb +249 -0
  23. data/lib/form_api/models/inline_response_401.rb +240 -0
  24. data/lib/form_api/models/inline_response_422.rb +242 -0
  25. data/lib/form_api/version.rb +15 -0
  26. data/script/clean +5 -0
  27. data/script/fix_gemspec.rb +31 -0
  28. data/script/generate_language +35 -0
  29. data/script/post_generate_language +9 -0
  30. data/script/swagger +35 -0
  31. data/script/test +24 -0
  32. data/spec/api/pdf_api_spec.rb +60 -0
  33. data/spec/api_client_spec.rb +226 -0
  34. data/spec/configuration_spec.rb +42 -0
  35. data/spec/models/data_spec.rb +42 -0
  36. data/spec/models/inline_response_201_spec.rb +52 -0
  37. data/spec/models/inline_response_201_submission_spec.rb +58 -0
  38. data/spec/models/inline_response_401_spec.rb +52 -0
  39. data/spec/models/inline_response_422_spec.rb +52 -0
  40. data/spec/spec_helper.rb +111 -0
  41. data/swagger-config.json +13 -0
  42. metadata +313 -0
@@ -0,0 +1,15 @@
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
+ module FormAPI
14
+ VERSION = "0.1.0"
15
+ end
data/script/clean ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ rm -rf lib/
@@ -0,0 +1,31 @@
1
+ bad_files = %q{s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }}
2
+ bad_test_files = %q{s.test_files = `find spec/*`.split("\n")}
3
+ good_files = %q{s.files = `git ls-files`.split("\n").uniq.sort.select{|f| !f.empty? }}
4
+ good_test_files = %q{s.test_files = `git ls-files spec test`.split("\n")}
5
+
6
+ development_dependency_marker = %q{ s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12'}
7
+ development_dependency_marker_plus_injection =
8
+ " s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12'
9
+
10
+ # added by script/fix_gemspec.rb.
11
+ s.add_development_dependency 'rake', '~>11.2', '>= 11.2.2'
12
+ s.add_development_dependency 'pry', '~>0.10', '>= 0.10.4'
13
+ # </added> : if the above lines are missing in the gemspec, then
14
+ # the matcher for autotest is probably broken"
15
+
16
+ filename = "form_api.gemspec"
17
+ content = File.read(filename)
18
+ [bad_files, bad_test_files, development_dependency_marker].each do |bad_content_to_check|
19
+ unless content.include?(bad_content_to_check)
20
+ raise "Couldn't find content in form_api.gemspec. Check matchers in there for: “#{bad_content_to_check}”"
21
+ end
22
+ end
23
+ updated_content = content.dup
24
+ updated_content.sub!(bad_files, good_files)
25
+ updated_content.sub!(bad_test_files, good_test_files)
26
+ updated_content.sub!(development_dependency_marker,
27
+ development_dependency_marker_plus_injection)
28
+
29
+ File.open(filename, "w") do |file|
30
+ file.write(updated_content)
31
+ end
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,9 @@
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
data/script/swagger ADDED
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+ set -e
3
+ cd "$(dirname "$0")/.."
4
+
5
+ SWAGGER_CODGEN_REVISION=$(cat .swagger-revision 2> /dev/null || true)
6
+ if [ "$SWAGGER_CODGEN_REVISION" = "" ]; then
7
+ echo "Set a revision of swagger-codegen to use in .swagger-revision"
8
+ exit 1
9
+ fi
10
+
11
+ if [ ! -d "swagger-codegen" ]; then
12
+ git clone https://github.com/swagger-api/swagger-codegen
13
+ fi
14
+
15
+ (
16
+ cd swagger-codegen
17
+ if [[ "${#SWAGGER_CODGEN_REVISION}" -lt 40 ]]; then
18
+ # resolve git tags / branch names
19
+ SWAGGER_CODGEN_REVISION=$(git show "$SWAGGER_CODGEN_REVISION" --format="%H")
20
+ fi
21
+ if [[ $(cat .git/HEAD) != "$SWAGGER_CODGEN_REVISION" ]]; then
22
+ git fetch
23
+ git checkout "$SWAGGER_CODGEN_REVISION"
24
+ mvn clean package
25
+ fi
26
+ )
27
+
28
+ executable="./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
29
+
30
+ if [ ! -f "$executable" ]; then
31
+ mvn clean package
32
+ fi
33
+
34
+ export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
35
+ java $JAVA_OPTS -jar $executable $*
data/script/test ADDED
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+ set -e
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ # check dependencies
6
+ ruby -v > /dev/null || (echo "ruby must be installed"; exit 1)
7
+ bundler -v > /dev/null || (echo "bundler must be installed"; exit 1)
8
+
9
+ bundle install
10
+
11
+ cd test
12
+
13
+ # runs a test file with PASS/FAIL message
14
+ run_test() {
15
+ ruby $1 && echo "PASS $1" || (echo "FAIL $1"; exit 1)
16
+ }
17
+
18
+ if [ "$1" == "" ]; then
19
+ for test in $(ls *.rb); do
20
+ run_test $test
21
+ done
22
+ else
23
+ run_test $1.rb
24
+ fi
@@ -0,0 +1,60 @@
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
+
16
+ # Unit tests for FormAPI::PDFApi
17
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
18
+ # Please update as you see appropriate
19
+ describe 'PDFApi' do
20
+ before do
21
+ # run before each test
22
+ @instance = FormAPI::PDFApi.new
23
+ end
24
+
25
+ after do
26
+ # run after each test
27
+ end
28
+
29
+ describe 'test an instance of PDFApi' do
30
+ it 'should create an instance of PDFApi' do
31
+ expect(@instance).to be_instance_of(FormAPI::PDFApi)
32
+ end
33
+ end
34
+
35
+ # unit tests for generate_pdf
36
+ # Generates a new PDF
37
+ #
38
+ # @param template_id
39
+ # @param [Hash] opts the optional parameters
40
+ # @option opts [Data] :data
41
+ # @return [InlineResponse201]
42
+ describe 'generate_pdf test' do
43
+ it "should work" do
44
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
45
+ end
46
+ end
47
+
48
+ # unit tests for get_submission
49
+ # Check the status of a PDF request
50
+ #
51
+ # @param submission_id
52
+ # @param [Hash] opts the optional parameters
53
+ # @return [InlineResponse201Submission]
54
+ describe 'get_submission test' do
55
+ it "should work" do
56
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,226 @@
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
+
15
+ describe FormAPI::ApiClient do
16
+ context 'initialization' do
17
+ context 'URL stuff' do
18
+ context 'host' do
19
+ it 'removes http from host' do
20
+ FormAPI.configure { |c| c.host = 'http://example.com' }
21
+ expect(FormAPI::Configuration.default.host).to eq('example.com')
22
+ end
23
+
24
+ it 'removes https from host' do
25
+ FormAPI.configure { |c| c.host = 'https://wookiee.com' }
26
+ expect(FormAPI::ApiClient.default.config.host).to eq('wookiee.com')
27
+ end
28
+
29
+ it 'removes trailing path from host' do
30
+ FormAPI.configure { |c| c.host = 'hobo.com/v4' }
31
+ expect(FormAPI::Configuration.default.host).to eq('hobo.com')
32
+ end
33
+ end
34
+
35
+ context 'base_path' do
36
+ it "prepends a slash to base_path" do
37
+ FormAPI.configure { |c| c.base_path = 'v4/dog' }
38
+ expect(FormAPI::Configuration.default.base_path).to eq('/v4/dog')
39
+ end
40
+
41
+ it "doesn't prepend a slash if one is already there" do
42
+ FormAPI.configure { |c| c.base_path = '/v4/dog' }
43
+ expect(FormAPI::Configuration.default.base_path).to eq('/v4/dog')
44
+ end
45
+
46
+ it "ends up as a blank string if nil" do
47
+ FormAPI.configure { |c| c.base_path = nil }
48
+ expect(FormAPI::Configuration.default.base_path).to eq('')
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "params_encoding in #build_request" do
55
+ let(:config) { FormAPI::Configuration.new }
56
+ let(:api_client) { FormAPI::ApiClient.new(config) }
57
+
58
+ it "defaults to nil" do
59
+ expect(FormAPI::Configuration.default.params_encoding).to eq(nil)
60
+ expect(config.params_encoding).to eq(nil)
61
+
62
+ request = api_client.build_request(:get, '/test')
63
+ expect(request.options[:params_encoding]).to eq(nil)
64
+ end
65
+
66
+ it "can be customized" do
67
+ config.params_encoding = :multi
68
+ request = api_client.build_request(:get, '/test')
69
+ expect(request.options[:params_encoding]).to eq(:multi)
70
+ end
71
+ end
72
+
73
+ describe "timeout in #build_request" do
74
+ let(:config) { FormAPI::Configuration.new }
75
+ let(:api_client) { FormAPI::ApiClient.new(config) }
76
+
77
+ it "defaults to 0" do
78
+ expect(FormAPI::Configuration.default.timeout).to eq(0)
79
+ expect(config.timeout).to eq(0)
80
+
81
+ request = api_client.build_request(:get, '/test')
82
+ expect(request.options[:timeout]).to eq(0)
83
+ end
84
+
85
+ it "can be customized" do
86
+ config.timeout = 100
87
+ request = api_client.build_request(:get, '/test')
88
+ expect(request.options[:timeout]).to eq(100)
89
+ end
90
+ end
91
+
92
+ describe "#deserialize" do
93
+ it "handles Array<Integer>" do
94
+ api_client = FormAPI::ApiClient.new
95
+ headers = {'Content-Type' => 'application/json'}
96
+ response = double('response', headers: headers, body: '[12, 34]')
97
+ data = api_client.deserialize(response, 'Array<Integer>')
98
+ expect(data).to be_instance_of(Array)
99
+ expect(data).to eq([12, 34])
100
+ end
101
+
102
+ it "handles Array<Array<Integer>>" do
103
+ api_client = FormAPI::ApiClient.new
104
+ headers = {'Content-Type' => 'application/json'}
105
+ response = double('response', headers: headers, body: '[[12, 34], [56]]')
106
+ data = api_client.deserialize(response, 'Array<Array<Integer>>')
107
+ expect(data).to be_instance_of(Array)
108
+ expect(data).to eq([[12, 34], [56]])
109
+ end
110
+
111
+ it "handles Hash<String, String>" do
112
+ api_client = FormAPI::ApiClient.new
113
+ headers = {'Content-Type' => 'application/json'}
114
+ response = double('response', headers: headers, body: '{"message": "Hello"}')
115
+ data = api_client.deserialize(response, 'Hash<String, String>')
116
+ expect(data).to be_instance_of(Hash)
117
+ expect(data).to eq({:message => 'Hello'})
118
+ end
119
+ end
120
+
121
+ describe "#object_to_hash" do
122
+ it "ignores nils and includes empty arrays" do
123
+ # uncomment below to test object_to_hash for model
124
+ #api_client = FormAPI::ApiClient.new
125
+ #_model = FormAPI::ModelName.new
126
+ # update the model attribute below
127
+ #_model.id = 1
128
+ # update the expected value (hash) below
129
+ #expected = {id: 1, name: '', tags: []}
130
+ #expect(api_client.object_to_hash(_model)).to eq(expected)
131
+ end
132
+ end
133
+
134
+ describe "#build_collection_param" do
135
+ let(:param) { ['aa', 'bb', 'cc'] }
136
+ let(:api_client) { FormAPI::ApiClient.new }
137
+
138
+ it "works for csv" do
139
+ expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
140
+ end
141
+
142
+ it "works for ssv" do
143
+ expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
144
+ end
145
+
146
+ it "works for tsv" do
147
+ expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
148
+ end
149
+
150
+ it "works for pipes" do
151
+ expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
152
+ end
153
+
154
+ it "works for multi" do
155
+ expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
156
+ end
157
+
158
+ it "fails for invalid collection format" do
159
+ expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
160
+ end
161
+ end
162
+
163
+ describe "#json_mime?" do
164
+ let(:api_client) { FormAPI::ApiClient.new }
165
+
166
+ it "works" do
167
+ expect(api_client.json_mime?(nil)).to eq false
168
+ expect(api_client.json_mime?('')).to eq false
169
+
170
+ expect(api_client.json_mime?('application/json')).to eq true
171
+ expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
172
+ expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
173
+
174
+ expect(api_client.json_mime?('application/xml')).to eq false
175
+ expect(api_client.json_mime?('text/plain')).to eq false
176
+ expect(api_client.json_mime?('application/jsonp')).to eq false
177
+ end
178
+ end
179
+
180
+ describe "#select_header_accept" do
181
+ let(:api_client) { FormAPI::ApiClient.new }
182
+
183
+ it "works" do
184
+ expect(api_client.select_header_accept(nil)).to be_nil
185
+ expect(api_client.select_header_accept([])).to be_nil
186
+
187
+ expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
188
+ expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
189
+ expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
190
+
191
+ expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
192
+ expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
193
+ end
194
+ end
195
+
196
+ describe "#select_header_content_type" do
197
+ let(:api_client) { FormAPI::ApiClient.new }
198
+
199
+ it "works" do
200
+ expect(api_client.select_header_content_type(nil)).to eq('application/json')
201
+ expect(api_client.select_header_content_type([])).to eq('application/json')
202
+
203
+ expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
204
+ expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
205
+ expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
206
+ expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
207
+ expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
208
+ end
209
+ end
210
+
211
+ describe "#sanitize_filename" do
212
+ let(:api_client) { FormAPI::ApiClient.new }
213
+
214
+ it "works" do
215
+ expect(api_client.sanitize_filename('sun')).to eq('sun')
216
+ expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
217
+ expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
218
+ expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
219
+ expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
220
+ expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
221
+ expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
222
+ expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
223
+ expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
224
+ end
225
+ end
226
+ end