diff --git a/lib/hubspot/connection.rb b/lib/hubspot/connection.rb index 7c87e2dc..e04093fc 100644 --- a/lib/hubspot/connection.rb +++ b/lib/hubspot/connection.rb @@ -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) diff --git a/lib/hubspot/file.rb b/lib/hubspot/file.rb index da68e248..9db6a42a 100644 --- a/lib/hubspot/file.rb +++ b/lib/hubspot/file.rb @@ -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 @@ -35,4 +46,4 @@ def destroy! end end -end +end \ No newline at end of file