Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit dbdb5af6f7e291f95f7455bf33ace4392464b12a @Leftium committed Dec 8, 2010
Showing with 80 additions and 0 deletions.
  1. +22 −0 LICENSE.txt
  2. +15 −0 README.txt
  3. +7 −0 mailsnake/__init__.py
  4. +36 −0 mailsnake/mailsnake.py
22 LICENSE.txt
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2010 John-Kim Murphy
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
15 README.txt
@@ -0,0 +1,15 @@
+MailSnake Python wrapper for MailChimp API 1.3
+
+[ usage ]
+>>> from mailsnake import MailSnake
+>>> ms = MailSnake('YOUR MAILCHIMP API KEY')
+>>> ms.ping()
+u "Everything's Chimpy!"
+
+[ note ]
+API parameters must be passed by name. For example:
+>>> ms.listMemberInfo(id='YOUR LIST ID', email_address='name@email.com')
+
+[ MailChimp API v1.3 documentation ]
+http://www.mailchimp.com/api/1.3/
+
7 mailsnake/__init__.py
@@ -0,0 +1,7 @@
+from mailsnake import *
+
+__author__ = 'John-Kim Murphy'
+__copyright__ = 'Copyright 2010, John-Kim Murphy'
+__credits__ = ['John-Kim Murphy',]
+__version__ = '1.3.0.0'
+
36 mailsnake/mailsnake.py
@@ -0,0 +1,36 @@
+import urllib, urllib2
+import json
+
+class MailSnake(object):
+ def __init__(self, apikey = '', extra_params = {}):
+ """
+ Cache API key and address.
+ """
+ self.apikey = apikey
+
+ self.default_params = {'apikey':apikey}
+ self.default_params.update(extra_params)
+
+ dc = 'us1'
+ if '-' in self.apikey:
+ dc = self.apikey.split('-')[1]
+ self.base_api_url = 'https://%s.api.mailchimp.com/1.3/?method=' % dc
+
+ def call(self, method, params = {}):
+ url = self.base_api_url + method
+ params.update(self.default_params)
+
+ post_data = urllib.urlencode(params)
+ response = urllib2.urlopen(url, post_data)
+
+ return json.loads(response.read())
+
+ def __getattr__(self, method_name):
+
+ def get(self, *args, **kwargs):
+ params = dict((i,j) for (i,j) in enumerate(args))
+ params.update(kwargs)
+ return self.call(method_name, params)
+
+ return get.__get__(self)
+

0 comments on commit dbdb5af

Please sign in to comment.
Something went wrong with that request. Please try again.