Java client for Twingly Search API (previously known as Twingly Analytics API). Twingly is a blog search service that provides a searchable API known as Twingly Search API.
Get the latest release from Maven Central.
import com.twingly.search.*;
public class Test{
public static void main(String[] args){
String apiKey = "API_KEY";
// create Client object using your API key
Client client = new UrlConnectionClient(apiKey);
String q = "spotify";
Result result = client.makeRequest(q);
// Get the total number of matches returned
int numberOfMatchesReturned = result.getNumberOfMatchesReturned();
// Get the total number of matches to the search query
int numberOfMatchesTotal = result.getNumberOfMatchesTotal();
// Get number of seconds it took to execute query
double secondsElapsed = result.getSecondsElapsed();
for (Post p : result.getPosts()){
System.out.println(p.getUrl()); // print url for each post
System.out.println(p.getTitle()); // print title for each post
}
}
}
To learn more about the features of this client, check out the example code that can be found in example.
To learn more about the capabilities of the API, please read the Twingly Search API documentation.
Additionally, you can create Client object with API key from Java system properties (property name is TWINGLY_SEARCH_KEY
):
import com.twingly.search.client.*;
public class Test{
public static void main(String[] args){
Client client = new UrlConnectionClient(); // create client object with API key from java system property
}
}
To do so, you will need to run Java with property. For example, run your own jar
file with twingly search key property:
java -jar myJar.jar -DTWINGLY_SEARCH_KEY=some_key_value
Given exception hierarchy is now available:
Check Twingly Search API documentation for additional information about error codes.
Make sure you have all the dependencies
gradlew assemble
Run the tests
gradlew check
Generate coverage report, using JaCoCo. Note that you need to run the tests first.
gradlew jacocoTestReport
open build/jacocoHtml/index.html
To be able to run the Betamax-based tests you need to add Betamax's certificate into Java's trust store, cacerts
:
sudo keytool -importcert -keystore $JAVA_HOME/jre/lib/security/cacerts -file betamax.pem -alias betamax -storepass changeit -noprompt
It is adviced to remove the certificate after testing is done:
sudo keytool -delete -keystore $JAVA_HOME/jre/lib/security/cacerts -alias betamax -storepass changeit -noprompt
Note that the temporary files generated by Betamax:
need to be removed if generated before Betamax's certificate was added to the trust store, tests will fail otherwise.
For more information, check out Betamax's SSL configuration documentation.
To generate java docs just run gradle task javadoc
:
gradlew javadoc
This will save javadocs in docs
folder under build-folder.
To generate one fat jar library with all compile dependencies just run gradle task generateOneJar
:
gradlew generateOneJar
This will save JAR file with all needed dependencies in build/libs/
with -all
suffix. (like twingly-search-api-java-all-0.0.1.jar
)
~/.gradle/gradle.properties
(see the example)brew install gpg
gpg --import <path to key>
version.properties
gradlew uploadArchives -Prelease
to release to the staging repositorygem install github_changelog_generator
CHANGELOG_GITHUB_TOKEN
to a personal access token to increase your GitHub API rate limitgithub_changelog_generator
The MIT License (MIT)
Copyright (c) 2012-2016 Twingly AB
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.