Class: BrowseEverything::Driver::Box
- Defined in:
- lib/browse_everything/driver/box.rb
Overview
Driver for accessing the Box API (www.box.com/home)
Constant Summary collapse
- ITEM_LIMIT =
99999
Class Attribute Summary collapse
-
.authentication_klass ⇒ Object
Returns the value of attribute authentication_klass.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#auth_link(*_args) ⇒ String
Authorization url that is used to request the initial access code from Box.
- #authorized? ⇒ Boolean
-
#connect(params, _data, _url_options) ⇒ Hash
Gets the appropriate tokens from Box using the access code returned from :auth_link:.
-
#contents(id = '') ⇒ Array<BrowseEverything::FileEntry>
Retrieves the file entry objects for a given path to Box resource.
- #icon ⇒ Object
-
#initialize(config_values) ⇒ Box
constructor
Constructor.
- #link_for(id) ⇒ Array<String, Hash>
- #validate_config ⇒ Object
Methods inherited from Base
#config, default_sorter, inherited, #key, #name
Constructor Details
#initialize(config_values) ⇒ Box
Constructor
22 23 24 25 |
# File 'lib/browse_everything/driver/box.rb', line 22 def initialize(config_values) self.class.authentication_klass ||= self.class.default_authentication_klass super(config_values) end |
Class Attribute Details
.authentication_klass ⇒ Object
Returns the value of attribute authentication_klass.
13 14 15 |
# File 'lib/browse_everything/driver/box.rb', line 13 def authentication_klass @authentication_klass end |
Class Method Details
.default_authentication_klass ⇒ Object
15 16 17 |
# File 'lib/browse_everything/driver/box.rb', line 15 def default_authentication_klass RubyBox::Session end |
Instance Method Details
#auth_link(*_args) ⇒ String
Authorization url that is used to request the initial access code from Box
63 64 65 |
# File 'lib/browse_everything/driver/box.rb', line 63 def auth_link(*_args) box_session.(callback.to_s) end |
#authorized? ⇒ Boolean
68 69 70 |
# File 'lib/browse_everything/driver/box.rb', line 68 def box_token.present? && box_refresh_token.present? && !token_expired? end |
#connect(params, _data, _url_options) ⇒ Hash
Gets the appropriate tokens from Box using the access code returned from :auth_link:
74 75 76 |
# File 'lib/browse_everything/driver/box.rb', line 74 def connect(params, _data, ) register_access_token(box_session.get_access_token(params[:code])) end |
#contents(id = '') ⇒ Array<BrowseEverything::FileEntry>
Retrieves the file entry objects for a given path to Box resource
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/browse_everything/driver/box.rb', line 39 def contents(id = '') folder = id.empty? ? box_client.root_folder : box_client.folder_by_id(id) values = [] folder.items(ITEM_LIMIT, 0, %w[name size created_at]).collect do |f| values << directory_entry(f) end @entries = values.compact @sorter.call(@entries) end |
#icon ⇒ Object
27 28 29 |
# File 'lib/browse_everything/driver/box.rb', line 27 def icon 'cloud' end |
#link_for(id) ⇒ Array<String, Hash>
53 54 55 56 57 58 59 |
# File 'lib/browse_everything/driver/box.rb', line 53 def link_for(id) file = box_client.file_by_id(id) download_url = file.download_url auth_header = { 'Authorization' => "Bearer #{@token}" } extras = { auth_header: auth_header, expires: 1.hour.from_now, file_name: file.name, file_size: file.size.to_i } [download_url, extras] end |
#validate_config ⇒ Object
31 32 33 34 |
# File 'lib/browse_everything/driver/box.rb', line 31 def validate_config return if config[:client_id] && config[:client_secret] raise InitializationError, 'Box driver requires both :client_id and :client_secret argument' end |