Sha256: 81cab2dc9013b029fe645330d234dadf9069027d21ed7d76fc4887ae05333605

Contents?: true

Size: 1.36 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
createsend-1.1.1 lib/createsend/administrator.rb
createsend-1.1.0 lib/createsend/administrator.rb