Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated versions, added new methods #27

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
### General info
MaleOrang provides access to [MailChimp API v3.0](http://developer.mailchimp.com/documentation/mailchimp/reference/overview/) methods from Java code. It is a replacement for [ecwid-mailchimp](https://github.com/Ecwid/ecwid-mailchimp/) which has now been deprecated.
MaleOrang provides access to [MailChimp API v3.0](http://developer.mailchimp.com/documentation/mailchimp/reference/overview/) methods from Java code. It is a continuation of [ecwid-mailchimp](https://github.com/Ecwid/maleorang) which is no longer supported.

MaleOrang is written in [Kotlin language](https://kotlinlang.org/) and can be used with any language which runs on JVM. Refer to the [javadoc pages](http://www.javadoc.io/doc/com.ecwid/maleorang/) for details.
MaleOrang is written in [Kotlin language](https://kotlinlang.org/) and can be used with any language which runs on JVM. Refer to the [javadoc pages](http://www.javadoc.io/doc/com.raisin/maleorang/) for details.

### Supported MailChimp API methods

Currently MaleOrang has wrappers for a limited number of MailChimp API methods, namely:
Currently MaleOrang has wrappers for a number of MailChimp API methods:
* [Members methods](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/)
* [List methods](https://developer.mailchimp.com/documentation/mailchimp/reference/lists/)
* [Campaign methods](https://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/)
* [Reports methods](https://developer.mailchimp.com/documentation/mailchimp/reference/reports/)
* [Batch Operations methods](http://developer.mailchimp.com/documentation/mailchimp/reference/batches/)
* Some of [Lists methods](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/)

However, it is easy to extend the API and add support for any method you need (see the samples below).

### Code samples

* [Using an existing method implementation (Java)](src/test/java/com/ecwid/maleorang/examples/ExistingMethodExample.java)
* [Using an existing method implementation (Kotlin)](src/test/java/com/ecwid/maleorang/method/v3_0/lists/members/MembersTest.kt)
* [Using a custom method implementation (Java)](src/test/java/com/ecwid/maleorang/examples/CustomMethodExample.java)
* [Using an existing method implementation (Java)](https://github.com/raisin-gmbh/maleorang/blob/master/src/test/kotlin/com/ecwid/maleorang/examples/ExistingMethodExample.java)
* [Using an existing method implementation (Kotlin)](https://github.com/raisin-gmbh/maleorang/blob/master/src/test/kotlin/com/ecwid/maleorang/method/v3_0/lists/members/MembersTest.kt)
* [Using a custom method implementation (Java)](https://github.com/raisin-gmbh/maleorang/blob/master/src/test/kotlin/com/ecwid/maleorang/examples/CustomMethodExample.java)

### New features, changes, and bug fixes on version 3.0-0.9.7

Features
* [Reports method](https://developer.mailchimp.com/documentation/mailchimp/reference/reports/)
* [Reports SentTo method](https://developer.mailchimp.com/documentation/mailchimp/reference/reports/sent-to/)
* [DeleteMergeField method](https://developer.mailchimp.com/documentation/mailchimp/reference/lists/merge-fields/)

Changes
* Modified EditMemberMethod to allow emailAddress to be changed on a Member list.
* Added a Query String since parameter to GetEmailActivitysMethod.
* Enabled the overriding of the MailchimpClient method to facilitate mocking.
* Increased the connect and connectRequest timeOuts to 15 seconds, and the socketTimeOut to 5 minutes.
* Upgraded gradle wrapper to version 5.0 .
* Upgraded java version to 1.8 .
* Upgraded kotlin-stdlib and reflect libraries to 1.2.51 .

Bug fixes
* Corrected EditMergeFieldMethod response object to be MergeFieldInfo and not MemberInfo.

### New features, changes, and bug fixes on version 3.0-0.9.8

Changes
* Enhanced the MailchimpClient API to allow the optional parameterization of timeOut parameters (connectTimeOut, socketTimeOut, and connectionRequestTimeOut).

### Build tools integration

MaleOrang is accessible from [Maven Central](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.ecwid%22%20AND%20a%3A%22maleorang%22) so it can be easily integrated with your favorite build tools like Gradle or Maven.
MaleOrang is accessible from [Maven Central](https://mvnrepository.com/artifact/com.raisin/maleorang) so it can be easily integrated with your favorite build tools like Gradle or Maven.
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.9"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
}
}

plugins{
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
id 'java'
}

apply from: 'wrapper.gradle'
apply from: 'compile.gradle'
apply from: 'test.gradle'
Expand All @@ -18,9 +23,14 @@ repositories {
mavenCentral()
}

sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3"
compile "org.jetbrains.kotlin:kotlin-reflect:1.0.3"
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.51"
compile "org.jetbrains.kotlin:kotlin-reflect:1.2.51"
compile "com.google.guava:guava:19.0"
compile 'com.google.code.gson:gson:2.7'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
Expand Down
4 changes: 2 additions & 2 deletions compile.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'kotlin'

sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.8
targetCompatibility = 1.8

apply plugin: 'org.jetbrains.dokka'

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Thu Aug 04 16:09:12 SAMT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-5.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.14.1-all.zip
28 changes: 18 additions & 10 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -28,16 +28,16 @@ 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=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# 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" "$@"
8 changes: 1 addition & 7 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down Expand Up @@ -49,7 +49,6 @@ goto fail
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
13 changes: 13 additions & 0 deletions maleorang.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="maleorang" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.raisin" external.system.module.version="3.0-0.9.8" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
25 changes: 10 additions & 15 deletions publish.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apply plugin: 'maven'
apply plugin: 'signing'

group = 'com.ecwid'
group = 'com.raisin'
archivesBaseName = "maleorang"
version = '3.0-0.9.6'
version = '3.0-0.9.8'

task javadocJar(type: Jar) {
classifier = 'javadoc'
Expand Down Expand Up @@ -43,12 +43,12 @@ if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePass
description 'MailChimp API Wrapper for Java'
packaging 'jar'

url 'https://github.com/Ecwid/maleorang'
url 'https://github.com/raisin-gmbh/maleorang'

scm {
connection 'scm:git:[email protected]:Ecwid/maleorang.git'
developerConnection 'scm:git:[email protected]:Ecwid/maleorang.git'
url 'https://github.com/Ecwid/maleorang.git'
connection 'scm:git:[email protected]:raisin-gmbh/maleorang.git'
developerConnection 'scm:git:[email protected]:raisin-gmbh/maleorang.git'
url 'https://github.com/raisin-gmbh/maleorang.git'
}

licenses {
Expand All @@ -60,18 +60,13 @@ if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePass

developers {
developer {
id 'basil'
name 'Vasily Karyaev'
email '[email protected]'
}
developer {
id 'aqman1'
name 'Grigory Osin'
email '[email protected]'
id 'apalacios'
name 'Alejandro Palacios'
email '[email protected]'
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ import java.util.logging.Logger
*
* @constructor Thread safety of the created instances depends on the supplied [connector].
*/
open class MailchimpClient protected constructor (
private val apiKey: String, private val connector: Connector
open class MailchimpClient protected constructor(
private val apiKey: String, private val connector: Connector, private val connectTimeOut: Int , private val socketTimeOut: Int, private val connectionRequestTimeOut: Int
) : Closeable {
private val log = Logger.getLogger(javaClass.getName())

/**
* Instances created via this constructor are thread safe since they share a thread safe pool of http connections.
* However in terms of performance it doesn't matter whether you reuse the same instance for the whole application or re-create it on every operation.
* TimeOut parameters are optional. If not provided, Mailchimp client will use 15000 Milliseconds for connect and connectionRequest timeouts, and 300000 Milliseconds for
* socketTimeOut
*/
constructor(apiKey: String) : this(apiKey, HttpClientConnector())
@JvmOverloads
constructor(apiKey: String, connectTimeOut: Int = 15000, socketTimeOut: Int = 300000, connectionRequestTimeOut: Int = 15000) :
this(apiKey, HttpClientConnector(connectTimeOut, socketTimeOut, connectionRequestTimeOut), connectTimeOut, socketTimeOut, connectionRequestTimeOut)


/**
* Execute a MailChimp API method.
Expand All @@ -31,7 +36,7 @@ open class MailchimpClient protected constructor (
* @return execution result
*/
@Throws(IOException::class, MailchimpException::class)
fun <R : MailchimpObject> execute(method: MailchimpMethod<R>): R {
open fun <R : MailchimpObject> execute(method: MailchimpMethod<R>): R {
val methodInfo = MailchimpMethodInfo(method)
val request = Connector.Request(methodInfo.httpMethod.name, methodInfo.buildUrl(apiKey), "ignorable", apiKey, methodInfo.requestBody)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import org.apache.commons.codec.binary.Base64
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.*
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager
import org.apache.http.util.EntityUtils

import java.io.IOException
import java.net.URI
import java.nio.charset.Charset

/**
* Implementation of [Connector] which uses Apache HttpClient library to access MailChimp API service point.
*/
open class HttpClientConnector(builder: HttpClientBuilder) : Connector {
open class HttpClientConnector(builder: HttpClientBuilder, val connectTimeOut: Int, val socketTimeOut: Int, val connectionRequestTimeOut: Int) : Connector {
private val client = builder.build()

/**
* Creates instances sharing the same [PoolingHttpClientConnectionManager](http://static.javadoc.io/org.apache.httpcomponents/httpclient/4.5.2/org/apache/http/impl/conn/PoolingClientConnectionManager.html).
*/
constructor() : this(DEFAULT_HTTPCLIENT_BUILDER)
constructor(connectTimeOut: Int,socketTimeOut: Int, connectionRequestTimeOut: Int) :
this(DEFAULT_HTTPCLIENT_BUILDER(connectTimeOut,socketTimeOut,connectionRequestTimeOut),connectTimeOut,socketTimeOut,connectionRequestTimeOut)

@Throws(IOException::class)
override fun call(request: Connector.Request): Connector.Response {
Expand Down Expand Up @@ -62,12 +61,16 @@ open class HttpClientConnector(builder: HttpClientBuilder) : Connector {
private companion object {
private val UTF8 = Charsets.UTF_8

private val DEFAULT_HTTPCLIENT_BUILDER = HttpClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(15000).setSocketTimeout(15000).setConnectionRequestTimeout(15000).build())
.setConnectionManager(PoolingHttpClientConnectionManager().apply {
defaultMaxPerRoute = 10
maxTotal = 10
})
.setConnectionManagerShared(true)
fun DEFAULT_HTTPCLIENT_BUILDER(connectTimeOut: Int, socketTimeOut: Int, connectionRequestTimeOut: Int): HttpClientBuilder {
val clientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(connectTimeOut).setSocketTimeout(socketTimeOut).setConnectionRequestTimeout(connectionRequestTimeOut).build())
.setConnectionManager(PoolingHttpClientConnectionManager().apply {
defaultMaxPerRoute = 10
maxTotal = 10
})
.setConnectionManagerShared(true)
return clientBuilder;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sealed class EditMemberMethod : MailchimpMethod<MemberInfo>() {

@JvmField
@Field
val email_address: String
var email_address: String
) : EditMemberMethod() {
@JvmField
@PathParam
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ecwid.maleorang.method.v3_0.lists.merge_fields

import com.ecwid.maleorang.MailchimpObject
import com.ecwid.maleorang.MailchimpMethod;
import com.ecwid.maleorang.annotation.APIVersion
import com.ecwid.maleorang.annotation.HttpMethod
import com.ecwid.maleorang.annotation.Method
import com.ecwid.maleorang.annotation.PathParam

/**
* @author Raisin-AlejandroPalacios
*
* [Remove merge field from a specific list](https://developer.mailchimp.com/documentation/mailchimp/reference/lists/merge-fields/)
*
*/
@Method(httpMethod = HttpMethod.DELETE, version = APIVersion.v3_0, path = "/lists/{list_id}/merge-fields/{merge_id}")
class DeleteMergeFieldMethod(
@JvmField
@PathParam
val list_id: String,

@JvmField
@PathParam
val merge_id: Int
) : MailchimpMethod<MailchimpObject>()






Loading