Beispiel #1
0
 def _put(self, path, callback, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = Soup.Message.new('PUT', self._url(path))
     body = urlencode(args)
     msg.set_request('application/x-www-form-urlencoded',
                     Soup.MemoryUse.COPY, body)
     download_json(msg, self._cancellable, callback, None)
Beispiel #2
0
 def _post(self, path, callback, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = Soup.Message.new('POST', self._url(path))
     post_body = urlencode(args)
     if not isinstance(post_body, bytes):
         post_body = post_body.encode("ascii")
     msg.set_request('application/x-www-form-urlencoded',
                     Soup.MemoryUse.COPY, post_body)
     download_json(msg, self._cancellable, callback, None)
Beispiel #3
0
 def _post(self, path, callback, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = Soup.Message.new('POST', self._url(path))
     post_body = urlencode(args)
     if not isinstance(post_body, bytes):
         post_body = post_body.encode("ascii")
     msg.set_request('application/x-www-form-urlencoded',
                     Soup.MemoryUse.COPY, post_body)
     download_json(msg, self._cancellable, callback, None)
Beispiel #4
0
 def _handle_search_response(self, message, json_dict, data=None):
     if not json_dict:
         print_d('Server did not return any valid JSON')
         return self.emit('search-complete', [])
     try:
         results = json_dict.get('results', [])
         covers = filter(None, (self.result_for(r.get('cover_image', None))
                                for r in results))
         if covers:
             return self.emit('search-complete', list(covers))
         res_url = results[0].get('resource_url', '')
     except IndexError:
         return self.emit('search-complete', [])
     else:
         msg = Soup.Message.new('GET',
                                "%s?%s" % (res_url, self.credentials))
         download_json(msg, self.cancellable, self._handle_album_data, None)
Beispiel #5
0
 def _handle_search_response(self, message, json_dict, data=None):
     if not json_dict:
         print_d('Server did not return any valid JSON')
         return self.emit('search-complete', [])
     try:
         results = json_dict.get('results', [])
         covers = filter(None, (self.result_for(r.get('cover_image', None))
                                for r in results))
         if covers:
             return self.emit('search-complete', list(covers))
         res_url = results[0].get('resource_url', '')
     except IndexError:
         return self.emit('search-complete', [])
     else:
         msg = Soup.Message.new('GET',
                                "%s?%s" % (res_url, self.credentials))
         download_json(msg, self.cancellable, self._handle_album_data, None)
Beispiel #6
0
    def search_data(self, message, json_dict, data=None):
        if not json_dict:
            print_d('Server did not return valid JSON')
            return self.emit('search-complete', [])

        # debug
        # self.pretty_json(json_dict)

        try:
            res_url = json_dict.get('results', [])[0].get('resource_url', '')
        except IndexError:
            res_url = ''

        if not res_url:
            print_d('Album data is not available')
            return self.emit('search-complete', [])

        msg = Soup.Message.new('GET', res_url + self.credentials)
        download_json(msg, self.cancellable, self.album_data, None)
Beispiel #7
0
 def search(self):
     if not self.url:
         return self.emit('search-complete', [])
     msg = Soup.Message.new('GET', self.url)
     download_json(msg, self.cancellable, self.album_data, None)
Beispiel #8
0
 def _get(self, path, callback, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = Soup.Message.new('GET', self._url(path, args))
     download_json(msg, self._cancellable, callback, None)
Beispiel #9
0
 def _get(self, path, callback, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = Soup.Message.new('GET', self._url(path, args))
     download_json(msg, self._cancellable, callback, None)
Beispiel #10
0
 def search(self):
     if not self.url:
         return self.emit('search-complete', [])
     msg = Soup.Message.new('GET', self.url)
     download_json(msg, self.cancellable, self.album_data, None)
Beispiel #11
0
 def search(self):
     if not self.url:
         return self.emit('search-complete', [])
     msg = Soup.Message.new('GET', self.url)
     download_json(msg, self.cancellable, self._handle_search_response,
                   None)
Beispiel #12
0
 def _get(self, path, callback, data=None, **kwargs):
     args = self._default_params()
     args.update(kwargs)
     msg = self._add_auth_to(Soup.Message.new('GET', self._url(path, args)))
     download_json(msg, self._cancellable, callback, data, self._on_failure)