Sha256: ef30a2699ce335a8642c6f21ee197afd2d35d18054b93c1e0eb1ce8d10e5d958

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

require 'createsend'
require 'json'

module CreateSend
  # Represents an administrator and associated functionality.
  class Administrator
    attr_reader :email_address

    def initialize(email_address)
      @email_address = email_address
    end

    # Gets an adminsitrator by email address.
    def self.get(email_address)
      options = { :query => { :email => email_address } }
      response = CreateSend.get "/admins.json", options
      Hashie::Mash.new(response)
    end

    # Adds an adminstrator to the account
    def self.add(email_address, name)
      options = { :body => {
        :EmailAddress => email_address,
        :Name => name
      }.to_json }
      response = CreateSend.post "/admins.json", options
      Hashie::Mash.new(response)
    end

    # Updates the administator details
    def update(new_email_address, name)
      options = {
        :query => { :email => @email_address },
        :body => {
          :EmailAddress => new_email_address,
          :Name => name
        }.to_json }
      CreateSend.put '/admins.json', options
      # Update @email_address, so this object can continue to be used reliably
      @email_address = new_email_address
    end

    # deletes this administrator from the account
    def delete
      options = { :query => { :email => @email_address } }
      CreateSend.delete '/admins.json', options
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
createsend-2.5.1 lib/createsend/administrator.rb
createsend-2.5.0 lib/createsend/administrator.rb
createsend-2.4.0 lib/createsend/administrator.rb
createsend-2.3.0 lib/createsend/administrator.rb
createsend-2.2.0 lib/createsend/administrator.rb
createsend-2.1.0 lib/createsend/administrator.rb
createsend-2.0.0 lib/createsend/administrator.rb