com.kakao.PhotoKakaoStoryPostParamBuilder.java Source code

Java tutorial

Introduction

Here is the source code for com.kakao.PhotoKakaoStoryPostParamBuilder.java

Source

/**
 * Copyright 2014 Kakao Corp.
 *
 * Redistribution and modification in source or binary forms are not permitted without specific prior written permission.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kakao;

import org.json.JSONArray;

import android.os.Bundle;
import com.kakao.KakaoParameterException.ERROR_CODE;
import com.kakao.helper.ServerProtocol;

/*
 * Param Name           Param Type         
 * imageURLs           String     o       ? URL 
 * content               String     x       
*/

/**
 * (Photo)  ?    Builder?.
 * ?  ?.
 * @author MJ
*/
public class PhotoKakaoStoryPostParamBuilder extends BasicKakaoStoryPostParamBuilder {
    private String content;
    private final JSONArray imageURLs = new JSONArray();

    /**
     *    ? url?  .
     * @param imageURLs  
     */
    public PhotoKakaoStoryPostParamBuilder(final String[] imageURLs) {
        for (final String imagePath : imageURLs)
            this.imageURLs.put(imagePath);
    }

    /**
     * ?? ? .
     * @param content ?? ? ?
     */
    public PhotoKakaoStoryPostParamBuilder setContent(final String content) {
        this.content = content;
        return this;
    }

    /**
     *  ? ? Bundle .
     * @return  ? ? Bundle 
     */
    public Bundle build() throws KakaoParameterException {
        if (imageURLs.length() == 0)
            throw new KakaoParameterException(ERROR_CODE.CORE_PARAMETER_MISSING,
                    "addImageURL(String) is required.");
        final Bundle parameters = super.build();
        if (content != null)
            parameters.putString(ServerProtocol.CONTENT_KEY, content);
        if (imageURLs.length() != 0)
            parameters.putString(ServerProtocol.IMAGE_URL_LIST_KEY, imageURLs.toString());
        return parameters;
    }
}