Sha256: 59a42a73e6a4a749177abffe34eb401320a0520def1c04bd989fb629a5827d6e

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

require 'contextio/api/association_helpers'

class ContextIO
  class EmailAddress
    def self.association_name
      :email_address
    end
    ContextIO::API::AssociationHelpers.register_resource(self, :email_address)

    # (see ContextIO#api)
    attr_reader :api, :account, :email, :validated, :primary
    private :validated, :primary
    #
    # @private
    #
    # For internal use only. Users of this gem shouldn't be calling this
    # directly.
    #
    # @param [API] api A handle on the Context.IO API.
    # @param [Hash{String, Symbol => String, Numeric, Boolean}] options A Hash
    #   of attributes describing the resource.
    def initialize(api, options = {})
      @api = api
      @account = options.delete(:account) || options.delete('account')

      options.each do |key, value|
        instance_variable_set("@#{key}", value)

        unless self.respond_to?(key)
          define_singleton_method(key) do
            instance_variable_get("@#{key}")
          end
        end
      end
    end

    def validated?
      !!validated
    end

    def primary?
      !!primary
    end

    def set_primary
      api.request(:post, resource_url, primary: 1)['success']
    end

    def delete
      api.request(:delete, resource_url)['success']
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
contextio-1.3.0 lib/contextio/email_address.rb
contextio-1.2.4 lib/contextio/email_address.rb
contextio-1.2.3 lib/contextio/email_address.rb
contextio-1.2.2 lib/contextio/email_address.rb
contextio-1.2.1 lib/contextio/email_address.rb
contextio-1.2.0 lib/contextio/email_address.rb
contextio-1.1.0 lib/contextio/email_address.rb
contextio-1.0.1 lib/contextio/email_address.rb
contextio-1.0.0 lib/contextio/email_address.rb