Default the data wrapper to off. When converting based on types, don't convert things that are already strings or unicode
This commit is contained in:
@@ -164,7 +164,7 @@ def build_from_document(
|
|||||||
auth_discovery = {}
|
auth_discovery = {}
|
||||||
|
|
||||||
if model is None:
|
if model is None:
|
||||||
features = service.get('features', ['dataWrapper'])
|
features = service.get('features', [])
|
||||||
model = JsonModel('dataWrapper' in features)
|
model = JsonModel('dataWrapper' in features)
|
||||||
resource = createResource(http, base, model, requestBuilder, developerKey,
|
resource = createResource(http, base, model, requestBuilder, developerKey,
|
||||||
service, future)
|
service, future)
|
||||||
@@ -192,7 +192,10 @@ def _cast(value, schema_type):
|
|||||||
A string representation of 'value' based on the schema_type.
|
A string representation of 'value' based on the schema_type.
|
||||||
"""
|
"""
|
||||||
if schema_type == 'string':
|
if schema_type == 'string':
|
||||||
return str(value)
|
if type(value) == type('') or type(value) == type(u''):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
return str(value)
|
||||||
elif schema_type == 'integer':
|
elif schema_type == 'integer':
|
||||||
return str(int(value))
|
return str(int(value))
|
||||||
elif schema_type == 'number':
|
elif schema_type == 'number':
|
||||||
@@ -200,7 +203,10 @@ def _cast(value, schema_type):
|
|||||||
elif schema_type == 'boolean':
|
elif schema_type == 'boolean':
|
||||||
return str(bool(value)).lower()
|
return str(bool(value)).lower()
|
||||||
else:
|
else:
|
||||||
return str(value)
|
if type(value) == type('') or type(value) == type(u''):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
def createResource(http, baseUrl, model, requestBuilder,
|
def createResource(http, baseUrl, model, requestBuilder,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def main():
|
|||||||
storage = Storage('moderator.dat')
|
storage = Storage('moderator.dat')
|
||||||
credentials = storage.get()
|
credentials = storage.get()
|
||||||
if credentials is None or credentials.invalid == True:
|
if credentials is None or credentials.invalid == True:
|
||||||
moderator_discovery = build("moderator", "v1").auth_discovery()
|
moderator_discovery = build('moderator', 'v1').auth_discovery()
|
||||||
|
|
||||||
flow = FlowThreeLegged(moderator_discovery,
|
flow = FlowThreeLegged(moderator_discovery,
|
||||||
consumer_key='anonymous',
|
consumer_key='anonymous',
|
||||||
@@ -44,53 +44,45 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("moderator", "v1", http=http)
|
p = build('moderator', 'v1', http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
"data": {
|
'description': 'Share and rank tips for eating healthy and cheap!',
|
||||||
"description": "Share and rank tips for eating healthy and cheap!",
|
'name': 'Eating Healthy & Cheap',
|
||||||
"name": "Eating Healthy & Cheap",
|
'videoSubmissionAllowed': False
|
||||||
"videoSubmissionAllowed": False
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = p.series().insert(body=series_body).execute()
|
||||||
print "Created a new series"
|
print 'Created a new series'
|
||||||
|
|
||||||
topic_body = {
|
topic_body = {
|
||||||
"data": {
|
'description': 'Share your ideas on eating healthy!',
|
||||||
"description": "Share your ideas on eating healthy!",
|
'name': 'Ideas',
|
||||||
"name": "Ideas",
|
'presenter': 'liz'
|
||||||
"presenter": "liz"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
topic = p.topics().insert(seriesId=series['id']['seriesId'],
|
topic = p.topics().insert(seriesId=series['id']['seriesId'],
|
||||||
body=topic_body).execute()
|
body=topic_body).execute()
|
||||||
print "Created a new topic"
|
print 'Created a new topic'
|
||||||
|
|
||||||
submission_body = {
|
submission_body = {
|
||||||
"data": {
|
'attachmentUrl': 'http://www.youtube.com/watch?v=1a1wyc5Xxpg',
|
||||||
"attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg",
|
'attribution': {
|
||||||
"attribution": {
|
'displayName': 'Bashan',
|
||||||
"displayName": "Bashan",
|
'location': 'Bainbridge Island, WA'
|
||||||
"location": "Bainbridge Island, WA"
|
},
|
||||||
},
|
'text': 'Charlie Ayers @ Google'
|
||||||
"text": "Charlie Ayers @ Google"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
|
submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
|
||||||
topicId=topic['id']['topicId'], body=submission_body).execute()
|
topicId=topic['id']['topicId'], body=submission_body).execute()
|
||||||
print "Inserted a new submisson on the topic"
|
print 'Inserted a new submisson on the topic'
|
||||||
|
|
||||||
vote_body = {
|
vote_body = {
|
||||||
"data": {
|
'vote': 'PLUS'
|
||||||
"vote": "PLUS"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p.votes().insert(seriesId=topic['id']['seriesId'],
|
p.votes().insert(seriesId=topic['id']['seriesId'],
|
||||||
submissionId=submission['id']['submissionId'],
|
submissionId=submission['id']['submissionId'],
|
||||||
body=vote_body)
|
body=vote_body)
|
||||||
print "Voted on the submission"
|
print 'Voted on the submission'
|
||||||
except CredentialsInvalidError:
|
except CredentialsInvalidError:
|
||||||
print 'Your credentials are no longer valid.'
|
print 'Your credentials are no longer valid.'
|
||||||
print 'Please re-run this application to re-authorize.'
|
print 'Please re-run this application to re-authorize.'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/python2.4
|
#!/usr/bin/python2.4
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright 2010 Google Inc.
|
# Copyright 2010 Google Inc.
|
||||||
#
|
#
|
||||||
@@ -100,6 +101,7 @@ class Discovery(unittest.TestCase):
|
|||||||
self._check_query_types(request)
|
self._check_query_types(request)
|
||||||
request = zoo.query(q="foo", i=1, n=1, b=False, a=[1,2,3], o={'a':1}, e='bar')
|
request = zoo.query(q="foo", i=1, n=1, b=False, a=[1,2,3], o={'a':1}, e='bar')
|
||||||
self._check_query_types(request)
|
self._check_query_types(request)
|
||||||
|
|
||||||
request = zoo.query(q="foo", i="1", n="1", b="", a=[1,2,3], o={'a':1}, e='bar')
|
request = zoo.query(q="foo", i="1", n="1", b="", a=[1,2,3], o={'a':1}, e='bar')
|
||||||
self._check_query_types(request)
|
self._check_query_types(request)
|
||||||
|
|
||||||
@@ -134,7 +136,8 @@ class Discovery(unittest.TestCase):
|
|||||||
self.http = HttpMock(datafile('zoo.json'), {'status': '200'})
|
self.http = HttpMock(datafile('zoo.json'), {'status': '200'})
|
||||||
zoo = build('zoo', 'v1', self.http)
|
zoo = build('zoo', 'v1', self.http)
|
||||||
self.assertTrue(getattr(zoo, 'animals'))
|
self.assertTrue(getattr(zoo, 'animals'))
|
||||||
request = zoo.animals().list(name="bat", projection="size")
|
|
||||||
|
request = zoo.animals().list(name='bat', projection="size")
|
||||||
parsed = urlparse.urlparse(request.uri)
|
parsed = urlparse.urlparse(request.uri)
|
||||||
q = parse_qs(parsed[4])
|
q = parse_qs(parsed[4])
|
||||||
self.assertEqual(q['name'], ['bat'])
|
self.assertEqual(q['name'], ['bat'])
|
||||||
|
|||||||
Reference in New Issue
Block a user