box_active_storage 0.1.0 → 0.1.2
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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e7237db7301f78334b69940318fdac234833f62ecef9865be3cea29b708451d
|
|
4
|
+
data.tar.gz: 05c86cfc1f14ca30b37a243450e011b032997cdeb5da5f871e2ad4f8b801318a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 690f942551e8d42be2afc340a6b3d50c1bf2b6f81b2b79be3465d1863cdaf224b5e8de1228049bf745adb7173c37dba03da912f56a6b264281db6175944b1d15
|
|
7
|
+
data.tar.gz: 286aab942b97fd6b5fcd2cfcaaecfbe7f6cc3e6c018c15bb10ed65e830b68f31409521ef50d251b199d257882da34528630db0bf4daedd4be8cd4fd2f770da6e
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module BoxActiveStorage
|
|
2
|
+
class FileSharedLink
|
|
3
|
+
class ClientError < StandardError; end
|
|
4
|
+
class UnauthorizedError < StandardError; end
|
|
5
|
+
class ForbiddenError < StandardError; end
|
|
6
|
+
class NotFoundError < StandardError; end
|
|
7
|
+
class InvalidFormatError < StandardError; end
|
|
8
|
+
class EtagNotMatchingError < StandardError; end
|
|
9
|
+
|
|
10
|
+
def get(token:, id:)
|
|
11
|
+
response = ::HTTParty.get("https://api.box.com/2.0/files/#{id}?fields=shared_link",
|
|
12
|
+
headers: { 'Authorization': token },
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
if response.code != 200
|
|
16
|
+
raise UnauthorizedError.new(response.body) if response.code == 401
|
|
17
|
+
raise NotFoundError.new(response.body) if response.code == 404
|
|
18
|
+
raise InvalidFormatError.new(response.body) if response.code == 405
|
|
19
|
+
raise StandardError.new(response.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
JSON.parse!(response.body)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add(token:, id:, attributes: { access: 'open' })
|
|
26
|
+
response = ::HTTParty.put("https://api.box.com/2.0/files/#{id}?fields=shared_link",
|
|
27
|
+
headers: { 'Authorization': token },
|
|
28
|
+
body: JSON.generate({ shared_link: attributes })
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if response.code != 200
|
|
32
|
+
raise ClientError.new(response.body) if response.code == 400
|
|
33
|
+
raise UnauthorizedError.new(response.body) if response.code == 401
|
|
34
|
+
raise ForbiddenError.new(response.body) if response.code == 403
|
|
35
|
+
raise NotFoundError.new(response.body) if response.code == 404
|
|
36
|
+
raise InvalidFormatError.new(response.body) if response.code == 405
|
|
37
|
+
raise EtagNotMatchingError.new(response.body) if response.code == 412
|
|
38
|
+
raise StandardError.new(response.body)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
JSON.parse!(response.body)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def remove(token:, id:)
|
|
45
|
+
response = ::HTTParty.put("https://api.box.com/2.0/files/#{id}?fields=shared_link",
|
|
46
|
+
headers: { 'Authorization': token },
|
|
47
|
+
body: JSON.generate({ shared_link: nil })
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if response.code != 200
|
|
51
|
+
raise ClientError.new(response.body) if response.code == 400
|
|
52
|
+
raise UnauthorizedError.new(response.body) if response.code == 401
|
|
53
|
+
raise ForbiddenError.new(response.body) if response.code == 403
|
|
54
|
+
raise NotFoundError.new(response.body) if response.code == 404
|
|
55
|
+
raise InvalidFormatError.new(response.body) if response.code == 405
|
|
56
|
+
raise EtagNotMatchingError.new(response.body) if response.code == 412
|
|
57
|
+
raise StandardError.new(response.body)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
JSON.parse!(response.body)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.get(...) = new.get(...)
|
|
64
|
+
def self.add(...) = new.add(...)
|
|
65
|
+
def self.update(...) = new.add(...)
|
|
66
|
+
def self.remove(...) = new.remove(...)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -5,9 +5,9 @@ class BoxActiveStorage::Folder
|
|
|
5
5
|
class UnrecognizedError < StandardError; end
|
|
6
6
|
class BlockedError < StandardError; end
|
|
7
7
|
|
|
8
|
-
def information(id:)
|
|
8
|
+
def information(token:, id:)
|
|
9
9
|
response = ::HTTParty.get("https://api.box.com/2.0/folders/#{id}",
|
|
10
|
-
headers: { 'Authorization':
|
|
10
|
+
headers: { 'Authorization': token },
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
if response.code != 200
|
|
@@ -20,9 +20,9 @@ class BoxActiveStorage::Folder
|
|
|
20
20
|
JSON.parse!(response.body)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def create(name:, parent: '0')
|
|
23
|
+
def create(token:, name:, parent: '0')
|
|
24
24
|
response = ::HTTParty.post("https://api.box.com/2.0/folders",
|
|
25
|
-
headers: { 'Authorization':
|
|
25
|
+
headers: { 'Authorization': token },
|
|
26
26
|
body: {
|
|
27
27
|
name: name,
|
|
28
28
|
parent: { id: parent }
|
|
@@ -40,14 +40,14 @@ class BoxActiveStorage::Folder
|
|
|
40
40
|
JSON.parse!(response.body)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def update(id:, name: nil, parent: nil)
|
|
43
|
+
def update(token:, id:, name: nil, parent: nil)
|
|
44
44
|
body = {}
|
|
45
45
|
|
|
46
46
|
body = body.merge({ name: name }) if name.present?
|
|
47
47
|
body = body.merge({ attributes: JSON.generate({ parent: { id: parent } }) }) if parent.present?
|
|
48
48
|
|
|
49
49
|
response = ::HTTParty.put("https://api.box.com/2.0/folders",
|
|
50
|
-
headers: { 'Authorization':
|
|
50
|
+
headers: { 'Authorization': token },
|
|
51
51
|
body: body
|
|
52
52
|
)
|
|
53
53
|
|
|
@@ -24,7 +24,7 @@ module BoxActiveStorage::Token
|
|
|
24
24
|
})
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
-
raise StandardError(response) unless response.code == 200
|
|
27
|
+
raise ::StandardError.new(response) unless response.code == 200
|
|
28
28
|
|
|
29
29
|
parsed_response = JSON.parse!(response.body)
|
|
30
30
|
refresh_in = Time.now + parsed_response['expires_in'].seconds
|
data/lib/box_active_storage.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'httparty'
|
|
4
|
+
|
|
3
5
|
require_relative "box_active_storage/file"
|
|
6
|
+
require_relative "box_active_storage/file_shared_link"
|
|
4
7
|
require_relative "box_active_storage/folder"
|
|
5
8
|
require_relative "box_active_storage/token"
|
|
6
9
|
require_relative "box_active_storage/version"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: box_active_storage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- JoelGamer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- lib/active_storage/service/box_service.rb
|
|
40
40
|
- lib/box_active_storage.rb
|
|
41
41
|
- lib/box_active_storage/file.rb
|
|
42
|
+
- lib/box_active_storage/file_shared_link.rb
|
|
42
43
|
- lib/box_active_storage/folder.rb
|
|
43
44
|
- lib/box_active_storage/token.rb
|
|
44
45
|
- lib/box_active_storage/version.rb
|