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 6 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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ dependencies {
compile 'joda-time:joda-time:2.9.4'

testCompile 'org.testng:testng:6.8.21'
testCompile 'org.powermock:powermock-mockito-release-full:1.5.4'

Choose a reason for hiding this comment

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

There is a way to mock the response without this lib (see below), so please remove it

}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu Aug 04 16:09:12 SAMT 2016
#Tue Oct 04 22:38:57 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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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 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: Object? = null

Choose a reason for hiding this comment

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

This field should be of type MailchimpObject (so that the info could be taken from mapping).


@JvmField
@Field
var vip: Boolean? = null

@JvmField
@Field
var date: String? = null

Choose a reason for hiding this comment

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

This field should be of type Date


@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.


fun setId(id: String): AbuseReportInfo{
Copy link

@basiliscus basiliscus Oct 9, 2016

Choose a reason for hiding this comment

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

It seems that you've added a kind of "builder" methods. This is not a Kotlin-way to build objects. In Kotlin you build objects as follows:

val abuseReport = AbuseReportInfo().apply {
    id = "1234"
    ...
}

Please remove these methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it was made for chaining methods and build object in test method more easily. For example:
AbuseReportInfo().setId("2345").setCampaign_id("6789");
The "Kotlin way" is also nice and i didn't know it, thanks. I will follow it.

this.id = id
return this
}

fun setCampaign_id(campaign_id: String): AbuseReportInfo{
this.campaign_id = campaign_id
return this
}

fun setListId(list_id: String): AbuseReportInfo{
this.list_id = list_id
return this
}

fun setEmailId(email_id: String): AbuseReportInfo{
this.email_id = email_id
return this
}

fun setEmailAddress(email_address: String): AbuseReportInfo{
this.email_address = email_address
return this
}

fun setMergeFields(merge_fields: Object): AbuseReportInfo{
this.merge_fields = merge_fields
return this
}

fun setVip(vip: Boolean): AbuseReportInfo{
this.vip = vip
return this
}

fun setDate(date: String): AbuseReportInfo{
this.date = date
return this
}

fun setLinks(_links: List<LinkInfo>): AbuseReportInfo{
this._links = _links
return this
}
}
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,54 @@
package com.ecwid.maleorang.method.v3_0.lists.members

import com.ecwid.maleorang.MailchimpClient
import com.ecwid.maleorang.method.v3_0.lists.GetAbuseReportsMethod
import org.testng.Assert
import org.testng.annotations.Parameters
import org.testng.annotations.Test

class AbuseReportsTest
@Parameters("mailchimp.test.apikey", "mailchimp.test.listid", "mailchimp.test.abusereportid")
constructor(private val apiKey: String, private val listId: String, private val abuseReportId: String) {

// inline fun <reified T : Any> mock(): T = mock(T::class.java)

// var json = "{\"id\": 42,\"campaign_id\": \"839488a60b\",\"list_id\": \"1a2df69511\",\"email_id\": \"62eeb292278cc15f5817cb78f7790b08\",\"email_address\": \"urist.mcvankab@freddiesjokes.com\",\"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\" }]}"
// var request = Connector.Request(HttpMethod.GET.name, "", "", "", "")
// var response = Connector.Response(200, "", json)

@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() {
//
// var connector = HttpClientConnector()
// var spiedConnector = spy(connector)
//
// var callMock = mock<HttpClientConnector>()
// `when`(spiedConnector.call()).thenReturn(response)

Choose a reason for hiding this comment

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

The response could be mocked this way:

        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\": \"urist.mcvankab@freddiesjokes.com\",\"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() { }
        })

//
// MailchimpClient(apiKey).use { client ->
// client.execute(GetAbuseReportMethod(listId, abuseReportId)).apply {
// Assert.assertNotNull(id)
// Assert.assertNotNull(campaign_id)
// Assert.assertNotNull(listId)
// 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 test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test {
}

doFirst {
['mailchimp.test.apikey', 'mailchimp.test.listid'].each { prop ->
['mailchimp.test.apikey', 'mailchimp.test.listid', 'mailchimp.test.abusereportid'].each { prop ->
systemProperty prop, project.getProperty(prop)
}
}
Expand Down
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