Class: ET::Subscriber

Inherits:
CUDSupport show all
Defined in:
lib/exact-target-api/subscriber.rb

Instance Attribute Summary collapse

Attributes inherited from GetSupport

#filter

Attributes inherited from BaseObject

#client, #endpoint, #lastRequestID, #obj, #props

Instance Method Summary collapse

Methods inherited from CUDSupport

#delete, #patch, #post

Methods inherited from GetSupport

#get, #getMoreResults, #info

Methods inherited from BaseObject

#stringify_keys!, #symbolize_keys!

Constructor Details

#initialize(client, list_id = nil) ⇒ Subscriber

Returns a new instance of Subscriber.



5
6
7
8
9
10
# File 'lib/exact-target-api/subscriber.rb', line 5

def initialize(client, list_id = nil)
  super()
  @client = client
  @list_id =  list_id
  @obj = 'Subscriber'
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/exact-target-api/subscriber.rb', line 3

def code
  @code
end

#emailObject (readonly)

Returns the value of attribute email.



3
4
5
# File 'lib/exact-target-api/subscriber.rb', line 3

def email
  @email
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/exact-target-api/subscriber.rb', line 3

def message
  @message
end

#resultsObject (readonly)

Returns the value of attribute results.



3
4
5
# File 'lib/exact-target-api/subscriber.rb', line 3

def results
  @results
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/exact-target-api/subscriber.rb', line 3

def status
  @status
end

Instance Method Details

#create(params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/exact-target-api/subscriber.rb', line 12

def create(params = {})
  stringify_keys!(params)

  email = params.delete('email')
  raise("Please provide email") if email.blank?

  list_id = if params['list']
    params.delete('list').id
  elsif params['list_id']
    params.delete('list_id')
  elsif @list_id
    @list_id
  end

  props = {'EmailAddress' => email}
  props['SubscriberKey'] = params.delete('SubscriberKey') if params['SubscriberKey']

  props['Lists'] =  [{'ID' => list_id.to_s}] if list_id

  if params.count > 0
     props['Attributes'] = params.map do |k, v|
      {'Name' => k.to_s, 'Value' => v}
    end
  end

  res = post(props)
  if assign_values(res)
    @email = email
    @list_id = list_id
  end

  self
end

#find(email) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/exact-target-api/subscriber.rb', line 46

def find(email)
  @email = email

  props = ["SubscriberKey", "EmailAddress", "Status"]
  filter = {'Property' => 'SubscriberKey', 'SimpleOperator' => 'equals', 'Value' => email}

  res = get(props, filter)
  if assign_values(res)
    @email = email
  end

  self
end

#update(params) ⇒ Object



60
61
62
63
64
65
# File 'lib/exact-target-api/subscriber.rb', line 60

def update(params)
  params.merge!('EmailAddress' => @email)

  # TODO ...

end