Commits

Branko Vukelic  committed 762bccf

Fixed endpoint class because API docs are horrible

  • Participants
  • Parent commits 6f0a898

Comments (0)

Files changed (2)

File mstranslator/endpoints/__init__.py

+from base import *
+from translate import TranslateEndpoint
+

File mstranslator/endpoints/base.py

 
 from urllib import urlencode
 
+from mstranslator.utils import Constant
+
+__all__ = ['AUDIO', 'CONTENT', 'Endpoint', 'GetEndpoint']
+
+AUDIO = Constant(
+    MAX='MaxQuality',
+    MIN='MinSize',
+)
+
+CONTENT = Constant(
+    HTML='text/html',
+    TXT='text/plain',
+)
+
+LANGUAGES = (
+    ('ar' 'Arabic'),
+    ('bg' 'Bulgarian'),
+    ('ca', 'Catalan'),
+    ('zh-CHS', 'Chinese (Simplified)'),
+    ('zh-CHT', 'Chinese (Traditional)'),
+    ('cs', 'Czech'),
+    ('da', 'Danish'),
+    ('nl', 'Dutch'),
+    ('en', 'English'),
+    ('et', 'Estonian'),
+    ('fa', 'Persian (Farsi)'),
+    ('fi', 'Finnish'),
+    ('fr', 'French'),
+    ('de', 'German'),
+    ('el', 'Greek'),
+    ('ht', 'Haitian Creole'),
+    ('he', 'Hebrew'),
+    ('hi', 'Hindi'),
+    ('hu', 'Hungarian'),
+    ('id', 'Indonesian'),
+    ('it', 'Italian'),
+    ('ja', 'Japanese'),
+    ('ko', 'Korean'),
+    ('lv', 'Latvian'),
+    ('lt', 'Lithuanian'),
+    ('mww', 'Hmong Daw'),
+    ('no', 'Norwegian'),
+    ('pl', 'Polish'),
+    ('pt', 'Portuguese'),
+    ('ro', 'Romanian'),
+    ('ru', 'Russian'),
+    ('sk', 'Slovak'),
+    ('sl', 'Slovenian'),
+    ('es', 'Spanish'),
+    ('sv', 'Swedish'),
+    ('th', 'Thai'),
+    ('tr', 'Turkish'),
+    ('uk', 'Ukrainian'),
+    ('vi', 'Vietnamese '),
+)
+
+LANGUAGE_CODES = [l[0] for l in LANGUAGES]
 
 class Endpoint(object):
     endpoint = None
-    api_protocol = 'http'
-    api_host = 'api.microsofttranslator.com'
-    api_version = 'v2'
-    api_endpoint_base = 'Http.svc'
+    api_protocol = 'https'
+    api_base = 'api.datamarket.azure.com/Bing/MicrosoftTranslator'
+    api_version = 'v1'
     params = {}
     data = None
 
         pass
 
     def convert_kwargs(self, kwargs):
+        if 'self' in kwargs:
+            del kwargs['self']
         if 'tfrom' in kwargs:
             kwargs['from'] = kwargs['tfrom']
             del kwargs['tfrom']
 
         final = ''
         parts = s.split('_')
-        final += parts.pop(0).lower()
 
         for p in parts:
             final += p[0].upper() + p[1:]
         if not self.endpoint:
             raise NotImplementedError('You must set endpoint attribute')
 
-        return '%s://%s/%s/%s/%s' % (
+        return '%s://%s/%s/%s' % (
             self.api_protocol,
-            self.api_host,
+            self.api_base,
             self.api_version,
-            self.api_endpoint_base,
             self.endpoint
         )
 
         raise NotImplementedError('Please override this method in subclass')
 
 
-class GetEndpoint(object):
+class GetEndpoint(Endpoint):
     def store_data(self):
         raise RuntimeError('GET endpoints have no data')