-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
fun setId(id: String): AbuseReportInfo{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Please remove these methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The response could be mocked this way:
|
||
// | ||
// 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) | ||
// } | ||
// } | ||
// } | ||
} |
There was a problem hiding this comment.
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