Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated API #6

Merged
merged 37 commits into from
Mar 4, 2016
Merged

Updated API #6

merged 37 commits into from
Mar 4, 2016

Conversation

xSAVIKx
Copy link
Contributor

@xSAVIKx xSAVIKx commented Feb 22, 2016

I've update java API, so now it's up-to-date with rubi API.
Added spock unit tests and one functional test stub.
moved project from ANT to Gradle.
introduced separate tasks to generate javaDocs and OneJar (with all needed dependencies).
moved project from custom XML-parser to general, easy-to-update JAXB solution.
added support for future error-handling and provided custom TwinglyException wrapper for any exception happened.

added initial gradle structure and renamed package.
added test dependencies to gradle build
added settings.gradle file
use JAXB instead of custom SAX parser
remove most parameters from Query fields and move them to methods as arguments.
add Language enum to provide all possible supported languages
removed not used anymore files
updated gradle build
added unit tests written with Spock to provide code coverage
added javadoc to each class
added gradle task to generate javadoc
generated javadoc
added exception handling support and changed all runtime exceptions to custom TwinglyException.
changed XML fetching to use custom User agent
remove javadoc folder from repo, cause it's easy to generate
update build.gradle with prettier task names and doc location property
update readme with up-to-date examples
@@ -0,0 +1,37 @@
package com.twingly.search;
Copy link
Contributor

Choose a reason for hiding this comment

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

How are these tests run, it seems like they need to be manually invoked now?

@walro
Copy link
Contributor

walro commented Feb 23, 2016

I like the enum for the languages in Language.java, but we add support for new languages from time to time. The changes proposed here forces a release of a new version, with the languages added to the enum. I think that we need to keep it a bit more open, perhaps the enum could be used as a helper, but you are still able to use arbitrary language codes.

@walro
Copy link
Contributor

walro commented Feb 23, 2016

I also think it might make sense the separate the client from the query as we have done in the Ruby case (split into two classes, Client and Query). Keep the network related code in the Client and the logics adhering to creating/formatting the query in the Query class. WDYT of that?

