Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to look up and delete file from file manager #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/hubspot-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'hubspot/owner'
require 'hubspot/engagement'
require 'hubspot/subscription'
require 'hubspot/file'

module Hubspot
def self.configure(config={})
Expand Down
38 changes: 38 additions & 0 deletions lib/hubspot/file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'hubspot/utils'
require 'base64'
require 'pp'

module Hubspot
#
# HubSpot Files API
#
# {https://developers.hubspot.com/docs/methods/files/post_files}
#
class File
GET_FILE_PATH = "/filemanager/api/v2/files/:file_id"
DELETE_FILE_PATH = "/filemanager/api/v2/files/:file_id/full-delete"
LIST_FILE_PATH = "/filemanager/api/v2/files"

attr_reader :id
attr_reader :properties

def initialize(response_hash)
@id = response_hash["id"]
@properties = response_hash
end

class << self
def find_by_id(file_id)
response = Hubspot::Connection.get_json(GET_FILE_PATH, { file_id: file_id })
new(response)
end
end

# Permanently delete a file and all related data and thumbnails from file manager.
# {https://developers.hubspot.com/docs/methods/files/hard_delete_file_and_associated_objects}
def destroy!
Hubspot::Connection.post_json(DELETE_FILE_PATH, params: {file_id: id})
end

end
end
173 changes: 173 additions & 0 deletions spec/fixtures/vcr_cassettes/file_delete.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions spec/fixtures/vcr_cassettes/file_find.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading