Skip to content

Example: subscriber source creation

Stefano Varesi edited this page Apr 9, 2015 · 2 revisions
package com.contactlab.api.ws.examples;

import com.contactlab.api.ws.ClabService;
import com.contactlab.api.ws.ClabService_Service;
import com.contactlab.api.ws.domain.AuthToken;
import com.contactlab.api.ws.domain.Field;
import com.contactlab.api.ws.domain.SubscriberSource;
import com.contactlab.api.ws.domain.SubscriberSourceField;

public class CreateSubscriberSource {

    public static void main(String[] args) {
        ClabService clabService = new ClabService_Service().getClabServicePort();

        AuthToken token = clabService.borrowToken(Parameters.apiKey, Parameters.userKey);

        SubscriberSource subscriberSource = null;
        SubscriberSourceField name = null;
        SubscriberSourceField email = null;
        SubscriberSourceField birth = null;
        SubscriberSourceField gender = null;
        SubscriberSourceField privacy = null;

        subscriberSource = new SubscriberSource();
        subscriberSource.setName("Some users with JAVA");

        // defining the fields
        name = new SubscriberSourceField();
        name.setName("Name");
        name.setType(Field.STRING);
        name.setEmailField(false);
        subscriberSource.getFields().add(name);

        email = new SubscriberSourceField();
        email.setName("Email");
        email.setType(Field.STRING);
        email.setEmailField(true);
        subscriberSource.getFields().add(email);

        birth = new SubscriberSourceField();
        birth.setName("Birth");
        birth.setType(Field.DATE);
        subscriberSource.getFields().add(birth);

        gender = new SubscriberSourceField();
        gender.setName("Gender");
        gender.setType(Field.CHAR);
        subscriberSource.getFields().add(gender);

        privacy = new SubscriberSourceField();
        privacy.setName("Privacy");
        privacy.setType(Field.FLAG);
        subscriberSource.getFields().add(privacy);

        subscriberSource = clabService.addSubscriberSource(token, subscriberSource);
        System.out.println("Created userdb " + subscriberSource.getIdentifier());
        clabService.invalidateToken(token);
    }
}