un_fichier_api 1.0.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: 7f81fa83036d5ed8f4de68659c07c57cb5c354a5b1e73d48314e1ee2ee0a2d3b
4
+ data.tar.gz: 9b35734b308400ddbcd912503b47101c335894d13b740073a7f56a7f74f47b53
5
+ SHA512:
6
+ metadata.gz: cb6d75b94d24d654094619e18b1a4858d69288760090e015a907a3e70c2cd3873eb9da7f2bfa5295a919da6945c639fbf567398478607c5b60ee44c94ba67723
7
+ data.tar.gz: 173c0aeec77a9973f5f6f26830b1220170f2ea86ee64d3746d8965189f89227ade65adaf8b20d914dad60a809df213394f5967b9b5cb3edddd313f0e793e245a
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+
2
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in un_fichier_api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ un_fichier_api (1.0.0)
5
+ activesupport (~> 6.1.0)
6
+ faraday (~> 1.2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ concurrent-ruby (1.1.8)
18
+ faraday (1.2.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ ruby2_keywords
21
+ i18n (1.8.9)
22
+ concurrent-ruby (~> 1.0)
23
+ minitest (5.14.3)
24
+ multipart-post (2.1.1)
25
+ rake (10.5.0)
26
+ ruby2_keywords (0.0.4)
27
+ tzinfo (2.0.4)
28
+ concurrent-ruby (~> 1.0)
29
+ zeitwerk (2.4.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 2.0)
36
+ rake (~> 10.0)
37
+ un_fichier_api!
38
+
39
+ BUNDLED WITH
40
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Valentin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,301 @@
1
+ # UnFichierApi
2
+
3
+ UnFichierApi provide you a simple way to use the 1Fichier API with Ruby (https://1fichier.com/api.html).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'un_fichier_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install un_fichier_api
20
+
21
+ ## Usage
22
+
23
+ To begin, you must have a 1Fichier API key and reference it in a initializer like this:
24
+
25
+ ```ruby
26
+ UnFichierApi::Base.api_key = 'MY_API_KEY'
27
+ ```
28
+
29
+ UnFichierApi provide you few objects that help you to call the 1Fichier API:
30
+ - [File](#file-object)
31
+ - [Folder](#folder-object)
32
+ - [Ftp](#ftp-object)
33
+ - [FtpUser](#ftp-user-object)
34
+ - [Remote](#remote-upload-object)
35
+ - [User](#user-object)
36
+
37
+ Objects to be develop in future (if you want develop it, [don't hesitate](#contributing)):
38
+ - Upload
39
+
40
+ All methods describe below have default listed params. You should replace default params by your own. 1Fichier has their own default values, for folder_id value for example.
41
+
42
+ Please refer to the 1Fichier API documentation [here](https://1fichier.com/api.html) for all informations about API.
43
+
44
+ ### File object
45
+
46
+ **Download a file**
47
+ ```ruby
48
+ UnFichierApi::File.download(url: nil, inline: nil, cdn: nil, restrict_ip: nil, single: nil, pass: nil, no_ssl: nil, folder_id: nil, filename: nil, sharing_user: nil)
49
+ ```
50
+ `url` : Download link
51
+ `inline` : (optional) 0 or 1, if "inline" option enabled. You can always add "&inline=1" to the supplied url
52
+ `cdn` : (optional) 0 or 1, if using your CDN credits (forced if Premium / Access and identified server)
53
+ `restrict_ip` : (optional - for CDN only). 0 (default): No restriction, 1: Prohibits IP changes, 2: Prohibits any sub-requests
54
+ `single` : (optional). 0 (default) : Child requests allowed. 1: Prohibits any sub-requests
55
+ `pass` : (optional) Access password to the file, if restricted by password.
56
+ `no_ssl` : (optional) Disable SSL on the download link
57
+ `folder_id` : Folder ID (if groupware sharing with hidden download link option)
58
+ `filename` : Filename (if groupware sharing with hidden download link option)
59
+ `sharing_user` : Email of the user who shares his resource (essential if folder_id = 0 - if the file is at the root)
60
+
61
+ <br>
62
+
63
+ **Get informations about a file**
64
+ ```ruby
65
+ UnFichierApi::File.info(url: nil, pass: nil, folder_id: nil, filename: nil, sharing_user: nil)
66
+ ```
67
+ `url`: (required) Url of the file
68
+ `pass` : (optional) Access password to the file, if restricted by password. Options, if it's a groupware shared folder file with the hidden download link feature.
69
+ `folder_id` : Folder ID
70
+ `filename` : Filename (exact/case sensitive)
71
+ `sharing_user` : Email of the account that shares the folder (useful if root folder / folder_id=0)
72
+
73
+ <br>
74
+
75
+ **List files of a folder**
76
+ ```ruby
77
+ UnFichierApi::File.list(folder_id: nil, sharing_user: nil, sent_before: nil, sent_after: nil)
78
+ ```
79
+ `folder_id` : (optional) Folder identifier. Root if unspecified or 0. -1 allow to list all files of the account
80
+ `sharing_user` : (optional) Email of the user sharing his folder - used if folder_id = 0 / root folder sent_before/sent_after : (optional) Allow to limit the return by date (can be used separately or not)
81
+ `sent_before/sent_after` : (optional) Limit the result by date. Params can be combined or not.
82
+
83
+ <br>
84
+
85
+ **Copy file(s) in a folder**
86
+ ```ruby
87
+ UnFichierApi::File.copy(urls: [], folder_id: nil, pass: nil, sharing_user: nil, rename: nil)
88
+ ```
89
+ `urls` : List (array) of files (download links) to copy. Copy all the files whose access is not restricted to you.
90
+ `folder_id` : Identifier of target folder / destination (0 or not specified if root).
91
+ `pass` : Access password (optional)
92
+ `sharing_user` : Email of the user sharing his destination resource (used if folder_id = 0 or empty)
93
+ `rename` : (optional) Rename the file (works with 1 URL only)
94
+
95
+ <br>
96
+
97
+ **Move file(s) in a new folder**
98
+ ```ruby
99
+ UnFichierApi::File.move(urls: [], destination_folder_id: nil, destination_user: nil, rename: nil)
100
+ ```
101
+ `urls` : List (array) of files (download links) to move. Allows you to move only your own files or files to which you have write access (groupware shares).
102
+ `destination_folder_id` : Identifier of the target folder (Root of your account if "0." Must be defined.).
103
+ `destination_user` : Email of the user sharing his destination resource (used if destination_folder_id = 0 or empty)
104
+ `rename` : (optional) Rename the file (works with 1 URL only)
105
+
106
+ <br>
107
+
108
+ **Rename file(s)**
109
+ ```ruby
110
+ UnFichierApi::File.rename(urls: [])
111
+ ```
112
+ `urls` : List (array) of files (download links) to rename. Only works with the account files (see example below).
113
+ ```ruby
114
+ urls: [
115
+ { url: 'https://1fichier.com/my_example', filename: 'my_filename' }
116
+ ]
117
+ ```
118
+
119
+ <br>
120
+
121
+ **Remove file(s)**
122
+ ```ruby
123
+ UnFichierApi::File.remove(files: [])
124
+ ```
125
+ `files` : List (array) of files (download links) to remove. Precise a code for the files not linked to an account (optional). See example below.
126
+ ```ruby
127
+ files: [
128
+ { url: 'https://1fichier.com/my_example', code: 'my_code' }
129
+ ]
130
+ ```
131
+
132
+ <br>
133
+
134
+ **Scan file (with 1Fichier antivirus)**
135
+ ```ruby
136
+ UnFichierApi::File.scan(url: nil)
137
+ ```
138
+ `url`: (required) url of the file to scan.
139
+
140
+ <br>
141
+
142
+ **Change attributes of file(s)**
143
+ ```ruby
144
+ UnFichierApi::File.change_attributes(urls: [], filename: nil, description: nil, pass: nil, no_ssl: nil, inline: nil, cdn: nil, acl: { ip: [], country: [], email: [], premium: nil })
145
+ ```
146
+ `urls` : List (array) files (download links) to edit. You can act on your files as well as the files to which you are authorized in write mode
147
+ `filename` : Change the file name. Only works with a single file
148
+ `description` : Modify the description of the file(s) (may be empty)
149
+ `pass` : Change the access password. 6 characters minimum. (may be empty to remove)
150
+ `no_ssl` : Force default access without SSL encryption
151
+ `inline` : Forces "inline" access, informs the browser of the content-type and does not force the opening of a download box.
152
+ `cdn` : Flag the files in "CDN".
153
+ `acl` : Advanced access controls. Can be empty to remove
154
+ `acl/ip` : List of IPs to allow. CIDR format.
155
+ `acl/country` : List of countries to allow
156
+ `acl/email` : List of registered users emails to allow
157
+ `acl/premium` : Only allow our customers (Premium / Access)
158
+
159
+ ### Folder object
160
+
161
+ **List folders**
162
+ ```ruby
163
+ UnFichierApi::Folder.list(folder_id: nil, sharing_user: nil, files: nil)
164
+ ```
165
+ `folder_id` : Identifier of the folder. Root if unspecified or 0.
166
+ `sharing_user` : Email of the user who shares the folder (mandatory if sharing the root folder - ignored otherwise)
167
+ `files` : (optional) : Add files list of the folder
168
+
169
+ <br>
170
+
171
+ **Create a folder**
172
+ ```ruby
173
+ UnFichierApi::Folder.create(name: nil, folder_id: nil, sharing_user: nil)
174
+ ```
175
+ `name`: Folder name
176
+ `folder_id` : Identifier of the parent folder. Root if unspecified or 0.
177
+ `sharing_user` : (optional) Email of the user sharing a folder (required if groupware sharing the root folder)
178
+
179
+ <br>
180
+
181
+ **Move a folder**
182
+ ```ruby
183
+ UnFichierApi::Folder.move(folder_id: nil, destination_folder_id: nil, destination_user: nil, rename: nil)
184
+ ```
185
+ `folder_id` : Folder ID to move (source)
186
+ `destination_folder_id` : Destination folder ID (root if "0")
187
+ `destination_user` : User email (used in the case of a groupware share with destination_folder_id = 0)
188
+ `rename` : New name for the folder (ignore destination_*)
189
+
190
+ <br>
191
+
192
+ **Remove a folder**
193
+ ```ruby
194
+ UnFichierApi::Folder.remove(folder_id: nil)
195
+ ```
196
+ `folder_id` : Folder ID to remove
197
+
198
+ <br>
199
+
200
+ **Share a folder**
201
+ ```ruby
202
+ UnFichierApi::Folder.share(folder_id: nil, share: nil, pass: nil, shares: [])
203
+ ```
204
+ `folder_id` : Folder ID
205
+ `share` : If public sharing accessible via URL like https://1fichier.com/dir/abdef
206
+ `pass` : If "share", possibility to set an access password (6 characters minimum)
207
+ `shares` : Groupware shares with other registered users (0 or empty array to remove any groupware share)
208
+ `shares/email` : Registered user email address
209
+ `shares/rw` : If allow in write mode
210
+ `shares/hide_links` : Hide download links (implies shares/rw = 0)
211
+
212
+ ### Ftp object
213
+
214
+ **Processing request to upload your files in FTP**
215
+ ```ruby
216
+ UnFichierApi::Ftp.process
217
+ ```
218
+
219
+ ### Ftp user object
220
+
221
+ **List the FTP users**
222
+ ```ruby
223
+ UnFichierApi::FtpUser.list
224
+ ```
225
+
226
+ <br>
227
+
228
+ **Create a FTP user**
229
+ ```ruby
230
+ UnFichierApi::FtpUser.create(user: nil, pass: nil, folder_id: nil)
231
+ ```
232
+ `user` : (required) Username
233
+ `pass` : (required) Password
234
+ `folder_id` : (optional) Destination folder identifier when upload files
235
+
236
+ <br>
237
+
238
+ **Remove a FTP user**
239
+ ```ruby
240
+ UnFichierApi::FtpUser.remove(user: nil)
241
+ ```
242
+ `user` : (required) Username
243
+
244
+ ### Remote upload object
245
+
246
+ **List the remote uploads**
247
+ ```ruby
248
+ UnFichierApi::Remote.list
249
+ ```
250
+
251
+ <br>
252
+
253
+ **Info about a remote upload request**
254
+ ```ruby
255
+ UnFichierApi::Remote.info(id: nil)
256
+ ```
257
+ `id` : Remote upload request identifier identifier
258
+
259
+ <br>
260
+
261
+ **Create a remote upload request**
262
+ ```ruby
263
+ UnFichierApi::Remote.request(urls: [], folder_id: nil, headers: {})
264
+ ```
265
+ `urls` : List (array) of files (download links) to upload to the account.
266
+ `folder_id` : Destination folder (root if empty or "0")
267
+ `headers/name` : Alphanumeric characters accepted, including '-'. Insensitive to the box according to the RFC. We will normalize the variable in lowercase except for the first letter of words (eg Content-Type)
268
+ `headers/value` : Accepted alphanumeric characters, including space, tab (excluding the first and last characters) [-_+=%?,'"/]
269
+
270
+ Example of `headers` value :
271
+ ```ruby
272
+ headers: {
273
+ 'Name1': 'my_value_1',
274
+ 'Name2': 'my_value_2'
275
+ }
276
+ ```
277
+
278
+ ### User object
279
+
280
+ **Get/update informations about the user**
281
+ ```ruby
282
+ UnFichierApi::User.info(ftp_mode: nil, ftp_did: nil, ftp_report: nil, ru_report: nil, default_domain: nil, page_limit: nil, default_port: nil, default_port_files: nil, use_cdn: nil, download_menu: nil)
283
+ ```
284
+ `ftp_mode` : Mode of treatment of files uploaded by FTP. 0/automatic - 1/manual
285
+ `ftp_did` : Destination folder ID of files uploaded by FTP (default root/0)
286
+ `ftp_report` : Send a notification email after processing files uploaded by FTP.
287
+ `ru_report` : Sending a notification email after processing a Remote Upload request.
288
+ `default_domain` : Default file hosting domain (see table).
289
+ `page_limit` : Limit the number of files show on a page (web interface)
290
+ `default_port` : Default download port. 0/HTTP SSL - 1/HTTP
291
+ `default_port_files` : Default download port for your files. 0/HTTP SSL - 1/HTTP
292
+ `use_cdn` : Use your CDN credits for your own downloads.
293
+ `download_menu` : Display the download menu
294
+
295
+ ## Contributing
296
+
297
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ValentinSoyer/1-fichier-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
298
+
299
+ ## License
300
+
301
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'un_fichier_api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'un_fichier_api/base'
2
+ require 'un_fichier_api/file'
3
+ require 'un_fichier_api/folder'
4
+ require 'un_fichier_api/ftp_user'
5
+ require 'un_fichier_api/ftp'
6
+ require 'un_fichier_api/remote'
7
+ require 'un_fichier_api/user'
8
+ require 'un_fichier_api/version'
9
+
10
+ module UnFichierApi
11
+ class Error < StandardError; end
12
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'faraday'
5
+ require 'un_fichier_api/helpers/request_helper'
6
+
7
+ module UnFichierApi
8
+ class Base
9
+ include Helpers::RequestHelper
10
+
11
+ # Attributes
12
+ class_attribute :api_key, default: 'grzgKtlt6rCbiArOvZZHXO9wYqjtIDZa'
13
+
14
+ # Methods
15
+ class << self
16
+ def call(path:, method: :post, body: {}, headers: {})
17
+ connection.headers.merge! headers
18
+
19
+ response = connection.send(method, path) do |req|
20
+ req.body = body.to_json
21
+ end
22
+
23
+ JSON.parse response.body
24
+ end
25
+
26
+ def connection
27
+ @connection ||= Faraday.new(
28
+ url: 'https://api.1fichier.com/v1',
29
+ headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{api_key}" },
30
+ request: { timeout: 120 }
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class File < Base
5
+ # Methods
6
+ class << self
7
+ def change_attributes(urls: [], filename: nil, description: nil, pass: nil, no_ssl: nil, inline: nil, cdn: nil, acl: { ip: [], country: [], email: [], premium: nil })
8
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
9
+ call path: action_route('chattr'), body: body
10
+ end
11
+
12
+ def copy(urls: [], folder_id: nil, pass: nil, sharing_user: nil, rename: nil)
13
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
14
+ call path: action_route('cp'), body: body
15
+ end
16
+
17
+ def download(url: nil, inline: nil, cdn: nil, restrict_ip: nil, single: nil, pass: nil, no_ssl: nil, folder_id: nil, filename: nil, sharing_user: nil)
18
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
19
+ call path: 'download/get_token.cgi', body: body
20
+ end
21
+
22
+ def info(url: nil, pass: nil, folder_id: nil, filename: nil, sharing_user: nil)
23
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
24
+ call path: action_route('info'), body: body
25
+ end
26
+
27
+ def list(folder_id: nil, sharing_user: nil, sent_before: nil, sent_after: nil)
28
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
29
+ call path: action_route('ls'), body: body
30
+ end
31
+
32
+ def move(urls: [], destination_folder_id: nil, destination_user: nil, rename: nil)
33
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
34
+ call path: action_route('mv'), body: body
35
+ end
36
+
37
+ def remove(files: [])
38
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
39
+ call path: action_route('rm'), body: body
40
+ end
41
+
42
+ def rename(urls: [])
43
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
44
+ call path: action_route('rename'), body: body
45
+ end
46
+
47
+ def scan(url: nil)
48
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
49
+ call path: action_route('scan'), body: body
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class Folder < Base
5
+ # Methods
6
+ class << self
7
+ def create(name: nil, folder_id: nil, sharing_user: nil)
8
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
9
+ call path: action_route('mkdir'), body: body
10
+ end
11
+
12
+ def list(folder_id: nil, sharing_user: nil, files: nil)
13
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
14
+ call path: action_route('ls'), body: body
15
+ end
16
+
17
+ def move(folder_id: nil, destination_folder_id: nil, destination_user: nil, rename: nil)
18
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
19
+ call path: action_route('mv'), body: body
20
+ end
21
+
22
+ def remove(folder_id: nil)
23
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
24
+ call path: action_route('rm'), body: body
25
+ end
26
+
27
+ def share(folder_id: nil, share: nil, pass: nil, shares: [])
28
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
29
+ call path: action_route('share'), body: body
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class Ftp < Base
5
+ # Methods
6
+ class << self
7
+ def process
8
+ call path: action_route('process')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class FtpUser < Base
5
+ # Methods
6
+ class << self
7
+ def create(user: nil, pass: nil, folder_id: nil)
8
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
9
+ call path: action_route('add'), body: body
10
+ end
11
+
12
+ def list
13
+ call path: action_route('ls')
14
+ end
15
+
16
+ def remove(user: nil)
17
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
18
+ call path: action_route('rm'), body: body
19
+ end
20
+
21
+ private
22
+
23
+ def action_route(action_name)
24
+ "ftp/users/#{action_name}.cgi"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ module Helpers
5
+ module RequestHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ class_methods do
9
+ private
10
+
11
+ def action_route(action_name)
12
+ "#{self.name.demodulize.underscore}/#{action_name}.cgi"
13
+ end
14
+
15
+ def body_from_parameters(parameters:, method_binding:)
16
+ Hash[parameters.map do |type, arg|
17
+ next if method_binding.local_variable_get(arg).nil?
18
+ [arg, method_binding.local_variable_get(arg)]
19
+ end.compact]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class Remote < Base
5
+ # Methods
6
+ class << self
7
+ def info(id: nil)
8
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
9
+ call path: action_route('info'), body: body
10
+ end
11
+
12
+ def list
13
+ call path: action_route('ls')
14
+ end
15
+
16
+ def request(urls: [], folder_id: nil, headers: {})
17
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
18
+ call path: action_route('request'), body: body
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnFichierApi
4
+ class User < Base
5
+ # Methods
6
+ class << self
7
+ def info(ftp_mode: nil, ftp_did: nil, ftp_report: nil, ru_report: nil, default_domain: nil, page_limit: nil, default_port: nil, default_port_files: nil, use_cdn: nil, download_menu: nil)
8
+ body = body_from_parameters parameters: method(__method__).parameters, method_binding: binding
9
+ call path: action_route('info'), body: body
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module UnFichierApi
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'un_fichier_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'un_fichier_api'
7
+ spec.version = UnFichierApi::VERSION
8
+ spec.authors = ['Valentin Soyer']
9
+ spec.email = ['valent.soyer@gmail.com']
10
+ spec.summary = %q{Provide a simple way to use the 1Fichier API (https://1fichier.com/api.html).}
11
+ spec.homepage = 'https://github.com/ValentinSoyer/1-fichier-api'
12
+ spec.license = 'MIT'
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 2.0'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_dependency 'activesupport', '~> 6.1.0'
29
+ spec.add_dependency 'faraday', '~> 1.2.0'
30
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: un_fichier_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Valentin Soyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 6.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 6.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ description:
70
+ email:
71
+ - valent.soyer@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/un_fichier_api.rb
85
+ - lib/un_fichier_api/base.rb
86
+ - lib/un_fichier_api/file.rb
87
+ - lib/un_fichier_api/folder.rb
88
+ - lib/un_fichier_api/ftp.rb
89
+ - lib/un_fichier_api/ftp_user.rb
90
+ - lib/un_fichier_api/helpers/request_helper.rb
91
+ - lib/un_fichier_api/remote.rb
92
+ - lib/un_fichier_api/user.rb
93
+ - lib/un_fichier_api/version.rb
94
+ - un_fichier_api.gemspec
95
+ homepage: https://github.com/ValentinSoyer/1-fichier-api
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/ValentinSoyer/1-fichier-api
100
+ source_code_uri: https://github.com/ValentinSoyer/1-fichier-api
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Provide a simple way to use the 1Fichier API (https://1fichier.com/api.html).
120
+ test_files: []