diff --git a/.gitignore b/.gitignore
index b6bca6e..459d0fe 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,35 +1,132 @@
+# Created by https://www.gitignore.io/api/macos,maven,gradle,intellij
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+.idea
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+gradle.properties
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
*.iml
+modules.xml
+.idea/misc.xml
*.ipr
-*.iws
-.idea/
-
-# Eclipse
-.settings
-.classpath
-.project
-.metadata
-*.launch
-.metadata
-bin/
-tmp/
-*.tmp
-*.bak
-*.swp
-*~.nib
-
-# packages
-*.class
-*.jar
-*.war
-*.ear
-
-# maven
-target/
-# Mac
+# Sonarlint plugin
+.idea/sonarlint
+
+### macOS ###
+# General
.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### Maven ###
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+
+### Gradle ###
+.gradle
+/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
+
+
+# End of https://www.gitignore.io/api/macos,maven,gradle,intellij
+
-# Project
-Test.java
+### Project specific ###
src/test/*
diff --git a/LICENSE.md b/LICENSE.md
index f85d0b1..49e6f43 100755
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
# The MIT License (MIT)
-Copyright (c) 2015 - 2017 Alexander Weiß
+Copyright (c) 2015 - 2018 Alexander Weiß
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
diff --git a/README.md b/README.md
index ce506ec..2317c6e 100755
--- a/README.md
+++ b/README.md
@@ -3,11 +3,6 @@ Simple api for accessing Mailchimp - Work in progess
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/gr4h4n/bananaj/master/LICENSE.md)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.alexanderwe/bananaj/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.alexanderwe/bananaj)
-
-
-
-
# Introduction
bananaj provides an Java wrapper for the MailChimp API 3.0. It is possible access your MailChimp data through Java.
@@ -22,9 +17,20 @@ Add this dependency to your pom.xml to use **bananaj** in your project.
com.github.alexanderwe
bananaj
- 0.5.0
+ 0.5.1
```
+or with Gradle
+
+```
+repositories {
+ maven { url "http://repo.maven.apache.org/maven2" }
+}
+
+dependencies {
+ compile group: 'com.github.alexanderwe', name: 'bananaj', version: '0.5.1'
+}
+```
## MailChimpObject class
Most of the com.github.alexanderwe.bananaj.model classes extend the MailChimpObject class.They are immutable, to prevent asynchronous data between the client and the MailChimp server.
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..59787e8
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,95 @@
+apply plugin: "java"
+apply plugin: "maven"
+apply plugin: "maven-publish"
+apply plugin: 'signing'
+
+group = 'com.github.alexanderwe'
+version = '0.5.1'
+
+description = 'A simple MailChimp API wrapper written in Java'
+
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
+
+repositories {
+ maven { url "http://repo.maven.apache.org/maven2" }
+}
+
+dependencies {
+ compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
+ compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
+ compile group: 'org.json', name: 'json', version: '20180130'
+ compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
+}
+
+task javadocJar(type: Jar) {
+ classifier = 'javadoc'
+ from javadoc
+}
+
+task sourcesJar(type: Jar) {
+ classifier = 'sources'
+ from sourceSets.main.allSource
+}
+
+task fatJar(type: Jar) {
+ baseName = 'bananaj'
+ from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
+ with jar
+}
+
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ from components.java
+
+ artifact javadocJar
+ artifact sourcesJar
+
+ pom {
+ name = 'bananaj'
+ description = 'A simple MailChimp API wrapper written in Java'
+ url = 'https://github.com/alexanderwe/bananaj'
+ licenses {
+ license {
+ name = 'MIT'
+ url = 'https://raw.githubusercontent.com/alexanderwe/bananaj/master/LICENSE.md'
+ }
+ }
+ developers {
+ developer {
+ name = 'Alexander Weiß'
+ email = 'https://www.github.com/alexanderwe'
+ }
+ }
+ scm {
+ connection = 'scm:git:git://github.com/alexanderwe/bananaj.git'
+ developerConnection = 'scm:git:git://github.com/alexanderwe/bananaj.git'
+ url = 'https://github.com/alexanderwe/bananaj'
+ }
+ issueManagement {
+ url = 'https://github.com/alexanderwe/bananaj/issues'
+ system = 'GitHub'
+ }
+ }
+ }
+ }
+ repositories {
+ maven {
+ url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
+ credentials {
+ username ossrhUsername
+ password ossrhPassword
+ }
+ }
+ }
+}
+
+signing {
+ sign publishing.publications.mavenJava
+}
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..6b6ea3a
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..0e680f3
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..e95643d
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pom.xml b/pom.xml
deleted file mode 100755
index 5dc3aad..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-
-
- 4.0.0
-
- com.github.alexanderwe
- bananaj
- 1.2.5-alpha
- jar
-
- bananaj
- A simple MailChimp API wrapper written in Java
- https://github.com/alexanderwe/bananaj
-
-
-
- MIT
- https://raw.githubusercontent.com/alexanderwe/bananaj/master/LICENSE.md
- repo
-
-
-
-
-
-
- Alexander Weiß
- https://www.github.com/alexanderwe
-
-
-
-
-
- scm:git:git://github.com/alexanderwe/bananaj.git
- scm:git:git://github.com/alexanderwe/bananaj.git
- https://github.com/alexanderwe/bananaj
-
-
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
-
-
- UTF-8
- 1.8
- 1.8
-
-
-
-
-
- commons-codec
- commons-codec
- 1.10
-
-
-
- net.sourceforge.jexcelapi
- jxl
- 2.6.12
-
-
-
- org.json
- json
- 20160212
-
-
-
- org.apache.httpcomponents
- httpclient
- 4.5.5
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.5.1
-
-
- 1.8
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.6
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.4
-
-
- attach-javadocs
-
- jar
-
-
-
-
- -Xdoclint:none
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..9942a63
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'bananaj'
diff --git a/src/main/java/com/github/alexanderwe/bananaj/connection/Connection.java b/src/main/java/com/github/alexanderwe/bananaj/connection/Connection.java
index 07a346b..be6dcde 100755
--- a/src/main/java/com/github/alexanderwe/bananaj/connection/Connection.java
+++ b/src/main/java/com/github/alexanderwe/bananaj/connection/Connection.java
@@ -1,25 +1,19 @@
package com.github.alexanderwe.bananaj.connection;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-
+import com.github.alexanderwe.bananaj.exceptions.TransportException;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.EntityBuilder;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPatch;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.*;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
+import org.json.JSONException;
+import org.json.JSONObject;
-import com.github.alexanderwe.bananaj.exceptions.TransportException;
+import java.io.*;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/**
* Created by Alexander on 10.08.2016.
@@ -27,254 +21,181 @@
public class Connection {
- public String do_Get(URL url, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpGet httpget = new HttpGet(url.toURI());
- httpget.addHeader("Authorization", authorization);
- response = httpclient.execute(httpget);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'GET' request to URL : " + url);
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " GET " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- } catch (Exception e) {
- throw new TransportException("GET " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
-
- public String do_Post(URL url, String post_string, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpPost httppost = new HttpPost(url.toURI());
- httppost.addHeader("Authorization", authorization);
- httppost.addHeader("Content-Type", "application/json; charset=UTF-8");
- httppost.setEntity(EntityBuilder.create().setText(post_string).build());
- response = httpclient.execute(httppost);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'POST' request to URL : " + url + System.lineSeparator() + "Send data: " + (post_string.length() > 500 ? post_string.substring(0, 500)+"..." : post_string));
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " POST " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- }
- return null;
- } catch (Exception e) {
- throw new TransportException("POST " + post_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
-
- public String do_Patch(URL url, String patch_string, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpPatch httppatch = new HttpPatch(url.toURI());
- httppatch.addHeader("Authorization", authorization);
- httppatch.addHeader("Content-Type", "application/json; charset=UTF-8");
- httppatch.setEntity(EntityBuilder.create().setText(patch_string).build());
- response = httpclient.execute(httppatch);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'PATCH' request to URL : " + url + System.lineSeparator() + "Send data: " + (patch_string.length() > 500 ? patch_string.substring(0, 500)+"..." : patch_string));
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " PATCH " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- }
- return null;
- } catch (Exception e) {
- throw new TransportException("PATCH " + patch_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
-
- public String do_Put(URL url, String put_string, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpPut httpput = new HttpPut(url.toURI());
- httpput.addHeader("Authorization", authorization);
- httpput.addHeader("Content-Type", "application/json; charset=UTF-8");
- httpput.setEntity(EntityBuilder.create().setText(put_string).build());
- response = httpclient.execute(httpput);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'PUT' request to URL : " + url + System.lineSeparator() + "Send data: " + (put_string.length() > 500 ? put_string.substring(0, 500)+"..." : put_string));
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " PUT " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- }
- return null;
- } catch (Exception e) {
- throw new TransportException("PUT " + put_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
-
- public String do_Post(URL url, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpPost httppost = new HttpPost(url.toURI());
- httppost.addHeader("Authorization", authorization);
- httppost.addHeader("Content-Type", "application/json; charset=UTF-8");
- response = httpclient.execute(httppost);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'POST' request to URL : " + url);
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " POST " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- }
- return null;
- } catch (Exception e) {
- throw new TransportException("POST " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
-
- public String do_Delete(URL url, String authorization) throws TransportException {
- CloseableHttpClient httpclient = null;
- CloseableHttpResponse response = null;
- InputStream entityStream = null;
-
- try {
- httpclient = HttpClients.createDefault();
- HttpDelete httpdelete = new HttpDelete(url.toURI());
- httpdelete.addHeader("Authorization", authorization);
- httpdelete.addHeader("Content-Type", "application/json; charset=UTF-8");
- response = httpclient.execute(httpdelete);
-
- int responseCode = response.getStatusLine().getStatusCode();
- //System.out.println("\nSending 'DELETE' request to URL : " + url);
- //System.out.println("Response Code : " + responseCode + "\n");
- if (responseCode >= 400) {
- throw new TransportException("Error: " + responseCode + " DELETE " + url.toExternalForm() + " " + response.getStatusLine().getReasonPhrase());
- }
-
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- long length = entity.getContentLength();
- entityStream = entity.getContent();
- StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int)length : 200);
- try (Reader reader = new BufferedReader(new InputStreamReader
- (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- strbuilder.append((char) c);
- }
- }
- return strbuilder.toString();
- }
- return null;
- } catch (Exception e) {
- throw new TransportException("DELETE " + url.toExternalForm() + " failed", e);
- } finally {
- if (entityStream != null) {try {entityStream.close();} catch (Exception e) { }}
- if (response != null) {try {response.close();} catch (Exception e) { }}
- }
- }
+ public String do_Get(URL url, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient;
+
+ HttpGet httpget = new HttpGet(url.toURI());
+ httpget.addHeader("Authorization", authorization);
+ httpclient = HttpClients.createDefault();
+ try (CloseableHttpResponse response = httpclient.execute(httpget)) {
+
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("GET", url.toExternalForm(), response);
+ }
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("GET " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+ public String do_Post(URL url, String post_string, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient;
+
+
+ HttpPost httppost = new HttpPost(url.toURI());
+ httppost.addHeader("Content-Type", "application/json; charset=UTF-8");
+ httppost.addHeader("Authorization", authorization);
+ httppost.setEntity(EntityBuilder.create().setBinary(post_string.getBytes(StandardCharsets.UTF_8)).build());
+
+ httpclient = HttpClients.createDefault();
+ try (CloseableHttpResponse response = httpclient.execute(httppost)) {
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("POST", url.toExternalForm(), response);
+ }
+
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("POST " + post_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+ public String do_Patch(URL url, String patch_string, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient;
+
+
+ HttpPatch httppatch = new HttpPatch(url.toURI());
+ httppatch.addHeader("Content-Type", "application/json; charset=UTF-8");
+ httppatch.addHeader("Authorization", authorization);
+ httppatch.setEntity(EntityBuilder.create().setBinary(patch_string.getBytes(StandardCharsets.UTF_8)).build());
+
+ httpclient = HttpClients.createDefault();
+ try (CloseableHttpResponse response = httpclient.execute(httppatch)) {
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("PATCH", url.toExternalForm(), response);
+ }
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("PATCH " + patch_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+
+ public String do_Put(URL url, String put_string, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient;
+
+ HttpPut httpput = new HttpPut(url.toURI());
+ httpput.addHeader("Content-Type", "application/json; charset=UTF-8");
+ httpput.addHeader("Authorization", authorization);
+ httpput.setEntity(EntityBuilder.create().setBinary(put_string.getBytes(StandardCharsets.UTF_8)).build());
+
+ httpclient = HttpClients.createDefault();
+ try (CloseableHttpResponse response = httpclient.execute(httpput)) {
+
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("DELETE", url.toExternalForm(), response);
+ }
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("PUT " + put_string.length() + " bytes to " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+ public String do_Post(URL url, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient = null;
+
+ HttpPost httppost = new HttpPost(url.toURI());
+ httppost.addHeader("Content-Type", "application/json; charset=UTF-8");
+ httppost.addHeader("Authorization", authorization);
+ httpclient = HttpClients.createDefault();
+
+ try (CloseableHttpResponse response = httpclient.execute(httppost)) {
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("POST", url.toExternalForm(), response);
+ }
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("POST " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+ public String do_Delete(URL url, String authorization) throws TransportException, URISyntaxException {
+ CloseableHttpClient httpclient;
+
+ HttpDelete httpdelete = new HttpDelete(url.toURI());
+ httpdelete.addHeader("Content-Type", "application/json; charset=UTF-8");
+ httpdelete.addHeader("Authorization", authorization);
+
+ httpclient = HttpClients.createDefault();
+ try (CloseableHttpResponse response = httpclient.execute(httpdelete)) {
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode > 299) {
+ throw buildTransportError("DELETE", url.toExternalForm(), response);
+ }
+
+ return createResponseFromEntity(response.getEntity());
+ } catch (Exception e) {
+ throw new TransportException("DELETE " + url.toExternalForm() + " failed", e);
+ }
+ }
+
+
+ private String createResponseFromEntity(HttpEntity entity) throws IOException {
+ InputStream entityStream;
+ if (entity != null) {
+ long length = entity.getContentLength();
+ entityStream = entity.getContent();
+ StringBuilder strbuilder = new StringBuilder(length > 16 && length < Integer.MAX_VALUE ? (int) length : 200);
+ try (Reader reader = new BufferedReader(new InputStreamReader
+ (entityStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
+ int c;
+ while ((c = reader.read()) != -1) {
+ strbuilder.append((char) c);
+ }
+ }
+ return strbuilder.toString();
+ }
+ return null;
+ }
+
+ private TransportException buildTransportError(String verb, String url, CloseableHttpResponse response) {
+ int responseCode = response.getStatusLine().getStatusCode();
+ JSONObject errObj;
+ try {
+ errObj = new JSONObject(createResponseFromEntity(response.getEntity()));
+ String errType = getErrorObjString(errObj, "type");
+ String errTitle = getErrorObjString(errObj, "title");
+ String errDetail = getErrorObjString(errObj, "detail");
+ String errInstance = getErrorObjString(errObj, "instance");
+ return new TransportException("Status: " + Integer.toString(responseCode) + " " + verb + ": " + url + " Reason: " + response.getStatusLine().getReasonPhrase()
+ + " - " + errTitle + " Details: " + errDetail + " Instance: " + errInstance + " Type: " + errType);
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ }
+ return new TransportException("Status: " + Integer.toString(responseCode) + " " + verb + ": " + url + " Reason: " + response.getStatusLine().getReasonPhrase());
+ }
+
+
+ private String getErrorObjString(JSONObject errObj, String key) {
+ if (errObj.has(key)) {
+ return errObj.getString(key);
+ }
+ return "";
+ }
}
+
diff --git a/src/main/java/com/github/alexanderwe/bananaj/exceptions/TransportException.java b/src/main/java/com/github/alexanderwe/bananaj/exceptions/TransportException.java
index 8b08cfe..9108e98 100644
--- a/src/main/java/com/github/alexanderwe/bananaj/exceptions/TransportException.java
+++ b/src/main/java/com/github/alexanderwe/bananaj/exceptions/TransportException.java
@@ -5,6 +5,7 @@
/**
* @author USCRIGA
+ * TODO: Maybe add some additional fields like type, title, detail etc. to make them accessible to the user
*
*/
public class TransportException extends Exception {
@@ -23,6 +24,7 @@ public TransportException(String message) {
super(message);
}
+
/**
* @param cause the cause. (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
diff --git a/src/main/java/com/github/alexanderwe/bananaj/model/filemanager/FileManagerFile.java b/src/main/java/com/github/alexanderwe/bananaj/model/filemanager/FileManagerFile.java
index 2c83b5a..35a0f62 100755
--- a/src/main/java/com/github/alexanderwe/bananaj/model/filemanager/FileManagerFile.java
+++ b/src/main/java/com/github/alexanderwe/bananaj/model/filemanager/FileManagerFile.java
@@ -120,11 +120,10 @@ public FileManagerFile (Builder b){
this.folder_id = b.folderId;
}
-
/**
* Change the name of the file
- * @param newName
- * @
+ * @param name
+ * @throws Exception
*/
public void changeName(String name) throws Exception{
JSONObject changedFileName = new JSONObject();
@@ -136,9 +135,8 @@ public void changeName(String name) throws Exception{
/**
* Change the folder of this file
- * @param The id of the folder. Setting folderID to "0" will remove a file from its current folder.
- * @throws Exception
- * @throws
+ * @param folderID Setting folderID to "0" will remove a file from its current folder.
+ * @throws Exception
*/
public void changeFolder(int folderID) throws Exception {
JSONObject changedFileName = new JSONObject();
diff --git a/src/main/java/com/github/alexanderwe/bananaj/model/list/MailChimpList.java b/src/main/java/com/github/alexanderwe/bananaj/model/list/MailChimpList.java
index ac3f24f..6c579e3 100755
--- a/src/main/java/com/github/alexanderwe/bananaj/model/list/MailChimpList.java
+++ b/src/main/java/com/github/alexanderwe/bananaj/model/list/MailChimpList.java
@@ -161,14 +161,12 @@ public Member updateMember(Member member) throws Exception {
if (member.getEmail_type() != null) {
json.put("email_type", member.getEmail_type().value());
}
- jsonPut(json, "status", member.getStatus().getStringRepresentation());
+ json.put( "status", member.getStatus().getStringRepresentation());
{
JSONObject mergeFields = new JSONObject();
HashMap mergeFieldsMap = member.getMerge_fields();
- Iterator it = mergeFieldsMap.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
+ for (String key : mergeFieldsMap.keySet()) {
mergeFields.put(key, mergeFieldsMap.get(key));
}
json.put("merge_fields", mergeFields);
@@ -177,81 +175,26 @@ public Member updateMember(Member member) throws Exception {
{
JSONObject interests = new JSONObject();
HashMap interestsMap = member.getInterest();
- Iterator it = interestsMap.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
+ for (String key : interestsMap.keySet()) {
interests.put(key, interestsMap.get(key));
}
json.put("interests",interests);
}
- jsonPut(json, "ip_signup", member.getIp_signup());
- jsonPut(json, "timestamp_signup", member.getTimestamp_signup());
- jsonPut(json, "ip_opt", member.getIp_opt());
- jsonPut(json, "timestamp_opt", member.getTimestamp_opt());
+ json.put("ip_signup", member.getIp_signup());
+ json.put("timestamp_signup", member.getTimestamp_signup());
+ json.put( "ip_opt", member.getIp_opt());
+ json.put("timestamp_opt", member.getTimestamp_opt());
try {
String results = getConnection().do_Patch(new URL(connection.getListendpoint()+"/"+this.getId()+"/members/"+member.getId()),json.toString(),connection.getApikey());
- //this.membercount++;
+ this.membercount++;
return new Member(this, new JSONObject(results));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
-
- public Member createUpdateMember(Member member) throws Exception {
- JSONObject json = new JSONObject();
- json.put("email_address", member.getEmail_address());
- if (member.getStatus_if_new() != null) {
- json.put("status_if_new", member.getStatus_if_new().getStringRepresentation());
- }
- if (member.getEmail_type() != null) {
- json.put("email_type", member.getEmail_type().value());
- }
- jsonPut(json, "status", member.getStatus().getStringRepresentation());
- {
- JSONObject mergeFields = new JSONObject();
- HashMap mergeFieldsMap = member.getMerge_fields();
- Iterator it = mergeFieldsMap.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
- mergeFields.put(key, mergeFieldsMap.get(key));
- }
- json.put("merge_fields", mergeFields);
- }
-
- {
- JSONObject interests = new JSONObject();
- HashMap interestsMap = member.getInterest();
- Iterator it = interestsMap.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
- interests.put(key, interestsMap.get(key));
- }
- json.put("interests",interests);
- }
- jsonPut(json, "ip_signup", member.getIp_signup());
- jsonPut(json, "timestamp_signup", member.getTimestamp_signup());
- jsonPut(json, "ip_opt", member.getIp_opt());
- jsonPut(json, "timestamp_opt", member.getTimestamp_opt());
-
- try {
- String results = getConnection().do_Put(new URL(connection.getListendpoint()+"/"+this.getId()+"/members/"+member.getId()),json.toString(),connection.getApikey());
- //this.membercount++;
- return new Member(this, new JSONObject(results));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void jsonPut(JSONObject json, String fieldName, String value) {
- if (value != null) {
- json.put(fieldName, value);
- }
- }
-
/**
* Add a member with first and last name
* @param status
@@ -269,13 +212,15 @@ public void addMember(MemberStatus status, String emailAddress, HashMap pair = it.next();
it.remove(); // avoids a ConcurrentModificationException
- merge_fields.put(pair.getKey().toString(), pair.getValue());
+ merge_fields.put(pair.getKey(), pair.getValue());
}
member.put("status", status.getStringRepresentation());
member.put("email_address", emailAddress);
member.put("merge_fields", merge_fields);
+ System.out.println(member.toString());
getConnection().do_Post(url,member.toString(),connection.getApikey());
+
this.membercount++;
}
diff --git a/src/main/java/com/github/alexanderwe/bananaj/model/list/member/Member.java b/src/main/java/com/github/alexanderwe/bananaj/model/list/member/Member.java
index a72b20c..e6648e7 100755
--- a/src/main/java/com/github/alexanderwe/bananaj/model/list/member/Member.java
+++ b/src/main/java/com/github/alexanderwe/bananaj/model/list/member/Member.java
@@ -115,7 +115,11 @@ public Member(String id, MailChimpList mailChimpList, HashMap me
this.memberInterest = new HashMap();
this.connection = connection;
}
-
+
+ public Member() {
+
+ }
+
/**
* Update the mailChimpList of this member
* @param listId