001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2014 Richard "Shred" Körber 005 * http://flattr4j.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 */ 019package org.shredzone.flattr4j.model; 020 021import org.shredzone.flattr4j.connector.FlattrObject; 022 023/** 024 * A miniature representation of a {@link Thing}. 025 * <p> 026 * This class is not threadsafe. 027 * 028 * @author Richard "Shred" Körber 029 * @since 2.9 030 */ 031public class MiniThing extends Resource implements ThingId { 032 private static final long serialVersionUID = 520173054571474737L; 033 034 public MiniThing(FlattrObject data) { 035 super(data); 036 } 037 038 /** 039 * Thing's unique id at Flattr. 040 */ 041 @Override 042 public String getThingId() { 043 return String.valueOf(data.getInt("id")); 044 } 045 046 /** 047 * URL that returns details of this resource as JSON. 048 */ 049 public String getResource() { 050 return data.get("resource"); 051 } 052 053 /** 054 * Human readable link to this resource at Flattr. 055 */ 056 public String getLink() { 057 return data.get("link"); 058 } 059 060 /** 061 * How many times this Thing was flattred. 062 */ 063 public int getClicks() { 064 return data.getInt("flattrs"); 065 } 066 067 /** 068 * URL of the Thing. 069 */ 070 public String getUrl() { 071 return data.get("url"); 072 } 073 074 /** 075 * Title of the Thing. 076 */ 077 public String getTitle() { 078 return data.get("title"); 079 } 080 081 /** 082 * URL of an image for this Thing. Empty string if there is none. 083 */ 084 public String getImage() { 085 return (data.has("image") ? data.get("image") : ""); 086 } 087 088}