uploadfuse 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +35 -0
- data/README.md +50 -0
- data/Rakefile +12 -0
- data/bin/console +20 -0
- data/bin/setup +8 -0
- data/lib/upload_fuse/client.rb +48 -0
- data/lib/upload_fuse/collection.rb +27 -0
- data/lib/upload_fuse/error.rb +4 -0
- data/lib/upload_fuse/object.rb +19 -0
- data/lib/upload_fuse/objects/upload.rb +5 -0
- data/lib/upload_fuse/resource.rb +60 -0
- data/lib/upload_fuse/resources/uploads.rb +31 -0
- data/lib/upload_fuse/version.rb +5 -0
- data/lib/upload_fuse.rb +21 -0
- data/lib/uploadfuse.rb +1 -0
- data/uploadfuse.gemspec +33 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 65382f39e78ba8480a5b5403c599633f9bf238a02580b3bbfb54514096295eb5
|
4
|
+
data.tar.gz: 44b861f3e0769e731549ed3ca079d1708a086e83a592e73a3970da67308e2d41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c112f7517c0ba60c48b76ca535d339f3e4fccff8a2d0012696d03616be5443239e1cc34ff7224f74b509b6b8e39dcb6eb9c870e741167be5e06fb80620bc531
|
7
|
+
data.tar.gz: b5a8de54ea6f2e657dc05104d715b36353783ba15606b83eb9a1cc15fd8c7dd69821abf7118db4f39608e4c4401b1c528813b53c5975867e2162730fcadd4bba
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ACCESS_TOKEN=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
uploadfuse (0.1.0)
|
5
|
+
faraday (~> 2.0)
|
6
|
+
faraday-multipart (~> 1.0)
|
7
|
+
marcel (~> 1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
dotenv (2.7.6)
|
13
|
+
faraday (2.7.6)
|
14
|
+
faraday-net_http (>= 2.0, < 3.1)
|
15
|
+
ruby2_keywords (>= 0.0.4)
|
16
|
+
faraday-multipart (1.0.4)
|
17
|
+
multipart-post (~> 2)
|
18
|
+
faraday-net_http (3.0.2)
|
19
|
+
marcel (1.0.2)
|
20
|
+
minitest (5.15.0)
|
21
|
+
multipart-post (2.3.0)
|
22
|
+
rake (13.0.6)
|
23
|
+
ruby2_keywords (0.0.5)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x86_64-linux
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
dotenv
|
30
|
+
minitest (~> 5.0)
|
31
|
+
rake (~> 13.0)
|
32
|
+
uploadfuse!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.3.22
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# UploadFuse
|
2
|
+
|
3
|
+
**This Library is a work in progress**
|
4
|
+
|
5
|
+
This is a Ruby library for interacting with the UploadFuse API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "uploadfuse"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Set Access Token
|
18
|
+
|
19
|
+
Firstly you'll need to create an API Access Token on your bucket page.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@client = UploadFuse::Client.new(access_token: "")
|
23
|
+
```
|
24
|
+
|
25
|
+
### Uploads
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Retrieves a list of Uploads for your Bucket
|
29
|
+
@client.uploads.list
|
30
|
+
|
31
|
+
# Retrieves an Upload
|
32
|
+
@client.uploads.get id: "abc123"
|
33
|
+
#=> #<UploadFuse::Upload token="abc123fb...
|
34
|
+
|
35
|
+
# Upload a file
|
36
|
+
@client.uploads.create_from_file file: File.new("myfile.jpg")
|
37
|
+
#=> #<UploadFuse::Upload token="63a3f8fb...
|
38
|
+
|
39
|
+
# Upload a file from a URL
|
40
|
+
@client.uploads.create_from_url url: "https://files.deanpcmad.com/abc.jpg"
|
41
|
+
#=> #<UploadFuse::Upload token="5e85e4a8...
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/uploadfuse.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "upload_fuse"
|
6
|
+
|
7
|
+
# Load environment variables from .env file
|
8
|
+
require 'dotenv/load'
|
9
|
+
|
10
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
11
|
+
# with your gem easier. You can also use a different console, if you like.
|
12
|
+
|
13
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
14
|
+
# require "pry"
|
15
|
+
# Pry.start
|
16
|
+
|
17
|
+
@client = UploadFuse::Client.new(access_token: ENV["ACCESS_TOKEN"])
|
18
|
+
|
19
|
+
require "irb"
|
20
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module UploadFuse
|
2
|
+
class Client
|
3
|
+
BASE_URL = "https://uploadfuse.com/api/v1"
|
4
|
+
|
5
|
+
attr_reader :access_token, :adapter
|
6
|
+
|
7
|
+
def initialize(access_token:, adapter: Faraday.default_adapter, stubs: nil)
|
8
|
+
@access_token = access_token
|
9
|
+
@adapter = adapter
|
10
|
+
|
11
|
+
# Test stubs for requests
|
12
|
+
@stubs = stubs
|
13
|
+
end
|
14
|
+
|
15
|
+
def uploads
|
16
|
+
UploadsResource.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection
|
20
|
+
@connection ||= Faraday.new(BASE_URL + "?api_token=#{access_token}") do |conn|
|
21
|
+
# conn.request :authorization, :Bearer, access_token
|
22
|
+
|
23
|
+
conn.headers = {
|
24
|
+
"User-Agent" => "uploadfuse/v#{VERSION} (github.com/deanpcmad/uploadfuse)",
|
25
|
+
"Accept" => "application/json",
|
26
|
+
"Content-Type" => "application/json",
|
27
|
+
}
|
28
|
+
|
29
|
+
conn.request :json
|
30
|
+
conn.response :json
|
31
|
+
|
32
|
+
conn.adapter adapter, @stubs
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Uses Faraday Multipart (lostisland/faraday-multipart)
|
37
|
+
def connection_upload
|
38
|
+
@connection ||= Faraday.new(BASE_URL + "?api_token=#{access_token}") do |conn|
|
39
|
+
# conn.request :authorization, :Bearer, access_token
|
40
|
+
conn.request :multipart
|
41
|
+
|
42
|
+
conn.headers = {
|
43
|
+
"User-Agent" => "uploadfuse/v#{VERSION} (github.com/deanpcmad/uploadfuse)"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module UploadFuse
|
2
|
+
class Collection
|
3
|
+
attr_reader :data, :total
|
4
|
+
|
5
|
+
def self.from_response(response, type:, key: nil)
|
6
|
+
body = response.body
|
7
|
+
|
8
|
+
if key.is_a?(String)
|
9
|
+
data = body["data"][key].map { |attrs| type.new(attrs) }
|
10
|
+
total = body["data"]["total"]
|
11
|
+
else
|
12
|
+
data = body["data"].map { |attrs| type.new(attrs) }
|
13
|
+
total = body["data"].count
|
14
|
+
end
|
15
|
+
|
16
|
+
new(
|
17
|
+
data: data,
|
18
|
+
total: total
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(data:, total:)
|
23
|
+
@data = data
|
24
|
+
@total = total
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module UploadFuse
|
4
|
+
class Object < OpenStruct
|
5
|
+
def initialize(attributes)
|
6
|
+
super to_ostruct(attributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ostruct(obj)
|
10
|
+
if obj.is_a?(Hash)
|
11
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
12
|
+
elsif obj.is_a?(Array)
|
13
|
+
obj.map { |o| to_ostruct(o) }
|
14
|
+
else # Assumed to be a primitive value
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module UploadFuse
|
2
|
+
class Resource
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_request(url, params: {}, headers: {})
|
12
|
+
handle_response client.connection.get(url, params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(url, body: {}, headers: {})
|
16
|
+
handle_response client.connection.post(url, body, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def patch_request(url, body:, headers: {})
|
20
|
+
handle_response client.connection.patch(url, body, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def put_request(url, body:, headers: {})
|
24
|
+
handle_response client.connection.put(url, body, headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_request(url, params: {}, headers: {})
|
28
|
+
handle_response client.connection.delete(url, params, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_response(response)
|
32
|
+
case response.status
|
33
|
+
when 400
|
34
|
+
raise Error, "Error 400: Your request was malformed. '#{response.body["errors"][0]["detail"]}'"
|
35
|
+
when 401
|
36
|
+
raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
|
37
|
+
when 403
|
38
|
+
raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
|
39
|
+
when 404
|
40
|
+
raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
|
41
|
+
when 409
|
42
|
+
raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
|
43
|
+
when 429
|
44
|
+
raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
|
45
|
+
when 500
|
46
|
+
raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
|
47
|
+
when 503
|
48
|
+
raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
|
49
|
+
when 501
|
50
|
+
raise Error, "Error 501: This resource has not been implemented. '#{response.body["error"]}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
if response.body && response.body["error"]
|
54
|
+
raise Error, "Error #{response.body["error"]["code"]} - #{response.body["error"]["message"]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module UploadFuse
|
2
|
+
class UploadsResource < Resource
|
3
|
+
|
4
|
+
def list
|
5
|
+
response = get_request("uploads")
|
6
|
+
Collection.from_response(response, type: Upload)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(id:)
|
10
|
+
response = get_request("uploads/#{id}")
|
11
|
+
Upload.new(response.body["data"]) if response.success?
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_from_file(file:)
|
15
|
+
content_type = Marcel::MimeType.for file
|
16
|
+
|
17
|
+
# This method uses Faraday Multipart (lostisland/faraday-multipart)
|
18
|
+
payload = {}
|
19
|
+
payload[:file] = Faraday::Multipart::FilePart.new(file, content_type)
|
20
|
+
|
21
|
+
response = client.connection_upload.post "uploads", payload
|
22
|
+
Upload.new(JSON.parse(response.body)["data"]) if response.success?
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_from_url(url:)
|
26
|
+
response = post_request("uploads", body: {url: url})
|
27
|
+
Upload.new(response.body["data"]) if response.success?
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/upload_fuse.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "faraday/multipart"
|
5
|
+
require "marcel"
|
6
|
+
|
7
|
+
require_relative "upload_fuse/version"
|
8
|
+
|
9
|
+
module UploadFuse
|
10
|
+
|
11
|
+
autoload :Client, "upload_fuse/client"
|
12
|
+
autoload :Collection, "upload_fuse/collection"
|
13
|
+
autoload :Error, "upload_fuse/error"
|
14
|
+
autoload :Resource, "upload_fuse/resource"
|
15
|
+
autoload :Object, "upload_fuse/object"
|
16
|
+
|
17
|
+
autoload :UploadsResource, "upload_fuse/resources/uploads"
|
18
|
+
|
19
|
+
autoload :Upload, "upload_fuse/objects/upload"
|
20
|
+
|
21
|
+
end
|
data/lib/uploadfuse.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "upload_fuse"
|
data/uploadfuse.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/upload_fuse/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "uploadfuse"
|
7
|
+
spec.version = UploadFuse::VERSION
|
8
|
+
spec.authors = ["Dean Perry"]
|
9
|
+
spec.email = ["dean@deanpcmad.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby library for interacting with the UploadFuse API"
|
12
|
+
spec.homepage = "https://github.com/deanpcmad/uploadfuse"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/uploadfuse"
|
17
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "faraday", "~> 2.0"
|
31
|
+
spec.add_dependency "faraday-multipart", "~> 1.0"
|
32
|
+
spec.add_dependency "marcel", "~> 1.0"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uploadfuse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Perry
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
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: faraday-multipart
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: marcel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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: '1.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- dean@deanpcmad.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".env.example"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/upload_fuse.rb
|
70
|
+
- lib/upload_fuse/client.rb
|
71
|
+
- lib/upload_fuse/collection.rb
|
72
|
+
- lib/upload_fuse/error.rb
|
73
|
+
- lib/upload_fuse/object.rb
|
74
|
+
- lib/upload_fuse/objects/upload.rb
|
75
|
+
- lib/upload_fuse/resource.rb
|
76
|
+
- lib/upload_fuse/resources/uploads.rb
|
77
|
+
- lib/upload_fuse/version.rb
|
78
|
+
- lib/uploadfuse.rb
|
79
|
+
- uploadfuse.gemspec
|
80
|
+
homepage: https://github.com/deanpcmad/uploadfuse
|
81
|
+
licenses: []
|
82
|
+
metadata:
|
83
|
+
homepage_uri: https://github.com/deanpcmad/uploadfuse
|
84
|
+
source_code_uri: https://github.com/deanpcmad/uploadfuse
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.6.0
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Ruby library for interacting with the UploadFuse API
|
104
|
+
test_files: []
|