Sha256: f528cfca3f2d2a530793578a8b0213517da02e19b34d84f52ac17c49ef31990d

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

require_relative 'api/resource_collection'
require_relative 'source'

class ContextIO
  class SourceCollection
    include ContextIO::API::ResourceCollection

    self.resource_class = ContextIO::Source
    self.association_name = :sources

    belongs_to :account

    # Creates a new source for an account.
    #
    # @param [String] email The email address for the new source.
    # @param [String] server The address of the server for the source.
    # @param [String] username The name for logging into the server. Often the
    #   same as the email.
    # @param [Boolean] use_ssl Whether to use SSL for the new source.
    # @param [Numeric, String] port The port to connect on.
    # @param [String] type Currently, only 'IMAP' is supported.
    # @param [Hash{String, Symbol => String}] options Information you can
    #   provide at creation. Check out the Context.IO documentation for what's
    #   required and what's optional.
    def create(email, server, username, use_ssl, port, type, options={})
      api_args = options.merge(
        'email' => email,
        'server' => server,
        'username' => username,
        'use_ssl' => use_ssl ? '1' : '0',
        'port' => port.to_s,
        'type' => type
      )

      result_hash = api.request(:post, resource_url, api_args)

      result_hash.delete('success')

      resource_class.new(api, result_hash)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contextio-1.5.0 lib/contextio/source_collection.rb
contextio-1.4.0 lib/contextio/source_collection.rb
contextio-1.3.0 lib/contextio/source_collection.rb
contextio-1.2.4 lib/contextio/source_collection.rb
contextio-1.2.3 lib/contextio/source_collection.rb
contextio-1.2.2 lib/contextio/source_collection.rb