Class: CreateSend::Segment
- Inherits:
-
Object
- Object
- CreateSend::Segment
- Defined in:
- lib/createsend/segment.rb
Overview
Represents a subscriber list segment and associated functionality.
Instance Attribute Summary collapse
-
#segment_id ⇒ Object
readonly
Returns the value of attribute segment_id.
Class Method Summary collapse
-
.create(list_id, title, rules) ⇒ Object
Creates a new segment.
Instance Method Summary collapse
-
#add_rule(subject, clauses) ⇒ Object
Adds a rule to this segment.
-
#clear_rules ⇒ Object
Clears all rules of this segment.
-
#delete ⇒ Object
Deletes this segment.
-
#details ⇒ Object
Gets the details of this segment.
-
#initialize(segment_id) ⇒ Segment
constructor
A new instance of Segment.
-
#subscribers(date, page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the active subscribers in this segment.
-
#update(title, rules) ⇒ Object
Updates this segment.
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_id ⇒ Object (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) = { :body => { :Title => title, :Rules => rules }.to_json } response = CreateSend.post "/segments/#{list_id}.json", 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) = { :body => { :Subject => subject, :Clauses => clauses }.to_json } response = CreateSend.post "/segments/#{segment_id}/rules.json", end |
#clear_rules ⇒ Object
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 |
#delete ⇒ Object
Deletes this segment.
63 64 65 |
# File 'lib/createsend/segment.rb', line 63 def delete response = CreateSend.delete "/segments/#{segment_id}.json", {} end |
#details ⇒ Object
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") = { :query => { :date => date, :page => page, :pagesize => page_size, :orderfield => order_field, :orderdirection => order_direction } } response = get "active", 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) = { :body => { :Title => title, :Rules => rules }.to_json } response = CreateSend.put "/segments/#{segment_id}.json", end |