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.impl;
020
021import org.shredzone.flattr4j.connector.Connection;
022import org.shredzone.flattr4j.connector.Connector;
023import org.shredzone.flattr4j.connector.RequestType;
024import org.shredzone.flattr4j.exception.FlattrException;
025import org.shredzone.flattr4j.oauth.AccessToken;
026
027/**
028 * A {@link Connector} that connects to the Flattr web service.
029 *
030 * @author Richard "Shred" Körber
031 */
032public class FlattrConnector implements Connector {
033    private String baseUrl = "https://api.flattr.com/rest/v2/";
034
035    private AccessToken accessToken;
036
037    @Override
038    public Connection create() throws FlattrException {
039        return create(RequestType.GET);
040    }
041
042    @Override
043    public Connection create(RequestType type) throws FlattrException {
044        FlattrConnection connection = new FlattrConnection(type);
045        connection.url(baseUrl);
046        if (accessToken != null) {
047            connection.token(accessToken);
048        }
049        return connection;
050    }
051
052    /**
053     * Base URL of the API. Must end with a trailing slash!
054     */
055    public String getBaseUrl()                  { return baseUrl; }
056    public void setBaseUrl(String baseUrl)      { this.baseUrl = baseUrl; }
057
058    /**
059     * {@link AccessToken} to be used for authorized calls.
060     */
061    public AccessToken getAccessToken()         { return accessToken; }
062    public void setAccessToken(AccessToken accessToken) { this.accessToken = accessToken; }
063
064}