def sign_in(self): """ Sign into Zuora. If we have already signed it, this will just return the original object """ if hasattr(self, 'gizmo'): return self.gizmo gizmo = SurveyGizmo( api_version=self.extras.get('api_version', 'v5'), api_token=self.extras.get('api_token'), api_token_secret=self.extras.get('api_token_secret') ) self.gizmo = gizmo return gizmo
from unittest import TestCase from surveygizmo import SurveyGizmo client = SurveyGizmo( base_url='', api_token='token', api_token_secret='secret', prepare_url=True, ) class AccountTests(TestCase): resource = client.api.account def test_list(self): with self.assertRaises(NotImplementedError): self.resource.list() def test_get(self): path, params = self.resource.get() self.assertEqual(path, 'head/account/') def test_create(self): with self.assertRaises(NotImplementedError): self.resource.create() def test_update(self): with self.assertRaises(NotImplementedError): self.resource.update() def test_copy(self):
def test_prepare_url_override(self): client = SurveyGizmo(api_token='token', api_token_secret='secret', prepare_url=False) client.api.base_url = '' _, params = client.api.survey.list(_prepare_url=True) self.assertNotIn('_prepare_url', params)
def __init__(self): self.client = SurveyGizmo( api_version='v4', api_token=properties.SURVEYGIZMO_API_TOKEN, api_token_secret=properties.SURVEYGIZMO_API_SECRET )
import os from surveygizmo import SurveyGizmo # SurveyGizmo object initialization client = SurveyGizmo( api_version='v5', api_token=os.getenv('SG_API_TOKEN'), api_token_secret=os.getenv('SG_API_TOKEN_SECRET') ) # A list of surveys surveys = client.api.survey.list() if not surveys['result_ok']: print('Something went wrong and request for survey list has ended with error') exit(1) # Pick first survey as a test sample survey test_survey = surveys['data'][0] # Fetch the test survey responses responses = client.api.surveyresponse.list(test_survey['id']) if not responses['result_ok']: print('Something went wrong and request for survey responses list has ended with error') exit(1) # Let's try to access each response answers and URL attributes for response in responses['data']: print("Response ID {0}".format(response['id'])) # Print out each response's URL variables # Since url_variables is a dict, we traverse
def main(survey_id, bucket, output_folder, output_file, results_per_page, start, end, **kwargs): logger.info("Writing to %s/%s/%s", bucket, output_folder, output_file) client = SurveyGizmo( api_version='v5', api_token=os.getenv("SUMO_SURVEYGIZMO_TOKEN"), api_token_secret=os.getenv("SUMO_SURVEYGIZMO_KEY"), handler52x=surveygizmo.default_52xhandler, ) # Prepare our output to GCS gcsfs = open_fs(bucket + "/?strict=False") gcsfs.makedirs(output_folder, recreate=True) output = gcsfs.open(output_folder + "/" + output_file, "w") # Prepare our CSV writer into GCS writer = csv.writer(output, delimiter=',', quoting=csv.QUOTE_ALL, skipinitialspace=True) writer.writerow(OUTPUT_FIELDS) start_date = start.strftime(SURVEYGIZMO_DATE_FORMAT) end_date = end.strftime(SURVEYGIZMO_DATE_FORMAT) logger.info("Extrating from %s to %s", start_date, end_date) # Prepare our filtered query query = client.api.surveyresponse query = query.filter('date_submitted', '>=', start_date) query = query.filter('date_submitted', '<', end_date) page = 1 total_pages = 0 result_ok = True total_responses = 0 while result_ok: responses = query.list(survey_id, page=page, resultsperpage=results_per_page) result_ok = responses['result_ok'] total_pages = responses['total_pages'] for response in responses['data']: survey_data = response['survey_data'] response_data = [response[k] for k in SURVEY_GIZMO_FIELDS] questions_data = [ survey_data[str(q)].get('answer', '') for q in SURVEY_GIZMO_QUESTIONS ] writer.writerow(response_data + questions_data) total_responses += 1 # Dump out some progress if total_responses % int(responses['results_per_page']) == 0: logger.info("[p:%.3d/%.3d] Total responses: %d/%d", page, total_pages, total_responses, responses['total_count']) # Go to the next page or we are done page = page + 1 if page > total_pages: break logger.info("Processed a total of %d/%r responses", total_responses, responses['total_count'])
from surveygizmo import SurveyGizmo key = "" secret = "" client = SurveyGizmo( api_version='v4', # example token from SurveyGizmo docs api_token=key, api_token_secret=secret) for i in client.api.survey.list()["data"]: print(i["title"]) client.api.survey.filter('createdon', '>=', '2020-01-01').list()