Class: ContextIO::AccountCollection

Inherits:
Object
  • Object
show all
Includes:
ContextIO::API::ResourceCollection
Defined in:
lib/contextio/account_collection.rb

Overview

Represents a collection of email accounts for your Context.IO account. You can use this to add a new one to your account, iterate over them, or fetch a specific one.

You can also limit which accounts belongin the collection using the where method. Valid keys are: email, status, status_ok, limit and offset. See the Context.IO documentation for more explanation of what each key means.

Examples:

You can iterate over them with each:

contextio.accounts.each do |accounts|
  puts .email_addresses
end

You can lazily access a specific one with square brackets:

 = contextio.accounts['some id']

Lazily limit based on a hash of criteria with where:

disabled_accounts = contextio.accounts.where(status: 'DISABLED')

Instance Attribute Summary

Attributes included from ContextIO::API::ResourceCollection

#resource_url, #where_constraints

Instance Method Summary collapse

Methods included from ContextIO::API::ResourceCollection

#[], #each, #empty?, #size, #where

Instance Method Details

#create(options = {}) ⇒ Account

Creates a new email account for your Context.IO account.

Parameters:

  • options (Hash{String, Symbol => String}) (defaults to: {})

    Information you can provide at creation: email, first_name and/or last_name. If the collection isn't already limited by email, then you must provide it.

Returns:

  • (Account)

    A new email account instance based on the data you input.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/contextio/account_collection.rb', line 38

def create(options={})
  email = options.delete(:email) || options.delete('email') ||
    where_constraints[:email] || where_constraints['email']

  if email.nil?
    raise ArgumentError, "You must provide an email for new Accounts."
  end

  result_hash = api.request(
    :post,
    resource_url,
    options.merge(email: email)
  )

  result_hash.delete('success')

  resource_class.new(api, result_hash)
end