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; 020 021import java.util.Collection; 022import java.util.List; 023 024import org.shredzone.flattr4j.connector.RateLimit; 025import org.shredzone.flattr4j.exception.FlattrException; 026import org.shredzone.flattr4j.model.Activity; 027import org.shredzone.flattr4j.model.AutoSubmission; 028import org.shredzone.flattr4j.model.Category; 029import org.shredzone.flattr4j.model.Flattr; 030import org.shredzone.flattr4j.model.Language; 031import org.shredzone.flattr4j.model.MiniThing; 032import org.shredzone.flattr4j.model.SearchQuery; 033import org.shredzone.flattr4j.model.SearchResult; 034import org.shredzone.flattr4j.model.Submission; 035import org.shredzone.flattr4j.model.Subscription; 036import org.shredzone.flattr4j.model.Thing; 037import org.shredzone.flattr4j.model.ThingId; 038import org.shredzone.flattr4j.model.User; 039import org.shredzone.flattr4j.model.UserId; 040import org.shredzone.flattr4j.oauth.RequiredScope; 041import org.shredzone.flattr4j.oauth.Scope; 042 043/** 044 * Service calls to the Flattr REST API. 045 * <p> 046 * All calls will decrement the remaining rate by one, unless noted otherwise. 047 * 048 * @author Richard "Shred" Körber 049 */ 050public interface FlattrService { 051 052 /** 053 * Gets a {@link Thing} for the given {@link ThingId}. 054 * 055 * @param thingId 056 * {@link ThingId} of the Thing to be fetched 057 * @return {@link Thing} 058 */ 059 Thing getThing(ThingId thingId) throws FlattrException; 060 061 /** 062 * Gets a {@link Thing} by its registered URL. 063 * 064 * @param url 065 * Thing's URL 066 * @return {@link Thing} of the URL that was found, {@code null} if nothing was found 067 * @since 2.0 068 */ 069 Thing getThingByUrl(String url) throws FlattrException; 070 071 /** 072 * Gets a {@link Thing} by its autosubmit URL. 073 * <p> 074 * Uses two rates! 075 * 076 * @param submission 077 * {@link AutoSubmission} to check for 078 * @return {@link Thing} of the submission if found, {@code null} if nothing was found 079 * @since 2.0 080 */ 081 Thing getThingBySubmission(AutoSubmission submission) throws FlattrException; 082 083 /** 084 * Gets a list of {@link Thing} most recently submitted by the given user. This list 085 * is limited to 30 entries. 086 * 087 * @param user 088 * {@link UserId} to find the Things of 089 * @return List of {@link Thing} submitted by the user 090 * @since 2.0 091 */ 092 List<Thing> getThings(UserId user) throws FlattrException; 093 094 /** 095 * Gets a list of {@link Thing} most recently submitted by the given user. 096 * 097 * @param user 098 * {@link UserId} to find the Things of 099 * @param count 100 * Number of entries per page, {@code null} defaults to 30 entries 101 * @param page 102 * Page number (counted from 1), or {@code null} to turn off paging 103 * @return List of {@link Thing} submitted by the user 104 * @since 2.0 105 */ 106 List<Thing> getThings(UserId user, Integer count, Integer page) throws FlattrException; 107 108 /** 109 * Gets a list of {@link Thing} by a collection of thing IDs. 110 * 111 * @param thingIds 112 * Collection of {@link ThingId}. The order of {@link Thing} returned may 113 * not match the order of the provided IDs. 114 * @return List of {@link Thing} fetched 115 * @since 2.0 116 */ 117 List<Thing> getThings(Collection<? extends ThingId> thingIds) throws FlattrException; 118 119 /** 120 * Searches for {@link Thing}. 121 * 122 * @param query 123 * {@link SearchQuery}, or {@code null} to search for everything 124 * @param count 125 * Number of entries per page, {@code null} defaults to 30 entries 126 * @param page 127 * Page number (counted from 1), or {@code null} to turn off paging 128 * @return {@link SearchResult} 129 * @since 2.0 130 */ 131 SearchResult searchThings(SearchQuery query, Integer count, Integer page) throws FlattrException; 132 133 /** 134 * Gets the {@link User} profile of the given user ID. 135 * 136 * @param user 137 * {@link UserId} to get a profile for 138 * @return {@link User} profile of that user 139 */ 140 User getUser(UserId user) throws FlattrException; 141 142 /** 143 * Gets all {@link Flattr} most recently posted by the given user ID. Limited to 30 144 * results. 145 * 146 * @param user 147 * {@link UserId} to get the result for 148 * @return List of {@link Flattr} posted by the user 149 * @since 2.0 150 */ 151 List<Flattr> getFlattrs(UserId user) throws FlattrException; 152 153 /** 154 * Gets all {@link Flattr} most recently posted by the given user ID. 155 * 156 * @param user 157 * {@link UserId} to get the result for 158 * @param count 159 * Number of entries per page, {@code null} defaults to 30 entries 160 * @param page 161 * Page number (counted from 1), or {@code null} to turn off paging 162 * @return List of {@link Flattr} posted by the user 163 * @since 2.0 164 */ 165 List<Flattr> getFlattrs(UserId user, Integer count, Integer page) throws FlattrException; 166 167 /** 168 * Gets all {@link Flattr} most recently posted for the given thing ID. 169 * 170 * @param thing 171 * {@link ThingId} to get the result for 172 * @return List of {@link Flattr} posted by the user 173 * @since 2.0 174 */ 175 List<Flattr> getFlattrs(ThingId thing) throws FlattrException; 176 177 /** 178 * Gets all {@link Flattr} most recently posted for the given thing ID. 179 * 180 * @param thing 181 * {@link ThingId} to get the result for 182 * @param count 183 * Number of entries per page, {@code null} defaults to 30 entries 184 * @param page 185 * Page number (counted from 1), or {@code null} to turn off paging 186 * @return List of {@link Flattr} posted by the user 187 * @since 2.0 188 */ 189 List<Flattr> getFlattrs(ThingId thing, Integer count, Integer page) throws FlattrException; 190 191 /** 192 * Returns all {@link Activity} of the given user ID. 193 * 194 * @param user 195 * {@link UserId} to get the result for 196 * @param type 197 * activity type. {@code null} defaults to {@link Activity.Type#OUTGOING}. 198 * @return List of {@link Activity} 199 * @since 2.0 200 */ 201 List<Activity> getActivities(UserId user, Activity.Type type) throws FlattrException; 202 203 /** 204 * Gets a list of all Flattr {@link Category}. 205 * <p> 206 * <em>Note:</em> The result is not cached. 207 * 208 * @return List of Flattr {@link Category}. 209 */ 210 List<Category> getCategories() throws FlattrException; 211 212 /** 213 * Gets a list of all Flattr {@link Language}. 214 * <p> 215 * <em>Note:</em> The result is not cached. 216 * 217 * @return List of Flattr {@link Language}. 218 */ 219 List<Language> getLanguages() throws FlattrException; 220 221 /** 222 * Creates a new Thing. The authenticated user will be the owner of the Thing. 223 * 224 * @param thing 225 * {@link Submission} to be submitted 226 * @return {@link ThingId} of the {@link Thing} that was created 227 * @since 2.0 228 */ 229 @RequiredScope(Scope.THING) 230 ThingId create(Submission thing) throws FlattrException; 231 232 /** 233 * Updates a Thing. 234 * 235 * @param thing 236 * {@link Thing} to be modified 237 * @since 2.0 238 */ 239 @RequiredScope(Scope.THING) 240 void update(Thing thing) throws FlattrException; 241 242 /** 243 * Deletes a Thing. 244 * 245 * @param thingId 246 * {@link ThingId} to delete 247 * @since 2.0 248 */ 249 @RequiredScope(Scope.THING) 250 void delete(ThingId thingId) throws FlattrException; 251 252 /** 253 * Flattrs a Thing. This means that the Thing is flattr-ed by the associated user. 254 * 255 * @param thingId 256 * {@link ThingId} to flattr 257 * @return {@link MiniThing} of the flattr-ed thing (containing an updated click 258 * count) 259 * @since 2.9 260 */ 261 @RequiredScope(Scope.FLATTR) 262 MiniThing flattr(ThingId thingId) throws FlattrException; 263 264 /** 265 * Flattrs an {@link AutoSubmission}. If the submission has not been submitted to 266 * Flattr yet, it will automatically be submitted before. 267 * 268 * @param submission 269 * {@link AutoSubmission} to flattr 270 * @return {@link MiniThing} of the flattr-ed thing (containing an updated click 271 * count) 272 * @since 2.9 273 */ 274 @RequiredScope(Scope.FLATTR) 275 MiniThing flattr(AutoSubmission submission) throws FlattrException; 276 277 /** 278 * Flattrs a URL. 279 * 280 * @param url 281 * URL to flattr 282 * @return {@link MiniThing} of the flattr-ed thing (containing an updated click 283 * count) 284 * @since 2.9 285 */ 286 @RequiredScope(Scope.FLATTR) 287 MiniThing flattr(String url) throws FlattrException; 288 289 /** 290 * Subscribes a {@link Thing}. 291 * 292 * @param thingId 293 * {@link ThingId} to subscribe 294 * @since 2.6 295 */ 296 @RequiredScope(Scope.FLATTR) 297 void subscribe(ThingId thingId) throws FlattrException; 298 299 /** 300 * Cancels subscription of a {@link Thing}. 301 * 302 * @param thingId 303 * {@link ThingId} to unsubscribed 304 * @since 2.6 305 */ 306 @RequiredScope(Scope.FLATTR) 307 void unsubscribe(ThingId thingId) throws FlattrException; 308 309 /** 310 * Gets the {@link User} profile of the associated user. 311 * 312 * @return {@link User} profile of oneself 313 */ 314 @RequiredScope() 315 User getMyself() throws FlattrException; 316 317 /** 318 * Returns all {@link Thing} submitted by the associated user. Limited to 30 entries. 319 * 320 * @return List of {@link Thing} 321 * @since 2.0 322 */ 323 @RequiredScope() 324 List<Thing> getMyThings() throws FlattrException; 325 326 /** 327 * Returns all {@link Thing} submitted by the associated user. 328 * 329 * @param count 330 * Number of entries per page, {@code null} defaults to 30 entries 331 * @param page 332 * Page number (counted from 1), or {@code null} to turn off paging 333 * @return List of {@link Thing} 334 * @since 2.0 335 */ 336 @RequiredScope() 337 List<Thing> getMyThings(Integer count, Integer page) throws FlattrException; 338 339 /** 340 * Returns all {@link Flattr} submitted by the associated user. Limited to 30 entries. 341 * 342 * @return List of {@link Flattr} 343 * @since 2.0 344 */ 345 @RequiredScope() 346 List<Flattr> getMyFlattrs() throws FlattrException; 347 348 /** 349 * Returns all {@link Flattr} submitted by the associated user. 350 * 351 * @param count 352 * Number of entries per page, {@code null} defaults to 30 entries 353 * @param page 354 * Page number (counted from 1), or {@code null} to turn off paging 355 * @return List of {@link Flattr} 356 * @since 2.0 357 */ 358 @RequiredScope() 359 List<Flattr> getMyFlattrs(Integer count, Integer page) throws FlattrException; 360 361 /** 362 * Returns all {@link Activity} of the associated user. 363 * 364 * @param type 365 * activity type. {@code null} defaults to {@link Activity.Type#OUTGOING}. 366 * @return List of {@link Activity} 367 * @since 2.0 368 */ 369 @RequiredScope() 370 List<Activity> getMyActivities(Activity.Type type) throws FlattrException; 371 372 /** 373 * Returns all {@link Subscription} of the associated user. 374 * 375 * @return List of {@link Subscription} 376 * @since 2.6 377 */ 378 @RequiredScope(Scope.FLATTR) 379 List<Subscription> getMySubscriptions() throws FlattrException; 380 381 /** 382 * Returns the {@link Subscription} of the given {@link Thing}. Only the subscriptions 383 * of the associated user are accessible. 384 * <p> 385 * Note: This call is emulated by flattr4j. Depending on the number of subscriptions 386 * of the associated user, this call may take some time and cause increased network 387 * traffic. It may also increment the rate counter by more than 1. 388 * 389 * @param thingId 390 * {@link ThingId} to get the subscription of 391 * @return {@link Subscription} of this thing, or {@code null} if there is no such 392 * subscription 393 * @since 2.6 394 */ 395 @RequiredScope(Scope.FLATTR) 396 Subscription getSubscription(ThingId thingId) throws FlattrException; 397 398 /** 399 * Toggles the pause state of the subscription of the given {@link Thing}. 400 * 401 * @param thingId 402 * {@link ThingId} of the thing to toggle the pause state of 403 * @return {@code true} if the subscription is now paused, {@code false} if the 404 * subscription was resumed. 405 * @since 2.6 406 */ 407 @RequiredScope(Scope.FLATTR) 408 boolean toggleSubscription(ThingId thingId) throws FlattrException; 409 410 /** 411 * Pauses or resumes a {@link Subscription}. If the subscription is already in the 412 * desired state, nothing will happen. 413 * <p> 414 * Note: There is currently no way to explicitely set the pause state of a 415 * subscription via Flattr API. flattr4j emulates this call by toggling the pause 416 * state to get the current state, and if necessary, toggling it again to set the 417 * subscription to the desired state (which means that the rate counter is incremented 418 * by 2). This call is not atomic. If the second toggle call should fail, it will 419 * leave the subscription in the opposite state. 420 * 421 * @param thingId 422 * {@link ThingId} of the thing to set the pause state 423 * @param paused 424 * {@code true}: pause subscription, {@code false}: resume subscription 425 * @since 2.6 426 */ 427 @RequiredScope(Scope.FLATTR) 428 void pauseSubscription(ThingId thingId, boolean paused) throws FlattrException; 429 430 /** 431 * Sets the full mode. Defaults to {@code false}. 432 * 433 * @param full 434 * {@code true}: use full requests, {@code false}: use standard requests 435 * @since 2.2 436 */ 437 void setFullMode(boolean full); 438 439 /** 440 * Is the full mode currently enabled? 441 * 442 * @return {@code true}: full requests, {@code false}: standard requests 443 * @since 2.2 444 */ 445 boolean isFullMode(); 446 447 /** 448 * Gets the current rate limit from the server. 449 * <p> 450 * Unlike {@link #getLastRateLimit()}, this call actively queries the current rate 451 * limits from the server. 452 * <p> 453 * {@link #getLastRateLimit()} is untouched by this call. 454 * 455 * @return Rate limit. 456 * @since 2.5 457 */ 458 RateLimit getCurrentRateLimit() throws FlattrException; 459 460 /** 461 * Gets a {@link RateLimit} instance that reflects the rate limit and remaining rate 462 * returned by the last API call. 463 * <p> 464 * This method does not block and does not connect to the network. 465 * 466 * @return Rate limit. 467 * @since 2.0 468 */ 469 RateLimit getLastRateLimit(); 470 471}