box_active_storage 0.1.0 → 0.1.1

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: 56950dc6a327d09c817d1db342c167313140bdef613fb5d79ddeb2a30148ff43
4
- data.tar.gz: f93aebbe4a1fc38c920afa097551fbc4bf10533a471d4cba6421e0edec8c4f0b
3
+ metadata.gz: 85c07457d4573ee9f0e352cc216de2c43eaf4ec61447b4ce174c2b7d76b0d09e
4
+ data.tar.gz: 7375e1bd71e6e7d0d04f11666ac420fb7a2f88c51819b950b7026c1fdd5d3955
5
5
  SHA512:
6
- metadata.gz: 35a1eeee26b0d34ee6c18d5fdfd141b9ab28ce0551ae369a80d70b47524de9c88de633487b824b46f76bf75aabf61395585fddc9de51e217c81b75bd7742c9fd
7
- data.tar.gz: 4d7f6442c833b63d8a509d54cc8f7645f0e35846cc0b7e861eee7ef26655f4e25a4aa9e235a5a6a3437f1da4cb1626169dffa615b1008759649e11e1a65fa285
6
+ metadata.gz: 9291f0cf3d375af718d8fc21d72d411a5e32fe751d14acd9c163b569ab0ad3323d9526500937bc27ba8a1729dca629aa7c84ff92fd8d098a2a2efcead5d6f455
7
+ data.tar.gz: fb6e92cca8aaa85c13c3619e125212c7463a33fcdee474261f3853ef531738ae7a0606a632fbc52893cc12815d49ec7683d5caee6c19247e7fd7f9fb1702ae93
@@ -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': @token },
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': @token },
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': @token },
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BoxActiveStorage
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "box_active_storage/file"
4
+ require_relative "box_active_storage/file_shared_link"
4
5
  require_relative "box_active_storage/folder"
5
6
  require_relative "box_active_storage/token"
6
7
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JoelGamer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-30 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -35,10 +35,10 @@ files:
35
35
  - ".rubocop.yml"
36
36
  - README.md
37
37
  - Rakefile
38
- - box_active_storage.gemspec
39
38
  - lib/active_storage/service/box_service.rb
40
39
  - lib/box_active_storage.rb
41
40
  - lib/box_active_storage/file.rb
41
+ - lib/box_active_storage/file_shared_link.rb
42
42
  - lib/box_active_storage/folder.rb
43
43
  - lib/box_active_storage/token.rb
44
44
  - lib/box_active_storage/version.rb
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/box_active_storage/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "box_active_storage"
7
- spec.version = BoxActiveStorage::VERSION
8
- spec.authors = ["JoelGamer"]
9
- spec.email = ["gtheodoro@rescocompany.com"]
10
-
11
- spec.summary = "This Gem is for integrating Box.com with ActiveStorage."
12
- # spec.description = "TODO: Write a longer description or delete this line."
13
- spec.homepage = "https://github.com/RESCO-Company/box_active_storage"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/RESCO-Company/box_active_storage"
21
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
29
- end
30
- end
31
- spec.bindir = "exe"
32
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
34
-
35
- # Uncomment to register a new dependency of your gem
36
- spec.add_dependency "httparty", '~> 0.22'
37
-
38
- # For more information and examples about making a new gem, check out our
39
- # guide at: https://bundler.io/guides/creating_gem.html
40
- end