def _get_id_from_result(self, result_json): """ 保存結果jsonから登録IDを取得 """ if result_json: try: result_dict = simplejson.loads(result_json) except simplejson.JSONDecodeError, e: Log.warn(e) return None else: return result_dict['entry'][0]['id']
def _get_id_from_result(self, result_json): """ 保存結果jsonから登録IDを取得 """ if result_json: try: result_dict = simplejson.loads(result_json) except simplejson.JSONDecodeError, e: Log.warn(e) return None else: return result_dict['entry'][0]['id']
def _api_request(self, method, user_id, text_id = None, data = None): """ apiにリスエスト送信 返り値 正常時: リスエストのレスポンス 異常時: None Send request to api. Return value usualy: response from request when there are problems :None """ path = self._api_path(method, text_id) header = {'Content-Type': 'application/json; cahrset=utf8'} response = None for retry in xrange(self.RETRY_COUNT): try: if method in ['POST', 'PUT']: response = self.container.oauth_request( method, user_id, path, data = data, headers = header, url_tail='', body_hash=True ) else: if text_id != None: response = self.container.oauth_request(method, user_id, path) break except TypeError: Log.warn('Inspection: %s: response type error. userid:%s' % (method, user_id)) continue except HTTPError as e: Log.warn('Inspection: %s: response HTTPError %s. textid:%s, userid:%s' % (method, e.code, text_id, user_id)) continue return response
def request_payment(self, osuser_id, item_id, item_name, item_point, item_description, item_image_url, callback_path, finish_path, item_message='', item_quantity=1, is_test=False): """ 課金処理開始 Arguments request: Django requestインスタンス osuser_id: OpensocialUserのID item_id: アイテムID アイテムを識別するためのID item_name: アイテム名 item_point: アイテム価格 item_description: アイテム説明文 item_image_url: アイテム画像のURL callback_url: コールバックURL finish_url: 購入完了URL item_message: メッセージ(GREEのみ) default='' item_quantity: アイテムの個数 default=1 is_test: テストフラグ(mixiのみ有効) default=False Return payment_url: 購入画面のURL。 次に進むべきページのURL Start processing the payment. Arguments request: Django request instance osuser_id: ID of OpensocialUser item_id: Item ID item_name: Item Name item_point: Item price item_description: Item description item_image_url: Url of item image callback_url: callback url finish_url: purchase finish url item_message: message(only for GREE) default='' item_quantity: item number default=1 is_test: test flag(only for mixi) default=False Return payment_url: payment url.the url which will be redirected. """ if not isinstance(item_id, IntType): # item_idはintでなければならない #item_id has to be in int raise callback_url = self._create_callback_url(callback_path) finish_url = self._create_finish_url(finish_path) app_user_agent = self.request.session.get('app_user_agent', None) platform = "ios" if app_user_agent is not None and app_user_agent == "iOS" else None paydata = self._create_paydata(item_id, item_name, item_point, item_description, item_image_url, callback_url, finish_url, item_message, item_quantity, is_test, platform) recv_data = self._api_request(osuser_id, paydata) Log.debug(recv_data) if recv_data is None: # 課金データ作成に失敗した場合 # if you failed to make payment data Log.warn( 'Payment Data: osuser_id:%s, item_id:%s, item_name:%s, item_point:%s, item_description:%s, item_image_url:%s, callback_url:%s, finish_url:%s' % (osuser_id, item_id, item_name, item_point, item_description, item_image_url, callback_url, finish_url)) raise json = simplejson.loads(recv_data) point_code = json['entry'][0]['paymentId'] point_date = json['entry'][0]['orderedTime'] point_url = json['entry'][0]['transactionUrl'] app_user_agent = self.request.session.get('app_user_agent', None) # 決済情報を保存 # saves payment information PaymentInfo.objects.create( point_code=point_code, item_id=item_id, osuser_id=osuser_id, point=item_point, quantity=item_quantity, send_data=paydata, point_date=point_date, point_url=point_url, recv_data=recv_data, device=self.device_type(), ) return point_url
def request_payment(self, osuser_id, item_id, item_name, item_point, item_description, item_image_url, callback_path, finish_path, item_message='', item_quantity=1, is_test=False): """ 課金処理開始 Arguments request: Django requestインスタンス osuser_id: OpensocialUserのID item_id: アイテムID アイテムを識別するためのID item_name: アイテム名 item_point: アイテム価格 item_description: アイテム説明文 item_image_url: アイテム画像のURL callback_url: コールバックURL finish_url: 購入完了URL item_message: メッセージ(GREEのみ) default='' item_quantity: アイテムの個数 default=1 is_test: テストフラグ(mixiのみ有効) default=False Return payment_url: 購入画面のURL。 次に進むべきページのURL Start processing the payment. Arguments request: Django request instance osuser_id: ID of OpensocialUser item_id: Item ID item_name: Item Name item_point: Item price item_description: Item description item_image_url: Url of item image callback_url: callback url finish_url: purchase finish url item_message: message(only for GREE) default='' item_quantity: item number default=1 is_test: test flag(only for mixi) default=False Return payment_url: payment url.the url which will be redirected. """ if not isinstance(item_id, IntType): # item_idはintでなければならない #item_id has to be in int raise callback_url = self._create_callback_url(callback_path) finish_url = self._create_finish_url(finish_path) app_user_agent = self.request.session.get('app_user_agent', None) platform = "ios" if app_user_agent is not None and app_user_agent == "iOS" else None paydata = self._create_paydata(item_id, item_name, item_point, item_description, item_image_url, callback_url, finish_url, item_message, item_quantity, is_test, platform) recv_data = self._api_request(osuser_id, paydata) Log.debug(recv_data) if recv_data is None: # 課金データ作成に失敗した場合 # if you failed to make payment data Log.warn('Payment Data: osuser_id:%s, item_id:%s, item_name:%s, item_point:%s, item_description:%s, item_image_url:%s, callback_url:%s, finish_url:%s' % (osuser_id, item_id, item_name, item_point, item_description, item_image_url, callback_url, finish_url)) raise json = simplejson.loads(recv_data) point_code = json['entry'][0]['paymentId'] point_date = json['entry'][0]['orderedTime'] point_url = json['entry'][0]['transactionUrl'] app_user_agent = self.request.session.get('app_user_agent', None) # 決済情報を保存 # saves payment information PaymentInfo.objects.create( point_code = point_code, item_id = item_id, osuser_id = osuser_id, point = item_point, quantity = item_quantity, send_data = paydata, point_date = point_date, point_url = point_url, recv_data = recv_data, device = self.device_type(), ) return point_url
def blacklist_check(self, userid, target_userid, caching=False, cache_update=None): """ 二者間でのブラックリストチェック userid が target_userid をブラックリスト登録してるか? 任意でキャッシュできる(デフォルトではキャッシュしない) (GREE規約上、ブラックリストは24時間キャッシュできるようだが、しない) 引数 userid target_userid caching cache_update 返り値 is_data : Trueなら、ブラックリストに登録している Falseなら、ブラックリストに登録されていない "Blacklist checking" between the two persons:whether the "userid" has registered "target_userid" for blacklist? You can cache it if you want(but by default you can`t cache it) arguments userid target_userid caching cache_update return value is_data : if True,registerd on blacklist if False,not registerd on blacklist """ from django.conf import settings if settings.OPENSOCIAL_DEBUG: return False #requestor_id = self.container.request.osuser.userid path = '/ignorelist/%s/@all/%s/' % (str(userid), str(target_userid)) cache_key = path data = [] # test #cache_update = True if caching and cache_update == False: is_data = GsocialCache.get_cache(cache_key) #print 'cache', is_data if is_data != None: return is_data for retry_count in xrange(self.RETRY_COUNT): try: res = self.get_response(userid, path) #res = self.get_response(requestor_id, path) data = simplejson.loads(res) break except TypeError: Log.warn('Blacklist: response type error. retry:%s' % retry_count) continue except Exception: Log.warn('Blacklist: response error. retry:%s' % retry_count) continue Log.debug(data) if not data: Log.error("Blacklist: not data.") raise self.container.ResponseError('Blacklist API','Get ignorelist (gree).') if 'entry' in data and data['entry']: is_data = True else: is_data = False #print 'no cache', is_data if caching: GsocialCache.set_cache(cache_key, is_data) return is_data
def blacklist_check(self, userid, target_userid, caching=False, cache_update=None): """ 二者間でのブラックリストチェック userid が target_userid をブラックリスト登録してるか? 任意でキャッシュできる(デフォルトではキャッシュしない) (GREE規約上、ブラックリストは24時間キャッシュできるようだが、しない) 引数 userid target_userid caching cache_update 返り値 is_data : Trueなら、ブラックリストに登録している Falseなら、ブラックリストに登録されていない "Blacklist checking" between the two persons:whether the "userid" has registered "target_userid" for blacklist? You can cache it if you want(but by default you can`t cache it) arguments userid target_userid caching cache_update return value is_data : if True,registerd on blacklist if False,not registerd on blacklist """ from django.conf import settings if settings.OPENSOCIAL_DEBUG: return False #requestor_id = self.container.request.osuser.userid path = '/ignorelist/%s/@all/%s/' % (str(userid), str(target_userid)) cache_key = path data = [] # test #cache_update = True if caching and cache_update == False: is_data = GsocialCache.get_cache(cache_key) #print 'cache', is_data if is_data != None: return is_data for retry_count in xrange(self.RETRY_COUNT): try: res = self.get_response(userid, path) #res = self.get_response(requestor_id, path) data = simplejson.loads(res) break except TypeError: Log.warn('Blacklist: response type error. retry:%s' % retry_count) continue except Exception: Log.warn('Blacklist: response error. retry:%s' % retry_count) continue Log.debug(data) if not data: Log.error("Blacklist: not data.") raise self.container.ResponseError('Blacklist API', 'Get ignorelist (gree).') if 'entry' in data and data['entry']: is_data = True else: is_data = False #print 'no cache', is_data if caching: GsocialCache.set_cache(cache_key, is_data) return is_data