Skip to content

Commit f8e46d9

Browse files
committed
Merge remote-tracking branch 'origin' into fix/add_create_or_update_method_to_collection
2 parents c729415 + 73e5383 commit f8e46d9

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
strategy:
1515
matrix:
1616
ruby:
17-
- 2.5
1817
- 2.6
1918
- 2.7
2019
- 3.0
20+
- 3.1
2121
- jruby-9.1
2222
- jruby-9.2
2323
steps:

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Zendesk API Client
22

3-
![Test](https://github.com/zendesk/zendesk_api_client_rb/workflows/Test/badge.svg)
3+
[![Test](https://github.com/zendesk/zendesk_api_client_rb/workflows/Test/badge.svg)](https://github.com/zendesk/zendesk_api_client_rb/actions/workflows/main.yml?query=branch%3Amaster)
44
[![Gem Version](https://badge.fury.io/rb/zendesk_api.svg)](https://badge.fury.io/rb/zendesk_api)
55
[![Code Climate](https://codeclimate.com/github/zendesk/zendesk_api_client_rb.svg)](https://codeclimate.com/github/zendesk/zendesk_api_client_rb)
66

@@ -227,6 +227,7 @@ To facilitate a smaller number of requests and easier manipulation of associated
227227
For example:
228228
A `ZendeskAPI::Ticket` is associated with `ZendeskAPI::User` through the `requester_id` field.
229229
API requests for that ticket return a structure similar to this:
230+
230231
```json
231232
"ticket": {
232233
"id": 1,
@@ -244,11 +245,9 @@ tickets = client.tickets.include(:users)
244245
# Or client.tickets(:include => :users)
245246
# Does *NOT* make a request to the server since it is already loaded
246247
tickets.first.requester # => #<ZendeskAPI::User id=...>
247-
```
248248

249-
OR
249+
# OR
250250

251-
```ruby
252251
ticket = client.tickets.find!(:id => 1, :include => :users)
253252
ticket.requester # => #<ZendeskAPI::User id=...>
254253
```
@@ -426,7 +425,17 @@ installation.destroy!
426425
ZendeskAPI::AppInstallation.destroy!(client, :id => 123)
427426
```
428427

429-
## Note on Patches/Pull Requests
428+
## Running the gem locally
429+
430+
See `.github/workflows/main.yml` to understand the CI process.
431+
432+
```
433+
bundle exec rake # Runs the tests
434+
bundle exec rubocop # Runs the lint (use `--fix` for autocorrect)
435+
```
436+
437+
## Contributing
438+
430439
1. Fork the project.
431440
2. Make your feature addition or bug fix.
432441
3. Add tests for it. This is important so that we don't break it in a future
@@ -438,7 +447,7 @@ ZendeskAPI::AppInstallation.destroy!(client, :id => 123)
438447

439448
## Copyright and license
440449

441-
Copyright 2015-2021 Zendesk
450+
Copyright 2015-2022 Zendesk
442451

443452
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
444453
You may obtain a copy of the License at

lib/zendesk_api/collection.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def fetch!(reload = false)
187187
end
188188
path_query_link = (@query || path)
189189
@response = get_response(path_query_link)
190-
190+
191191
if path_query_link == "search/export"
192192
handle_cursor_response(@response.body)
193193
else
@@ -318,28 +318,23 @@ def to_s
318318
end
319319
end
320320

321-
alias :to_str :to_s
322-
323321
def to_param
324322
map(&:to_param)
325323
end
326324

327-
def has_more_results?(response)
328-
return false unless response["meta"].present? && response["results"].present?
329-
330-
response["meta"]["has_more"] && response["results"].length > 0
325+
def more_results?(response)
326+
response["meta"].present? && response["results"].present?
331327
end
328+
alias_method :has_more_results?, :more_results? # For backward compatibility with 1.33.0 and 1.34.0
332329

333330
def get_response_body(link)
334-
response_body = @client.connection.send("get", link).body
335-
336-
response_body
331+
@client.connection.send("get", link).body
337332
end
338333

339334
def get_next_page_data(original_response_body)
340335
link = original_response_body["links"]["next"]
341336

342-
while link do
337+
while link
343338
response = get_response_body(link)
344339

345340
original_response_body["results"] = original_response_body["results"] + response["results"]
@@ -446,7 +441,7 @@ def handle_cursor_response(response_body)
446441
raise ZendeskAPI::Error::NetworkError, @response.env
447442
end
448443

449-
response_body = get_next_page_data(response_body) if has_more_results?(response_body)
444+
response_body = get_next_page_data(response_body) if more_results?(response_body)
450445

451446
body = response_body.dup
452447
results = body.delete(@resource_class.model_key) || body.delete("results")

spec/core/collection_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,18 @@ def to_proc
883883

884884
it "should not have more results" do
885885
stub_json_request(:get, %r{search/export\?query=hello}, json(:results => [],
886-
:meta => {has_more: false}))
886+
:meta => { has_more: false }))
887887

888888
subject.fetch
889889
response = subject.instance_variable_get(:@response).body
890+
expect(subject.more_results?(response)).to be(false)
890891
expect(subject.has_more_results?(response)).to be(false)
891892
end
892893

893894
it "should not have more pages data" do
894895
stub_json_request(:get, %r{search/export\?query=hello}, json(:results => [],
895-
:meta => {has_more: false},
896-
:links => {:next => nil}))
896+
:meta => { has_more: false },
897+
:links => { :next => nil }))
897898

898899
subject.fetch
899900
response = subject.instance_variable_get(:@response).body

spec/core/search_export_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
require 'core/spec_helper'
22

33
describe ZendeskAPI::SearchExport do
4-
context ".new" do
4+
describe ".new" do
55
context "when given an existing class" do
6-
it "should return the correct class" do
7-
expect(ZendeskAPI::SearchExport.new(nil, { "result_type" => "user" })).to be_instance_of(ZendeskAPI::User)
6+
it "returns an instance of the specific class" do
7+
expect(ZendeskAPI::SearchExport.new(nil, "result_type" => "user")).to be_instance_of(ZendeskAPI::User)
88
end
99
end
1010

1111
context "when given a nonexistent class" do
12-
it "should return an object of the type Search::Result" do
13-
expect(ZendeskAPI::SearchExport.new(nil, { "result_type" => "blah" })).to be_instance_of(ZendeskAPI::SearchExport::Result)
12+
it "returns an instance of the generic Search::Result" do
13+
expect(ZendeskAPI::SearchExport.new(nil, "result_type" => "blah")).to be_instance_of(ZendeskAPI::SearchExport::Result)
1414
end
1515
end
1616

1717
context "when not given anything" do
18-
it "should return an object of the type Search::Result" do
18+
it "returns an instance of Search::Result by default" do
1919
expect(ZendeskAPI::SearchExport.new(nil, {})).to be_instance_of(ZendeskAPI::SearchExport::Result)
2020
end
2121
end

0 commit comments

Comments
 (0)