示例#1
0
    def _request(self, url, method='get', data=None, headers=None):
        if not self.token:
            #SublimeHelper.message('Please login and try again')
            #self.login(force=True)
            return
            # replay
            #return self._request(url, method=method, data=data)
        all_headers = self._get_headers()
        if headers:
            all_headers.update(headers)

        result = getattr(requests, method)(url, data=data, headers=all_headers)
        if result.status_code == 201:
            return result.json()
        elif result.json().has_key('error'):
            data= result.json()
            if data.get('error', {}).get('code') == 401:
                SublimeHelper.message('ERROR 401, please restart auth process : %s' % data.get('error', {}).get('message'))
            else:
                SublimeHelper.message('ERROR : %s' % data.get('error', {}).get('message'))
            # replay
            #return self._request(url, method=method, data=data)
        else:
            return result.json()
        raise Exception('error calling %s' % url)
 def finished(code):
     result = callback(code)
     if not result:
         SublimeHelper.message("invalid OAuth code, try again :/")
     else:
         SublimeHelper.message("Authentification success!  You can now browse and edit your Google Apps Scripts files.")
     return result
示例#3
0
 def finished(code):
     result = callback(code)
     if not result:
         SublimeHelper.message("invalid OAuth code, try again :/")
     else:
         SublimeHelper.message(
             "Authentification success!  You can now browse and edit your Google Apps Scripts files."
         )
     return result
 def run(self, edit):
     self.browser = get_GoogleAppsScriptsBrowser()
     if not self.browser.token:
         #SublimeHelper.message('Please login and try again')
         return
     self.update_projects()
     if not self.projects:
         SublimeHelper.message('Cannot fetch projects, or no project found')
         return
     self.prompt_projects()
示例#5
0
 def run(self, edit):
     self.browser = get_GoogleAppsScriptsBrowser()
     if not self.browser.token:
         #SublimeHelper.message('Please login and try again')
         return
     self.update_projects()
     if not self.projects:
         SublimeHelper.message('Cannot fetch projects, or no project found')
         return
     self.prompt_projects()
 def on_post_save(self, view):
     ''' retrieve the full project data and update this file source only '''
     project_id = view.settings().get('GoogleAppsScripts-project')
     file_id = view.settings().get('GoogleAppsScripts-file')
     if file_id:
         region = sublime.Region(0, view.size())
         contents = view.substr(region)
         self.browser = get_GoogleAppsScriptsBrowser()
         if self.browser.update_file(project_id, file_id, contents):
             SublimeHelper.message('File saved to Google Drive')
         else:
             SublimeHelper.message('Error saving file; check the ST console')
def oauth_ask_token_flow(auth_url, callback):
    ''' present the url to user and an input to paste the oauth token '''
    SublimeHelper.message('A URL has been copied to your clipboard!  Open a browser window logged in under the Google Apps account that you wish to associate with this plugin, then paste the URL from your clipboard into that browser.  Approve the request and copy the generated token back into the input box below.')
    sublime.set_clipboard(auth_url)
    def finished(code):
        result = callback(code)
        if not result:
            SublimeHelper.message("invalid OAuth code, try again :/")
        else:
            SublimeHelper.message("Authentification success!  You can now browse and edit your Google Apps Scripts files.")
        return result
    SublimeHelper.show_input("Oauth code : ", "", finished)
示例#8
0
 def on_post_save(self, view):
     ''' retrieve the full project data and update this file source only '''
     project_id = view.settings().get('GoogleAppsScripts-project')
     file_id = view.settings().get('GoogleAppsScripts-file')
     if file_id:
         region = sublime.Region(0, view.size())
         contents = view.substr(region)
         self.browser = get_GoogleAppsScriptsBrowser()
         if self.browser.update_file(project_id, file_id, contents):
             SublimeHelper.message('File saved to Google Drive')
         else:
             SublimeHelper.message(
                 'Error saving file; check the ST console')
示例#9
0
def oauth_ask_token_flow(auth_url, callback):
    ''' present the url to user and an input to paste the oauth token '''
    SublimeHelper.message(
        'A URL has been copied to your clipboard!  Open a browser window logged in under the Google Apps account that you wish to associate with this plugin, then paste the URL from your clipboard into that browser.  Approve the request and copy the generated token back into the input box below.'
    )
    sublime.set_clipboard(auth_url)

    def finished(code):
        result = callback(code)
        if not result:
            SublimeHelper.message("invalid OAuth code, try again :/")
        else:
            SublimeHelper.message(
                "Authentification success!  You can now browse and edit your Google Apps Scripts files."
            )
        return result

    SublimeHelper.show_input("Oauth code : ", "", finished)