xSAVIKx and others added 6 commits February 23, 2016 16:23
now all processes related to making request is done inside client, so that query object is now responsible for Query creation and delegating other request stuff to client.
changed Language enum, so now it won't through exception, but will return null, if no language for ISO code was found.
changed functionality of Query creation, so that it could be created with custom language - now your should pass String object instead of Language enum instance to build query.
added access to execute gradlew
added ability to use create query object with properly set environment variable with Twingly API key.
added betamax dependencies to gradle build
added client javadoc
* The type Query.
*/
public class Query {
private static final String BASE_URL = "http://api.twingly.com";
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed it was changed from https to http in an earlier commit, what didn't work with https?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Betamax won't work with https right now, or maybe some changes to client should be done.
Actually, I've found that Betamax should work well on https with apache httpclient, but it's over 700kb without its own dependencies and I think you don't need it.)
Maybe with betamax update the situation will change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. I think we can live with large dependencies if that is what it takes to get https going. If it's just betamax, would it be possible to just pull those dependencies in for just the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately - no.
If we want to use betamax with https right now (actually, they are going to publish new beta in the beginning of march) - we need to use httpclient also to retrieve data from API.
(It's how I see it now.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, Betamax will use what the Twingly Search API client uses.

Exactly what are the problem with HTTPS and Betamax? Is it something with our SSL setup on the server-side?

Just looking at "IMPLEMENTATIONS" at http://betamax.software/ it sounds like it should work with both implementations they present.

Copy link
Contributor

Choose a reason for hiding this comment

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

@xSAVIKx but you only have the problem when using betamax? otherwise the client works fine with https, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dentarg Yeap, it's only related to Betamax usage.
Without betamax testing everything is working perfectly with URLConnection or Apache HTTP clients

Copy link
Contributor

Choose a reason for hiding this comment

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

To get things progressing, I think we'll have to live without Betamax for now. We need https support. Ruby tests using VCR may be implemented/ported using mocks or appropriate fixtures instead for the time being.

Also, I think the constants BASE_URL and SEARCH_PATH might be more suited in the Client class. Mostly due to that how we have split in other API clients, but I think it makes sense :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll also play today with mock-server, maybe it'll be more suitable for such tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! 👍

@dentarg
Copy link
Contributor

dentarg commented Feb 24, 2016

I played around with the gradle wrapper (I understand why this is the future over maven 😄) and when running the tests (gradlew check and gradlew test) I noticed there wasn't any output from the tests. Example of what output I refer to can be seen at https://travis-ci.org/twingly/twingly-search-api-ruby/jobs/109909967. That's one of the reason we like rspec (for Ruby) and behaviour testing. Is there any way to achieve that for the tests here? Perhaps the tests aren't running yet?

add tests logging
@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Feb 24, 2016

I'll play with gradle tests output.

adjusted test logging level
test {
testLogging.showStandardStreams = true
testLogging {
events "PASSED", "STARTED", "FAILED", "SKIPPED"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice with output but I think that STARTED is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@walro , IMO it has clearer view, when you see that it was started and, after that, the result, but if you want - I'll remove started event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be that I am more used to just seeing one line per test. We can always add STARTED back later on, if we change our minds.

xSAVIKx and others added 7 commits February 29, 2016 19:54
added +x permission to gradlew and gradlew.bat and removed chmod command from "before_install" section in travis config
added +x permission to gradlew and gradlew.bat and removed chmod command from "before_install" section in travis config
created 2 implementations for Client interface
updated spock tests due to new approach
changed twingly protocol from http to https
removed betamax from dependencies and repositories
update build.gradle for future easier publishing

update readme to be more correct

update clients javadoc
added xml results from ruby repo and tested them against new Java API
@twingly-mob
Copy link
Member

@xSAVIKx why is there support for two different HttpClients? ApacheHttpClient and UrlConnectionClient. It seems like the latter is the default client. It's less maintenance for us to just keep one around, that would also remove the need for the AbstractClient and possibly even the interface.

… refactorings

ensure that every file in repo ends with new line
remove obsolete LICENSE.txt file
update copyright date in readme
update readme with gradlew usage instead of gradle in examples
@dentarg
Copy link
Contributor

dentarg commented Mar 2, 2016

@xSAVIKx okay, thanks

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

@twingly-mob
They were created for test purposes, while I was testing betamax usage.
As for the clients: UrlConnectionClient is more simple, but have less possibilities to be configured.
And for the interface - it's always better to use interface than implementation for clearer usage and better test-possibilities.
If you want me to remove one of clients - OK, I'll do it.

@twingly-mob
Copy link
Member

The relationship between Client and Query objects seems a bit off. We think it would make more sense that the end-user explicitly instantiates the Client object and not the Query object. We do this in our other clients, for instance: https://github.com/twingly/twingly-search-api-python#usage and https://github.com/twingly/twingly-search-api-php#usage.

Also, the Query class holds the BASE_URL and SEARCH_PATH constants, those would make more sense in the Client or the Constants class.

@twingly-mob
Copy link
Member

And for the interface - it's always better to use interface than implementation for clearer usage and better test-possibilities.
If you want me to remove one of clients - OK, I'll do it

Yes, please remove one of them. It doesn't really matter that much which one - keep the one you like the most. :)

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

@twingly-mob
It's not good Java style to get Query from Client, while Query won't be used inside Client...

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

I'd suggest to make some QueryBuilder that will generate valid Query object and than use it with Client, like:

Client client = new Client();
Query query = QueryBuilder.create(apiKey).setLanguage(language).setStartTime(startTime).setEndTime(endTime).setSearchPattern(searchPattern).build();
Result result = client.makeRequest(query);

Or smth similar to that. It's kind of correct style.

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

There's no need, actually, to handle Client instance inside Query object, moreover, IMO, it's logically wrong to do so.

@twingly-mob
Copy link
Member

I'd suggest to make some QueryBuilder that will generate valid Query object and than use it with Client, like:

This was basically exactly what we just were discussing here. :) Our other clients should probably look a bit more like what you just proposed.

@twingly-mob
Copy link
Member

There's no need, actually, to handle Client instance inside Query object, moreover, IMO, it's logically wrong to do so.

Yeah, we added the execute method on the query for convenience, but as you said, it introduced two-way-coupling, the client needs to know about queries and vice-versa.

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

I agree, but, you know, it smells like CR, actually...
I'll change it, but, you know. it should be planned before implementation started.

@twingly-mob
Copy link
Member

I agree, but, you know, it smells like CR, actually...
I'll change it, but, you know. it should be planned before implementation started.

Agreed, we can discuss this on Upwork.

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented Mar 2, 2016

OK, lets do it.

xSAVIKx added 11 commits March 2, 2016 14:15
removed ApacheHttpClient and merged AbstractClient functionality with UrlConnectionClient.
merged tests from AbstractClientUnmarshallingSpockTest to urlConnectionClientSpockTest
 Extend exception with more speialized ones as:
 TwinglyException -> TwinglySearchException (just renamed)
 TwinglySearchServerException - super class for all server exceptions
 TwinglySearchServerAPIKeyDoesNotExistException - should be thrown when no API key was found
 TwinglySearchServerAPIKeyUnauthorizedException - should be thrown when API key is not authorized for any action
 TwinglySearchServerServiceUnavailableException - should be thrown when service is not available

 Refactor models, so that all models are now stored under domain package.
 Extended OperationResult with OperationResultType enum for easier usage.
updated example to fetch all possible results up to last publish date
added helper method "areAllResultsReturned" to Result class
added NPE check for languages in Query class
twingly-mob added a commit that referenced this pull request Mar 4, 2016
@twingly-mob twingly-mob merged commit bc6030c into twingly:master Mar 4, 2016
This was referenced Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants