Ejemplo n.º 1
0
class Register(SimpleCommand):

    def __init__(self, args):
        self.auth = Auth(args.user, args.password)
        self.init_query()
        self.init_payload()
        
    def init_query(self):
        self.query = Query(filters=[self.auth.to_basicauth()])
        self.build_query()

    def build_query(self):
        self.query.concat_path(GITHUB_AUTHORIZATION_PATH)

    def build_payload(self):
        self.payload["scopes"] = APP_SCOPES
        self.payload["note"] = APP_NOTE

    def invoke(self):
        try:
            access_token = self.auth.get_access_token_api()
        except UnauthorizedUser:
            print u"Try to register this appliation."
            print u"*" * 50
        except Exception:
            raise
        else:
            print u"You have already registered your account with this application."
            print u"Your access_token is {0}".format(access_token)
            return access_token

        response = self.query.do_POST(
                                payload=self.payload,
                                )
        return self.on_receive(response)

    def on_receive(self, response):
        print u"You successfully register your account with this application."
        print u"Your access_token is {0}\n".format(response["token"])
        print u"Please do `export {0}={1}`.".format(APP_TOKEN, response["token"])
        return response
Ejemplo n.º 2
0
class Register(SimpleCommand):

    def __init__(self, args):
        self.auth = Auth(args.user, args.password)
        self.init_query()
        self.init_payload()
        
    def init_query(self):
        self.query = Query(filters=[self.auth.to_basicauth()])
        self.build_query()

    def build_query(self):
        self.query.concat_path(GITHUB_AUTHORIZATION_PATH)

    def build_payload(self):
        self.payload["scopes"] = APP_SCOPES
        self.payload["note"] = APP_NOTE

    def invoke(self):
        try:
            access_token = self.auth.get_access_token_api()
        except UnauthorizedUser:
            print("Try to register this appliation.")
            print("*" * 50)
        except Exception:
            raise
        else:
            print("You have already registered your account with this application.")
            print("Your access_token is {0}".format(access_token))
            return access_token

        response = self.query.do_POST(
                                payload=self.payload,
                                )
        return self.on_receive(response)

    def on_receive(self, response):
        print("You successfully register your account with this application.")
        print("Your access_token is {0}\n".format(response["token"]))
        print("Please do `export {0}={1}`.".format(APP_TOKEN, response["token"]))
        return response
Ejemplo n.º 3
0
 def init_query(self):
     access_token = None
     if not self.is_anonymous:
         access_token = Auth().get_access_token(is_api=True)
     self.query = Query(access_token=access_token)
     self.build_query()
Ejemplo n.º 4
0
 def init_query(self):
     try:
         self.query = Query(access_token=Auth().get_access_token())
     except (UnSetUserKeyError, UnauthorizedUser):
         self.query = Query()
     self.build_query()
Ejemplo n.º 5
0
 def __init__(self, args):
     self.auth = Auth(args.user, args.password)
     self.init_query()
     self.init_payload()
Ejemplo n.º 6
0
 def __init__(self, args):
     self.auth = Auth(args.user, args.password)
     self.init_query()
     self.init_payload()