/**
* Copyright 2018 Huawei Technologies Co.,Ltd.
* 
* 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 OCRDemo;
import com.huawei.ais.demo.ocr.*;
import java.io.IOException;
import java.net.URISyntaxException;
import org.apache.http.HttpResponse;
import org.apache.commons.io.IOUtils;

public class OCRDemo {
	public static void main(String[] args) throws URISyntaxException, UnsupportedOperationException, IOException{
		/*
		 * Token demo code
		 * */
		String Username="xxx";
		String Password="xxx";
		String Domainname="xxx"; //if it's not IAM user the Domain_name is the same with username
		String Regionname="cn-north-1";
		String HttpEndpoint="ocr.cn-north-1.myhuaweicloud.com";
		try {
			HWOcrClientToken ocrClient= new HWOcrClientToken(Domainname,Username,Password,Regionname,HttpEndpoint);
			HttpResponse response=ocrClient.requestOcrServiceBase64("/v1.0/ocr/id-card", "./data/id-card-demo.png");
			System.out.println(response);
			String content = IOUtils.toString(response.getEntity().getContent(), "utf-8");
			System.out.println(content); 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
		
		/*
		 * AK/SK demo code
		 * */
		String Httpendpoint="https://ocr.cn-north-1.myhuaweicloud.com"; //httpendpoint for the service
		String Region="cn-north-1";   //region name for the service
		String AK="xxx";  //AK from authentication
		String SK="xxx"; //SK from authentication
		try {
			HWOcrClientAKSK ocrClient=new HWOcrClientAKSK(Httpendpoint,Region,AK,SK);
			HttpResponse response=ocrClient.requestOcrServiceBase64("/v1.0/ocr/id-card", "./data/id-card-demo.png");
			System.out.println(response);
			String content = IOUtils.toString(response.getEntity().getContent(), "utf-8");
			System.out.println(content);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
