Sha256: 108fc135330d88a80b179393e6bfa0295ed7ffb4149717ec6f2cb3c9208445a4
Contents?: true
Size: 1.94 KB
Versions: 18
Compression:
Stored size: 1.94 KB
Contents
require_relative 'api/resource_collection' require_relative 'account' class ContextIO # 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](http://context.io/docs/2.0/accounts#get) for # more explanation of what each key means. # # @example You can iterate over them with `each`: # contextio.accounts.each do |accounts| # puts account.email_addresses # end # # @example You can lazily access a specific one with square brackets: # account = contextio.accounts['some id'] # # @example Lazily limit based on a hash of criteria with `where`: # disabled_accounts = contextio.accounts.where(status: 'DISABLED') class AccountCollection include ContextIO::API::ResourceCollection self.resource_class = ContextIO::Account self.association_name = :accounts # Creates a new email account for your Context.IO account. # # @param [Hash{String, Symbol => String}] options 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. # # @return [Account] A new email account instance based on the data you # input. 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 end end
Version data entries
18 entries across 18 versions & 1 rubygems