Sha256: 07945478dbea1a31f13cadda1439ead3c06433cc677952057da1153024bfa046

Contents?: true

Size: 667 Bytes

Versions: 2

Compression:

Stored size: 667 Bytes

Contents

# frozen_string_literal: true

require "freefeed/utils"
require "mimemagic"

module Freefeed
  module V1
    module Attachments
      # @param [String, Pathname, IO] source could by a file path
      # or an IO object
      def create_attachment(source)
        options = { form: { file: file(source) } }
        authenticated_request(:post, "/v1/attachments", options)
      end

      private

      def file(source)
        HTTP::FormData::File.new(source, content_type: content_type(source))
      end

      def content_type(source)
        return MimeMagic.by_magic(source) if source.is_a?(IO)
        MimeMagic.by_path(source.to_s)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
freefeed-0.5.1 lib/freefeed/v1/attachments.rb
freefeed-0.5.0 lib/freefeed/v1/attachments.rb