Skip to content

Commit

Permalink
Merge pull request #28 from mailerlite/fix/page-parameter-to-cursor-p…
Browse files Browse the repository at this point in the history
…agination

fix: page parameter to cursor pagination fix
  • Loading branch information
dinomh authored Dec 6, 2024
2 parents 975d55d + 55ad440 commit 48d59a7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
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

0 comments on commit 48d59a7

Please sign in to comment.