Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Support search for more than 200 tickets #22

Merged
merged 4 commits into from
Oct 22, 2021
Merged

Conversation

RyanSheridan11
Copy link
Contributor

@RyanSheridan11 RyanSheridan11 commented Oct 14, 2021

Trying to fix up the search_tickets method so I can use it to search for a bunch of trade confirmation tickets to rerun.
It looks like theres about 700 or so tickets that I need to find in the search

@RyanSheridan11 RyanSheridan11 requested a review from alto October 14, 2021 23:33
@RyanSheridan11 RyanSheridan11 self-assigned this Oct 14, 2021
@RyanSheridan11 RyanSheridan11 force-pushed the search-tickets-max-results branch from 639031c to 62fca2f Compare October 15, 2021 00:03
lib/vimaly/client.rb Outdated Show resolved Hide resolved
@RyanSheridan11 RyanSheridan11 force-pushed the search-tickets-max-results branch from 62fca2f to 384d309 Compare October 17, 2021 21:44
The search_tickets function should now get up to 5000 tickets.
It does this by making multiple requests with pagination at the maximum
amount of 500 per request
lib/vimaly/client.rb Outdated Show resolved Hide resolved
Ticket.from_vimaly(search_response, ticket_type_map, bin_map, custom_fields)
end

break unless search_response # If reponse is nil then we know we've got all the data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a case statement for this, like this:

response_tickets = case search_response
  when Array
    ...
  when Hash
    
  else # or when NilClass
    break
end

Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
end
elsif search_response.instance_of? Hash # Will be a hash when only 1 ticket is returned. (most likely because max_results is 1)
Ticket.from_vimaly(search_response, ticket_type_map, bin_map, custom_fields)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could return [Ticket.from_vimaly(search_response, ticket_type_map, bin_map, custom_fields)] here, which allows you to not check for unless search_response.instance_of? Hash below.

break if response_tickets.size < max_results # Can finish search because we've returned all there is.
end

tickets << response_tickets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response_tickets is an Array and tickets is an Array, right? Then << doesn't do what you think it does (adding the content of one to the other), it adds the response_tickets as one item into tickets. You can do this instead:

ticket += response_tickets

@RyanSheridan11 RyanSheridan11 requested a review from alto October 22, 2021 01:03
Copy link
Member

@alto alto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No further complaints ❤️

@alto alto changed the title Try use a max amount of tickets to return. previous default was 200 Support search for more than 200 tickets Oct 22, 2021
@alto alto merged commit 4fcc6c3 into master Oct 22, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants