Skip to content
Browse files

Merge pull request #5 from zalun/issue_3-add_screenshots

Screenshot create added
  • Loading branch information...
2 parents f62964b + 469251b commit 9a570a9042447566edeaa987c2f2d35e5f51e829 @fwenzel fwenzel committed Jun 27, 2012
Showing with 75 additions and 4 deletions.
  1. +30 −0 python/app/commands.py
  2. +0 −2 python/app/config.py
  3. +42 −1 python/lib/marketplace.py
  4. +3 −1 python/main.py
View
30 python/app/commands.py
@@ -51,3 +51,33 @@ def status(auth, app_id):
return {'success': True,
'message': '\n'.join(
['%s: %s' % (k, v) for k, v in content.items()])}
+
+def add_screenshot(auth, app_id, filename):
+ response = auth.create_screenshot(app_id, filename)
+ if response.status_code != 201:
+ return {'success': False,
+ 'message': 'Error, status code: %d, \nMessage: %s' % (
+ response.status_code, response.content)}
+ return {'success': True,
+ 'message': '\n'.join(
+ ['%s: %s' % (k, v) for k, v in response.content.items()])}
+
+def get_screenshot(auth, screenshot_id):
+ response = auth.get_screenshot(screenshot_id)
+ if response.status_code != 200:
+ return {'success': False,
+ 'message': 'Error, status code: %d, \nMessage: %s' % (
+ response.status_code, response.content)}
+ content = json.loads(response.content)
+ return {'success': True,
+ 'message': '\n'.join(
+ ['%s: %s' % (k, v) for k, v in response.content.items()])}
+
+def del_screenshot(auth, screenshot_id):
+ response = auth.del_screenshot(screenshot_id)
+ if response.status_code != 204:
+ return {'success': False,
+ 'message': 'Error, status code: %d, \nMessage: %s' % (
+ response.status_code, response.content)}
+ return {'success': True,
+ 'message': 'Screenshot deleted'}
View
2 python/app/config.py
@@ -7,8 +7,6 @@
CONSUMER_SECRET = (environ['CONSUMER_SECRET']
if 'CONSUMER_SECRET' in environ else 'consumer_secret')
-CONSUMER = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
-
MARKETPLACE_PORT = (environ['MARKETPLACE_PORT']
if 'MARKETPLACE_PORT' in environ else 443)
MARKETPLACE_DOMAIN = (environ['MARKETPLACE_DOMAIN']
View
43 python/lib/marketplace.py
@@ -10,6 +10,8 @@
import time
import urllib
+from base64 import b64encode
+
import httplib2
import oauth2 as oauth
import requests
@@ -26,6 +28,8 @@
'validation_result': '/apps/validation/%s/',
'create': '/apps/app/',
'app': '/apps/app/%s/',
+ 'create_screenshot': '/apps/preview/?app=%s',
+ 'screenshot': '/apps/preview/%s/',
}
def _get_args(consumer):
@@ -205,7 +209,7 @@ def status(self, app_id):
:returns: HttResponse:
* status_code (int) 200 if successful
- * content (dict) with all available app information
+ * content (JSON String) with all available app information
"""
return self.get(self.url('app') % app_id)
@@ -214,3 +218,40 @@ def delete(self, app_id):
"""
# XXX: This isn't yet implemented on API
return self.remove(self.url('app') % app_id)
+
+ def create_screenshot(self, app_id, filename, position=1):
+ """Add a screenshot to the web app identified by by ``app_id``.
+ Screenshots are ordered by ``position``.
+
+ :returns: HttpResponse:
+ * status_code (int) 201 is successful
+ * content (dict) containing screenshot data
+ """
+ # prepare file for upload
+ with open(filename, 'rb') as s_file:
+ s_content = s_file.read()
+ s_encoded = b64encode(s_content)
+ url = self.url('create_screenshot') % app_id
+ # TODO find the mimetype of the file
+ mimetype = 'image/jpg'
+ data = {'position': position,
+ 'file': {'type': mimetype,
+ 'data': s_encoded}}
+ return self.post(url, data)
+
+ def get_screenshot(self, screenshot_id):
+ """Get information about screenshot or video
+
+ :returns HttpResponse:
+ * status_code (int) 200 is successful
+ * content (JSON string)
+ """
+ return self.get(self.url('screenshot') % screenshot_id)
+
+ def del_screenshot(self, screenshot_id):
+ """Deletes screenshot
+
+ :returns: HttpResponse:
+ * status_code (int) 204 if successful
+ """
+ return self.get(self.url('screenshot') % screenshot_id)
View
4 python/main.py
@@ -10,7 +10,9 @@
'is_manifest_valid': app.commands.is_manifest_valid,
'create': app.commands.create,
'status': app.commands.status,
- 'add_screenshot': app.commands.add_screenshot}
+ 'add_screenshot': app.commands.add_screenshot,
+ 'get_screenshot': app.commands.get_screenshot,
+ 'del_screenshot': app.commands.del_screenshot}
parser = argparse.ArgumentParser(description='Command line Marketplace client')
parser.add_argument('method', type=str, help='command to be run on arguments',

0 comments on commit 9a570a9

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