Snippets

Purvesh Khona Create Braango Number

Created by Purvesh Khona
/**
 * 
 */
package com.braango.virtualdealer.braangonumber;

import java.util.List;
import java.util.Map;

import com.braango.client.ApiCallback;
import com.braango.client.ApiClient;
import com.braango.client.ApiException;
import com.braango.client.braangoapi.BraangonumbersApi;
import com.braango.client.braangoapi.EmailsApi;
import com.braango.client.braangoapi.GroupsApi;
import com.braango.client.braangoapi.WebhooksApi;
import com.braango.client.braangomodel.BraangoNumberCreateInput;
import com.braango.client.braangomodel.BraangoNumberCreateInputBody;
import com.braango.client.braangomodel.BraangoNumberInput;
import com.braango.client.braangomodel.BraangoNumberOutput;
import com.braango.client.braangomodel.BraangoNumberOutputBodyData;
import com.braango.client.braangomodel.EmailOutputBodyData;
import com.braango.client.braangomodel.GroupOutput;
import com.braango.client.braangomodel.GroupOutputBodyData;
import com.braango.client.braangomodel.RequestHeader;
import com.braango.client.braangomodel.EmailInput;
import com.braango.client.braangomodel.EmailInputBody;
import com.braango.client.braangomodel.EmailOutput;
import com.braango.client.braangomodel.WebhookOutput;
import com.braango.client.braangomodel.WebhookOutputBodyData;

/**
 * @author braango
 * 
 *    Sample code showing how to create
 *    one braango number for subdealer
 *    for given group
 *   
 *
 */
public class CreateOneBraangoNumber {

	static String basePath = "https://testapi2.braango.com/v2/braango";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		ApiClient braangoApiClient = new ApiClient();
		// TEST auth token. Please contact
		// sales@braango.com to have one
		// created for you
		String authToken = "ISNWF0P30WM0CMK";
		braangoApiClient.setBasePath(basePath);

		// Set the auth_token for api client to
		// interact with Braango system
		braangoApiClient.setApiKey(authToken);

		// Api key is authorization to to access
		// resources within braango system
		//
		// This key is different than auth_token
		// that is used to validate the master account

		String apiKey = "ISNfTMNOumV3xYNDd2g";

		// Create webhookApi api. 
		BraangonumbersApi braangoNumberApi = new BraangonumbersApi(braangoApiClient);
		

		ApiCallback<BraangoNumberOutput> callBack = new ApiCallback<BraangoNumberOutput>() {

			@Override
			public void onUploadProgress(long bytesWritten, 
					long contentLength,
					boolean done) {

				System.out
						.println("Place holder for tracking"
								+ " request progress");

			}

			@Override
			public void onSuccess(BraangoNumberOutput result, int statusCode,
					Map<String, List<String>> responseHeaders) {

				BraangoNumberOutputBodyData braangoNumbers = result.getBody()
						.getData();
				
				
				

				System.out.println("Braango Numbers : " + braangoNumbers.getBraangoNumberList());

			}

			@Override
			public void onFailure(ApiException e, int statusCode,
					Map<String, List<String>> responseHeaders) {
				System.out.println("Error is " + statusCode + " "
						+ e.getResponseBody());

			}

			@Override
			public void onDownloadProgress(long bytesRead, long contentLength,
					boolean done) {

			}
		};

		
		BraangoNumberCreateInput braangoNumberInput = new BraangoNumberCreateInput();
		RequestHeader hdr = new RequestHeader();
		hdr.setAccountType("partner");
		hdr.setApiKey(apiKey);
		hdr.setId("create-braango-number");
		braangoNumberInput.setHeader(hdr);
		
		
		
		BraangoNumberCreateInputBody  body = new BraangoNumberCreateInputBody();
		
		// All all the personnel in represented
		// by this group for this sub-dealer
		body.setAllPersonnel(true);
		body.setFakeBraangoNumber(true);
		braangoNumberInput.setBody(body);
		
		try {
			String subDealerId = "subdealers1002";
			
			
			// Group for which the braango number is being created
			String group = "DEFAULT";
			braangoNumberApi.createBraangoNumberAsync(subDealerId, group, braangoNumberInput, callBack);
			
			
		} catch (ApiException e1) {
			e1.printStackTrace();
		}
	}

}

Comments (0)