Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Trying to pass to github

  • Loading branch information...
commit 7b268292b04d57a446f1be0c05cd52fcdb9d82e5 0 parents
mathias authored
4 .gitignore
@@ -0,0 +1,4 @@
+
+*~
+*.pyc
+
14 LICENSE
@@ -0,0 +1,14 @@
+Copyright (c) 2013 Mathias Bustamante.
+All rights reserved.
+
+Redistribution and use in source and binary forms are permitted
+provided that the above copyright notice and this paragraph are
+duplicated in all such forms and that any documentation,
+advertising materials, and other materials related to such
+distribution and use acknowledge that the software was developed
+by the <organization>. The name of the
+University may not be used to endorse or promote products derived
+from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1  MANIFEST
@@ -0,0 +1 @@
+include README.md LICENSE
73 README.md
@@ -0,0 +1,73 @@
+python-meli
+=======
+
+```python-meli``` is a wrapper for MercadoLibre API, current version of the API is
+V1, this wrapper does not yet totally supports the entire API, see below for
+supported endpoints.
+
+Features
+--------
+
+* Categories and Listings:
+ - Fully supported, see [the docs](http://developers.mercadolibre.com/API-directory/)
+* Locations and Currencies
+ - Fully supported, see [the docs](http://developers.mercadolibre.com/API-directory/)
+
+Installation
+------------
+
+ (pip install | easy_install) python-meli
+
+... or, you can clone the repo and install it the old fashioned way
+
+ git clone https://mathiasbc@bitbucket.org/mathiasbc/python-meli.git
+ cd python-meli
+ sudo python setup.py install
+
+Usage
+-----
+
+Every method below returns a JSON of the the endpoint response, the following example is just to show the basic usage of this wrapper, however I recommend you to read the meli.py module to see what does every method exactle does and what parameters can be passed to them.
+
+
+###### Mercado Libre endpoints
+
+```python
+from meli.meli import MercadoLibre
+
+MELI = MercadoLibre()
+
+# Locations and Currencies =================================================
+print MELI.countries()
+print MELI.country_detail(country_id='PE')
+print MELI.state_detail(state_id='PE-ARE')
+print MELI.city_detail(city_id='TVBFQ0FSRTE0YjA5')
+print MELI.currencies()
+print MELI.currency_detail(currency_id='PEN')
+print MELI.currency_conversion(currency_id_from='PEN', currency_id_to='USD')
+
+
+# Categories and Listings ==================================================
+print MELI.sites()
+print MELI.site_detail(site_id='MPE')
+print MELI.site_domains(site_domain_url='www.mercadolibre.com.pe')
+print MELI.site_listing_types(site_id='MPE')
+print MELI.site_listing_exposures(site_id='MPE', listing_exposure_id='low')
+print MELI.site_listing_prices(site_id='MPE', price=10000, quantity=10)
+print MELI.site_categories(site_id='MPE')
+print MELI.category_detail(category_id='MPE1182')
+```
+
+
+Notes
+-----
+For the moment oauth is not supported, I'm currently working on it.
+
+
+
+Want to help?
+-------------
+Python-MELI is a usefull wrapper but I would greatly appreciate any help, you could contribute writing the Wiki or forking and then making pull request with new features. Feel free to contact me.
+
+
+(c) 2012 - Mathias Bustamante mathias@worldrat.com - Distributed under the BSD license - Made in Peru.
0  meli/__init__.py
No changes.
4 meli/constants.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+
+DEFAULT_API_VERSION = "v1"
+API_PARTIAL_URL = "https://%(api_version)s.api.mercadolibre.com"
73 meli/endpoints.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+# Users and Apps ==============================================================
+
+# /users/
+
+# /users/:id
+#USER_DETAIL = "/users/%(user_id)s" # Append user_id
+
+# /users/{user_id}/addresses?access_token={...}
+#USER_ADDRESSES = \
+# "/users/%(user_id)s/addresses?access_token=%(access_token)s"
+
+# /users/{user_id}/accepted_payment_methods
+#USER_ACCEPTED_PAY_METHOD = "/users/%(user_id)s/accepted_payment_methods"
+
+# /applications/{app_id}
+# /scopes
+
+
+# Categories and Listings ======================================================
+
+# /sites Sites where MELI runs
+SITES = "/sites"
+
+# /sites/{site_id}
+SITE_DETAIL = "/sites/%(site_id)s"
+
+# /site_domains/{site_domain_url} Retrieves info about the domain
+SITE_DOMAINS = "/site_domains/%(site_domain_url)s"
+
+# /sites/{site_id}/listing_types
+# Retrieves information about the listing types.
+SITE_LISTING_TYPES = "/sites/%(site_id)s/listing_types"
+
+# /sites/{site_id}/listing_exposures
+SITE_LISTING_EXPOSURES = "/sites/%(site_id)s/listing_exposures/"
+
+# /sites/{site_id}/listing_prices?price=1
+SITE_LISTING_PRICES = "/sites/%(site_id)s/listing_prices"
+
+# /sites/{site_id}/categories
+SITE_CATEGORIES = "/sites/%(site_id)s/categories"
+
+# /categories/{category_id} Information about specific category
+CATEGORY_DETAIL = "/categories/%(category_id)s"
+
+# /categories/{category_id}/attributes I could not make it work
+CATEGORY_ATTRIBUTES = ""
+
+
+# Locations and Currencies =====================================================
+
+# /countries List the countries
+COUNTRIES = "/countries"
+
+# /countries/{country_id} Info for the country
+COUNTRY_DETAIL = "/countries/%(country_id)s"
+
+# /states/{state_id} Info for a given State
+STATE_DETAIL = "/states/%(state_id)s"
+
+# /cities/{city_id} Info for the given state
+CITY_DETAIL = "/cities/%(city_id)s"
+
+# /currencies Info of the MercadoLibre currencies
+CURRENCIES = "/currencies"
+
+# /currencies/{currency_id}
+CURRENCY_DETAIL = "/currencies/%(currency_id)s"
+
+# /currency_conversions/search?from={currency_id}&to={currency_id}
+CURRENCY_CONVERSION = "/currency_conversions/search"
223 meli/meli.py
@@ -0,0 +1,223 @@
+# -*- coding: utf-8 -*-
+
+import endpoints
+import constants
+import utils
+from methods import get, post
+
+class MercadoLibre(object):
+ """
+ Object that contains all the functionallity that MELI API offers
+ """
+
+ def __init__(self, api_version=None):
+ """
+ If api_version is not passed it defaults to the one on contants.py
+ """
+ if api_version is not None:
+ self.API_VERSION = str(api_version)
+ else:
+ self.API_VERSION = constants.DEFAULT_API_VERSION
+
+ self.API_PREFIX_URL = constants.API_PARTIAL_URL % {
+ 'api_version': self.API_VERSION
+ }
+
+ def sites(self):
+ """
+ Returns information about the sites where MercadoLibre runs as JSON.
+ """
+ url = self.API_PREFIX_URL + endpoints.SITES
+ response = get(url)
+ return response
+
+ def site_detail(self, site_id):
+ """
+ @site_id: id of the request site, MPE (PERU)
+ @return: Returns the detailed information of a site as JSON.
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_DETAIL % {
+ 'site_id': site_id
+ }
+ response = get(url)
+ return response
+
+ def site_domains(self, site_domain_url):
+ """
+ @site_domain_url: www.mercadolibre.com.pe
+ @returns: Information about specific domain as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_DOMAINS % {
+ 'site_domain_url': site_domain_url
+ }
+ response = get(url)
+ return response
+
+
+ def site_listing_types(self, site_id):
+ """
+ @site_id: id of the request site, MPE (PERU)
+ @return: Returns information about the listing types as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_LISTING_TYPES % {
+ 'site_id': site_id
+ }
+ response = get(url)
+ return response
+
+ def site_listing_exposures(self, site_id, listing_exposure_id=None):
+ """
+ Lisits the different exposures types on MercadoLibre
+
+ @site_id: id of the request site, MPE (PERU)
+ @listing_exposure_id: id of the exposure, low, mid, high...
+
+ @return: Returns advertising exposures as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_LISTING_EXPOSURES % {
+ 'site_id': site_id
+ }
+
+ # adding exposure_id .../low
+ if listing_exposure_id is not None:
+ url += listing_exposure_id
+
+ response = get(url)
+ return response
+
+ def site_listing_prices(self, site_id, price,
+ listing_type_id=None, quantity=None,
+ category_id=None, currency_id=None
+ ):
+ """
+ Lists the prices of listing items by different criteria
+
+ @site_id: id of the request site, MPE (PERU)
+ @price: price of the object, 500
+ @listing_type_id: gold, premium, silver, bronce, free
+ @quantity: amount of pulicid items, 5
+ @category_id: , MLA1744
+ @currency_id: USD(US dollars), PEN(Soles)
+
+ @return: Returns the listing prices as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_LISTING_PRICES % {
+ 'site_id': site_id
+ }
+
+ # create query params
+ params = {'price': price, 'listing_type_id': listing_type_id,
+ 'quantity': quantity, 'category_id': category_id,
+ 'currency_id': currency_id
+ }
+
+ # erase fields with None
+ utils.erase_none_values(params)
+
+ response = get(url, params=params)
+ return response
+
+ def site_categories(self, site_id):
+ """
+ @site_id: id of the request categories, MPE (PERU)
+ @return: Returns the site categories as JSON.
+ """
+ url = self.API_PREFIX_URL + endpoints.SITE_CATEGORIES % {
+ 'site_id': site_id
+ }
+
+ response = get(url)
+ return response
+
+ def category_detail(self, category_id):
+ """
+ @category_id: MPE1182
+ @returns Information of the category as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.CATEGORY_DETAIL % {
+ 'category_id': category_id
+ }
+
+ response = get(url)
+ return response
+
+ def countries(self):
+ """
+ @return: Countries on MercadoLibre as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.COUNTRIES
+ response = get(url)
+ return response
+
+ def country_detail(self, country_id):
+ """
+ @country_id: PE(Peru), AR(Agentina)...
+ @return: Detailed info of a country as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.COUNTRY_DETAIL % {
+ 'country_id': country_id
+ }
+
+ response = get(url)
+ return response
+
+ def state_detail(self, state_id):
+ """
+ @state_id: PE-ARE(Arequipa-Peru)...
+ @return: Detailed info for given state as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.STATE_DETAIL % {
+ 'state_id': state_id
+ }
+
+ response = get(url)
+ return response
+
+ def city_detail(self, city_id):
+ """
+ @city_id: TVBFQ0FSRTE0YjA5 (Arequipa-Arequipa-Peru)
+ @returns: Detailed info for the given city as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.CITY_DETAIL % {
+ 'city_id': city_id
+ }
+
+ response = get(url)
+ return response
+
+ def currencies(self):
+ """
+ @return: Info of the currencies in MercadoLibre as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.CURRENCIES
+ response = get(url)
+ return response
+
+ def currency_detail(self, currency_id):
+ """
+ @currency_id: PEN (Soles, Peru)...
+ @return: Info of the given currency
+ """
+ url = self.API_PREFIX_URL + endpoints.CURRENCY_DETAIL % {
+ 'currency_id': currency_id
+ }
+
+ response = get(url)
+ return response
+
+ def currency_conversion(self, currency_id_from, currency_id_to):
+ """
+ @currency_id_from: currency to convert, PEN
+ @currency_id_to: currency to convert to, USD
+ @returns: Information about the conversion as JSON
+ """
+ url = self.API_PREFIX_URL + endpoints.CURRENCY_CONVERSION
+
+ # create query params
+ params = { 'from': currency_id_from, 'to': currency_id_to }
+
+ response = get(url, params=params)
+ return response
+
+
+
22 meli/methods.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+
+import requests
+
+def get(request_url, params=None):
+
+ if params is not None:
+ response = requests.get(request_url, params=params)
+ else:
+ response = requests.get(request_url)
+ return response.json()
+ # try:
+ # response = requests.get(request_url)
+ # if response.code == '200':
+ # return response.content
+ # else:
+ # print "Something was not OK not code 200"
+ # except:
+ # print "Something went on on the request GET"
+
+def post(request_url, param_dict=None):
+ pass
8 meli/utils.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+
+def erase_none_values(param_dict):
+ """ erases none values from dict """
+ for k, v in param_dict.items():
+ if v is None:
+ del param_dict[k]
47 setup.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+import os
+from distutils.core import setup
+
+version = '1.0'
+
+classifiers = [
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: BSD License",
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2.4",
+ "Programming Language :: Python :: 2.5",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.0",
+ "Programming Language :: Python :: 3.1",
+ "Programming Language :: Python :: 3.2",
+ "Programming Language :: Python :: 3.3",
+ "Operating System :: OS Independent",
+ "Topic :: Software Development :: Libraries",
+]
+
+root_dir = os.path.dirname(__file__)
+if not root_dir:
+ root_dir = '.'
+long_desc = open(root_dir + '/README.md').read()
+
+setup(
+ name='python-meli',
+ version=version,
+ url='https://bitbucket.org/mathiasbc/python-meli',
+ download_url='https://mathiasbc@bitbucket.org/mathiasbc/python-meli.git',
+ author='Mathias Bustamante',
+ author_email='mathias@worldrat.com',
+ license='BSD License',
+ install_requires=[
+ 'requests',
+ ],
+ py_modules=['meli'],
+ description='Mercado Libre API wrapper',
+ classifiers=classifiers,
+ long_description=long_desc,
+ keywords='Mercado Libre API',
+)
28 test.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+from meli.meli import MercadoLibre
+
+
+if __name__ == "__main__":
+ MELI = MercadoLibre()
+
+ # Locations and Currencies =================================================
+ print MELI.countries()
+ #print MELI.country_detail(country_id='PE')
+ #print MELI.state_detail(state_id='PE-ARE')
+ #print MELI.city_detail(city_id='TVBFQ0FSRTE0YjA5')
+ #print MELI.currencies()
+ #print MELI.currency_detail(currency_id='PEN')
+ #print MELI.currency_conversion(currency_id_from='PEN', currency_id_to='USD')
+
+ # Users and Apps ===========================================================
+
+
+ # Categories and Listings ==================================================
+ #print MELI.sites()
+ #print MELI.site_detail(site_id='MPE')
+ #print MELI.site_domains(site_domain_url='www.mercadolibre.com.pe')
+ #print MELI.site_listing_types(site_id='MPE')
+ #print MELI.site_listing_exposures(site_id='MPE', listing_exposure_id='low')
+ #print MELI.site_listing_prices(site_id='MPE', price=10000, quantity=10)
+ #print MELI.site_categories(site_id='MPE')
+ #print MELI.category_detail(category_id='MPE1182')
Please sign in to comment.
Something went wrong with that request. Please try again.