1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.security.MessageDigest;
import java.math.BigInteger;

// signup for an APIKEY here: https://linkpeek.com/signup

class Api_v1 {
    /***LinkPeek.com API v1 helper class***/
    String APIKEY, SECRET;

    public Api_v1( String apikey, String secret ) {
        this.APIKEY = apikey;
        this.SECRET = secret;
    }
    
    public String make( String uri, String size ) throws Exception {
        String out, token;

        String message = this.SECRET + uri + size;

        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update( message.getBytes() );
        BigInteger hash = new BigInteger(1, md5.digest());
       
        token = hash.toString(16);

        out = "http://linkpeek.com/api/v1?uri="+uri+"&apikey="+this.APIKEY+"&token="+token+"&size="+size;

        return out;
    }
}

class TestApi_v1 {
    /** Test the API v1 **/
    public static void main(String[] args) throws Exception {
        Api_v1 api = new Api_v1( "your-key", "your-secret" );
        System.out.println( api.make( "lostquery.com", "336x336" ) );
        System.out.println( api.make( "lostquery.com", "400x200" ) );
        System.out.println( api.make( "http://lostquery.com", "200x400" ) );
    }
}