<commit_before>/**
 * Copyright (C) 2009-2013 Dell, Inc
 * See annotations for authorship information
 *
 * ====================================================================
 * 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 org.dasein.cloud.joyent;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.dasein.cloud.CloudErrorType;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.security.joyent.*;

public class JoyentMethod {
    static private final Logger logger = SmartDataCenter.getLogger(JoyentMethod.class, "std");
    static private final Logger wire   = SmartDataCenter.getLogger(JoyentMethod.class, "wire");

    static public final String VERSION = "~6.5";
    
    private JoyentClientFactory clientFactory;
    private JoyentHttpAuth httpAuth;
    
    public JoyentMethod(@Nonnull SmartDataCenter provider) {
        this.clientFactory = new DefaultClientFactory();
        this.httpAuth = new SignatureHttpAuth(provider.getContext());
    }
    
    public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws CloudException, InternalException {
        if( logger.isTraceEnabled() ) {
            logger.trace("ENTER - " + JoyentMethod.class.getName() + ".doDelete(" + endpoint + "," + resource + ")");
        }
        if( wire.isDebugEnabled() ) {
            wire.debug("");
            wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
        }
        try {
            HttpClient client = clientFactory.getClient(endpoint);
            HttpDelete delete = new HttpDelete(endpoint + "/my/" + resource);
            httpAuth.addPreemptiveAuth(delete);

            delete.addHeader("Accept", "application/json");
            delete.addHeader("X-Api-Version", VERSION);
            if( wire.isDebugEnabled() ) {
                wire.debug(delete.getRequestLine().toString());
                for( Header header : delete.getAllHeaders() ) {
                    wire.debug(header.getName() + ": " + header.getValue());
                }
                wire.debug("");<commit_msg>X-Api-Version update to 7.1<commit_after>/**
 * Copyright (C) 2009-2013 Dell, Inc
 * See annotations for authorship information
 *
 * ====================================================================
 * 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 org.dasein.cloud.joyent;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.dasein.cloud.CloudErrorType;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.security.joyent.*;

public class JoyentMethod {
    static private final Logger logger = SmartDataCenter.getLogger(JoyentMethod.class, "std");
    static private final Logger wire   = SmartDataCenter.getLogger(JoyentMethod.class, "wire");

    static public final String VERSION = "~7.1";
    
    private JoyentClientFactory clientFactory;
    private JoyentHttpAuth httpAuth;
    
    public JoyentMethod(@Nonnull SmartDataCenter provider) {
        this.clientFactory = new DefaultClientFactory();
        this.httpAuth = new SignatureHttpAuth(provider.getContext());
    }
    
    public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws CloudException, InternalException {
        if( logger.isTraceEnabled() ) {
            logger.trace("ENTER - " + JoyentMethod.class.getName() + ".doDelete(" + endpoint + "," + resource + ")");
        }
        if( wire.isDebugEnabled() ) {
            wire.debug("");
            wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
        }
        try {
            HttpClient client = clientFactory.getClient(endpoint);
            HttpDelete delete = new HttpDelete(endpoint + "/my/" + resource);
            httpAuth.addPreemptiveAuth(delete);

            delete.addHeader("Accept", "application/json");
            delete.addHeader("X-Api-Version", VERSION);
            if( wire.isDebugEnabled() ) {
                wire.debug(delete.getRequestLine().toString());
                for( Header header : delete.getAllHeaders() ) {
                    wire.debug(header.getName() + ": " + header.getValue());
                }
                wire.debug("");
{'fraction_non_alphanumeric': 0.1701858108108108, 'fraction_numerical': 0.0045045045045045045, 'mean_word_length': 3.1720493247210806, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6983734', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1813, 'n_words': 468}