-
Notifications
You must be signed in to change notification settings - Fork 105
Api search support #99
Conversation
14add6b
to
0233427
Compare
lib/tracker_api/client.rb
Outdated
@@ -113,7 +116,7 @@ def paginate(path, options = {}, &block) | |||
if block_given? | |||
yield(data, @last_response) | |||
else | |||
data.concat(@last_response.body) if @last_response.body.is_a?(Array) | |||
data.concat(@last_response.body) if @last_response.body.is_a?(Array) || @last_response.body.is_a?(Hash) | |||
end | |||
end | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like #paginate
is only ever expecting Arrays. I didn't dig in on the repercussions of also allowing Hashes; tests pass.
lib/tracker_api/endpoints/search.rb
Outdated
@client = client | ||
end | ||
|
||
def get(project_id, query, params={}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Add method documentation. This shouldn't be too verbose. Pivotal Tracker allows just about anything.
@@ -0,0 +1,12 @@ | |||
module TrackerApi | |||
module Resources | |||
class SearchResultContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question 1: Notice this is including the Shared::Base
. These resources don't require IDs though, so are there any changes to be made to the top level Base? It seems strange to have Resources without IDs. Am I missing anything?
Observation: I didn't make this a Shared
resource since there isn't any attributes that are shared between a top-level SearchResultContainer
or EpicsSearchResult
or StoriesSearchResult
, and this allows endpoints to be made specifically for epic or story search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably makes sense to move the attribute :id
and Equalizer
code into its own subclass of Base so classes that don't need an id
don't have to have one. I think it is fine to leave for now since it doesn't hurt anything and I am working on a major refactor that will change much of this anyway. So not worth the effort now.
lib/tracker_api/endpoints/search.rb
Outdated
raise ArgumentError, 'Valid query required to search' unless query.is_a?(String) | ||
|
||
params.key?(:body) ? params[:body][:query] = query : params[:body] = { query: query } | ||
data = client.paginate("/projects/#{project_id}/search", params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Tracker API docs do not explicitly state the search endpoint is paginated like they do with the stories endpoint. My guess is that the search endpoint is not paginated so you might be able to use a single get
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you're right. I missed that from the docs. Thanks!
lib/tracker_api/endpoints/search.rb
Outdated
|
||
raise Errors::UnexpectedData, 'Hash of search results expect' unless data.is_a? Hash | ||
|
||
create_search_results(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Virtus does all the conversion for you so you might be able to return Resources::SearchResultContainer.new(data)
here.
class EpicsSearchResult | ||
include Shared::Base | ||
|
||
attribute :epics, Array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you specify the type of object in the array Virtus will coerce them for you. attribute :epics, Array[Resources::Epic]
- The search endpoint is not paginated, so use a standard `GET` instead of attempting to send paginated params. - Virtus will coerce responses into specified Resources if the resource is specified in the attribute. This greatly improves readability of `#search` and more clearly documents what we expect to receive from a search request.
2 similar comments
@@ -0,0 +1,12 @@ | |||
module TrackerApi | |||
module Resources | |||
class SearchResultContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably makes sense to move the attribute :id
and Equalizer
code into its own subclass of Base so classes that don't need an id
don't have to have one. I think it is fine to leave for now since it doesn't hurt anything and I am working on a major refactor that will change much of this anyway. So not worth the effort now.
test/minitest_helper.rb
Outdated
@@ -28,7 +28,8 @@ | |||
PT_USER_1 = { username: 'trackerapi1', password: 'trackerapi1', token: 'd55c3bc1f74346b843ca84ba340b29bf', project_id: 1027488, workspace_id: 375106, id: 1266314 } | |||
PT_USER_2 = { username: 'trackerapi2', password: 'trackerapi2', token: 'ab4c5895f57995bb7547986eacf91160', project_ids: [1027488, 1027492], workspace_id: 581707, id: 1266316 } | |||
PT_USER_3 = { username: 'trackerapi3', password: 'trackerapi3', token: '77f9b9a466c436e6456939208c84c973', project_id: 1027494 } | |||
PT_USERS = [PT_USER_1, PT_USER_2, PT_USER_3] | |||
PT_USER_4 = { username: 'trackerapi4', password: 'trackerapi4', token: 'b764325e019df5c28896d1aa2fe27225', project_id: 1991595 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create another tracker account? Can you just use one of the existing ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably makes more sense to use one of the existing users, but when I started writing the test I wanted to search for something in our company's sandbox account so I could see the search coming back with stuff I expected. That said, it would probably work just fine using a search term with one of the other tokens provided that token is still valid and the search term matches something in a project dependant on that token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use any of the 3 accounts. Create a few stories in the account and then search for them. Should be fine.
Initial thoughts on wrapping Pivotal Tracker's
/search
endpoint in this gem.