Permalink
Browse files

Fixed strange api bug

  • Loading branch information...
1 parent 93e7973 commit 0537513e693e53b38c8b98dd3b8aaeabead3a659 Henrik Berggren committed May 5, 2009
Showing with 18 additions and 13 deletions.
  1. +5 −4 app.yaml
  2. +6 −5 the-cloud-player.py
  3. +7 −4 utils.py
View
@@ -20,7 +20,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
application: the-cloud-player
-version: 2
+version: 3
runtime: python
api_version: 1
@@ -34,13 +34,14 @@ handlers:
- url: /images
static_dir: images
-- url: .*
- script: the-cloud-player.py
-
- url: /favicon.ico
static_files: images/favicon.ico
upload: images/favicon.ico
- url: /robots.txt
static_files: robots.txt
upload: robots.txt
+
+- url: .*
+ script: the-cloud-player.py
+
View
@@ -25,6 +25,7 @@
import random
import logging
+import urllib
from google.appengine.ext import db
@@ -56,7 +57,8 @@ def post(self):
class API(webapp.RequestHandler):
def get(self):
- sc_api_url = "http://api.soundcloud.com/"
+
+ sc_api_url = "http://api.soundcloud.com"
callback = self.request.get('callback')
api_parameters = utils.extract_parameters(self.request.uri)
if api_parameters:
@@ -66,14 +68,13 @@ def get(self):
hit = memcache.get(parameters_hash)
if hit is None:
try:
- response = urlfetch.fetch(url = sc_api_url + api_parameters,method=urlfetch.GET, headers={'Content-Type': 'text/javascript; charset=utf-8'})
+ response = urlfetch.fetch(url = sc_api_url + urllib.quote_plus(api_parameters),method=urlfetch.GET, headers={'Content-Type': 'text/javascript; charset=utf-8'})
memcache.set(parameters_hash, response.content, 10800)
- utils.print_with_callback(callback, response.content. self.response)
+ utils.print_with_callback(callback, response.content, self.response)
except:
utils.print_with_callback(callback, utils.status_code_json(408), self.response)
else:
- utils.print_with_callback(callback, hit, self.response)
-
+ utils.print_with_callback(callback, hit, self.response)
class PlayerPage(webapp.RequestHandler):
def get(self):
View
@@ -158,10 +158,13 @@ def extract_parameters(url):
return None
def print_with_callback(callback, content, response):
- response.out.write(callback)
- response.out.write("(")
- response.out.write(content)
- response.out.write(")")
+ if len(str(callback)) > 0:
+ response.out.write(callback)
+ response.out.write("(")
+ response.out.write(content)
+ response.out.write(")")
+ else:
+ response.out.write(content)
def strip_named_parameter(parameter_to_remove, url):
p = re.compile('&'+parameter_to_remove+'[^&]*')

0 comments on commit 0537513

Please sign in to comment.