def foursquare(self, request, network, response): """ Helper function to handle the callbacks for foursquare """ verification_string = request.GET.get('code', '') if not verification_string: # probably the user didn't accept our advances return response.send(errors=NETWORK_HTTP_ERROR % network.name) token_request_args = {'client_id' : network.getAppId(), 'client_secret': network.getSecret(), 'redirect_uri': network.getCallBackURL(request), 'grant_type' : 'authorization_code', 'code' : verification_string} result = utils.makeAPICall(domain=network.base_url, apiHandler=network.access_token_path, queryData=token_request_args, secure=True) network_user = utils.makeAPICall(domain=network.base_url, apiHandler='v2/users/self', queryData={'oauth_token':result['access_token']}, headers={'Accept':'application/json'}, secure=True) network_dict = {} network_dict['access_token'] = result['access_token'] network_dict['uuid'] = network_user['id'] network_dict['name_in_network'] = '%s %s' % (network_user['firstName'], network_user['lastName']) network_dict['network'] = network self.finish_callback(request, response, network_dict=network_dict)
def facebook(self, request, network, response): """ Helper function to handle the callbacks for facebook """ verification_string = request.GET.get('code', '') if not verification_string: # probably the user didn't accept our advances return response.send(errors=NETWORK_HTTP_ERROR % network.name) token_request_args = {'client_id' : network.getAppId(), 'client_secret': network.getSecret(), 'redirect_uri': network.getCallBackURL(request), 'code' : verification_string} result = utils.makeAPICall(domain=network.base_url, apiHandler=network.access_token_path, queryData=token_request_args, secure=True, deserializeAs=None) ret = urlparse.parse_qs(result, keep_blank_values=False) access_token = ret['access_token'][0] ret = utils.makeAPICall(domain=network.base_url, apiHandler='me?access_token=%s' % access_token, secure=True) network_dict = {} network_dict['access_token'] = access_token network_dict['uuid'] = ret['id'] network_dict['name_in_network'] = ret['name'] network_dict['network'] = network self.finish_callback(request, response, network_dict=network_dict)
def facebook(self, request, credentials, network): postData = {'access_token': credentials.token} postData.update(self.get_facebook_post_data(request)) utils.makeAPICall(network.base_url, '%s/feed' % credentials.uuid, postData=postData, secure=True, deserializeAs='skip')
def facebook(self, profile, network, credentials): friends = utils.makeAPICall(network.base_url, 'me/friends', queryData={'access_token': credentials.token}, secure=True) return [x['id'] for x in friends['data']]
def latitude(self, request, network, response): """ Helper Function to handle the callbacks for Google Latitude """ verification_string = request.GET.get('code', '') error = request.GET.get('error', '') if error: return response.send(errors=error) if not verification_string: # probably the user didn't accept our advances return response.send(errors=NETWORK_HTTP_ERROR % network.name) token_request_args = {'client_id' : network.getAppId(), 'client_secret': network.getSecret(), 'redirect_uri': network.getCallBackURL(request), 'grant_type' : 'authorization_code', 'code' : verification_string} result = utils.makeAPICall(domain=network.base_url, apiHandler=network.access_token_path, postData=token_request_args, secure=True) network_user = utils.makeAPICall(domain=network.base_url, apiHandler='users/me', queryData={'access_token':result['access_token']}, headers={'Accept':'application/json'}, secure=True) network_dict = {} network_dict['access_token'] = result['access_token'] network_dict['refresh_token'] = result['refresh_token'] network_dict['timeout'] = datetime.datetime.utcnow() + datetime.timedelta(seconds=result['expires_in']) network_dict['uuid'] = result['username'] network_dict['name_in_network'] = '%s %s' % (network_user['first_name'], network_user['last_name']) network_dict['network'] = network self.finish_callback(request, response, network_dict=network_dict)
def create(self, request, response): """ Receives receipt from client, verifies with apple, makes necessary db changes to provide the product API Handler: POST /receipt/apple PARAMS: @receipt_data [string]: this is the receipt data apple gave you in the transactionReceipt property of your receipt """ receipt_data = request.POST.get('receipt_data') profile = request.user.get_profile() if not receipt_data: transaction.rollback() return response.send(errors='Please provide the data from "transactionReceipt" in order to process your purchase') encoded_data = base64.b64encode(receipt_data) json_data = simplejson.dumps({"receipt-data": encoded_data}) result = utils.makeAPICall(consts.APPLE_STORE_URL, consts.VERIFY_RECIEPT_API_HANDLER, rawPostData=json_data, secure=True) if not result['status'] == 0: response.set(apple_response=result) transaction.rollback() return response.send(errors='Invalid receipt', status=500) receipt = result['receipt'] try: AppleReceipt.objects.get(original_transaction_id=receipt['original_transaction_id']) transaction.rollback() return response.send(errors="Invalid receipt", status=500) except AppleReceipt.DoesNotExist: pass receipt['purchase_date'] = datetime.datetime.strptime(receipt['purchase_date'], "%Y-%m-%d %H:%M:%S Etc/%Z") receipt['original_purchase_date'] = datetime.datetime.strptime(receipt['original_purchase_date'], "%Y-%m-%d %H:%M:%S Etc/%Z") receipt['profile'] = profile apple_receipt = AppleReceipt.objects.create(**receipt) transaction.commit() return self.redeem(request, apple_receipt, response)