Sha256: a85f9f2b526e6eaa65ce807b6da6aa8afcaa1771ed524d240e7035b302f179ac

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 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|
        key = key.to_s.gsub('-', '_')

        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-2.0.0 lib/contextio/email_address.rb
contextio-1.8.1 lib/contextio/email_address.rb
contextio-1.8.0 lib/contextio/email_address.rb
contextio-1.7.2 lib/contextio/email_address.rb
contextio-1.7.1 lib/contextio/email_address.rb
contextio-1.7.0 lib/contextio/email_address.rb
contextio-1.6.0 lib/contextio/email_address.rb
contextio-1.5.0 lib/contextio/email_address.rb
contextio-1.4.0 lib/contextio/email_address.rb