def do_business(self): super(SengLoginEmail, self).do_business() app = self.result if app: fetch_command = UrlFetchCommand(self.url_passwordless_login, {'email': self.email, 'app_id': app.app_id, 'token': app.token, 'hook': self.return_url, 'lang': self.lang}, method='POST') fetch_command.execute() else: self.add_error('app_data', 'Must save Passwordless App Credentials before login calls')
def test_http_get(self): params = {'id': 'foo', 'token': 'bar'} url = 'http://foo.bar.com/rest' rpc = Mock() result = Mock() result.status_code = 200 result.content = '{"ticket":"123456"}' rpc.get_result = Mock(return_value=result) gaeutil.urlfetch.create_rpc = Mock(return_value=rpc) fetch = Mock() gaeutil.urlfetch.make_fetch_call = fetch command = UrlFetchCommand(url, params, validate_certificate=False) command.execute() self.assertEqual(result, command.result) fetch.assert_called_once_with(rpc, '%s?%s' % (url, urllib.urlencode(params)), None, method=urlfetch.GET, validate_certificate=False, headers={})
def do_business(self, stop_on_error=True): super(FetchNotificationDetail, self).do_business(stop_on_error) access_data = self.result notification_url = router.to_path( 'https://ws.pagseguro.uol.com.br/v3/transactions/notifications', self.notification_code, email=access_data.email, token=access_data.token) fetch_cmd = UrlFetchCommand(notification_url) fetch_cmd() if fetch_cmd.result and fetch_cmd.result.content: content = fetch_cmd.result.content content_dct = xmltodict.parse(content, 'ISO-8859-1') self.code = content_dct['transaction']['code'] self.status = XML_STATUS_TO_MODEL_STATUS[content_dct['transaction'] ['status']] self.net_amount = content_dct['transaction']['netAmount'] try: self.result = content_dct['transaction']['reference'] except KeyError: self.xml = content self.add_error('no_reference', content) else: self.add_error('pagseguro', 'Notification not contacted')
def do_business(self): super(PasswordlessDetailCheck, self).do_business() if not self.errors: app = self.result self.result = None fetch_cmd = UrlFetchCommand(self.detail_url, {'ticket': self.ticket, 'app_id': app.app_id, 'token': app.token}, 'POST').execute() self.errors.update(fetch_cmd.errors) if not self.errors: dct = json.loads(fetch_cmd.result.content) cmd_parallel = CommandParallel(GetMainUserByEmail(dct['email']), GetPasswordlessUser(dct['id'])) cmd_parallel.execute() main_user, passwordless_user = cmd_parallel[0].result, cmd_parallel[1].result if passwordless_user: main_user = MainUserSearch(passwordless_user).execute().result elif main_user: passwordless_user_key = PasswordlessUser(external_id=dct['id']).put() self._to_commit = ExternalToMainUser(origin=passwordless_user_key, destination=main_user.key) else: main_user = MainUser(name=dct['email'], email=dct['email']) passwordless_user = PasswordlessUser(external_id=dct['id']) ndb.put_multi([main_user, passwordless_user]) self._to_commit = ExternalToMainUser(origin=passwordless_user.key, destination=main_user.key) self.result = main_user
def index(nome): url_base = 'https://api.github.com/users' url_usuario = to_path(url_base, nome) url_repos = to_path(url_usuario, 'repos') usuario_cmd = UrlFetchCommand( url_usuario, headers={'Accept': 'application/vnd.github.v3+json'}) repo_cmd = UrlFetchCommand( url_repos, headers={'Accept': 'application/vnd.github.v3+json'}) repos_json, usuario_json = _chamar_api(repo_cmd, usuario_cmd) usuario_dct = json.loads(usuario_json) repos_dct = json.loads(repos_json) contexto = { 'nome': nome, 'avatar': usuario_dct['avatar_url'], 'repos': [(r['name'], r['html_url']) for r in repos_dct] } return TemplateResponse(contexto, 'github.html')
def index(_resp, nome): url_base = 'https://api.github.com/users' url_usuario = to_path(url_base, nome) url_repos = to_path(url_usuario, 'repos') usuario_cmd = UrlFetchCommand( url_usuario, headers={'Accept': 'application/vnd.github.v3+json'}) repo_cmd = UrlFetchCommand( url_repos, headers={'Accept': 'application/vnd.github.v3+json'}) CommandParallel(usuario_cmd, repo_cmd).execute() usuario_json = json.loads(usuario_cmd.result.content) repo_json = json.loads(repo_cmd.result.content) contexto = { 'nome': nome, 'avatar': usuario_json['avatar_url'], 'repos': [(r['name'], r['html_url']) for r in repo_json] } return TemplateResponse(contexto, 'github.html')
def handle_previous(self, command): access_data = command.access_data items = command.items client_form = command.client_form address_form = command.address_form self.payment = command.result params = _make_params(access_data.email, access_data.token, self.redirect_url, client_form.name, client_form.email, self.payment.key.id(), items, address_form, self.currency) params = { k: unicode(v).encode('iso-8859-1') for k, v in params.iteritems() } self.fetch_cmd = UrlFetchCommand(_PAYMENT_URL, params, urlfetch.POST, self.headers) self.append(self.fetch_cmd)