Class: Qualtrics::Recipient

Inherits:
Entity
  • Object
show all
Defined in:
lib/qualtrics/recipient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#configuration, configuration, #get, get, #library_id, #library_id=, #persisted?, post, #post, #success?, underscore_attributes

Constructor Details

#initialize(options = {}) ⇒ Recipient

qualtrics_attribute :library_id, ‘LibraryID’



7
8
9
10
11
# File 'lib/qualtrics/recipient.rb', line 7

def initialize(options={})
  set_attributes(options)
  @panel_id = options[:panel_id]
  @id = options[:id]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def email
  @email
end

#embedded_dataObject

Returns the value of attribute embedded_data.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def embedded_data
  @embedded_data
end

#external_dataObject

Returns the value of attribute external_data.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def external_data
  @external_data
end

#first_nameObject

Returns the value of attribute first_name.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def id
  @id
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def language
  @language
end

#last_nameObject

Returns the value of attribute last_name.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def last_name
  @last_name
end

#panel_idObject

Returns the value of attribute panel_id.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def panel_id
  @panel_id
end

#unsubscribedObject

Returns the value of attribute unsubscribed.



3
4
5
# File 'lib/qualtrics/recipient.rb', line 3

def unsubscribed
  @unsubscribed
end

Class Method Details

.attribute_mapObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/qualtrics/recipient.rb', line 87

def self.attribute_map
  {
    'LibraryID'        => :library_id,
    'PanelID'          => :panel_id,
    'Email'            => :email,
    'FirstName'        => :first_name,
    'LastName'         => :last_name,
    'ExternalDataRef'  => :external_data,
    'Language'         => :language,
    'ED'               => :embedded_data,
    'Unsubscribed'     => :unsubscribed
  }
end

Instance Method Details

#attributesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/qualtrics/recipient.rb', line 23

def attributes
  {
      'LibraryID'        => library_id,
      'PanelID'          => panel_id,
      'Email'            => email,
      'FirstName'        => first_name,
      'LastName'         => last_name,
      'ExternalDataRef'  => external_data,
      'Language'         => language,
      'ED'               => embedded_data,
      'Unsubscribed'     => unsubscribed
  }.delete_if {|key, value| value.nil? }
end

#deleteObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/qualtrics/recipient.rb', line 73

def delete
  response = post('removeRecipient', {
      'LibraryID' => library_id,
      'RecipientID' => id,
      'PanelID' => panel_id
  })

  if response.success?
    true
  else
    false
  end
end

#info_hashObject



53
54
55
56
57
58
59
60
# File 'lib/qualtrics/recipient.rb', line 53

def info_hash
  response = get('getRecipient', {'LibraryID' => library_id, 'RecipientID' => id})
  if response.success? && !response.result['Recipient'].nil?
    response.result['Recipient']
  else
    false
  end
end

#panel=(panel) ⇒ Object



37
38
39
# File 'lib/qualtrics/recipient.rb', line 37

def panel=(panel)
  self.panel_id = panel.id
end

#response_historyObject



101
102
103
104
105
106
# File 'lib/qualtrics/recipient.rb', line 101

def response_history
  info_hash["RecipientResponseHistory"].map do |r|
    response = Hash[r.map{|k,v| [Qualtrics::Submission.attribute_map[k], v]}]
    Qualtrics::Submission.new(response)
  end
end

#saveObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/qualtrics/recipient.rb', line 41

def save
  return false if !valid?
  response = post('addRecipient', attributes)

  if response.success?
    self.id = response.result['RecipientID']
    true
  else
    false
  end
end

#set_attributes(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/qualtrics/recipient.rb', line 13

def set_attributes(options={})
  @email = options[:email]
  @first_name = options[:first_name]
  @last_name = options[:last_name]
  @language = options[:language]
  @external_data = options[:external_data]
  @embedded_data = options[:embedded_data]
  @unsubscribed = options[:unsubscribed]
end

#update(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/qualtrics/recipient.rb', line 62

def update(options={})
  set_attributes(options)
  response = post('updateRecipient', update_params)

  if response.success?
    true
  else
    false
  end
end