Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Conversation

masonnl
Copy link
Contributor

@masonnl masonnl commented Apr 5, 2017

Initial thoughts on wrapping Pivotal Tracker's /search endpoint in this gem.

@masonnl masonnl force-pushed the api-search-support branch from 14add6b to 0233427 Compare April 5, 2017 18:49
@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage decreased (-0.06%) to 96.474% when pulling 0233427 on masonnl:api-search-support into 032c0cf on dashofcode:master.

@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage decreased (-0.06%) to 96.474% when pulling 0233427 on masonnl:api-search-support into 032c0cf on dashofcode:master.

@@ -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
Copy link
Contributor Author

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.

@client = client
end

def get(project_id, query, params={})
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@masonnl masonnl mentioned this pull request Apr 5, 2017
2 tasks
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)

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.

Copy link
Contributor Author

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!


raise Errors::UnexpectedData, 'Hash of search results expect' unless data.is_a? Hash

create_search_results(data)

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

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.
@coveralls
Copy link

coveralls commented Apr 6, 2017

Coverage Status

Coverage decreased (-0.06%) to 96.474% when pulling 4cc37c0 on masonnl:api-search-support into 032c0cf on dashofcode:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 96.474% when pulling 4cc37c0 on masonnl:api-search-support into 032c0cf on dashofcode:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 96.474% when pulling 4cc37c0 on masonnl:api-search-support into 032c0cf on dashofcode:master.

@coveralls
Copy link

coveralls commented Apr 6, 2017

Coverage Status

Coverage decreased (-0.1%) to 96.404% when pulling 032000d on masonnl:api-search-support into 032c0cf on dashofcode:master.

@masonnl masonnl changed the title [WIP] Api search support Api search support Apr 6, 2017
@coveralls
Copy link

coveralls commented Apr 6, 2017

Coverage Status

Coverage increased (+0.1%) to 96.671% when pulling 50ec77f on masonnl:api-search-support into 032c0cf on dashofcode:master.

@coveralls
Copy link

coveralls commented Apr 6, 2017

Coverage Status

Coverage increased (+0.1%) to 96.671% when pulling 50ec77f on masonnl:api-search-support into 032c0cf on dashofcode:master.

@@ -0,0 +1,12 @@
module TrackerApi
module Resources
class SearchResultContainer
Copy link
Contributor

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.

@@ -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 }
Copy link
Contributor

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?

Copy link
Contributor Author

@masonnl masonnl Apr 8, 2017

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.

Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Apr 10, 2017

Coverage Status

Coverage increased (+0.1%) to 96.674% when pulling ed5f9e6 on masonnl:api-search-support into 032c0cf on dashofcode:master.

@forest forest merged commit 62caf2a into irphilli:master Apr 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants