-from __future__ import absolute_import
+"""
+YouMagine communication module.
+This module handles all communication with the YouMagine API.
+"""
__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
import json
import httplib as httpclient
import urllib
+import textwrap
class httpUploadDataStream(object):
+ """
+ For http uploads we need a readable/writable datasteam to use with the httpclient.HTTPSConnection class.
+ This is used to facilitate file uploads towards Youmagine.
+ """
def __init__(self, progressCallback):
self._dataList = []
self._totalLength = 0
return self._totalLength
class Youmagine(object):
+ """
+ Youmagine connection object. Has various functions to communicate with Youmagine.
+ These functions are blocking and thus this class should be used from a thread.
+ """
def __init__(self, authToken, progressCallback = None):
self._hostUrl = 'api.youmagine.com'
self._viewUrl = 'www.youmagine.com'
('Jewelry', 7),
('Maker/DIY', 8),
('Miniatures', 9),
+ ('Toys', 10),
+ ('3D printer parts and enhancements', 11),
('Other', 1),
]
self._licenses = [
- ('Creative Commons - Share Alike', 'cc'),
- ('Creative Commons - Attribution-NonCommercial-ShareAlike', 'ccnc'),
+ ('Creative Commons - Attribution Share Alike', 'ccbysa'),
+ ('Creative Commons - Attribution Non-Commercial ShareAlike', 'ccbyncsa'),
+ ('Creative Commons - Attribution No Derivatives', 'ccbynd'),
+ ('Creative Commons - Attribution Non-Commercial No Derivatives', 'ccbyncsa'),
('GPLv3', 'gplv3'),
]
return True
def createDesign(self, name, description, category, license):
- res = self._request('POST', '/designs.json', {'design[name]': name, 'design[excerpt]': description, 'design[design_category_id]': filter(lambda n: n[0] == category, self._categories)[0][1], 'design[license]': filter(lambda n: n[0] == license, self._licenses)[0][1]})
+ excerpt = description
+ description = ''
+ if len(excerpt) >= 300:
+ lines = textwrap.wrap(excerpt, 300)
+ excerpt = lines[0]
+ description = '\n'.join(lines[1:])
+ res = self._request('POST', '/designs.json', {'design[name]': name, 'design[excerpt]': excerpt, 'design[description]': description, 'design[design_category_id]': filter(lambda n: n[0] == category, self._categories)[0][1], 'design[license]': filter(lambda n: n[0] == license, self._licenses)[0][1]})
if 'id' in res:
return res['id']
print res
def publishDesign(self, id):
res = self._request('PUT', '/designs/%d/mark_as/publish.json' % (id), {'ignore': 'me'})
if res is not None:
- print res
return False
return True
return {'error': error}
-#Fake Youmagine class to test without internet
class FakeYoumagine(Youmagine):
- def __init__(self, authToken):
+ """
+ Fake Youmagine class to test without internet, acts the same as the YouMagine class, but without going to the internet.
+ Assists in testing UI features.
+ """
+ def __init__(self, authToken, callback):
super(FakeYoumagine, self).__init__(authToken)
self._authUrl = 'file:///C:/Models/output.html'
self._authToken = None
def _request(self, method, url, postData = None, files = None):
print "Err: Tried to do request: %s %s" % (method, url)
-
-def main():
- ym = Youmagine('j3rY9kQF62ptuZF7vqbR')
- if not ym.isAuthorized():
- print "Failed to authorize"
- return
- for design in ym.listDesigns():
- print design['name']