Class: MailerLite::Segments
- Inherits:
-
Object
- Object
- MailerLite::Segments
- Defined in:
- lib/mailerlite/segments/segments.rb
Overview
This is a class for manipulating the Segments from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#delete(segment_id) ⇒ HTTP::Response
Deletes the specified Segments.
-
#get_subscribers(segment_id:, filter: {}, limit: nil, after: nil) ⇒ HTTP::Response
Get Subscribers assigned to the specified Segment.
-
#initialize(client: MailerLite::Client.new) ⇒ Segments
constructor
Inits the ‘Segments` class with the specified `client`.
-
#list(limit: nil, page: nil) ⇒ HTTP::Response
Returns a list of Segments that match the specified filter criteria.
-
#update(segment_id:, name:) ⇒ HTTP::Response
Update the specified Segment.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Segments
Inits the ‘Segments` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/segments/segments.rb', line 11 def initialize(client: MailerLite::Client.new) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailerlite/segments/segments.rb', line 6 def client @client end |
Instance Method Details
#delete(segment_id) ⇒ HTTP::Response
Deletes the specified Segments.
58 59 60 |
# File 'lib/mailerlite/segments/segments.rb', line 58 def delete(segment_id) client.http.delete("#{MAILERLITE_API_URL}/segments/#{segment_id}") end |
#get_subscribers(segment_id:, filter: {}, limit: nil, after: nil) ⇒ HTTP::Response
Get Subscribers assigned to the specified Segment.
44 45 46 47 48 49 50 51 52 |
# File 'lib/mailerlite/segments/segments.rb', line 44 def get_subscribers(segment_id:, filter: {}, limit: nil, after: nil) params = {} params['filter[status]'] = filter[:status] if filter.key?(:status) params['limit'] = limit if limit params['after'] = after if after uri = URI("#{MAILERLITE_API_URL}/segments/#{segment_id}/subscribers") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end |
#list(limit: nil, page: nil) ⇒ HTTP::Response
Returns a list of Segments that match the specified filter criteria.
20 21 22 23 24 25 26 |
# File 'lib/mailerlite/segments/segments.rb', line 20 def list(limit: nil, page: nil) params = {} params['limit'] = limit if limit params['page'] = page if page client.http.get("#{MAILERLITE_API_URL}/segments", json: params.compact) end |
#update(segment_id:, name:) ⇒ HTTP::Response
Update the specified Segment
33 34 35 36 |
# File 'lib/mailerlite/segments/segments.rb', line 33 def update(segment_id:, name:) params = { 'name' => name } client.http.put("#{MAILERLITE_API_URL}/segments/#{segment_id}", json: params.compact) end |