Class: CreateSend::Segment

Inherits:
CreateSend show all
Defined in:
lib/createsend/segment.rb

Overview

Represents a subscriber list segment and associated functionality.

Constant Summary

Constants included from CreateSend

USER_AGENT_STRING, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth, segment_id) ⇒ Segment

Returns a new instance of Segment.



6
7
8
9
# File 'lib/createsend/segment.rb', line 6

def initialize(auth, segment_id)
  @segment_id = segment_id
  super
end

Instance Attribute Details

#segment_idObject (readonly)

Returns the value of attribute segment_id.



4
5
6
# File 'lib/createsend/segment.rb', line 4

def segment_id
  @segment_id
end

Class Method Details

.create(auth, list_id, title, rule_groups) ⇒ Object

Creates a new segment.



12
13
14
15
16
17
18
19
# File 'lib/createsend/segment.rb', line 12

def self.create(auth, list_id, title, rule_groups)
  options = { :body => {
    :Title => title,
    :RuleGroups => rule_groups }.to_json }
  cs = CreateSend.new auth
  response = cs.post "/segments/#{list_id}.json", options
  response.parsed_response
end

Instance Method Details

#add_rule_group(rule_group) ⇒ Object

Adds a rule to this segment.



30
31
32
33
34
# File 'lib/createsend/segment.rb', line 30

def add_rule_group(rule_group)
  options = { :body => {
    :Rules => rule_group }.to_json }
  post "rules", options
end

#clear_rulesObject

Clears all rules of this segment.



56
57
58
# File 'lib/createsend/segment.rb', line 56

def clear_rules
  cs_delete "/segments/#{segment_id}/rules.json", {}
end

#deleteObject

Deletes this segment.



61
62
63
# File 'lib/createsend/segment.rb', line 61

def delete
  super "/segments/#{segment_id}.json", {}
end

#detailsObject

Gets the details of this segment



50
51
52
53
# File 'lib/createsend/segment.rb', line 50

def details
  response = cs_get "/segments/#{segment_id}.json", {}
  Hashie::Mash.new(response)
end

#subscribers(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the active subscribers in this segment.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/createsend/segment.rb', line 37

def subscribers(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "active", options
  Hashie::Mash.new(response)
end

#update(title, rule_groups) ⇒ Object

Updates this segment.



22
23
24
25
26
27
# File 'lib/createsend/segment.rb', line 22

def update(title, rule_groups)
  options = { :body => {
    :Title => title,
    :RuleGroups => rule_groups }.to_json }
  cs_put "/segments/#{segment_id}.json", options
end