Example #1
0
class Create(SimpleCommand):

    def __init__(self, args):
        self.files = map(abspath, args.files)
        self.init(args)
        
    def init(self, args):
        self.is_public = args.private
        self.description = args.description or u""
        self.payload = dict()
        self.is_anonymous = args.anonymous
        self.init_query()
        self.init_payload()
        
    def build_payload(self):
        self.payload["description"] = self.description
        self.payload["public"] = self.is_public
        self.payload["files"] = dict()
        for fpath in self.files:
            fname = basename(fpath)
            self.payload["files"].setdefault(fname, dict())
            self.payload["files"][fname]["content"] = open(fpath, "rb").read()

    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()

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

    def invoke(self):
        response = self.query.do_POST(payload=self.payload)
        return self.on_receive(response)

    def on_receive(self, response):
        self.clipboard_set(response["html_url"])
        print "CREATE ====> {0}".format(response["html_url"])
        for fpath in self.files:
            print fpath
        return response
Example #2
0
class Create(SimpleCommand):
    def __init__(self, args):
        self.files = list(map(abspath, args.files))
        self.init(args)

    def init(self, args):
        self.is_public = args.private
        self.description = args.description or ""
        self.payload = dict()
        self.is_anonymous = args.anonymous
        self.init_query()
        self.init_payload()

    def build_payload(self):
        self.payload["description"] = self.description
        self.payload["public"] = self.is_public
        self.payload["files"] = dict()
        for fpath in self.files:
            fname = basename(fpath)
            self.payload["files"].setdefault(fname, dict())
            self.payload["files"][fname]["content"] = open(fpath, "rb").read()

    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()

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

    def invoke(self):
        response = self.query.do_POST(payload=self.payload)
        return self.on_receive(response)

    def on_receive(self, response):
        self.clipboard_set(response["html_url"])
        print("CREATE ====> {0}".format(response["html_url"]))
        for fpath in self.files:
            print(fpath)
        return response
Example #3
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
Example #4
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
Example #5
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()
Example #6
0
 def init_query(self):
     try:
         self.query = Query(access_token=Auth().get_access_token())
     except (UnSetUserKeyError, UnauthorizedUser):
         self.query = Query()
     self.build_query()
Example #7
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()
Example #8
0
 def init_query(self):
     self.query = Query(filters=[self.auth.to_basicauth()])
     self.build_query()
Example #9
0
 def init_query(self):
     self.query = Query(filters=[self.auth.to_basicauth()])
     self.build_query()