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

Abuse reports getters #6

Open
wants to merge 7 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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Aug 04 16:09:12 SAMT 2016
#Sun Oct 09 18:36:17 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that the line below still refers to the old gradle version. You should run ./gradlew wrapper to complete Gradle upgrade

zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-3.1-all.zip
5 changes: 5 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,9 @@ function splitJvmOpts() {
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

# 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" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
6 changes: 0 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ecwid.maleorang.method.v3_0.lists

import com.ecwid.maleorang.MailchimpObject
import com.ecwid.maleorang.annotation.Field
import java.util.*

/**
* Created by apocheau on 27/08/16.
*/
class AbuseReportInfo : MailchimpObject() {

@JvmField
@Field
var id: String? = null

@JvmField
@Field
var campaign_id: String? = null

@JvmField
@Field
var list_id: String? = null

@JvmField
@Field
var email_id: String? = null

@JvmField
@Field
var email_address: String? = null

@JvmField
@Field
var merge_fields: MailchimpObject? = null

@JvmField
@Field
var vip: Boolean? = null

@JvmField
@Field
var date: Date? = null

@JvmField
@Field
var _links: List<LinkInfo>? = null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These "links" are included with every response and I find them useless. Do they really needed? If not, I'd prefer this field be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main goal of the connector is to give access to the data offered by the API.
As we are working on an opensource connector to MailChimp API, we shouldn't filter data.
Everyone using this connector would be able to choose whether to use this field or not.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ecwid.maleorang.method.v3_0.lists


import com.ecwid.maleorang.MailchimpMethod
import com.ecwid.maleorang.annotation.*

/**
* [Get details about a specific abuse report](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/abuse-reports/#read-get_lists_list_id_abuse_reports_report_id)
*/
@Method(httpMethod = HttpMethod.GET, version = APIVersion.v3_0, path = "/lists/{list_id}/abuse-reports/{report_id}")
class GetAbuseReportMethod(
@JvmField
@PathParam
val list_id: String,

@JvmField
@PathParam
val report_id: String
) : MailchimpMethod<AbuseReportInfo>() {

@JvmField
@QueryStringParam
var fields: String? = null

@JvmField
@QueryStringParam
var exclude_fields: String? = null

@JvmField
@QueryStringParam
var count: Int? = null

@JvmField
@QueryStringParam
var offset: Int? = null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count/offset params seem to be useless, as this method returns a single item. Perhaps, there is an error in the documentation.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.ecwid.maleorang.method.v3_0.lists


import com.ecwid.maleorang.MailchimpMethod
import com.ecwid.maleorang.MailchimpObject
import com.ecwid.maleorang.annotation.*

/**
* [Get information about abuse reports](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/abuse-reports/#read-get_lists_list_id_abuse_reports)
*/
@Method(httpMethod = HttpMethod.GET, version = APIVersion.v3_0, path = "/lists/{list_id}/abuse-reports")
class GetAbuseReportsMethod(
@JvmField
@PathParam
val list_id: String
) : MailchimpMethod<GetAbuseReportsMethod.Response>() {

@JvmField
@QueryStringParam
var fields: String? = null

@JvmField
@QueryStringParam
var exclude_fields: String? = null

@JvmField
@QueryStringParam
var count: Int? = null

@JvmField
@QueryStringParam
var offset: Int? = null

class Response : MailchimpObject() {
@JvmField
@Field
var abuse_reports: List<AbuseReportInfo>? = null

@JvmField
@Field
var list_id: String? = null

@JvmField
@Field
var total_items: Int? = null

@JvmField
@Field
var _links: List<LinkInfo>? = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.ecwid.maleorang.method.v3_0.lists

import com.ecwid.maleorang.MailchimpObject
import com.ecwid.maleorang.annotation.Field

/**
* Created by apocheau on 27/08/16.
*/
class LinkInfo : MailchimpObject() {

@JvmField
@Field
var rel: String? = null

@JvmField
@Field
var href: String? = null

@JvmField
@Field
var method: String? = null

@JvmField
@Field
var targetSchema: String? = null

@JvmField
@Field
var schema: String? = null

fun setRel(rel: String): LinkInfo{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove these chain methods as well

this.rel = rel
return this
}

fun setHref(href: String): LinkInfo{
this.href = href
return this
}

fun setMethod(method: String): LinkInfo{
this.method = method
return this
}

fun setTargetSchema(targetSchema: String): LinkInfo{
this.targetSchema = targetSchema
return this
}

fun setSchema(schema: String): LinkInfo{
this.schema = schema
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.ecwid.maleorang.method.v3_0.lists.members

import com.ecwid.maleorang.MailchimpClient
import com.ecwid.maleorang.connector.Connector
import com.ecwid.maleorang.method.v3_0.lists.GetAbuseReportMethod
import com.ecwid.maleorang.method.v3_0.lists.GetAbuseReportsMethod
import org.testng.Assert
import org.testng.annotations.Parameters
import org.testng.annotations.Test
import java.util.logging.Logger

class AbuseReportsTest
@Parameters("mailchimp.test.apikey", "mailchimp.test.listid")
constructor(private val apiKey: String, private val listId: String) {
private val log = Logger.getLogger(javaClass.getName())

@Test
fun testGetAbuseReports() {
MailchimpClient(apiKey).use { client ->
client.execute(GetAbuseReportsMethod(listId)).apply {
Assert.assertNotNull(listId)
Assert.assertNotNull(_links)
Assert.assertNotNull(abuse_reports)
Assert.assertNotNull(total_items)
}
}
}

@Test
fun testGetAbuseReport() {
class MockMailchimpClient : MailchimpClient(apiKey, object : Connector {
override fun call(request: Connector.Request): Connector.Response {
val json = "{\"id\": 42,\"campaign_id\": \"839488a60b\",\"list_id\": \"1a2df69511\",\"email_id\": \"62eeb292278cc15f5817cb78f7790b08\",\"email_address\": \"[email protected]\",\"date\": \"2015-07-15T19:19:31+00:00\",\"links\": [{\"rel\": \"self\",\"href\": \"https://usX.api.mailchimp.com/3.0/lists/1a2df69511/abuse-reports/42\",\"method\": \"GET\",\"targetSchema\": \"https://api.mailchimp.com/schema/3.0/Lists/Abuse/Instance.json\" },{ \"rel\": \"parent\",\"href\": \"https://usX.api.mailchimp.com/3.0/lists/1a2df69511/abuse-reports\",\"method\": \"GET\",\"targetSchema\": \"https://api.mailchimp.com/schema/3.0/Lists/Abuse/Collection.json\",\"schema\": \"https://api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Abuse.json\" }]}"
return Connector.Response(200, "", json)
}

override fun close() {
}
})

//TODO Improve test
MockMailchimpClient().use { client ->
client.execute(GetAbuseReportMethod(listId, "42")).apply {
Assert.assertNotNull(id)
Assert.assertNotNull(campaign_id)
Assert.assertNotNull(list_id)
Assert.assertNotNull(email_id)
Assert.assertNotNull(email_address)
// Assert.assertNotNull(merge_fields)
// Assert.assertNotNull(vip)
Assert.assertNotNull(date)
// Assert.assertNotNull(_links)
}
}
}
}
2 changes: 1 addition & 1 deletion wrapper.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
wrapper {
gradleVersion '2.14.1'
gradleVersion '3.1'
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"

if (gradle.gradleVersion != gradleVersion) {
Expand Down