Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: page parameter to cursor pagination fix #28

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -131,7 +131,7 @@ require "mailerlite-ruby"
# Intialize the class
subscribers = MailerLite::Subscribers.new

subscribers.update(email:'[email protected]', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')
subscribers.update('[email protected]', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')
```

### Get a subscriber
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mailerlite/groups/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/mailerlite/subscribers/subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mailerlite/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MailerLite
VERSION = '1.0.5'
VERSION = '1.0.6'
end
Loading