Class: MoxiworksPlatform::EmailCampaign

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers

Class Method Summary collapse

Methods inherited from Resource

accept_header, attr_accessor, attributes, #attributes, auth_header, check_for_error_in_response, content_type_header, #float_attrs, headers, #init_attrs_from_hash, #initialize, #method_missing, #numeric_attrs, #numeric_value_for, send_request, #to_hash, underscore, underscore_array, underscore_attribute_names, underscore_hash, user_agent_header

Constructor Details

This class inherits a constructor from MoxiworksPlatform::Resource

Dynamic Method Handling

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

Instance Attribute Details

#areaString

the area used for this EmailCampaign

This will likely be simply a zip code, but allow for arbitrary human readable

strings referencing geographical locations.

Returns:

  • (String)


45
46
47
# File 'lib/moxiworks_platform/email_campaign.rb', line 45

def area
  @area
end

#email_addressString

the email address that is configured for this email campaign

Returns:

  • (String)


30
31
32
# File 'lib/moxiworks_platform/email_campaign.rb', line 30

def email_address
  @email_address
end

#last_sentInteger

the Unix timestamp representing the date/time that the last email of this campaign was sent.

if no email has been sent for this campaign, the value will be 0

Returns:

  • (Integer)


53
# File 'lib/moxiworks_platform/email_campaign.rb', line 53

attr_writer :last_sent

#moxi_works_agent_idString

moxi_works_agent_id is the Moxi Works Platform ID of the agent which an ActionLog entry is or is to be associated with.

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    the Moxi Works Platform ID of the agent



10
11
12
# File 'lib/moxiworks_platform/email_campaign.rb', line 10

def moxi_works_agent_id
  @moxi_works_agent_id
end

#next_scheduledInteger

the Unix timestamp representing the date/time the next email of this campaign will be sent.

if no email is scheduled to be sent for this campaign, the value will be 0

Returns:

  • (Integer)


61
# File 'lib/moxiworks_platform/email_campaign.rb', line 61

attr_writer :next_scheduled

#partner_contact_idString

*your system's* unique ID for the Contact

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    your system's unique ID for the contact



18
19
20
# File 'lib/moxiworks_platform/email_campaign.rb', line 18

def partner_contact_id
  @partner_contact_id
end

#subscribed_atInteger

the Unix timestamp representing the date/time this campaign was created

Returns:

  • (Integer)


36
# File 'lib/moxiworks_platform/email_campaign.rb', line 36

attr_writer :subscribed_at

#subscription_typeString

the type of this EmailCampaign

Returns:

  • (String)


24
25
26
# File 'lib/moxiworks_platform/email_campaign.rb', line 24

def subscription_type
  @subscription_type
end

Class Method Details

.search(opts = {}) ⇒ Array

Search an Agent's Email Campaigns in Moxi Works Platform

Examples:

results = MoxiworksPlatform::EmailCampaign.search(
moxi_works_agent_id: '123abc',
partner_contact_id: 'mySystemsContactID'
  )

Parameters:

  • opts (Hash) (defaults to: {})

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this contact is associated

  • :partner_contact_id (String)

    REQUIRED Your system's unique ID for this contact.

Returns:

  • (Array)

    containing MoxiworkPlatform::EmailCampaign objects

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren't included



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/moxiworks_platform/email_campaign.rb', line 79

def self.search(opts={})
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  url ||= "#{MoxiworksPlatform::Config.url}/api/email_campaigns"
  required_opts = [:moxi_works_agent_id, :partner_contact_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  results = MoxiResponseArray.new()
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    results.headers = response.headers
    self.check_for_error_in_response(response)
    json = JSON.parse(response)

    results.page_number = 1
    results.total_pages = 1

    json.each do |r|
      results << MoxiworksPlatform::EmailCampaign.new(r) unless r.nil? or r.empty?
    end
  end
  results
end