001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2011 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.connector; 020 021import java.io.Serializable; 022import java.util.Date; 023 024/** 025 * Keeps the maximum rate of allowed calls and the remaining number of calls. 026 * <p> 027 * <em>Note:</em> The call limitation is posed by the Flattr API. This is not a limitation 028 * of flattr4j. 029 * 030 * @author Richard "Shred" Körber 031 */ 032public class RateLimit implements Serializable { 033 private static final long serialVersionUID = -4217480425094824497L; 034 035 private Long limit; 036 private Long remaining; 037 private Long current; 038 private Date reset; 039 040 public RateLimit() { 041 // default constructor 042 } 043 044 /** 045 * Copy constructor, creates a new {@link RateLimit} and copies the values of the 046 * given {@link RateLimit}. 047 * 048 * @param limit 049 * {@link RateLimit} to be copied 050 * @since 2.9 051 */ 052 public RateLimit(RateLimit limit) { 053 this.limit = limit.limit; 054 this.remaining = limit.remaining; 055 this.current = limit.current; 056 this.reset = limit.reset; 057 } 058 059 /** 060 * @since 2.5 061 */ 062 public RateLimit(FlattrObject data) { 063 setLimit(data.getLong("hourly_limit")); 064 setRemaining(data.getLong("remaining_hits")); 065 setCurrent(data.getLong("current_hits")); 066 setReset(data.getDate("reset_time_in_seconds")); 067 } 068 069 /** 070 * The maximum rate of allowed calls per time span. {@code null} if there is no such 071 * information available. 072 */ 073 public Long getLimit() { return limit; } 074 public void setLimit(Long limit) { this.limit = limit; } 075 076 /** 077 * The remaining rate of allowed calls per time span. {@code null} if there is no such 078 * information available. 079 */ 080 public Long getRemaining() { return remaining; } 081 public void setRemaining(Long remaining) { this.remaining = remaining; } 082 083 /** 084 * The number of calls made in the current time span. {@code null} if there is no such 085 * information available. 086 * 087 * @since 2.5 088 */ 089 public Long getCurrent() { return current; } 090 public void setCurrent(Long current) { this.current = current; } 091 092 /** 093 * The moment of the beginning of a new time span. {@code null} if there is no such 094 * information available. 095 * 096 * @since 2.5 097 */ 098 public Date getReset() { return reset; } 099 public void setReset(Date reset) { this.reset = reset; } 100 101}