Sha256: 356f7acdc585e2f4808cff5e13a8a807d4333a513d1f2e8fe5d7a1bfcab23c19

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require 'emaildirect'
require 'json'

module EmailDirect
  # Represents a source and associated functionality
  class Source
    class << self
      def all
        response = EmailDirect.get '/Sources'
        Hashie::Mash.new(response)
      end

      def create(name, options = {})
        options.merge! :Name => name
        response = EmailDirect.post '/Sources', :body => options.to_json
        Hashie::Mash.new(response)
      end
    end

    attr_reader :source_id

    def initialize(source_id)
      @source_id = source_id
    end

    def details
      response = get
      Hashie::Mash.new(response)
    end

    def members(options = {})
      response = get 'Members', options
      Hashie::Mash.new(response)
    end

    def update(name, options)
      options.merge! :Name => name
      response = EmailDirect.put uri_for, :body => options.to_json
      Hashie::Mash.new(response)
    end

    def delete
      response = EmailDirect.delete uri_for, {}
      Hashie::Mash.new(response)
    end

    def add_emails(email_addresses)
      options = { :EmailAddresses => Array(email_addresses) }
      response = EmailDirect.post uri_for('AddEmails'), :body => options.to_json
      Hashie::Mash.new(response)
    end

    private

    def get(action = nil, options = {})
      EmailDirect.get uri_for(action), :query => options
    end

    def uri_for(action = nil)
      action = "/#{action}" if action
      "/Sources/#{source_id}#{action}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
emaildirect-2.0.0 lib/emaildirect/source.rb
emaildirect-1.3.4 lib/emaildirect/source.rb
emaildirect-1.3.3 lib/emaildirect/source.rb
emaildirect-1.3.2 lib/emaildirect/source.rb
emaildirect-1.3.1 lib/emaildirect/source.rb
emaildirect-1.3.0 lib/emaildirect/source.rb