Giter Site home page Giter Site logo

dentarg / twingly-search-api-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xsavikx/twingly-search-api-java

0.0 2.0 0.0 1.2 MB

:mag: Twingly Analytics API in Java

Home Page: https://developer.twingly.com/resources/search/

Java 69.67% Groovy 30.33%

twingly-search-api-java's Introduction

twingly-search-api-java Build Status

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.

Example usage

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);
        // Create Query object using QueryBuilder for results in English published from startTime to endTime
        Query query = QueryBuilder.create("spotify").documentLanguage(Language.English).startTime(startTime).endTime(endTime).build();
        Result result = client.makeRequest(query);
        // 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
        }
    }
}

A Query object can be reused for several requests.

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.

API key from Java system properties

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

Exception handling

Given exception hierarchy is now available:

  • TwinglySearchException - super class for any TwinglySearch-related exception
    • 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

Requirements

Development

Tests

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

JavaDoc generation

To generate java docs just run gradle task javadoc:

gradlew javadoc

This will save javadocs in docs folder under build-folder.

One-jar generation

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)

License

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.

twingly-search-api-java's People

Contributors

xsavikx avatar mrcz avatar twingly-mob avatar roback avatar jage avatar walro avatar dentarg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.