Skip to content

Commit

Permalink
Merge pull request #1 from Phylante/1.1.x
Browse files Browse the repository at this point in the history
1.1.3
  • Loading branch information
Jocelyn Griselle committed Oct 19, 2015
2 parents 16e98f8 + 935a156 commit 3ebfdb4
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 173 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Released: **11-Sep-2014**
Last release: **10-Dec-2014**

Introduction
--------------
------------

**Shiba** is a Python package that provides interfaces to **PriceMinister Web services**. Currently, all features works
with *Python 2.7*.
Expand Down Expand Up @@ -63,7 +63,7 @@ Please refer to documentation for some information about testing options.


Documentation
--------------
-------------
Documentation is available on `GitHub pages`_.

Extra documentation from the `PriceMinister developper blog`_ might be useful.
Expand Down
28 changes: 14 additions & 14 deletions doc/Getting started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ First, import the main *Shiba* module, and create an instance of the *shibaconne
Then all you have to do is importing the management module you wish to work with, giving it your instanced connection class, and start dealing with those WebServices through its methods.

I want an example!
------------------------------
------------------
.. highlight:: python

This example will show you how to get new sales information on your seller account::

from Shiba.shibaconnection import ShibaConnection
from Shiba.salesmanagement import SalesManagement
from Shiba.shibaconnection import ShibaConnection
from Shiba.salesmanagement import SalesManagement

init = ShibaConnection("mysellerlogin", "mytokenpwd"[, sandbox=True """For testing purpose only (use Sandbox IDs)"""])
salestool = SalesManagement(init)
newsales = salestool.get_new_sales()
init = ShibaConnection("mysellerlogin", "mytokenpwd"[, sandbox=True """For testing purpose only (use Sandbox IDs)"""])
salestool = SalesManagement(init)
newsales = salestool.get_new_sales()

Now you can scroll the `ShibaResponseObject` object returned by the method::

purchaseid = newsales.content.response.sales.sale[0].purchaseid # Getting the first sale on the list, retrieving the purchase ID
purchasedate = newsales.content.response.sales.sale[0].purchasedate # Retrieving the purchase date
for each in newsales.content.iterchildren():
print each.tag # Will print each tag nodes from the first level
print newsales.namespace # Will print the current namespace (not that useful, but can help for some cases of further development)
print newsales.rawxml # Display the whole XML returned from WebServices and processed by Shiba
purchaseid = newsales.content.response.sales.sale[0].purchaseid # Getting the first sale on the list, retrieving the purchase ID
purchasedate = newsales.content.response.sales.sale[0].purchasedate # Retrieving the purchase date
for each in newsales.content.iterchildren():
print each.tag # Will print each tag nodes from the first level
print newsales.namespace # Will print the current namespace (not that useful, but can help for some cases of further development)
print newsales.rawxml # Display the whole XML returned from WebServices and processed by Shiba

And here we go! All you have to do is to find the methods fitting your needs.

Testing
----------
-------
Shiba comes with its tests, both offline and online ones.

