-
Notifications
You must be signed in to change notification settings - Fork 7
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
Updated API #6
Conversation
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; |
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.
How are these tests run, it seems like they need to be manually invoked now?
I like the enum for the languages in |
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? |
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"; |
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 noticed it was changed from https to http in an earlier commit, what didn't work with https?
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.
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.
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, 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?
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.
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.)
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 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.
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.
@xSAVIKx but you only have the problem when using betamax? otherwise the client works fine with https, correct?
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.
@dentarg Yeap, it's only related to Betamax usage.
Without betamax testing everything is working perfectly with URLConnection or Apache HTTP clients
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.
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 :)
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'll also play today with mock-server, maybe it'll be more suitable for such tests.
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.
Great! 👍
I played around with the gradle wrapper (I understand why this is the future over maven 😄) and when running the tests ( |
add tests logging
I'll play with gradle tests output. |
adjusted test logging level
test { | ||
testLogging.showStandardStreams = true | ||
testLogging { | ||
events "PASSED", "STARTED", "FAILED", "SKIPPED" |
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.
Nice with output but I think that STARTED is not needed
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.
@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.
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.
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.
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
@xSAVIKx why is there support for two different HttpClients? |
… 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
@xSAVIKx okay, thanks |
@twingly-mob |
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 |
Yes, please remove one of them. It doesn't really matter that much which one - keep the one you like the most. :) |
@twingly-mob |
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. |
There's no need, actually, to handle Client instance inside Query object, moreover, IMO, it's logically wrong to do so. |
This was basically exactly what we just were discussing here. :) Our other clients should probably look a bit more like what you just proposed. |
Yeah, we added the |
I agree, but, you know, it smells like CR, actually... |
Agreed, we can discuss this on Upwork. |
OK, lets do it. |
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.
…on for non-valid content types
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
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.