flatfile_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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f5cb0484e3340ab27e6a212fcb7e4def2af95749c2baefcb565fd5dc3c5c38f
4
+ data.tar.gz: 4c9bbc5c68a0e9b7fee0e6b270a24e0eab807c20e336280642759f488d2a6001
5
+ SHA512:
6
+ metadata.gz: 2e2e2bc212004d46197dd8faf9e0a0b61c1af416f556568a925142823df55affbfd132c47c0f31653ef06d2f7a73561da5d4a5e89f5f704c6981281b0566856a
7
+ data.tar.gz: 47f85b80c3b61401e019eb9ec25d3147a294a0e4b47851604d275c42935e3c39d6fdc8ca1f83cc248ad76b2fe436ed0faa41402ca237384e79fbe59bb254101b
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ # Unix-style newlines with a newline ending every file
4
+ [*]
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+
8
+ [*.rb]
9
+ charset = utf-8
10
+ indent_style = tab
11
+ indent_size = 4
12
+ trim_trailing_whitespace = true
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-11-30
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in flatfile_api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
data/README.md ADDED
@@ -0,0 +1,264 @@
1
+ # FlatfileApi
2
+
3
+ This software is an unofficial client for the Flatfile API, and is not endorsed by Flatfile.
4
+
5
+ It provides access to all available endpoints, but the documentation is patchy and most endpoints are untested. Use with caution.
6
+
7
+ If you can help document the endpoints, and provide example use cases, please feel free to send pull requests.
8
+
9
+ ### A note on naming conventions
10
+
11
+ The Flatfile API typically uses `CamelCase` for parameters, and hash key names (but not always). This gem converts everything to `snake_case`.
12
+
13
+ ### A note on pagination
14
+
15
+ Some of the endpoints are paginated; they can be identified as the ones that take `skip` and `take` as parameters. They are not required values and will default to `0` and `50` respectively. You can use these values to manage your own pagination, but you can also treat the response as an `Enumerable` and use `each`, `map`, `find`, etc. and it will automatically pull all results. Use with caution.
16
+
17
+ All the endpoints return either a `FlatfileApi::Response` or a `FlatfileApi::PaginatedResponse`.
18
+
19
+ On either response, use the `data` method to access the returned data.
20
+
21
+ ## Installation
22
+
23
+ Install the gem and add to the application's Gemfile by executing:
24
+
25
+ $ bundle add flatfile_api
26
+
27
+ If bundler is not being used to manage dependencies, install the gem by executing:
28
+
29
+ $ gem install flatfile_api
30
+
31
+ ## Usage
32
+
33
+ ### Get recent uploads
34
+
35
+ ```ruby
36
+ require 'flatfile_api'
37
+
38
+ client = FlatfileApi.new access_key_id: '12345', secret_access_key: '1234-456790-1234'
39
+ uploads = client.list_workspace_uploads license_key: '9999-234234-2342'
40
+ # => <FlatfileApi::PaginatedResponse:0x00007f508bdd6020 ...>
41
+
42
+ # Access the page of results directly:
43
+ uploads.data.first
44
+ # => {
45
+ # :license_id=>938427,
46
+ # :team_id=>10483,
47
+ # :environment_id=>"4248-585628-1322",
48
+ # :workspace_id=>nil,
49
+ # :schema_id=>nil,
50
+ # :embed_id=>nil,
51
+ # :end_user_id=>"6776-278654-6823",
52
+ # :filename=>
53
+ # "license-9999-234234-2342/batch-4752-164173-1238/upload-9663-680238-0901.csv",
54
+ # :source=>nil,
55
+ # :memo=>nil,
56
+ # :validated_in=>nil,
57
+ # :original_file=>"my upload.csv",
58
+ # ...
59
+
60
+ # Make use of the convenience functions:
61
+
62
+ # GOOD - it won't request more pages than it needs
63
+ uploads.take_while { |t| ... }
64
+
65
+ # NOT SO GOOD - using select like this forces every page to be fetched
66
+ uploads.select { |t| ... }
67
+
68
+ # PRETTY AWESOME - using Enumerable#lazy to postpone filtering
69
+ uploads.lazy.select { |t| /\.csv$/ === t[:original_file] }.first 5
70
+
71
+ # Just get all the uploads:
72
+ uploads.to_a
73
+
74
+ ```
75
+
76
+ ## Methods
77
+
78
+ ### exchange_access_key_for_jwt
79
+ | Name | Required | Type | Value | Description |
80
+ | ---- | -------- | ---- | ----- | ----------- |
81
+ | access_key_id | true | string | | Access Key generated in app |
82
+ | expires_in | | number | 43200 (default) | Sets an expiration (in seconds) |
83
+ | secret_access_key | true | string | | Secret Access Key generated in app |
84
+
85
+ Response: `FlatfileApi::Response`
86
+
87
+
88
+ ### download_an_upload
89
+ | Name | Required | Type | Value | Description |
90
+ | ---- | -------- | ---- | ----- | ----------- |
91
+ | batch_id | true | string | | A valid UUID |
92
+ | type | true | string | Enum: original, processed | File to download |
93
+
94
+ Response: `FlatfileApi::Response`
95
+
96
+
97
+ ### delete_an_upload
98
+ | Name | Required | Type | Value | Description |
99
+ | ---- | -------- | ---- | ----- | ----------- |
100
+ | batch_id | true | string | | A valid UUID |
101
+
102
+ Response: `FlatfileApi::Response`
103
+
104
+
105
+ ### bulk_delete_uploads
106
+ | Name | Required | Type | Value | Description |
107
+ | ---- | -------- | ---- | ----- | ----------- |
108
+ | older_than_quantity | true | string | | |
109
+ | older_than_unit | true | string | Enum: minute, hour, day, week, month | |
110
+ | send_email | true | string | Enum: true, false | |
111
+ | team_id | true | string | | |
112
+
113
+ Response: `FlatfileApi::Response`
114
+
115
+
116
+ ### list_workspace_uploads
117
+ | Name | Required | Type | Value | Description |
118
+ | ---- | -------- | ---- | ----- | ----------- |
119
+ | end_user_id | | string | | Valid endUserId for the Workspace |
120
+ | environment_id | | string | | Valid environmentId for the Workspace |
121
+ | license_key | true | string | | A valid licenseKey for the Workspace |
122
+ | search | | string | | Searches fileName, originalFile, memo |
123
+ | skip | | number | 0 (default) | The rows to skip before listing |
124
+ | take | | number | 50 (default) | The maximum number of rows to return |
125
+ | workspace_id | | string | | Valid workspaceId for the Workspace |
126
+
127
+ Response: `FlatfileApi::PaginatedResponse`
128
+
129
+
130
+ ### file_upload_meta_data
131
+ | Name | Required | Type | Value | Description |
132
+ | ---- | -------- | ---- | ----- | ----------- |
133
+ | batch_id | true | string | | A valid UUID |
134
+
135
+ Response: `FlatfileApi::Response`
136
+
137
+
138
+ ### sheet_name_for_file_upload
139
+ | Name | Required | Type | Value | Description |
140
+ | ---- | -------- | ---- | ----- | ----------- |
141
+ | license_key | | string | | A valid licenseKey for the Workspace |
142
+ | upload_id | true | string | | A valid UUID |
143
+
144
+ Response: `FlatfileApi::Response`
145
+
146
+
147
+ ### records_for_file_upload
148
+ | Name | Required | Type | Value | Description |
149
+ | ---- | -------- | ---- | ----- | ----------- |
150
+ | batch_id | true | string | | A valid UUID |
151
+ | created_at_end_date | | string | ISO 8601 | The maximum createdAt date to return |
152
+ | created_at_start_date | | string | ISO 8601 | The minimum createdAt date to return |
153
+ | deleted | | string | Enum: true, t, y, false, f, n | Return only deleted rows |
154
+ | skip | | number | 0 (default) | The rows to skip before listing |
155
+ | take | | number | 50 (default) | The maximum number of rows to return |
156
+ | updated_at_end_date | | string | ISO 8601 | The maximum updatedAt date to return |
157
+ | updated_at_start_date | | string | ISO 8601 | The minimum updatedAt date to return |
158
+ | valid | | string | Enum: true, t, y, false, f, n | Return only valid rows |
159
+
160
+ Response: `FlatfileApi::PaginatedResponse`
161
+
162
+
163
+ ### upload_to_workspace_sheet
164
+ | Name | Required | Type | Value | Description |
165
+ | ---- | -------- | ---- | ----- | ----------- |
166
+ | sheet_id | true | string | | A valid UUID |
167
+ | workspace_id | true | string | | A valid UUID |
168
+
169
+ Response: `FlatfileApi::Response`
170
+
171
+
172
+ ### fetch_workspace_sheet_records
173
+ | Name | Required | Type | Value | Description |
174
+ | ---- | -------- | ---- | ----- | ----------- |
175
+ | filter | | string | Enum: review, dismissed, accepted | Return only the filtered rows |
176
+ | merge_id | | string | | |
177
+ | nested | | boolean | | |
178
+ | record_ids | | string[] | | |
179
+ | sheet_id | true | string | | A valid UUID |
180
+ | skip | | number | 0 (default) | The rows to skip before listing |
181
+ | take | | number | 50 (default) | The maximum number of rows to return |
182
+ | valid | | string | Enum: true, t, y, false, f, n | Return only valid rows |
183
+ | workspace_id | true | string | | A valid UUID |
184
+
185
+ Response: `FlatfileApi::PaginatedResponse`
186
+
187
+
188
+ ### list_team_workspaces
189
+ | Name | Required | Type | Value | Description |
190
+ | ---- | -------- | ---- | ----- | ----------- |
191
+ | environment_id | | string | | Valid environmentId for the Workspace |
192
+ | skip | | number | 0 (default) | The rows to skip before listing |
193
+ | take | | number | 50 (default) | The maximum number of rows to return |
194
+ | team_id | true | string | | |
195
+
196
+ Response: `FlatfileApi::PaginatedResponse`
197
+
198
+
199
+ ### detail_workspace
200
+ | Name | Required | Type | Value | Description |
201
+ | ---- | -------- | ---- | ----- | ----------- |
202
+ | workspace_id | true | string | | A valid UUID |
203
+
204
+ Response: `FlatfileApi::Response`
205
+
206
+
207
+ ### invite_workspace_collaborator
208
+ | Name | Required | Type | Value | Description |
209
+ | ---- | -------- | ---- | ----- | ----------- |
210
+ | email | true | string | | Email address of invited collaborator |
211
+ | team_id | true | string | | |
212
+ | workspace_id | true | string | | A valid UUID |
213
+
214
+ Response: `FlatfileApi::Response`
215
+
216
+
217
+ ### list_workspace_invitations
218
+ | Name | Required | Type | Value | Description |
219
+ | ---- | -------- | ---- | ----- | ----------- |
220
+ | team_id | true | string | | |
221
+ | workspace_id | true | string | | A valid UUID |
222
+
223
+ Response: `FlatfileApi::Response`
224
+
225
+
226
+ ### list_workspace_collaborators
227
+ | Name | Required | Type | Value | Description |
228
+ | ---- | -------- | ---- | ----- | ----------- |
229
+ | team_id | true | string | | |
230
+ | workspace_id | true | string | | A valid UUID |
231
+
232
+ Response: `FlatfileApi::Response`
233
+
234
+
235
+ ### revoke_workspace_invitation
236
+ | Name | Required | Type | Value | Description |
237
+ | ---- | -------- | ---- | ----- | ----------- |
238
+ | email | true | string | | Email address of invited collaborator |
239
+ | team_id | true | string | | |
240
+ | workspace_id | true | string | | A valid UUID |
241
+
242
+ Response: `FlatfileApi::Response`
243
+
244
+
245
+ ### remove_workspace_collaborator
246
+ | Name | Required | Type | Value | Description |
247
+ | ---- | -------- | ---- | ----- | ----------- |
248
+ | email | true | string | | Email address of collaborator |
249
+ | team_id | true | string | | |
250
+ | user_id | true | string | | |
251
+ | workspace_id | true | string | | A valid UUID |
252
+
253
+ Response: `FlatfileApi::Response`
254
+
255
+
256
+ ## Development
257
+
258
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
259
+
260
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
261
+
262
+ ## Contributing
263
+
264
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyclotron3k/flatfile_api.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ class FlatfileApi
2
+ class PaginatedResponse
3
+ include Enumerable
4
+ # :pagination=>{:current_page=>1, :limit=>50, :offset=>0, :on_page=>50, :next_offset=>50, :total_count=>3918, :page_count=>79}
5
+
6
+ def initialize(response, client, method, path, path_params: {}, body_params: {}, query_params: nil)
7
+ @response = response
8
+ @client = client
9
+ @method = method
10
+ @path = path
11
+ @path_params = path_params
12
+ @body_params = body_params
13
+ @query_params = query_params
14
+ end
15
+
16
+ def data
17
+ @response[:data]
18
+ end
19
+
20
+ alias :page :data
21
+
22
+ def each(&block)
23
+ @response[:data].each { |item| block.call item }
24
+ next_page.each(&block) unless last_page?
25
+ end
26
+
27
+ private
28
+
29
+ def last_page?
30
+ @response[:pagination][:current_page] >= @response[:pagination][:page_count]
31
+ end
32
+
33
+ def next_page
34
+ @client.send(
35
+ :request,
36
+ @method,
37
+ @path,
38
+ path_params: @path_params,
39
+ body_params: @body_params,
40
+ query_params: @query_params.merge(skip: @response[:pagination][:next_offset])
41
+ )
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,12 @@
1
+ class FlatfileApi
2
+ class Response
3
+
4
+ attr_reader :data
5
+
6
+ def initialize(response)
7
+ @data = response
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,16 @@
1
+ # Appropriated from ActiveSupport/Inflector
2
+
3
+ class FlatfileApi
4
+ module StringTools
5
+ refine String do
6
+ def underscore
7
+ self.gsub(
8
+ /([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/
9
+ ) { ($1 || $2) << "_" }.tr(
10
+ "-",
11
+ "_"
12
+ ).downcase
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FlatfileApi
4
+ VERSION = "0.1.0"
5
+ end