Search in sources :

Example 1 with StaticListResult

use of org.talend.components.marketo.runtime.client.rest.response.StaticListResult in project components by Talend.

the class MarketoLeadClientTest method testGetListIdByName.

@Test
public void testGetListIdByName() throws Exception {
    doReturn(null).when(client).executeGetRequest(StaticListResult.class);
    try {
        client.getListIdByName("test_list");
        fail("Should not be here");
    } catch (MarketoException e) {
    }
    StaticListResult rr = new StaticListResult();
    rr.setSuccess(true);
    ListRecord lr = new ListRecord();
    lr.setId(666);
    rr.setResult(Arrays.asList(lr));
    doReturn(rr).when(client).executeGetRequest(StaticListResult.class);
    assertEquals(Integer.valueOf(666), client.getListIdByName("test_list"));
}
Also used : StaticListResult(org.talend.components.marketo.runtime.client.rest.response.StaticListResult) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) Test(org.junit.Test)

Example 2 with StaticListResult

use of org.talend.components.marketo.runtime.client.rest.response.StaticListResult in project components by Talend.

the class MarketoLeadClient method getListIdByName.

public Integer getListIdByName(String listName) throws MarketoException {
    current_uri = // 
    new StringBuilder(basicPath).append(// 
    API_PATH_LISTS_JSON).append(// 
    fmtParams(FIELD_ACCESS_TOKEN, accessToken, true)).append(fmtParams(FIELD_NAME, listName));
    StaticListResult getResponse = (StaticListResult) executeGetRequest(StaticListResult.class);
    if (getResponse == null) {
        throw new MarketoException(REST, messages.getMessage("error.response.null"));
    }
    if (!getResponse.isSuccess()) {
        throw new MarketoException(REST, getResponse.getErrors().toString());
    }
    if (getResponse.getResult().isEmpty()) {
        throw new MarketoException(REST, "No list match `" + listName + "`.");
    }
    return getResponse.getResult().get(0).getId();
}
Also used : StaticListResult(org.talend.components.marketo.runtime.client.rest.response.StaticListResult) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException)

Aggregations

StaticListResult (org.talend.components.marketo.runtime.client.rest.response.StaticListResult)2 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)2 Test (org.junit.Test)1 ListRecord (org.talend.components.marketo.runtime.client.rest.type.ListRecord)1