Class: VerticalResponse::API::Email

Inherits:
Resource show all
Defined in:
lib/verticalresponse/api/email.rb

Constant Summary collapse

MESSAGE_TYPE =
'email'

Instance Attribute Summary

Attributes inherited from Client

#access_token, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

class_for_resource, class_name, create, #delete, exclude_methods, find, #id, id_attribute_name, id_regexp, object_collection, resource_id_from_url, #stats, #update, #url, validate_supported_method!

Methods inherited from Client

add_default_query_param, assign_headers, base_service_uri, base_uri, base_uri_with_prefix, build_params, build_query_params, config, default_query_params, embed_resource, resource_uri, resource_uri_with_prefix, resource_uri_with_token

Constructor Details

#initialize(*args) ⇒ Email



35
36
37
38
# File 'lib/verticalresponse/api/email.rb', line 35

def initialize(*args)
  super
  @list_class = self.class.class_for_resource(List, id)
end

Class Method Details

.all(options = {}) ⇒ Object

The Email API does not support the ‘all’ method on its own for now. To get all emails we need to do it through the Message API



28
29
30
# File 'lib/verticalresponse/api/email.rb', line 28

def all(options = {})
  Message.all(options.merge({ :message_type => MESSAGE_TYPE }))
end

.resource_nameObject

Overwrite from parent class since it’s a special type of resource name (with messages at the beginning)



22
23
24
# File 'lib/verticalresponse/api/email.rb', line 22

def resource_name
  'messages/emails'
end

.resource_uri_suffixObject



16
17
18
# File 'lib/verticalresponse/api/email.rb', line 16

def resource_uri_suffix
  ['messages', 'emails']
end

Instance Method Details

#clicks_stats(options = {}) ⇒ Object



82
83
84
# File 'lib/verticalresponse/api/email.rb', line 82

def clicks_stats(options = {})
  detailed_stat(:clicks)
end

#launch(params = {}) ⇒ Object

Launches an email and return the response object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/verticalresponse/api/email.rb', line 53

def launch(params = {})
  # Supports receiving an array of List objects (Object Oriented)
  lists = params.delete(:lists)
  if lists
    params[:list_ids] ||= []
    params[:list_ids] += lists.map do |list|
      list.respond_to?(:id) ? list.id : list.to_i
    end
    # Remove duplicate IDs, if any
    params[:list_ids].uniq!
  end

  Response.new self.class.post(
    self.class.resource_uri(id),
    self.class.build_params(params)
  )
end

#lists(options = {}) ⇒ Object

Returns all the lists this email is targeted to



41
42
43
# File 'lib/verticalresponse/api/email.rb', line 41

def lists(options = {})
  @list_class.all(options)
end

#opens_stats(options = {}) ⇒ Object



78
79
80
# File 'lib/verticalresponse/api/email.rb', line 78

def opens_stats(options = {})
  detailed_stat(:opens)
end

#test_launch(params = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/verticalresponse/api/email.rb', line 45

def test_launch(params = {})
  Response.new self.class.post(
    self.class.resource_uri(id, 'test'),
    self.class.build_params(params)
  )
end

#unschedule(params = {}) ⇒ Object



71
72
73
74
75
76
# File 'lib/verticalresponse/api/email.rb', line 71

def unschedule(params = {})
  Response.new self.class.post(
    self.class.resource_uri(id, 'unschedule'),
    self.class.build_params(params)
  )
end

#unsubscribes_stats(options = {}) ⇒ Object



86
87
88
# File 'lib/verticalresponse/api/email.rb', line 86

def unsubscribes_stats(options = {})
  detailed_stat(:unsubscribes)
end