com.alibaba.ocean.rawsdk.example.RawSdkExample Maven / Gradle / Ivy
The newest version!
/**
*
*/
package com.alibaba.ocean.rawsdk.example;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.ocean.rawsdk.ApiExecutor;
import com.alibaba.ocean.rawsdk.client.entity.AuthorizationToken;
import com.alibaba.ocean.rawsdk.client.exception.OceanException;
import com.alibaba.ocean.rawsdk.example.param.ExampleFamilyGetParam;
import com.alibaba.ocean.rawsdk.example.param.ExampleFamilyGetResult;
import com.alibaba.ocean.rawsdk.example.param.ExampleFamilyPostParam;
import com.alibaba.ocean.rawsdk.example.param.ExampleFamilyPostResult;
/**
*
*
*
* @author hongbang.hb
*
*/
public class RawSdkExample {
/**
* It is an example to simulate the request without accessToken. In this
* example, the result is a complex object. You need not care if the
* signature is required, the signature is handled by SDK automatically.
*
* @param apiExecutor
*/
public void exampleFamilyGet(ApiExecutor apiExecutor) {
ExampleFamilyGetParam exampleFamilyGetParam = new ExampleFamilyGetParam();
exampleFamilyGetParam.setFamilyNumber(1);
ExampleFamilyGetResult exampleFamilyGetResult = null;
try {
exampleFamilyGetResult = apiExecutor.execute(exampleFamilyGetParam);
} catch (OceanException e) {
e.printStackTrace();
}
System.out.println("ExampleFamilyGet call, family information of Result:" + exampleFamilyGetResult.getResult());
}
/**
* It is an example to simulate the request which require accessToken. In
* this example, HouseImg is a byte array which simulate the feature of
* upload image. You need not care if the signature is required, the
* signature is handled by SDK automatically.
*
*
* @param apiExecutor
*
*/
public void exampleFamilyPost(ApiExecutor apiExecutor, String refreshToken) {
ExampleFamilyPostParam exampleFamilyPostParam = new ExampleFamilyPostParam();
//This example help us to understand how to send an complex request to Ocean.
exampleFamilyPostParam.setComments("Example for SDK");
//it is a complex request, SDK help us to create Json Object automatically.
exampleFamilyPostParam.setFamily(RawSdkExampleData.createFirstFamily());
//Also, if you need send some byte array information like image.
exampleFamilyPostParam.setHouseImg(RawSdkExampleData.getPicture("example.png"));
//Calling and get the result.
ExampleFamilyPostResult exampleFamilyPostResult = null;
try {
exampleFamilyPostResult = apiExecutor.execute(exampleFamilyPostParam);
} catch (OceanException e) {
e.printStackTrace();
}
System.out.println("ExampleFamilyPost call, Family information of Result:" + exampleFamilyPostResult.getResult());
System.out.println("ExampleFamilyPost call, Desc of Result:" + exampleFamilyPostResult.getResultDesc());
}
public static void main(String[] args) {
ApiExecutor apiExecutor = new ApiExecutor("1688", "xxxxxx");
RawSdkExample rawSdkExample = new RawSdkExample();
rawSdkExample.exampleFamilyGet(apiExecutor);
rawSdkExample.exampleFamilyPost(apiExecutor, "24d7ce74-65a7-4690-b265-5350f2b580b2");
}
}