I have begun work on a django app called satchmobile [1]. It is
essentially a set of web services that expose satchmo data in json
format. At this point it is very nascent and a bit hackish, but not
for long (Lord willing). I am using these services to create some
mobile apps for both android and iOS (i.e. iphone / ipad). The mobile
apps will likely remain closed-source, but I plan to contribute the
web services application back to the community.
Has the idea of satchmo web services been considered / discussed here
before? (The list archives seem to indicate no.) Is there any interest
in having these services included as an app within the satchmo project
itself? Basically I am trying to decide whether to fork/branch satchmo
and develop satchmobile as an app there, or to continue as I have
begun, with the web services in a project completely separate from
(although dependent upon) satchmo.
Any insight / feedback greatly appreciated!
1: https://bitbucket.org/sclaughl/satchmobile
--Stuart
I have implemented webservices on my shop, based on a snippet from the internet with soaplib (hereunder the skeleton). I also have a mobile version (raw hack) of the shop based on dojo mobile. It however keeps the logic of Satchmo
regards,
marc
import StringIO
import base64
from soaplib.serializers.primitive import Boolean, String
from soaplib.service import DefinitionBase, rpc
from soaplib.wsgi import Application
from django.conf import settings
from settings import PROJECT_DIR
from django.http import HttpResponse
def extract_basic_credentials(request):
"""Extact authorization basic credentials from request"""
username, password = None, None
if 'HTTP_AUTHORIZATION' in request.META:
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2:
if auth[0].lower() == "basic":
username, password = base64.b64decode(auth[1]).split(':')
return username, password
class Http401(Exception):
pass
class Http403(Exception):
pass
class DumbStringIO(StringIO.StringIO):
def read(self, n):
return self.getvalue()
# the class which acts as a wrapper between soaplib WSGI functionality and Django
class DjangoSoapApp(Application):
def authenticate(self, request):
"""Authenticate webservice request."""
ws_username = getattr(settings, 'WS_USERNAME', None)
if ws_username:
ws_password = getattr(settings, 'WS_PASSWORD', None)
username, password = extract_basic_credentials(request)
if username == None:
raise Http401("401 Authentication required.")
if username != ws_username or password != ws_password:
raise Http403("403 You're not authorized to use this webservice!")
def __call__(self, request):
# wrap the soaplib response into a Django response object
#self.authenticate(request)g
django_response = HttpResponse()
def start_response(status, headers):
status, reason = status.split(' ', 1)
django_response.status_code = int(status)
for header, value in headers:
django_response[header] = value
environ = request.META.copy()
environ['CONTENT_LENGTH'] = len(request.raw_post_data)
environ['wsgi.input'] = DumbStringIO(request.raw_post_data)
environ['wsgi.multithread'] = False
response = super(DjangoSoapApp, self).__call__(environ, start_response)
django_response.content = '\n'.join(response)
if django_response.status_code == 405:
return HttpResponse("405 Method not allowed for this webservice.",
'text/plain', status=405)
return django_response
from soaplib_handler import DjangoSoapApp
from soaplib.serializers.primitive import Boolean, String, Integer
from soaplib.serializers.clazz import Array
from soaplib.service import DefinitionBase, rpc
from soaplib.wsgi import Application
from django.utils import simplejson
from django.core import serializers
import logging
log = logging.getLogger()
# the class with actual web methods
class MesserShopService(DefinitionBase):
__tns__ = 'http://localhost:8000/webservice/liferay'
@rpc( String, String, String, _returns=String)
def Product(self,language, products):
---- retrieve the --- models you want
return proposals
my_Liferay = DjangoSoapApp([MesserShopService], MesserShopService.__tns__)
1: https://bitbucket.org/sclaughl/satchmobile
--Stuart
--
You received this message because you are subscribed to the Google Groups "Satchmo developers" group.
To post to this group, send email to satchmo-d...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-developers?hl=en.
I like your idea about having this application under satchmo_ext.
Frankly I don't know why I didn't think of that myself! In light of
that idea and Chris's reply, my current plan is to fork satchmo on
bitbucket and develop satchmobile as an app under satchmo_ext. That
way, when I make sufficient progress, I can simply submit a pull
request and go through the normal approval process to be included in
the main satchmo repository.
You also raise some good questions about testing. I need to do some
thinking about the best way to do this -- I feel it's a bit odd since
they are services without a client (or with various unknown clients,
you might say).
In terms of trying out the mobile apps, my colleague and I are still
discussing how to best do that. We very well may do something as you
suggested, e.g. freely distribute a mobile app that only has the
ability to browse the product catalog but lacks the ability to add to
cart, wishlist, etc. In the meantime, we have placed some information
(including screenshots) on my colleague's site [1,2]. The 'real' site
is forthcoming.
1: http://johnheerman.com/portfolio/
2: http://johnheerman.com/portfolio/kessel/
Thanks again for the feedback; it's always welcome!
--Stuart