From fa4a8c0001a109997c937cc879c7d53ba1e21e73 Mon Sep 17 00:00:00 2001 From: Dino Date: Fri, 6 Dec 2024 15:09:55 +0100 Subject: [PATCH 1/2] fix: page parameter to cursor pagination fix --- CHANGELOG.md | 3 +++ README.md | 6 +++--- lib/mailerlite/groups/groups.rb | 4 ++-- lib/mailerlite/subscribers/subscribers.rb | 4 ++-- lib/mailerlite/version.rb | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b883cd..f29f375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.0.6] - 2024-12-06 +- Page parameter to cursor pagination fix + ## [1.0.5] - 2024-03-12 - Update constant name diff --git a/README.md b/README.md index bb15203..977851b 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ require "mailerlite-ruby" # Intialize the class subscribers = MailerLite::Subscribers.new -subscribers.fetch(filter: { status: 'active' }) +subscribers.fetch(filter: { status: 'active' }, cursor: 'cursor') ``` ### Create a subscriber @@ -227,10 +227,10 @@ groups.delete(group_id) ```ruby require "mailerlite-ruby" -# Intialize the class +# Initialize the class groups = MailerLite::Groups.new -groups.get_subscribers(group_id:1234567, page:1, limit:10, filter:{'status': 'active'}) +groups.get_subscribers(group_id: 1234567, cursor: 'cursor', limit: 10, filter: { 'status': 'active' }) ``` ### Assign subscriber to a group diff --git a/lib/mailerlite/groups/groups.rb b/lib/mailerlite/groups/groups.rb index bc86d07..65ba3d0 100644 --- a/lib/mailerlite/groups/groups.rb +++ b/lib/mailerlite/groups/groups.rb @@ -54,12 +54,12 @@ def update(group_id:, name:) # @param limit [Integer] the maximum number of subscribers to return # @param page [Integer] the page number of the results to return # @return [HTTP::Response] the response from the API - def get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil) + def get_subscribers(group_id:, filter: {}, limit: nil, cursor: 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 + params['cursor'] = cursor if cursor client.http.get("#{MAILERLITE_API_URL}/groups/#{group_id}/subscribers", json: params.compact) end diff --git a/lib/mailerlite/subscribers/subscribers.rb b/lib/mailerlite/subscribers/subscribers.rb index 239b187..535e747 100644 --- a/lib/mailerlite/subscribers/subscribers.rb +++ b/lib/mailerlite/subscribers/subscribers.rb @@ -18,11 +18,11 @@ def initialize(client: MailerLite::Client.new) # @param limit [Integer] the maximum number of subscribers to return # @param page [Integer] the page number of the results to return # @return [HTTP::Response] the response from the API - def fetch(filter:, limit: nil, page: nil) + def fetch(filter:, limit: nil, cursor: nil) params = { 'filter[status]' => filter[:status] } params['limit'] = limit if limit - params['page'] = page if page + params['cursor'] = cursor if cursor uri = URI("#{MAILERLITE_API_URL}/subscribers") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) diff --git a/lib/mailerlite/version.rb b/lib/mailerlite/version.rb index 462b77c..9bf81de 100644 --- a/lib/mailerlite/version.rb +++ b/lib/mailerlite/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MailerLite - VERSION = '1.0.5' + VERSION = '1.0.6' end From 55ad44027e0f278dba62a6c683318f168491097a Mon Sep 17 00:00:00 2001 From: Dino Date: Fri, 6 Dec 2024 15:19:56 +0100 Subject: [PATCH 2/2] feat: readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 977851b..c8c3da9 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ require "mailerlite-ruby" # Intialize the class subscribers = MailerLite::Subscribers.new -subscribers.update(email:'some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4') +subscribers.update('some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4') ``` ### Get a subscriber