// Path: core/src/main/java/com/siteworx/cq5/ooyala/client/request/OoyalaPutRequest.java
// public class OoyalaPutRequest extends OoyalaRequest {
// 
// 	private JSONObject body;
// 	
// 	public OoyalaPutRequest(OoyalaApiCredential credentials) {
// 		super(credentials, HTTPMethod.PUT, "/v2/assets");
// 	}
// 	
// 	public OoyalaPutRequest(OoyalaApiCredential credentials, String pathSuffix) {
// 		super (credentials, HTTPMethod.PUT, "/v2/assets/" +pathSuffix);
// 	}
// 
// 	public JSONObject getBody() {
// 		return body;
// 	}
// 
// 	public void setBody(JSONObject body) {
// 		this.body = body;
// 	}
// }


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map.Entry;
import java.util.SortedMap;
import javax.ws.rs.core.MediaType;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.siteworx.cq5.ooyala.client.request.OoyalaPostRequest;
import com.siteworx.cq5.ooyala.client.request.OoyalaPutRequest;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.core.util.Base64;
package com.siteworx.cq5.ooyala.client;





/**
 * Copyright (c) 2012, Ooyala, Inc.
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * •	Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * •	Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation 
 *     and/or other materials provided with the distribution.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */

/**
 * Ooyala REST API client. The public methods in this class are thread-safe.
 *
 * @author leonardo@siteworx.com
 * @author rboll@siteworx.com
 *
 */
public class OoyalaPostClient extends OoyalaClient {
	
	private static final Logger log = LoggerFactory.getLogger(OoyalaClient.class);
	
	private final MessageDigest digest;
	private final Client client;
	
	/**
	 * Constructs the Ooyala Client.
	 *
	 * @throws NoSuchAlgorithmException Throws an exception if SHA-256 algorithm is not found by MessageDigest.
	 */
	public OoyalaPostClient(){
		try {
			digest = MessageDigest.getInstance("SHA-256");
			client = Client.create();
			client.setConnectTimeout(15000);//15 second timeout
			client.setReadTimeout(60000);//60 second timeout
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 
	 * @param request
	 * @return
	 * @throws OoyalaClientException
	 */
// Path: core/src/main/java/com/siteworx/cq5/ooyala/client/request/OoyalaPutRequest.java
// public class OoyalaPutRequest extends OoyalaRequest {
// 
// 	private JSONObject body;
// 	
// 	public OoyalaPutRequest(OoyalaApiCredential credentials) {
// 		super(credentials, HTTPMethod.PUT, "/v2/assets");
// 	}
// 	
// 	public OoyalaPutRequest(OoyalaApiCredential credentials, String pathSuffix) {
// 		super (credentials, HTTPMethod.PUT, "/v2/assets/" +pathSuffix);
// 	}
// 
// 	public JSONObject getBody() {
// 		return body;
// 	}
// 
// 	public void setBody(JSONObject body) {
// 		this.body = body;
// 	}
// }


// Path: core/src/main/java/com/siteworx/cq5/ooyala/client/OoyalaPostClient.java
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map.Entry;
import java.util.SortedMap;
import javax.ws.rs.core.MediaType;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.siteworx.cq5.ooyala.client.request.OoyalaPostRequest;
import com.siteworx.cq5.ooyala.client.request.OoyalaPutRequest;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.core.util.Base64;

package com.siteworx.cq5.ooyala.client;





/**
 * Copyright (c) 2012, Ooyala, Inc.
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * •	Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * •	Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation 
 *     and/or other materials provided with the distribution.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */

/**
 * Ooyala REST API client. The public methods in this class are thread-safe.
 *
 * @author leonardo@siteworx.com
 * @author rboll@siteworx.com
 *
 */
public class OoyalaPostClient extends OoyalaClient {
	
	private static final Logger log = LoggerFactory.getLogger(OoyalaClient.class);
	
	private final MessageDigest digest;
	private final Client client;
	
	/**
	 * Constructs the Ooyala Client.
	 *
	 * @throws NoSuchAlgorithmException Throws an exception if SHA-256 algorithm is not found by MessageDigest.
	 */
	public OoyalaPostClient(){
		try {
			digest = MessageDigest.getInstance("SHA-256");
			client = Client.create();
			client.setConnectTimeout(15000);//15 second timeout
			client.setReadTimeout(60000);//60 second timeout
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 
	 * @param request
	 * @return
	 * @throws OoyalaClientException
	 */
	public String request(OoyalaPutRequest request) throws OoyalaClientException {