Class: BanalDropboxApi

Inherits:
Object
  • Object
show all
Defined in:
app/models/banal_dropbox_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBanalDropboxApi

Returns a new instance of BanalDropboxApi.



4
5
6
7
8
9
10
11
12
13
14
# File 'app/models/banal_dropbox_api.rb', line 4

def initialize
  self.oauth_token = Rails.application.credentials.banal_dropbox_oauth_token

  # After oauth_token initialilzation, because the oauth_token is required 
  # when enabling dynamicly fetched (via api) values for the folllowing to instance variables
  @team_folder_id = "6139129136" # hardcoded to banal team folder for now
  @team_member_id = "dbmid:AABXMhNAuNmdg79aaoHQwu9PuuZeJM7yjFU" # hardcoded to my team member id for now

  self.instantiate_client
  self.inject_middleware # Dropbox Business API feature: https://github.com/Jesus/dropbox_api/issues/29
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



2
3
4
# File 'app/models/banal_dropbox_api.rb', line 2

def client
  @client
end

#oauth_tokenObject

Returns the value of attribute oauth_token.



2
3
4
# File 'app/models/banal_dropbox_api.rb', line 2

def oauth_token
  @oauth_token
end

Instance Method Details

#combined_path(path) ⇒ Object



20
21
22
# File 'app/models/banal_dropbox_api.rb', line 20

def combined_path(path)
  team_folder_path + path
end

#download(path, &block) ⇒ Object

Doesn’t work, although it is expected to work by me www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings If you can get this to work, you’l get a cookie 🍪def get_link(path)

client.create_shared_link_with_settings(combined_path(path))['url']

end



31
32
33
# File 'app/models/banal_dropbox_api.rb', line 31

def download(path, &block)
  client.download(combined_path(path), &block)
end

#fresh_clientObject



57
58
59
# File 'app/models/banal_dropbox_api.rb', line 57

def fresh_client
  DropboxApi::Client.new(self.oauth_token)
end

#hacky__business_api_team_foldersObject



44
45
46
47
48
49
50
51
# File 'app/models/banal_dropbox_api.rb', line 44

def hacky__business_api_team_folders
  `
    curl -X POST https://api.dropboxapi.com/2/team/team_folder/list \
      --header "Authorization: Bearer #{self.oauth_token}" \
      --header "Content-Type: application/json" \
      --data "{\\"limit\\": 100}"
  `
end

#hacky__business_api_team_membersObject



35
36
37
38
39
40
41
42
# File 'app/models/banal_dropbox_api.rb', line 35

def hacky__business_api_team_members
  `
    curl -X POST https://api.dropboxapi.com/2/team/members/list \
      --header "Authorization: Bearer #{self.oauth_token}" \
      --header "Content-Type: application/json" \
      --data "{\\"limit\\": 100,\\"include_removed\\": false}"
  `
end

#inject_middleware(middleware_injactable = self.client, select = :admin, team_member_id = @team_member_id) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'app/models/banal_dropbox_api.rb', line 61

def inject_middleware(middleware_injactable = self.client, select = :admin, team_member_id = @team_member_id)
  middleware_injactable.middleware.append do |connection|
    case select
    when :admin
      connection.headers['Dropbox-API-Select-Admin'] = team_member_id
    when :user
      connection.headers['Dropbox-API-Select-User'] = team_member_id
    end
  end
end

#instantiate_clientObject



53
54
55
# File 'app/models/banal_dropbox_api.rb', line 53

def instantiate_client
  @client = self.fresh_client
end

#team_folder_pathObject



16
17
18
# File 'app/models/banal_dropbox_api.rb', line 16

def team_folder_path
  "ns:#{@team_folder_id}"
end