Class: CreateSend::Person

Inherits:
CreateSend show all
Defined in:
lib/createsend/person.rb

Overview

Represents a person and associated functionality.

Constant Summary

Constants included from CreateSend

USER_AGENT_STRING, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth, client_id, email_address) ⇒ Person

Returns a new instance of Person.



7
8
9
10
11
# File 'lib/createsend/person.rb', line 7

def initialize(auth, client_id, email_address)
  @client_id = client_id
  @email_address = email_address
  super
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



4
5
6
# File 'lib/createsend/person.rb', line 4

def client_id
  @client_id
end

#email_addressObject (readonly)

Returns the value of attribute email_address.



5
6
7
# File 'lib/createsend/person.rb', line 5

def email_address
  @email_address
end

Class Method Details

.add(auth, client_id, email_address, name, access_level, password) ⇒ Object

Adds a person to the client. Password is optional. If ommitted, an email invitation will be sent to the person



23
24
25
26
27
28
29
30
31
32
# File 'lib/createsend/person.rb', line 23

def self.add(auth, client_id, email_address, name, access_level, password)
  options = { :body => {
    :EmailAddress => email_address,
    :Name => name,
    :AccessLevel => access_level,
    :Password => password }.to_json }
  cs = CreateSend.new auth
  response = cs.post "/clients/#{client_id}/people.json", options
  Hashie::Mash.new(response)
end

.get(auth, client_id, email_address) ⇒ Object

Gets a person by client ID and email address.



14
15
16
17
18
19
# File 'lib/createsend/person.rb', line 14

def self.get(auth, client_id, email_address)
  options = { :query => { :email => email_address } }
  cs = CreateSend.new auth
  response = cs.get "/clients/#{client_id}/people.json", options
  Hashie::Mash.new(response)
end

Instance Method Details

#deleteObject

deletes this person from the client



50
51
52
53
# File 'lib/createsend/person.rb', line 50

def delete
  options = { :query => { :email => @email_address } }
  super uri_for(client_id), options
end

#update(new_email_address, name, access_level, password) ⇒ Object

Updates the person details. password is optional and will only be updated if supplied



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/createsend/person.rb', line 36

def update(new_email_address, name, access_level, password)
  options = {
    :query => { :email => @email_address },
    :body => {
      :EmailAddress => new_email_address,
      :Name => name,
      :AccessLevel => access_level,
      :Password => password }.to_json }
  put uri_for(client_id), options
  # Update @email_address, so this object can continue to be used reliably
  @email_address = new_email_address
end

#uri_for(client_id) ⇒ Object



55
56
57
# File 'lib/createsend/person.rb', line 55

def uri_for(client_id)
  "/clients/#{client_id}/people.json"
end