Sha256: ca72e3b9bac59e69f86f42984022d2d4a98be60bbf7d814ee7c0c0513fe67950

Contents?: true

Size: 1.21 KB

Versions: 18

Compression:

Stored size: 1.21 KB

Contents

require_relative 'api/resource_collection'
require_relative 'message'

class ContextIO
  class MessageCollection
    include ContextIO::API::ResourceCollection

    self.resource_class = ContextIO::Message
    self.association_name = :messages

    belongs_to :account

    # You can pass a Folder object and this'll use the source from it, or you
    # can pass a folder label and a source label (from the API), if that's
    # easier for you.
    #
    # This is private because AFAICT, the oauth gem doesn't do POST requests
    # with Content-Type = 'multipart/form-data' easily. I think it might behoove
    # us to replace that dependency in the future, anyway, and we can fix this
    # at that point. In any case, this functionality was missing from previous
    # releases of the contextio gem, too.
    def create(raw_message, folder, source = nil)
      if folder.is_a?(ContextIO::Folder)
        folder_label = folder.name
        source_label = source || folder.source.label
      else
        folder_label = folder.to_s
        source_label = source.to_s
      end

      api.request(:post, resource_url, message: raw_message, dst_folder: folder_label, dst_source: source_label)['success']
    end
    private :create
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contextio-2.0.0 lib/contextio/message_collection.rb
contextio-1.8.1 lib/contextio/message_collection.rb
contextio-1.8.0 lib/contextio/message_collection.rb
contextio-1.7.2 lib/contextio/message_collection.rb
contextio-1.7.1 lib/contextio/message_collection.rb
contextio-1.7.0 lib/contextio/message_collection.rb
contextio-1.6.0 lib/contextio/message_collection.rb
contextio-1.5.0 lib/contextio/message_collection.rb
contextio-1.4.0 lib/contextio/message_collection.rb
contextio-1.3.0 lib/contextio/message_collection.rb
contextio-1.2.4 lib/contextio/message_collection.rb
contextio-1.2.3 lib/contextio/message_collection.rb
contextio-1.2.2 lib/contextio/message_collection.rb
contextio-1.2.1 lib/contextio/message_collection.rb
contextio-1.2.0 lib/contextio/message_collection.rb
contextio-1.1.0 lib/contextio/message_collection.rb
contextio-1.0.1 lib/contextio/message_collection.rb
contextio-1.0.0 lib/contextio/message_collection.rb