lib/createsend/segment.rb in createsend-2.5.1 vs lib/createsend/segment.rb in createsend-3.0.0
- old
+ new
@@ -1,40 +1,39 @@
-require 'createsend'
-require 'json'
-
module CreateSend
# Represents a subscriber list segment and associated functionality.
- class Segment
+ class Segment < CreateSend
attr_reader :segment_id
- def initialize(segment_id)
+ def initialize(auth, segment_id)
@segment_id = segment_id
+ super
end
# Creates a new segment.
- def self.create(list_id, title, rules)
+ def self.create(auth, list_id, title, rules)
options = { :body => {
:Title => title,
:Rules => rules }.to_json }
- response = CreateSend.post "/segments/#{list_id}.json", options
+ cs = CreateSend.new auth
+ response = cs.post "/segments/#{list_id}.json", options
response.parsed_response
end
# Updates this segment.
def update(title, rules)
options = { :body => {
:Title => title,
:Rules => rules }.to_json }
- response = CreateSend.put "/segments/#{segment_id}.json", options
+ response = cs_put "/segments/#{segment_id}.json", options
end
# Adds a rule to this segment.
def add_rule(subject, clauses)
options = { :body => {
:Subject => subject,
:Clauses => clauses }.to_json }
- response = CreateSend.post "/segments/#{segment_id}/rules.json", options
+ response = post "rules", options
end
# Gets the active subscribers in this segment.
def subscribers(date="", page=1, page_size=1000, order_field="email",
order_direction="asc")
@@ -48,35 +47,35 @@
Hashie::Mash.new(response)
end
# Gets the details of this segment
def details
- response = CreateSend.get "/segments/#{segment_id}.json", {}
+ response = cs_get "/segments/#{segment_id}.json", {}
Hashie::Mash.new(response)
end
# Clears all rules of this segment.
def clear_rules
- response = CreateSend.delete "/segments/#{segment_id}/rules.json", {}
+ response = cs_delete "/segments/#{segment_id}/rules.json", {}
end
# Deletes this segment.
def delete
- response = CreateSend.delete "/segments/#{segment_id}.json", {}
+ response = super "/segments/#{segment_id}.json", {}
end
private
def get(action, options = {})
- CreateSend.get uri_for(action), options
+ super uri_for(action), options
end
def post(action, options = {})
- CreateSend.post uri_for(action), options
+ super uri_for(action), options
end
def put(action, options = {})
- CreateSend.put uri_for(action), options
+ super uri_for(action), options
end
def uri_for(action)
"/segments/#{segment_id}/#{action}.json"
end
\ No newline at end of file