*New in 1.1.2*: Tests now running with mock.
Expand All @@ -60,7 +60,7 @@ Offline testing
Move into the *offline* subdirectory of *tests/*, and simply run *nosetests*.

Online testing
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^
If you want to run online test, you will primary need to get a **PriceMinister sandbox account** in order to proceed.

Then open up the *tests/online/Assets/nosetests.cfg* file and fill it up with your sandbox **login** and **token** (not password).
Expand Down
18 changes: 9 additions & 9 deletions doc/Shiba.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Shiba, from A to Z
===================
==================

About Shiba sub management modules
-----------------------------------
----------------------------------
All submodules included from the main **Shiba** package needs an instanced *ShibaConnection* class
defining your login and an identification token as parameter.

Expand All @@ -19,39 +19,39 @@ You can find some documentation about it looking into the lxml documentation_.
.. _documentation: http://lxml.de/objectify.html

AccountingManagement module
---------------------------------
---------------------------

.. automodule:: shiba.accountingmanagement
:members:
:undoc-members:
:show-inheritance:

InventoryManagement module
--------------------------------
--------------------------

.. automodule:: shiba.inventorymanagement
:members:
:undoc-members:
:show-inheritance:

MarketplaceManagement module
----------------------------------
----------------------------

.. automodule:: shiba.marketplacemanagement
:members:
:undoc-members:
:show-inheritance:

SalesManagement module
----------------------------
----------------------

.. automodule:: shiba.salesmanagement
:members:
:undoc-members:
:show-inheritance:

ShibaResponseObject module
----------------------------
--------------------------
Containing the object class returned by each method of the modules above.

.. automodule:: shiba.shibaresponseobject
Expand All @@ -60,15 +60,15 @@ Containing the object class returned by each method of the modules above.
:show-inheritance:

Shiba login ShibaConnection class
-----------------------------------
---------------------------------

.. automodule:: Shiba.shibaconnection
:members:
:undoc-members:
:show-inheritance:

Shiba exception classes
----------------------------
-----------------------

.. automodule:: shiba.shibaexceptions
:members:
Expand Down
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ This is the documentation for the `Shiba API`_ project on GitHub.
Hope you will find what you're looking for!

What is Shiba?
--------------------
--------------
**Shiba** is an API intended to bring an human handlable utilisation of the **PriceMinister WebServices** with **Python**.

It works through modules, imported to your scripts to fit your needs.

Contents
____________________
________

.. toctree::
:maxdepth: 2
Expand Down
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from setuptools import setup

setup(name= "Shiba",
packages= ["shiba"],
version = "1.1.2",
description= "A Python API for PriceMinister WebServices",
author= "Maxime Boguta",
author_email= "[email protected]",
url= "https://github.com/ShibaAPI/shiba",
download_url= "https://github.com/ShibaAPI/shiba/tarball/1.1.2",
keywords= ["api", "priceminister", "python", "webservices"],
setup(name="Shiba",
packages=["shiba"],
version="1.1.3",
description="A Python API for PriceMinister WebServices",
author="Maxime Boguta",
author_email="[email protected]",
url="https://github.com/ShibaAPI/shiba",
download_url="https://github.com/ShibaAPI/shiba/tarball/1.1.3",
keywords=["api", "priceminister", "python", "webservices"],
install_requires=["requests", "xmltodict", "lxml", "nose"],)
5 changes: 3 additions & 2 deletions shiba/accountingmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class AccountingManagement(object):
"""Accounting Management class, showing global financial operations on your account, or specific financial details
about an operation"""
def __init__(self, connection):
assert(isinstance(connection, ShibaConnection)), "error : you must give this instance a ShibaConnection instance"
assert(isinstance(connection, ShibaConnection)),\
"error : you must give this instance a ShibaConnection instance"
self.connection = connection

def get_operations(self, lastoperationdate=""):
Expand All @@ -43,4 +44,4 @@ def get_compensation_details(self, compensationid):
inf = ShibaTools.inf_constructor(self.connection, "getcompensationdetails", **locals())
url = ShibaTools.url_constructor(self.connection, inf)
obj = ShibaTools.retrieve_obj_from_url(url)
return obj
return obj
12 changes: 6 additions & 6 deletions shiba/marketplacemanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ def get_product_list(self, scope="", kw="", nav="", refs="", productids="", nbpr
"""
if (type(refs) is not list and type(refs) is not str and type(refs) is not unicode) or \
(type(productids) is not list and type(productids) is not str and type(productids) is not unicode):
raise ShibaCallingError \
("Shiba code error : expected list or str/unicode as refs and/or productids parameters"
", got " + unicode(type(refs)) + " as refs and " + unicode(type(productids))
+ " as productids instead.")
raise ShibaCallingError(
"Shiba code error : expected list or str/unicode as refs and/or productids parameters, got " +
unicode(type(refs)) + " as refs and " + unicode(type(productids)) +
" as productids instead.")
if type(refs) is list:
refs = ','.join(refs)
if type(productids) is list:
productids = ','.join(productids)
inf = ShibaTools.inf_constructor(self.connection, "listing", **locals())
url = ShibaTools.url_constructor(self.connection, inf, domain="http://ws.priceminister.com")
url = ShibaTools.url_constructor(self.connection, inf, domain="https://ws.priceminister.com")
obj = ShibaTools.retrieve_obj_from_url(url)
return obj

Expand All @@ -51,4 +51,4 @@ def get_category_map(self):
inf = ShibaTools.inf_constructor(self.connection, "categorymap", **locals())
url = ShibaTools.url_constructor(self.connection, inf, domain="http://ws.priceminister.com")
obj = ShibaTools.retrieve_obj_from_url(url)
return obj
return obj
2 changes: 1 addition & 1 deletion shiba/salesmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ def confirm_preorder(self, advertid, stock):
inf = ShibaTools.inf_constructor(self.connection, "confirmpreorder", **locals())
url = ShibaTools.url_constructor(self.connection, inf)
obj = ShibaTools.retrieve_obj_from_url(url)
return obj
return obj
54 changes: 30 additions & 24 deletions shiba/shibaconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ def __init__(self, login, pwd, sandbox=False):
self.login = str(login)
self.pwd = str(pwd)
self.domain = "https://ws.priceminister.com" if sandbox is False else "https://ws.sandbox.priceminister.com"
self.actionsinfo = \
{"producttypes": {"cat": "stock_ws", "version": "2011-11-29", "login": self.login, "pwd": self.pwd},
"producttypetemplate": {"cat": "stock_ws", "version": "2013-05-14", "login": self.login, "pwd": self.pwd},
"genericimportfile": {"cat": "stock_ws", "version": "2012-09-11", "login": self.login, "pwd": self.pwd},
"genericimportreport": {"cat": "stock_ws", "version": "2011-11-29", "login": self.login, "pwd": self.pwd},
"getavailableshippingtypes": {"cat": "sales_ws", "version": "2013-06-25", "login": self.login, "pwd": self.pwd},
"export": {"cat": "stock_ws", "version": "2014-01-28", "login": self.login, "pwd": self.pwd},
"listing": {"cat": "listing_ws", "version": "2014-01-28", "login": self.login, "pwd": self.pwd},
"categorymap": {"cat": "categorymap_ws", "version": "2011-10-11", "login": self.login, "pwd": self.pwd},
"getnewsales": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login, "pwd": self.pwd},
"acceptsale": {"cat": "sales_ws", "version": "2010-09-20", "login": self.login, "pwd": self.pwd},
"refusesale": {"cat": "sales_ws", "version": "2010-09-20", "login": self.login, "pwd": self.pwd},
"getcurrentsales": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login, "pwd": self.pwd},
"getbillinginformation": {"cat": "sales_ws", "version": "2011-03-29", "login": self.login, "pwd": self.pwd},
"getshippinginformation": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login, "pwd": self.pwd},
"getitemtodolist": {"cat": "sales_ws", "version": "2011-09-01", "login": self.login, "pwd": self.pwd},
"getiteminfos": {"cat": "sales_ws", "version": "2011-06-01", "login": self.login, "pwd": self.pwd},
"cancelitem": {"cat": "sales_ws", "version": "2011-02-02", "login": self.login, "pwd": self.pwd},
"contactusaboutitem": {"cat": "sales_ws", "version": "2011-09-01", "login": self.login, "pwd": self.pwd},
"contactuseraboutitem": {"cat": "sales_ws", "version": "2011-02-02", "login": self.login, "pwd": self.pwd},
"settrackingpackageinfos": {"cat": "sales_ws", "version": "2012-11-06", "login": self.login, "pwd": self.pwd},
"confirmpreorder": {"cat": "sales_ws", "version": "2013-01-09", "login": self.login, "pwd": self.pwd},
"getoperations": {"cat": "wallet_ws", "version": "2011-03-29", "login": self.login, "pwd": self.pwd},
"getcompensationdetails": {"cat": "sales_ws", "version": "2011-03-29", "login": self.login, "pwd": self.pwd}}
self.actionsinfo = {
"producttypes": {"cat": "stock_ws", "version": "2011-11-29", "login": self.login, "pwd": self.pwd},
"producttypetemplate": {"cat": "stock_ws", "version": "2013-05-14", "login": self.login, "pwd": self.pwd},
"genericimportfile": {"cat": "stock_ws", "version": "2012-09-11", "login": self.login, "pwd": self.pwd},
"genericimportreport": {"cat": "stock_ws", "version": "2011-11-29", "login": self.login, "pwd": self.pwd},
"getavailableshippingtypes": {"cat": "sales_ws", "version": "2013-06-25", "login": self.login,
"pwd": self.pwd},
"export": {"cat": "stock_ws", "version": "2014-01-28", "login": self.login, "pwd": self.pwd},
"listing": {"cat": "listing_ssl_ws", "version": "2015-07-05", "login": self.login, "pwd": self.pwd},
"categorymap": {"cat": "categorymap_ws", "version": "2011-10-11", "login": self.login, "pwd": self.pwd},
"getnewsales": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login, "pwd": self.pwd},
"acceptsale": {"cat": "sales_ws", "version": "2010-09-20", "login": self.login, "pwd": self.pwd},
"refusesale": {"cat": "sales_ws", "version": "2010-09-20", "login": self.login, "pwd": self.pwd},
"getcurrentsales": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login, "pwd": self.pwd},
"getbillinginformation": {"cat": "sales_ws", "version": "2011-03-29", "login": self.login,
"pwd": self.pwd},
"getshippinginformation": {"cat": "sales_ws", "version": "2014-02-11", "login": self.login,
"pwd": self.pwd},
"getitemtodolist": {"cat": "sales_ws", "version": "2011-09-01", "login": self.login, "pwd": self.pwd},
"getiteminfos": {"cat": "sales_ws", "version": "2011-06-01", "login": self.login, "pwd": self.pwd},
"cancelitem": {"cat": "sales_ws", "version": "2011-02-02", "login": self.login, "pwd": self.pwd},
"contactusaboutitem": {"cat": "sales_ws", "version": "2011-09-01", "login": self.login, "pwd": self.pwd},
"contactuseraboutitem": {"cat": "sales_ws", "version": "2011-02-02", "login": self.login, "pwd": self.pwd},
"settrackingpackageinfos": {"cat": "sales_ws", "version": "2012-11-06", "login": self.login,
"pwd": self.pwd},
"confirmpreorder": {"cat": "sales_ws", "version": "2013-01-09", "login": self.login, "pwd": self.pwd},
"getoperations": {"cat": "wallet_ws", "version": "2011-03-29", "login": self.login, "pwd": self.pwd},
"getcompensationdetails": {"cat": "sales_ws", "version": "2011-03-29", "login": self.login,
"pwd": self.pwd}
}
25 changes: 13 additions & 12 deletions shiba/shibatools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import requests
import xmltodict


"""Tools used by Shiba data retrieving classes"""


class ShibaTools(object):
@staticmethod
def __errors_check(obj):
Expand All @@ -39,20 +40,20 @@ def __errors_check(obj):
if "errorresponse" in obj.tag:
if "ServerError" == obj.error.code:
raise ShibaParameterError("Parameter error : " + obj.error.message +
" - Reason : " + obj.error.details.detail)
" - Reason : " + obj.error.details.detail)
if "ParameterError" == obj.error.code:
raise ShibaParameterError("Parameter error : " + obj.error.message +
" - Reason : " + obj.error.details.detail)
" - Reason : " + obj.error.details.detail)
if "InvalidUserConnection" == obj.error.code:
raise ShibaLoginError("Invalid user connection : " + obj.error.message +
" - Reason : " + obj.error.details.detail)
" - Reason : " + obj.error.details.detail)
if "InvalidUserRights" == obj.error.code:
if "Quota exceeded" in obj.error.message.text:
raise ShibaQuotaExceededError("Too many requests : " + obj.error.message +
" - Reason : " + obj.error.details.detail)
" - Reason : " + obj.error.details.detail)
else:
raise ShibaRightsError("Invalid user rights : " + obj.error.message +
" - Reason : " + obj.error.details.detail)
" - Reason : " + obj.error.details.detail)
return obj
return False

Expand All @@ -65,13 +66,12 @@ def post_request(url, data):
:rtype: plain text from servers response
"""
header = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 6.1; de-DE; rv:1.9.0.10) "
"Gecko/2009042316 Firefox/3.0.10 (.NET CLR 4.0.20506)"}
"Gecko/2009042316 Firefox/3.0.10 (.NET CLR 4.0.20506)"}
data = data.encode('utf-8')
d = {"file": data}
r = requests.post(url, files=d, headers=header)
return r.text


@staticmethod
def retrieve_obj_from_url(url, data=None):
"""Give it an URL, will send you back an object based on received XML from WebService, it removes and store
Expand Down Expand Up @@ -110,7 +110,8 @@ def retrieve_obj_from_url(url, data=None):
xmlepured = xmlepured.encode('utf-8')
obj = objectify.fromstring(xmlepured)
except:
raise ShibaUnknownServiceError("Unknown error from service or from internal modules : Service returned : " + xml)
raise ShibaUnknownServiceError(
"Unknown error from service or from internal modules : Service returned : " + xml)
if ShibaTools.__errors_check(obj) is not False:
try:
if "Unknown error" == obj.error.code:
Expand All @@ -121,7 +122,7 @@ def retrieve_obj_from_url(url, data=None):
" : " + obj.error.message + " - Reason : " + obj.error.details.detail)
except:
raise ShibaUnknownServiceError("An unknown error from the WebService has occurred - XML dump : " +
etree.tostring(obj))
etree.tostring(obj))
return ShibaResponseObject(namespace, obj, xml.encode('utf-8'))

@staticmethod
Expand Down Expand Up @@ -160,8 +161,8 @@ def inf_constructor(shibaconnection, action, **kwargs):
raise ShibaCallingError("Internal parameter error : shibaconnection parameter is not "
"a ShibaConnection instance")
if action not in shibaconnection.actionsinfo:
raise ShibaCallingError("Internal parameter error : action parameter "
+ action + " is unknown from the actions list")
raise ShibaCallingError("Internal parameter error : action parameter " +
action + " is unknown from the actions list")
newkwargs = {}
for each in kwargs:
if kwargs[each] is not None and kwargs[each] != "":
Expand Down
Loading

0 comments on commit 3ebfdb4

Please sign in to comment.