Skip to content

Commit

Permalink
Merge pull request #554 from zendesk/RED-1856-readme
Browse files Browse the repository at this point in the history
Doc improvement
  • Loading branch information
ecoologic authored Aug 21, 2023
2 parents 5d3b72a + 2ed1719 commit bdb733b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ zendesk_api_client_rb $ bundle console
`ZendeskAPI::Collections` can be paginated:

```ruby
# Note that CBP (cursor based pagination) is the default and preferred way
# and has fewer limitations on deep pagination
tickets = client.tickets.per_page(3)
page1 = tickets.fetch! # GET /api/v2/tickets?page[after]={cursor}&page[size]=3
page2 = tickets.next # GET /api/v2/tickets?page[after]={cursor}&page[size]=3
# ...

# OR...
# Note that OBP (offset based pagination) can incur to various limitations
tickets = client.tickets.page(2).per_page(3)

next_page = tickets.next # => 3
tickets.fetch! # GET /api/v2/tickets?page=3&per_page=3
previous_page = tickets.prev # => 2
Expand Down Expand Up @@ -221,7 +231,7 @@ ticket.attributes # => { "priority" => "urgent" }
ticket.save! # Will PUT => true
ticket.destroy! # => true

ZendeskAPI::Ticket.new(client, { :priority => "urgent" })
ZendeskAPI::Ticket.new(client, { priority: "urgent" })
ticket.new_record? # => true
ticket.save! # Will POST
```
Expand Down Expand Up @@ -455,7 +465,7 @@ bundle exec rubocop # Runs the lint (use `--fix` for autocorrect)

1. Fork the project.
2. Make your feature addition or bug fix.
3. Add tests for it. This is important so that we don't break it in a future
3. **Add tests for it**. This is important so that we don't break it in a future
version unintentionally.
4. Commit. Do not alter `Rakefile`, version, or history. (If you want to have
your own version, that is fine, but bump version in a commit by itself that
Expand All @@ -464,6 +474,17 @@ bundle exec rubocop # Runs the lint (use `--fix` for autocorrect)

**Note:** Live specs will likely fail for external contributors. The Zendesk devs can help with that. If you have permissions and some live specs unexpectedly fail, that might be a data error, see the REPL for that.

## Merging contributors pull requests

External contributions don't run live specs, so we need to use a workaround. Assuming a PR from `author:author/branch` to `default_branch`:

1. Create a branch in our repo `author_branch`
2. Change the destination branch of the PR to `author_branch`
3. Merge
4. Create a pr in our repo from `default_branch`
- Make sure they know the commits still carry their name
- [Example](https://github.com/zendesk/zendesk_api_client_rb/pull/553)

## Copyright and license

Copyright 2015-2023 Zendesk
Expand Down
6 changes: 3 additions & 3 deletions lib/zendesk_api/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def next
clear_cache
@options["page"] = @options["page"].to_i + 1
elsif (@query = @next_page)
# Send _only_ url param "?after=token" to get the next page
# Send _only_ url param "?page[after]=token" to get the next page
@options.page&.delete("before")
fetch(true)
else
Expand All @@ -243,7 +243,7 @@ def prev
clear_cache
@options["page"] -= 1
elsif (@query = @prev_page)
# Send _only_ url param "?before=token" to get the prev page
# Send _only_ url param "?page[before]=token" to get the prev page
@options.page&.delete("after")
fetch(true)
else
Expand Down Expand Up @@ -465,7 +465,7 @@ def array_method(name, *args, &block)
def next_collection(name, *args, &block)
opts = args.last.is_a?(Hash) ? args.last : {}
opts.merge!(collection_path: [*@collection_path, name], page: nil)
# why page: nil ?
# Why `page: nil`?
# when you do client.tickets.fetch followed by client.tickets.foos => the request to /tickets/foos will
# have the options page set to whatever the last options were for the tickets collection
self.class.new(@client, @resource_class, @options.merge(opts))
Expand Down

0 comments on commit bdb733b

Please sign in to comment.