Class: CreateSend::Segment

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

Overview

Represents a subscriber list segment and associated functionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(segment_id) ⇒ Segment

Returns a new instance of Segment.



9
10
11
# File 'lib/createsend/segment.rb', line 9

def initialize(segment_id)
  @segment_id = segment_id
end

Instance Attribute Details

#segment_idObject (readonly)

Returns the value of attribute segment_id.



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

def segment_id
  @segment_id
end

Class Method Details

.create(list_id, title, rules) ⇒ Object

Creates a new segment.



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

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

Instance Method Details

#add_rule(subject, clauses) ⇒ Object

Adds a rule to this segment.



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

def add_rule(subject, clauses)
  options = { :body => {
    :Subject => subject,
    :Clauses => clauses }.to_json }
  response = CreateSend.post "/segments/#{segment_id}/rules.json", options
end

#clear_rulesObject

Clears all rules of this segment.



58
59
60
# File 'lib/createsend/segment.rb', line 58

def clear_rules
  response = CreateSend.delete "/segments/#{segment_id}/rules.json", {}
end

#deleteObject

Deletes this segment.



63
64
65
# File 'lib/createsend/segment.rb', line 63

def delete
  response = CreateSend.delete "/segments/#{segment_id}.json", {}
end

#detailsObject

Gets the details of this segment



52
53
54
55
# File 'lib/createsend/segment.rb', line 52

def details
  response = CreateSend.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.



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

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, rules) ⇒ Object

Updates this segment.



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

def update(title, rules)
  options = { :body => {
    :Title => title,
    :Rules => rules }.to_json }
  response = CreateSend.put "/segments/#{segment_id}.json", options
end