Class: StreamSend::Subscriber

Inherits:
Resource
  • Object
show all
Defined in:
lib/streamsend.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#attributes, #errors, #errors=, find, #id, #initialize, #method_missing, #new_record?, #save, #to_xml, to_xml

Constructor Details

This class inherits a constructor from StreamSend::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class StreamSend::Resource

Class Method Details

.all(audience_id) ⇒ Object



140
141
142
143
144
145
146
147
148
149
# File 'lib/streamsend.rb', line 140

def self.all(audience_id)
  response = StreamSend.get("/audiences/#{audience_id}/people.xml")

  case response.code
  when 200
    response["people"].collect { |data| new(data, true)}
  else
    raise "Could not find any subscribers. Make sure your audience ID is correct. (#{response.code})"
  end
end

.create(subscriber_hash) ⇒ Object



151
152
153
154
155
# File 'lib/streamsend.rb', line 151

def self.create(subscriber_hash)
  resource = new(subscriber_hash)
  resource.save
  resource
end

.find_by_email_address(email_address, options = {}) ⇒ Object



157
158
159
160
161
# File 'lib/streamsend.rb', line 157

def self.find_by_email_address(email_address, options={})
  audience_id = options["audience_id"] || 1
  result = find("audience_id" => audience_id, "email_address" => email_address )
  result == [] ? nil : result
end

.resource_nameObject



163
164
165
# File 'lib/streamsend.rb', line 163

def self.resource_name
  "person"
end

.resource_path(options = {}) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/streamsend.rb', line 167

def self.resource_path(options={})
  opts = options.dup
  audience_id = opts.delete("audience_id") || 1
  id = opts.delete('id')
  if id.nil?
    params = opts.collect {|k,v| "#{k}=#{v}" }
    "/audiences/#{audience_id}/people.xml?#{params.join('&')}"
  else
    "/audiences/#{audience_id}/people/#{id}.xml"
  end
end

Instance Method Details

#email_addressObject



128
129
130
# File 'lib/streamsend.rb', line 128

def email_address
  @data['email_address']
end

#email_address=(val) ⇒ Object



132
133
134
# File 'lib/streamsend.rb', line 132

def email_address=(val)
  @data['email_address'] = val
end

#to_sObject



136
137
138
# File 'lib/streamsend.rb', line 136

def to_s
  "#{self.email_address}#{%{ (#{self.email_content_format})} unless self.email_content_format.blank?}"
end