Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
add Enabling an App functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bebef1987 committed Dec 3, 2012
1 parent c29cb9a commit baad2e7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
11 changes: 11 additions & 0 deletions example/commands.py
Expand Up @@ -150,3 +150,14 @@ def get_categories(client):
message += '%s: %s\n' % (cat['id'], cat['name'])
return {'success': True,
'message': message}

def app_state(client, app_id, status=None, disabled_by_user=None):
response = client.app_state(app_id, status, disabled_by_user)
if response.status_code != 202:
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 content.items()])}
3 changes: 2 additions & 1 deletion example/main.py
Expand Up @@ -15,7 +15,8 @@
'add_screenshot': commands.add_screenshot,
'get_screenshot': commands.get_screenshot,
'del_screenshot': commands.del_screenshot,
'get_categories': commands.get_categories}
'get_categories': commands.get_categories,
'app_state': commands.app_state}

def main():
parser = argparse.ArgumentParser(
Expand Down
33 changes: 32 additions & 1 deletion marketplace/client.py
Expand Up @@ -29,7 +29,8 @@
'app': '/apps/app/%s/',
'create_screenshot': '/apps/preview/?app=%s',
'screenshot': '/apps/preview/%s/',
'categories': '/apps/category/'}
'categories': '/apps/category/',
'enable': '/apps/status/%s/'}


class Client:
Expand Down Expand Up @@ -224,3 +225,33 @@ def get_categories(self):
"""Get all categories from Marketplae
"""
return self.conn.fetch('GET', self.url('categories'))

def app_state(self, app_id, status=None, disabled_by_user=None):
"""Once all the data has been completed and at least one screenshot created,
you can push the app to the review queue
status (optional): key statuses are
incomplete: incomplete
pending: pending
public: public
waiting: waiting to be public
disabled_by_user (optional): True or False
Valid transitions that users can initiate are:
waiting to be public to public: occurs when the app has been reviewed, but not yet been made public.
incomplete to pending: call this once your app has been completed and it will be added to the Marketplace review queue.
This can only be called if all the required data is there. If not, you'll get an error containing the reason
disabled_by_user: by changing this value from True to False you can enable or disable an app
"""
assert status is not None or disabled_by_user is not None
data = {}
if status:
data['status'] = status
if disabled_by_user:
data['disabled_by_user'] = disabled_by_user

return self.conn.fetch('PATCH',
self.url('enable') % app_id, data)
8 changes: 8 additions & 0 deletions marketplace/tests/test_client.py
Expand Up @@ -214,3 +214,11 @@ def test_add_screenshot(self):
data = json.loads(requests.post.call_args[1]['data'])
eq_(data['position'], 2)
eq_(data['file']['type'], 'image/jpeg')

def test_enable(self):
resp = {"status": "pending",
"disabled_by_user":True}
requests.patch = Mock(return_value=Response(202, json.dumps(resp)))

response = self.marketplace.app_state(123, status='pending', disabled_by_user='True')
eq_(response.status_code,202)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name='Marketplace',
version='0.1.3a',
version='0.1.4a',
packages=['marketplace', ],
license='Mozilla Public License (MPL 2.0)',
author='Piotr Zalewa',
Expand Down

0 comments on commit baad2e7

Please sign in to comment.