Skip to content
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
9 changes: 9 additions & 0 deletions lib/hubspot/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def post_json(path, opts)
no_parse ? response : response.parsed_response
end

def post_multipart(path, opts)
url = generate_url(path, opts[:params])
response = post(url, body: opts[:body], headers: { 'Content-Type' => '"multipart/form-data"' }, format: :multipart)
log_request_and_response url, response, opts[:body]
raise(Hubspot::RequestError.new(response)) unless response.success?

JSON.parse(response.body)
end

def put_json(path, opts)
url = generate_url(path, opts[:params])
response = put(url, body: opts[:body].to_json, headers: { 'Content-Type' => 'application/json' }, format: :json)
Expand Down
15 changes: 13 additions & 2 deletions lib/hubspot/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ def initialize(response_hash)
class << self
def find_by_id(file_id)
response = Hubspot::Connection.get_json(GET_FILE_PATH, { file_id: file_id })
new(response)
new(response)
end

# {https://developers.hubspot.com/docs/methods/files/post_files}
def create!(local_path, hubspot_folder_paths = '')
files = {'files': open(local_path)}
response = Hubspot::Connection.post_multipart(
LIST_FILE_PATH,
params: {},
body: { data: { "folder_paths": hubspot_folder_paths }, files: files }
)
new(response)
end
end

Expand All @@ -35,4 +46,4 @@ def destroy!
end

end
end
end