This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vasily Karyaev
committed
Sep 24, 2012
1 parent
e2c1db4
commit addbdaf
Showing
3 changed files
with
62 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/ecwid/mailchimp/connection/DefaultConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2012 Ecwid, Inc. | ||
* | ||
* 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.ecwid.mailchimp.connection; | ||
|
||
import java.io.IOException; | ||
import java.net.URLEncoder; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.BasicResponseHandler; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
|
||
/** | ||
* Default implementation of {@link MailChimpConnectionManager} | ||
* which uses Apache HttpClient library to access MailChimp API service point. | ||
* | ||
* @author Vasily Karyaev <[email protected]> | ||
*/ | ||
public class DefaultConnectionManager implements MailChimpConnectionManager { | ||
private final HttpClient http = new DefaultHttpClient(); | ||
|
||
@Override | ||
public String post(String url, String payload) throws IOException { | ||
HttpPost post = new HttpPost(url); | ||
post.setEntity(new StringEntity(URLEncoder.encode(payload, "UTF-8"))); | ||
return http.execute(post, new BasicResponseHandler()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
http.getConnectionManager().shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ecwid.mailchimp; | ||
package com.ecwid.mailchimp.connection; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
@@ -23,7 +23,7 @@ | |
* | ||
* @author Vasily Karyaev <[email protected]> | ||
*/ | ||
public interface MailChimpAPIConnection extends Closeable { | ||
public interface MailChimpConnectionManager extends Closeable { | ||
|
||
/** | ||
* Make a POST request to MailChimp API service point. | ||
|