// Path: src/main/java/org/graylog/collector/CollectorVersion.java
// public class CollectorVersion {
//     public static final CollectorVersion CURRENT;
//     static Logger LOG = Logger.getLogger(CollectorVersion.class.getName());
// 
//     static {
//         String version = "NONE";
//         String commitId = "NONE";
//         String commitIdShort = "NONE";
//         String timestamp = "NONE";
// 
//         final InputStream stream = CollectorVersion.class.getResourceAsStream("/collector-version.properties");
//         final Properties properties = new Properties();
// 
//         try {
//             properties.load(stream);
// 
//             version = properties.getProperty("version");
//             commitId = properties.getProperty("commit-id");
//             timestamp = properties.getProperty("timestamp");
// 
//             if (!isNullOrEmpty(commitId) && !"NONE".equals(commitId)) {
//                 commitIdShort = commitId.substring(0, 7);
//             }
//         } catch (IOException ignored) {
//             LOG.info("Can not Load The Properties");
//         }
// 
//         CURRENT = new CollectorVersion(version, commitId, commitIdShort, timestamp);
//     }
// 
//     private final String version;
//     private final String commitId;
//     private final String commitIdShort;
//     private final String timestamp;
// 
//     public CollectorVersion(String version, String commitId, String commitIdShort, String timestamp) {
//         this.version = version;
//         this.commitId = commitId;
//         this.commitIdShort = commitIdShort;
//         this.timestamp = timestamp;
//     }
// 
//     public String version() {
//         return version;
//     }
// 
//     public String commitId() {
//         return commitId;
//     }
// 
//     public String commitIdShort() {
//         return commitIdShort;
//     }
// 
//     public String timestamp() {
//         return timestamp;
//     }
// 
//     @Override
//     public String toString() {
//         return "v" + version + "(commit" + commitIdShort() + ")";
//     }
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import org.graylog.collector.CollectorVersion;
import org.graylog.collector.annotations.GraylogServerURL;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;
import javax.inject.Inject;
import javax.inject.Provider;
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.graylog.collector.serverapi;



public class RestAdapterProvider implements Provider<RestAdapter> {
    private final String graylogServerURL;

    @Inject
    public RestAdapterProvider(@GraylogServerURL String graylogServerURL) {
        this.graylogServerURL = graylogServerURL;
    }

    @Override
    public RestAdapter get() {
        return new RestAdapter.Builder()
                .setEndpoint(graylogServerURL)
                .setConverter(new JacksonConverter(new ObjectMapper()))
                .setRequestInterceptor(request -> {
// Path: src/main/java/org/graylog/collector/CollectorVersion.java
// public class CollectorVersion {
//     public static final CollectorVersion CURRENT;
//     static Logger LOG = Logger.getLogger(CollectorVersion.class.getName());
// 
//     static {
//         String version = "NONE";
//         String commitId = "NONE";
//         String commitIdShort = "NONE";
//         String timestamp = "NONE";
// 
//         final InputStream stream = CollectorVersion.class.getResourceAsStream("/collector-version.properties");
//         final Properties properties = new Properties();
// 
//         try {
//             properties.load(stream);
// 
//             version = properties.getProperty("version");
//             commitId = properties.getProperty("commit-id");
//             timestamp = properties.getProperty("timestamp");
// 
//             if (!isNullOrEmpty(commitId) && !"NONE".equals(commitId)) {
//                 commitIdShort = commitId.substring(0, 7);
//             }
//         } catch (IOException ignored) {
//             LOG.info("Can not Load The Properties");
//         }
// 
//         CURRENT = new CollectorVersion(version, commitId, commitIdShort, timestamp);
//     }
// 
//     private final String version;
//     private final String commitId;
//     private final String commitIdShort;
//     private final String timestamp;
// 
//     public CollectorVersion(String version, String commitId, String commitIdShort, String timestamp) {
//         this.version = version;
//         this.commitId = commitId;
//         this.commitIdShort = commitIdShort;
//         this.timestamp = timestamp;
//     }
// 
//     public String version() {
//         return version;
//     }
// 
//     public String commitId() {
//         return commitId;
//     }
// 
//     public String commitIdShort() {
//         return commitIdShort;
//     }
// 
//     public String timestamp() {
//         return timestamp;
//     }
// 
//     @Override
//     public String toString() {
//         return "v" + version + "(commit" + commitIdShort() + ")";
//     }
// }


// Path: src/main/java/org/graylog/collector/serverapi/RestAdapterProvider.java
import com.fasterxml.jackson.databind.ObjectMapper;
import org.graylog.collector.CollectorVersion;
import org.graylog.collector.annotations.GraylogServerURL;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;
import javax.inject.Inject;
import javax.inject.Provider;

/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.graylog.collector.serverapi;



public class RestAdapterProvider implements Provider<RestAdapter> {
    private final String graylogServerURL;

    @Inject
    public RestAdapterProvider(@GraylogServerURL String graylogServerURL) {
        this.graylogServerURL = graylogServerURL;
    }

    @Override
    public RestAdapter get() {
        return new RestAdapter.Builder()
                .setEndpoint(graylogServerURL)
                .setConverter(new JacksonConverter(new ObjectMapper()))
                .setRequestInterceptor(request -> {
                    request.addHeader("User-Agent", "LogInsight Collector " + CollectorVersion.CURRENT);