Class: MailerLite::Groups
- Inherits:
-
Object
- Object
- MailerLite::Groups
- Defined in:
- lib/mailerlite/groups/groups.rb
Overview
This is a class for manipulating the Groups from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#assign_subscriber(group_id:, subscriber:) ⇒ HTTP::Response
Assign Subscriber to the specified group.
-
#create(name:) ⇒ HTTP::Response
create a Group.
-
#delete(group_id) ⇒ HTTP::Response
Deletes the specified Groups.
-
#get(filter: {}, limit: nil, sort: nil, page: nil) ⇒ HTTP::Response
Returns a list of Groups that match the specified filter criteria.
-
#get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) ⇒ HTTP::Response
Get Subscribers assigned to the specified group.
-
#initialize(client: MailerLite::Client.new) ⇒ Groups
constructor
Inits the ‘Groups` class with the specified `client`.
-
#unassign_subscriber(group_id:, subscriber:) ⇒ HTTP::Response
Unassign Subscriber to the specified group.
-
#update(group_id:, name:) ⇒ HTTP::Response
Update the specified Group.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Groups
Inits the ‘Groups` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/groups/groups.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/groups/groups.rb', line 6 def client @client end |
Instance Method Details
#assign_subscriber(group_id:, subscriber:) ⇒ HTTP::Response
Assign Subscriber to the specified group.
70 71 72 |
# File 'lib/mailerlite/groups/groups.rb', line 70 def assign_subscriber(group_id:, subscriber:) client.http.post("#{MAILERLITE_API_URL}/subscribers/#{subscriber}/groups/#{group_id}") end |
#create(name:) ⇒ HTTP::Response
create a Group
36 37 38 39 |
# File 'lib/mailerlite/groups/groups.rb', line 36 def create(name:) params = { 'name' => name } client.http.post("#{MAILERLITE_API_URL}/groups", json: params.compact) end |
#delete(group_id) ⇒ HTTP::Response
Deletes the specified Groups.
86 87 88 |
# File 'lib/mailerlite/groups/groups.rb', line 86 def delete(group_id) client.http.delete("#{MAILERLITE_API_URL}/groups/#{group_id}") end |
#get(filter: {}, limit: nil, sort: nil, page: nil) ⇒ HTTP::Response
Returns a list of Groups that match the specified filter criteria.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mailerlite/groups/groups.rb', line 21 def get(filter: {}, limit: nil, sort: nil, page: nil) params = {} params['filter[name]'] = filter[:name] if filter.key?(:name) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page uri = URI("#{MAILERLITE_API_URL}/groups") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end |
#get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) ⇒ HTTP::Response
Get Subscribers assigned to the specified group.
57 58 59 60 61 62 63 64 |
# File 'lib/mailerlite/groups/groups.rb', line 57 def get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) params = {} params['filter[status]'] = filter[:status] if filter.key?(:status) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page client.http.get("#{MAILERLITE_API_URL}/groups/#{group_id}/subscribers", json: params.compact) end |
#unassign_subscriber(group_id:, subscriber:) ⇒ HTTP::Response
Unassign Subscriber to the specified group.
78 79 80 |
# File 'lib/mailerlite/groups/groups.rb', line 78 def unassign_subscriber(group_id:, subscriber:) client.http.delete("#{MAILERLITE_API_URL}/subscribers/#{subscriber}/groups/#{group_id}") end |
#update(group_id:, name:) ⇒ HTTP::Response
Update the specified Group
46 47 48 49 |
# File 'lib/mailerlite/groups/groups.rb', line 46 def update(group_id:, name:) params = { 'name' => name } client.http.put("#{MAILERLITE_API_URL}/groups/#{group_id}", json: params.compact) end |