Permalink
Browse files

Merge pull request #18 from zalun/creating_package

I'll merge it - too many commits anyway
  • Loading branch information...
2 parents b6ce526 + ae2bfba commit 44ecb3ee83a72c6d723da7c6a5d17a6f22b2c40b @zalun zalun committed Oct 8, 2012
View
27 LICENSE
@@ -1,27 +0,0 @@
-Copyright (c) 2012, Mozilla Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation
-and/or other materials provided with the distribution.
-
-* Neither the name of the Mozilla Corporation nor the names of its contributors
-may be used to endorse or promote products derived from this software without
-specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,45 +1,24 @@
-Examples of the Marketplace clients
-===================================
+Marketplace Client Library
+==========================
-Python
-######
-**Marketplace command line client**
+Mozilla is building a Marketplace to bring personalized discovery,
+worldwide distribution, and easy payments to the largest platform
+for app development: the Web.
-Install requirements::
+This library helps to create Python based sites or apps to communicate
+with Marketplace.
- cd python
- pip install -r requirements.txt
+You may find and collaborate your time and experience at
+https://github.com/mozilla/Marketplace.Python
-Test::
-
- nosetests
-
-Usage
------
-
-* Set CONSUMER_KEY and CONSUMER_SECRET environment variables::
-
- export CONSUMER_KEY=yourconsumerkey
- export CONSUMER_SECRET=yourconsumersecret
-
-* Validate manifest. Will return ``manifest_id`` which is needed for the next steps::
-
- python main.py validate_manifest http://mozilla.github.com/MarketplaceClientExample/manifest.webapp
+Testing
+#######
-* Check if the manifest is valid::
+Install test environment::
- python main.py is_manifest_valid your_manifest_id
-
-* Add app to marketplace, app_id will be returned::
-
- python main.py create your_manifest_id
-
-* Display status of the app::
-
- python main.py status your_app_id
-
-* Add screenshot (currently only JPEG) to app, some data including id will be returned::
-
- python main.py add_screenshot your_app_id ~/data/some.jpg
+ pip install mock
+ pip install nose
+Test::
+ nosetests
View
@@ -0,0 +1,36 @@
+Command Line Marketplace Client
+===============================
+
+Install requirements::
+
+ pip install -r requirements.txt
+
+Usage
+-----
+
+* Set CONSUMER_KEY and CONSUMER_SECRET environment variables::
+
+ export CONSUMER_KEY=yourconsumerkey
+ export CONSUMER_SECRET=yourconsumersecret
+
+* Validate manifest. Will return ``manifest_id`` which is needed for the next steps::
+
+ python main.py validate_manifest http://mozilla.github.com/MarketplaceClientExample/manifest.webapp
+
+* Check if the manifest is valid::
+
+ python main.py is_manifest_valid your_manifest_id
+
+* Add app to marketplace, app_id will be returned::
+
+ python main.py create your_manifest_id
+
+* Display status of the app::
+
+ python main.py status your_app_id
+
+* Add screenshot (currently only JPEG) to app, some data including id will be returned::
+
+ python main.py add_screenshot your_app_id ~/data/some.jpg
+
+
File renamed without changes.
@@ -1,13 +1,7 @@
-import time
-import requests
+"""Commands to run on the Marketplace API
+"""
import sys
-
import json
-import oauth2 as oauth
-
-import config
-
-from lib.marketplace import Marketplace
def validate_manifest(auth, manifest_url):
@@ -64,24 +58,24 @@ def update(auth, app_id):
# obtaining current data
data = json.loads(auth.status(app_id).content)
data['payment_type'] = data['premium_type']
- for k in data.keys():
- if k not in editable_keys:
- del data[k]
+ for key in data.keys():
+ if key not in editable_keys:
+ del data[key]
sys.stderr.write('Please provide data, hit Enter for no change\n')
- def get_value(k, v):
- variable = raw_input('%s (%s): ' % (k, v))
- if k in truthy_keys and not variable and not v:
+ def get_value(key, val):
+ variable = raw_input('%s (%s): ' % (key, val))
+ if key in truthy_keys and not variable and not val:
sys.stdout.write('This parameter is required.\n')
- variable = get_value(k, v)
+ variable = get_value(key, val)
return variable
- for k, v in data.items():
- if k in editable_keys:
- variable = get_value(k, v)
+ for key, val in data.items():
+ if key in editable_keys:
+ variable = get_value(key, val)
if variable != '':
- if isinstance(v, list):
- data[k] = variable.split(',')
+ if isinstance(val, list):
+ data[key] = variable.split(',')
else:
- data[k] = variable
+ data[key] = variable
response = auth.update(app_id, data)
if response.status_code != 202:
return {'success': False,
@@ -1,5 +1,5 @@
-import oauth2 as oauth
-
+"""Read config from environment variables
+"""
from os import environ
CONSUMER_KEY = (environ['CONSUMER_KEY']
View
@@ -0,0 +1,47 @@
+import argparse
+import sys
+
+import commands
+import config
+
+import marketplace
+
+COMMANDS = {'validate_manifest': commands.validate_manifest,
+ 'is_manifest_valid': commands.is_manifest_valid,
+ 'create': commands.create,
+ 'status': commands.status,
+ 'update': commands.update,
+ 'add_screenshot': commands.add_screenshot,
+ 'get_screenshot': commands.get_screenshot,
+ 'del_screenshot': commands.del_screenshot,
+ 'get_categories': commands.get_categories}
+
+def main():
+ parser = argparse.ArgumentParser(
+ description='Command line Marketplace client')
+ parser.add_argument('method', type=str,
+ help='command to be run on arguments', choices=COMMANDS.keys())
+ parser.add_argument('attrs', metavar='attr', type=str, nargs='*',
+ help='command arguments')
+ args = parser.parse_args()
+
+ client = marketplace.Client(
+ domain=config.MARKETPLACE_DOMAIN,
+ protocol=config.MARKETPLACE_PROTOCOL,
+ port=config.MARKETPLACE_PORT,
+ consumer_key=config.CONSUMER_KEY,
+ consumer_secret=config.CONSUMER_SECRET)
+
+ if args.attrs:
+ result = COMMANDS[args.method](client, *args.attrs)
+ else:
+ result = COMMANDS[args.method](client)
+
+ if result['success']:
+ sys.stdout.write('%s\n' % result['message'])
+ else:
+ sys.stderr.write('%s\n' % result['message'])
+ sys.exit(1)
+
+if __name__ == "__main__":
+ main()
View
@@ -0,0 +1 @@
+marketplace
View
@@ -0,0 +1,19 @@
+"""Marketplace Client Library
+
+https://wiki.mozilla.org/Marketplace
+
+Mozilla is building a Marketplace to bring personalized discovery,
+worldwide distribution, and easy payments to the largest platform
+for app development: the Web.
+
+This library helps to create Python based sites or apps to communicate
+with Marketplace.
+"""
+
+__version__ = '0.1'
+__all__ = [
+ 'Client',
+]
+__author__ = 'Piotr Zalewa <zalun@mozilla.com>'
+
+from .client import Client
Oops, something went wrong.

0 comments on commit 44ecb3e

Please sign in to comment.