├── .gitignore ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── docs ├── Makefile ├── actions.rst ├── comments.rst ├── conf.py ├── create.rst ├── index.rst ├── make.bat ├── manage.rst └── searching.rst ├── setup.cfg ├── setup.py └── simplegist ├── __init__.py ├── comments.py ├── config.py ├── do.py ├── mygist.py └── simplegist.py /.gitignore: -------------------------------------------------------------------------------- 1 | # setup.py output 2 | build/ 3 | dist/ 4 | simplegist.egg-info/ 5 | *.egg-info/ 6 | 7 | # OS Files 8 | .DS_Store 9 | .DS_Store? 10 | *.pyc 11 | *~ 12 | 13 | docs/_build 14 | docs/_static 15 | docs/_templates 16 | 17 | #pypi settings file 18 | .pyirc -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Varun Malhotra 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Github-Gist Api - python wrapper 2 | ================================ 3 | 4 | Python wrapper for ``GitHub's Gist API``. 5 | 6 | |Latest Version| |Downloads| 7 | 8 | .. |Latest Version| image:: https://img.shields.io/pypi/v/simplegist.svg 9 | :target: https://pypi.python.org/pypi/simplegist 10 | 11 | .. |Downloads| image:: https://img.shields.io/pypi/dm/simplegist.svg 12 | :target: https://pypi.python.org/pypi/simplegist 13 | 14 | Features 15 | -------- 16 | 17 | * Create Gists and get url, script and clone link on success (can be used for copy-paste purpose too) 18 | * View one's Gist(s) - name, description and it's content 19 | * Edit and Delete a gist 20 | * Search Gist(s) of any user; fork, star and unstar them 21 | * List all comments on any Gist, put/edit/delete a comment on a Gist 22 | 23 | Installation 24 | ------------- 25 | .. code-block:: bash 26 | 27 | $ pip install simplegist 28 | 29 | Download `here `_ and run ``python setup.py install`` after changing directory to ``/simplegist`` 30 | 31 | Generating Github API Access Token 32 | ---------------------------------- 33 | Go to Github's Account settings > Applications 34 | ``Create a new token`` and use it for making API requests instead of password 35 | 36 | Example Usage 37 | ------------- 38 | 39 | .. code-block:: python 40 | 41 | from simplegist import Simplegist 42 | 43 | ghGist = Simplegist(username='USERNAME', api_token='API_TOKEN') 44 | # or provide USERNAME and API_TOKEN in config.py file, so just, ghGist = Gist() 45 | 46 | # creating gist and getting url, script and clone link 47 | ghGist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public=1, content='_CONTENT_GOES_HERE') 48 | 49 | # List down all the names of authenticated user's Gists 50 | ghGist.profile().listall() 51 | 52 | # List down only the names of recent two Gists of user '_USERNAME' 53 | ghGist.search('_USERNAME').list(2) 54 | 55 | # List down all the comments on gist named '_GISTNAME' of user 'USERNAME' 56 | ghGist.comments().listall(user='_USERNAME', name='_GISTNAME') 57 | 58 | # ...and many more... 59 | 60 | Full Usage and Documentation 61 | ---------------------------- 62 | 63 | Visit here `READTHEDOCS `_ or `PYTHONHOSTED `_ 64 | 65 | Patches and suggestions are welcome 66 | ----------------------------------- 67 | 68 | .. code-block:: bash 69 | 70 | $ git clone https://github.com/softvar/simplegist.git 71 | $ cd simplegist 72 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/simplegist.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/simplegist.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/simplegist" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/simplegist" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/actions.rst: -------------------------------------------------------------------------------- 1 | Actions on gists 2 | ================ 3 | 4 | .. warning:: 5 | 6 | user must be authenticated 7 | 8 | Useful Information for below mentioned methods 9 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10 | 11 | Since all the below mentioned methods require GistName/GistID. GistName is provided only when calling methods for your own Gists. Whereas GistID can be provided for all. 12 | 13 | **GistID of other users' Gist can be easily extracted without opening browser. Refer to the** 14 | :doc:`searching` **section** 15 | 16 | Check a Gist for a star ``do().checkifstar(params)`` 17 | ---------------------------------------------------- 18 | 19 | Check any Gist for a star by providing Gistname(if that Gist belongs to you) or GistID. 20 | 21 | 22 | .. note:: 23 | 24 | Input 25 | 26 | ``name/id`` 27 | provide **name** only if that gist belongs to you 28 | , provide **id** for checking correspondong Gist 29 | 30 | *Required* 31 | 32 | .. code-block:: python 33 | 34 | GHgist.do().checkifstar(id='_GISTID') 35 | 36 | # provide your Gistname 37 | GHgist.do().checkifstar(name='_YOUR_GISTNAME') 38 | 39 | Star a Gist ``do().star(params)`` 40 | --------------------------------- 41 | 42 | Star any Gist by providing Gistname(if that Gist belongs to you) or GistID. 43 | 44 | 45 | .. note:: 46 | 47 | Input 48 | 49 | ``name/id`` 50 | provide **name** only if that gist belongs to you 51 | , provide **id** for starring corresponding Gist 52 | 53 | *Required* 54 | 55 | .. code-block:: python 56 | 57 | GHgist.do().star(id='_GISTID') 58 | 59 | # provide your Gistname 60 | GHgist.do().star(name='_YOUR_GISTNAME') 61 | 62 | Unstar a Gist ``do().unstar(params)`` 63 | ------------------------------------- 64 | 65 | UnStar any Gist by providing Gistname(if that Gist belongs to you) or GistID. 66 | 67 | 68 | .. note:: 69 | 70 | Input 71 | 72 | ``name/id`` 73 | 74 | provide **name** only if that gist belongs to you 75 | , provide **id** for unstarring corresponding Gist 76 | 77 | *Required* 78 | 79 | .. code-block:: python 80 | 81 | GHgist.do().unstar(id='_GISTID') 82 | 83 | # provide your Gistname 84 | GHgist.do().unstar(name='_YOUR_GISTNAME') 85 | 86 | Fork a Gist ``do().fork(params)`` 87 | --------------------------------- 88 | 89 | Fork other's Gist by providing GistID. 90 | 91 | 92 | .. note:: 93 | 94 | Input 95 | 96 | ``id`` 97 | provide **id** for forking corresponding Gist 98 | 99 | *Required* 100 | 101 | .. code-block:: python 102 | 103 | GHgist.do().fork(id='_GISTID') 104 | 105 | Other Docs 106 | ^^^^^^^^^^ 107 | 108 | * :doc:`index` 109 | * :doc:`create` 110 | * :doc:`manage` 111 | * :doc:`searching` 112 | * :doc:`comments` -------------------------------------------------------------------------------- /docs/comments.rst: -------------------------------------------------------------------------------- 1 | GistAPI for Comments Section 2 | ============================ 3 | 4 | 5 | Listing all the comments on your Gists ``comments().listall(params)`` 6 | --------------------------------------------------------------------- 7 | 8 | List all the contents of comments made on a single Gist by providing the GistName/GistID and USERNAME if the gist is not yours. 9 | 10 | .. note:: 11 | 12 | Input 13 | ``user`` - for listing out the comments on a Gist of *some* user. 14 | Optional 15 | 16 | Fetch all the comments on a Gist ``listall(name='*gistname*')`` ``listall(id='*gistid*')``. 17 | 18 | .. code-block:: python 19 | 20 | # listing comments on your gist = *GISTNAME* 21 | GHgist.comments().listall(name='GISTNAME') 22 | 23 | .. code-block:: python 24 | 25 | # listing comments on a gist of user = *GITHUBUSERNAME* 26 | GHgist.comments().listall(user='GITHUBUSERNAME', name='GISTNAME') 27 | 28 | Fetch a single comment on a Gist ``comments().get(params)`` 29 | ----------------------------------------------------------- 30 | 31 | Fetch any comment's contents just by providing it's GistName/GistID along with the CommentID. 32 | 33 | .. note:: 34 | 35 | Input 36 | 37 | ``name/id`` - GistName/GistID 38 | *Required* 39 | ``commentid`` - commentid of a comment 40 | *Required* 41 | 42 | .. code-block:: python 43 | 44 | GHgist.comments().get(name='bootstrap-min.css', commentid='862438') 45 | 46 | Post/Create a comment on a Gist ``comments().create(params)`` 47 | ------------------------------------------------------------- 48 | 49 | Post a comment on a Gist providing GistName/GistID, BODY of Comment and USERNAME. 50 | Commenting on your own Gist doesn't require USERNAME as an argument. 51 | 52 | .. note:: 53 | 54 | Input 55 | 56 | ``name/id`` - GistName/GistID 57 | *Required* 58 | ``body`` - contents of a comment to be posted 59 | *Required* 60 | ``user`` - comment on a Github user's gist 61 | *Optional* if commenting on your Gist only 62 | *Required* if commenting on others Gist 63 | 64 | .. code-block:: python 65 | 66 | # commenting on your own Gist with id='*GISTID*' and body='*CONTENTS_OF_COMMENT*' 67 | GHgist.comments().create(id='5948962', body='hello') 68 | 69 | # commenting on Github user = '*USERNAME*' with name='*GISTNAME*' with body='*CONTENTS_OF_COMMENT*' 70 | GHgist.comments().create(user='caspyin',name='curl.md', body='very helpful') 71 | 72 | Edit a comment on a Gist ``comments().edit(params)`` 73 | ---------------------------------------------------- 74 | 75 | Edit Body of any comment on a Gist by providing GistName/GistID, commentID, BODY to be edited and USERNAME (if the Gist is not yours). 76 | 77 | .. note:: 78 | 79 | Input 80 | name/id - GistName/GistID 81 | *Required* 82 | commentid - commentid of a comment 83 | *Required* 84 | body - contents of a comment to be posted 85 | *Required* 86 | user - comment on a Github user's gist 87 | *Optional* if commenting on your Gist only 88 | *Required* if commenting on others Gist 89 | 90 | .. code-block:: python 91 | 92 | GHgist.comments().edit(name='bootstrap-min.css', commentid='862438',body='heya! world') 93 | 94 | Delete a comment on a GIst ``comments().delete(params)`` 95 | -------------------------------------------------------- 96 | 97 | Delete any comment you have made on a Gist by provoding GistName/GistID along with commentID. 98 | 99 | .. warning:: 100 | user must be authenticated 101 | 102 | .. note:: 103 | 104 | Input 105 | name/id - GistName/GistID 106 | *Required* 107 | commentid - commentid of a comment 108 | *Required* 109 | 110 | .. code-block:: python 111 | 112 | GHgist.comments().delete(name='bootstrap-min.css', commentid='862454') 113 | 114 | Other Docs 115 | ^^^^^^^^^^ 116 | 117 | * :doc:`index` 118 | * :doc:`create` 119 | * :doc:`manage` 120 | * :doc:`actions` 121 | * :doc:`searching` 122 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # simplegist documentation build configuration file, created by 4 | # sphinx-quickstart on Mon Jul 15 12:56:40 2013. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = [] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'simplegist' 44 | copyright = u'2013, Varun Malhotra' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.3' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.3' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | # If true, keep warnings as "system message" paragraphs in the built documents. 90 | #keep_warnings = False 91 | 92 | 93 | # -- Options for HTML output --------------------------------------------------- 94 | 95 | # The theme to use for HTML and HTML Help pages. See the documentation for 96 | # a list of builtin themes. 97 | html_theme = 'default' 98 | 99 | # Theme options are theme-specific and customize the look and feel of a theme 100 | # further. For a list of options available for each theme, see the 101 | # documentation. 102 | #html_theme_options = {} 103 | 104 | # Add any paths that contain custom themes here, relative to this directory. 105 | #html_theme_path = [] 106 | 107 | # The name for this set of Sphinx documents. If None, it defaults to 108 | # " v documentation". 109 | #html_title = None 110 | 111 | # A shorter title for the navigation bar. Default is the same as html_title. 112 | #html_short_title = None 113 | 114 | # The name of an image file (relative to this directory) to place at the top 115 | # of the sidebar. 116 | #html_logo = None 117 | 118 | # The name of an image file (within the static path) to use as favicon of the 119 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 120 | # pixels large. 121 | #html_favicon = None 122 | 123 | # Add any paths that contain custom static files (such as style sheets) here, 124 | # relative to this directory. They are copied after the builtin static files, 125 | # so a file named "default.css" will overwrite the builtin "default.css". 126 | html_static_path = ['_static'] 127 | 128 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 129 | # using the given strftime format. 130 | #html_last_updated_fmt = '%b %d, %Y' 131 | 132 | # If true, SmartyPants will be used to convert quotes and dashes to 133 | # typographically correct entities. 134 | #html_use_smartypants = True 135 | 136 | # Custom sidebar templates, maps document names to template names. 137 | #html_sidebars = {} 138 | 139 | # Additional templates that should be rendered to pages, maps page names to 140 | # template names. 141 | #html_additional_pages = {} 142 | 143 | # If false, no module index is generated. 144 | #html_domain_indices = True 145 | 146 | # If false, no index is generated. 147 | #html_use_index = True 148 | 149 | # If true, the index is split into individual pages for each letter. 150 | #html_split_index = False 151 | 152 | # If true, links to the reST sources are added to the pages. 153 | #html_show_sourcelink = True 154 | 155 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 156 | #html_show_sphinx = True 157 | 158 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 159 | #html_show_copyright = True 160 | 161 | # If true, an OpenSearch description file will be output, and all pages will 162 | # contain a tag referring to it. The value of this option must be the 163 | # base URL from which the finished HTML is served. 164 | #html_use_opensearch = '' 165 | 166 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 167 | #html_file_suffix = None 168 | 169 | # Output file base name for HTML help builder. 170 | htmlhelp_basename = 'simplegistdoc' 171 | 172 | 173 | # -- Options for LaTeX output -------------------------------------------------- 174 | 175 | latex_elements = { 176 | # The paper size ('letterpaper' or 'a4paper'). 177 | #'papersize': 'letterpaper', 178 | 179 | # The font size ('10pt', '11pt' or '12pt'). 180 | #'pointsize': '10pt', 181 | 182 | # Additional stuff for the LaTeX preamble. 183 | #'preamble': '', 184 | } 185 | 186 | # Grouping the document tree into LaTeX files. List of tuples 187 | # (source start file, target name, title, author, documentclass [howto/manual]). 188 | latex_documents = [ 189 | ('index', 'simplegist.tex', u'simplegist Documentation', 190 | u'Varun Malhotra', 'manual'), 191 | ] 192 | 193 | # The name of an image file (relative to this directory) to place at the top of 194 | # the title page. 195 | #latex_logo = None 196 | 197 | # For "manual" documents, if this is true, then toplevel headings are parts, 198 | # not chapters. 199 | #latex_use_parts = False 200 | 201 | # If true, show page references after internal links. 202 | #latex_show_pagerefs = False 203 | 204 | # If true, show URL addresses after external links. 205 | #latex_show_urls = False 206 | 207 | # Documents to append as an appendix to all manuals. 208 | #latex_appendices = [] 209 | 210 | # If false, no module index is generated. 211 | #latex_domain_indices = True 212 | 213 | 214 | # -- Options for manual page output -------------------------------------------- 215 | 216 | # One entry per manual page. List of tuples 217 | # (source start file, name, description, authors, manual section). 218 | man_pages = [ 219 | ('index', 'simplegist', u'simplegist Documentation', 220 | [u'Varun Malhotra'], 1) 221 | ] 222 | 223 | # If true, show URL addresses after external links. 224 | #man_show_urls = False 225 | 226 | 227 | # -- Options for Texinfo output ------------------------------------------------ 228 | 229 | # Grouping the document tree into Texinfo files. List of tuples 230 | # (source start file, target name, title, author, 231 | # dir menu entry, description, category) 232 | texinfo_documents = [ 233 | ('index', 'simplegist', u'simplegist Documentation', 234 | u'Varun Malhotra', 'simplegist', 'One line description of project.', 235 | 'Miscellaneous'), 236 | ] 237 | 238 | # Documents to append as an appendix to all manuals. 239 | #texinfo_appendices = [] 240 | 241 | # If false, no module index is generated. 242 | #texinfo_domain_indices = True 243 | 244 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 245 | #texinfo_show_urls = 'footnote' 246 | 247 | # If true, do not generate a @detailmenu in the "Top" node's menu. 248 | #texinfo_no_detailmenu = False 249 | -------------------------------------------------------------------------------- /docs/create.rst: -------------------------------------------------------------------------------- 1 | Creating a gist 2 | =============== 3 | 4 | .. warning:: 5 | 6 | user must be authenticated 7 | 8 | .. note:: 9 | 10 | Input 11 | 12 | ``name`` 13 | *Optional* argument (*default auto-gistID*) 14 | ``description`` 15 | *Optional* argument (*default empty*) 16 | ``public`` 17 | *Optional* argument (*default public*) 18 | ``content`` 19 | *Required* argument 20 | 21 | 22 | Creating a Gist with all arguments ``create(params)`` 23 | ----------------------------------------------------- 24 | 25 | Create a new Gist simply by providing the parameters as specified above. 26 | 27 | .. code-block:: python 28 | 29 | # create a secret gist(public=0) 30 | GHgist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public=0, content='_CONTENT_GOES_HERE') 31 | 32 | Creating a Gist with *required* argument only ``create(params)`` 33 | ---------------------------------------------------------------- 34 | 35 | .. code-block:: python 36 | 37 | # create a gist with defaut name(gist:gistID, provided by github) 38 | GHgist.create(content='_CONTENT_GOES_HERE') 39 | 40 | Other Docs 41 | ^^^^^^^^^^ 42 | 43 | * :doc:`index` 44 | * :doc:`manage` 45 | * :doc:`actions` 46 | * :doc:`searching` 47 | * :doc:`comments` 48 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. simplegist documentation master file, created by 2 | sphinx-quickstart on Mon Jul 15 12:56:40 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to simplegist's documentation! 7 | ====================================== 8 | Helps in carrying out easy workflow for maintaining gists 9 | 10 | Features 11 | -------- 12 | 13 | * Creating gists returning the url, script and clone link for copy-paste purpose 14 | * Checkout one's gists - Name(s), Description and Content 15 | * Edit and Delete a gist 16 | * Search GitHub user's gist - fork, star and unstar them 17 | * List comments of any gist, make/edit a comment on a gist, delete a comment 18 | 19 | Installation 20 | ------------ 21 | .. code-block:: bash 22 | 23 | $ pip install simplegist 24 | 25 | Or download it from `here `_ and then, 26 | 27 | .. code-block:: bash 28 | 29 | $ cd /to/this/directory/ 30 | $ python install setup.py 31 | 32 | Generating Github API Access Token 33 | ---------------------------------- 34 | 35 | Go to Github's Account settings > Applications 36 | ``Create a new token`` and use it for making API requests instead of password. 37 | 38 | Creating an Instance 39 | --------------------- 40 | 41 | .. code-block:: python 42 | 43 | # if USERNAME and API_TOKEN are not provided in config.py 44 | GHgist = Simplegist(username='USERNAME',api_token='API_TOKEN') 45 | 46 | # else 47 | GHgist = Simplegist() 48 | 49 | Example Usage 50 | ------------- 51 | Below is an example to getting started with using GistAPI and its useful functionalities. 52 | 53 | 54 | .. code-block:: python 55 | 56 | from simplegist import SimpleGist 57 | 58 | # provide USERNAME and API_TOKEN in config.py file, so just, GHgist = Gist(), OR, 59 | GHgist = Simplegist(username='USERNAME',api_token='API_TOKEN') 60 | 61 | # creating gist and returning url, script, clone link 62 | GHgist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public=1, content='_CONTENT_GOES_HERE') 63 | 64 | # Lists all the names of authenticated user's gists 65 | GHgist.profile().listall() 66 | 67 | # Lists only the names of recent two gists of user '_USERNAME' 68 | GHgist.search('_USERNAME').list(2) 69 | 70 | # Lists all the comments on gist named '_GISTNAME' of user '_USERNAME' 71 | GHgist.comments().listall(user='_USERNAME',name='_GISTNAME') 72 | 73 | # ...and many more... 74 | 75 | Contents: 76 | --------- 77 | 78 | .. toctree:: 79 | :maxdepth: 2 80 | 81 | create 82 | manage 83 | actions 84 | searching 85 | comments 86 | 87 | Related Docs 88 | ============ 89 | 90 | * :doc:`create` 91 | * :doc:`manage` 92 | * :doc:`actions` 93 | * :doc:`searching` 94 | * :doc:`comments` 95 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\simplegist.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\simplegist.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/manage.rst: -------------------------------------------------------------------------------- 1 | Managing authenticated user's gists 2 | =================================== 3 | 4 | .. warning:: 5 | 6 | user must be authenticated 7 | 8 | 9 | Listing all the Gists ``profile().listall()`` 10 | --------------------------------------------- 11 | 12 | Fetch all the GistsNames. 13 | 14 | .. note:: 15 | 16 | Only recent 30 gists will be shown as per the Github API v3 17 | 18 | .. code-block:: python 19 | 20 | GHgist.profile().listall() 21 | 22 | Listing the required number of Gists ``profile().list(integer)`` 23 | ---------------------------------------------------------------- 24 | 25 | Fetch only the limited number of Gists ``list(4)``. 26 | 27 | .. note:: 28 | 29 | Input 30 | 31 | integer 32 | ``integer`` is **required** as an argument which will limit the number of Gists to be listed. 33 | 34 | .. code-block:: python 35 | 36 | GHgist.profile().list(4) 37 | 38 | Get GistName ``profile().getgist(id='_GISTID')`` 39 | ------------------------------------------------ 40 | 41 | Fetch Gist's name by provoding it's ID i.e. GistID. 42 | 43 | .. code-block:: python 44 | 45 | GHgist.profile().getgist(id='_GISTID') 46 | 47 | Fetch Gist-Link, Clone-Link and Embed-Script-Link of your gist ``profile().links(id/name)`` 48 | ------------------------------------------------------------------------------------------- 49 | 50 | .. note:: 51 | 52 | Input 53 | 54 | ``name/id`` - id should be correct so check response before using it further. 55 | *Required* 56 | 57 | .. code-block:: python 58 | 59 | GHgist.profile('YOURUSERNAME').links(id='_GISTID') 60 | GHgist.profile('YOURUSERNAME').links(name='_GISTNAME') 61 | 62 | Fetching the contents of a Gist ``profile().content(params)`` 63 | ------------------------------------------------------------- 64 | 65 | Fetch the contents of a Gist by name (GISTNAME) ``content(name='_GISTNAME')``. 66 | 67 | .. code-block:: python 68 | 69 | GHgist.profile().content(name='_GISTNAME') 70 | 71 | Fetch by id (GISTID) 72 | 73 | .. code-block:: python 74 | 75 | GHgist.profile().content(id='_GISTID') 76 | 77 | Listing the starred Gists ``profile().starred()`` 78 | ------------------------------------------------- 79 | 80 | List all your starred gists ``starred()`` 81 | 82 | .. code-block:: python 83 | 84 | GHgist.profile().starred() 85 | 86 | List only the required number of starred Gists ``starred(limit=2)``. 87 | 88 | .. note:: 89 | 90 | ``limit`` 91 | *Required* 92 | 93 | .. code-block:: python 94 | 95 | GHgist.profile().starred(limit=2) 96 | 97 | Get GistName ``profile().getgist(id='_GISTID')`` 98 | ------------------------------------------------ 99 | 100 | Fetch any of your Gist's name by provoding it's ID i.e. GISTID. 101 | 102 | .. code-block:: python 103 | 104 | GHgist.profile().getgist(id='_GistID') 105 | 106 | Editing a Gist ``profile().edit(params)`` 107 | ----------------------------------------- 108 | 109 | Edit a Gist by providing either GistName or GistID, and content. 110 | 111 | .. note:: 112 | 113 | Input 114 | 115 | ``description`` 116 | *Optional* 117 | ``name/id`` 118 | *Required* 119 | ``content`` 120 | *Required* 121 | 122 | 123 | .. code-block:: python 124 | 125 | # with all the arguments 126 | GHgist.profile().edit(description='_NEW_DESCRIPTION',name='_GISTNAME',content='_UPDATED_CONETNT_GOES_HERE') 127 | 128 | # with required arguments 129 | GHgist.profile().edit(id='_GISTID',content='_UPDATED_CONTENT_GOES_HERE') 130 | 131 | Getting a GistName using GistID ``profile().getMyID(params)`` 132 | ------------------------------------------------------------- 133 | 134 | Very useful in order to work hasslefree ``getMyID('_YOUR_GIST_NAME')``. 135 | 136 | .. code-block:: python 137 | 138 | GHgist.profile().getMyID('_YOUR_GIST_NAME') 139 | 140 | 141 | 142 | Deleting a Gist ``profile().delete(params)`` 143 | -------------------------------------------- 144 | 145 | Delete a gist by providing either GistName or GistID ``delete(id='_GISTID')``. 146 | 147 | .. note:: 148 | 149 | Input 150 | ``name/id`` 151 | *Required* 152 | 153 | .. code-block:: python 154 | 155 | GHgist.profile().delete(id='_GISTID') 156 | 157 | Other Docs 158 | ^^^^^^^^^^ 159 | 160 | * :doc:`index` 161 | * :doc:`create` 162 | * :doc:`actions` 163 | * :doc:`searching` 164 | * :doc:`comments` -------------------------------------------------------------------------------- /docs/searching.rst: -------------------------------------------------------------------------------- 1 | Search User's gists 2 | =================== 3 | 4 | Listing all the Gists ``search('_USERNAME').listall()`` 5 | ------------------------------------------------------- 6 | 7 | Fetch all the GistsNames of a Github User. 8 | 9 | .. note:: 10 | 11 | Only recent 30 gists will be shown as per the Github API v3 12 | 13 | .. code-block:: python 14 | 15 | GHgist.search('_USERNAME').listall() 16 | 17 | Listing the required number of Gists ``search('_USERNAME').list(integer)`` 18 | -------------------------------------------------------------------------- 19 | 20 | Fetch only the limited number of Gists. 21 | 22 | .. note:: 23 | 24 | Input 25 | 26 | integer 27 | ``integer`` is **required** as an argument which will limit the number of Gists to be listed. 28 | 29 | .. code-block:: python 30 | 31 | GHgist.search('_USERNAME').list(2) 32 | 33 | Fetching the contents of a Gist using GistName ``search('_USERNAME').content(params)`` 34 | -------------------------------------------------------------------------------------- 35 | 36 | Fetch the contents of a Gist by name (GistName). 37 | 38 | .. code-block:: python 39 | 40 | GHgist.search('_USERNAME').content(name='_GISTNAME') 41 | 42 | Fetching the contents of any Gist using GistID ``search('').content(id='_GISTID')`` 43 | ----------------------------------------------------------------------------------- 44 | 45 | Fetch by id (GistID) 46 | 47 | .. code-block:: python 48 | 49 | GHgist.search('').content(id='_GISTID') 50 | 51 | Fetch GistName ``search('').getgist(id='_GISTID')`` 52 | --------------------------------------------------- 53 | 54 | Fetch Gist's name by provoding it's ID i.e. GistID. 55 | 56 | .. code-block:: python 57 | 58 | GHgist.search('').getgist(id='_GISTID') 59 | 60 | Fetch Gist-Link, Clone-Link and Embed-Script-Link of searched gist ``search('_USERNAME/EMPTY').links(id/name)`` 61 | ------------------------------------------------------------------------------------------------------------------------------ 62 | 63 | It is very very useful and solves the dual purpose. Providing the username and a Gistname of that user not only provides the above mentioned Links but also let 'one' know about the GistID of that Gist. 64 | 65 | Moreover, this criteria can also be applied in finding 'one\'s' own Gist's GistID by providing Gistname. 66 | 67 | .. note:: 68 | 69 | Input 70 | 71 | ``name/id`` - 72 | if providing GistdID, Github-Username should be blank like search(''),links(id='_GISTID') 73 | if providing GistName, Github-Username is required like search('Github-User').links(name='THATUSERSGISTNAME') 74 | 75 | *Required* 76 | 77 | .. code-block:: python 78 | 79 | GHgist.search('').links(id='_GISTID') 80 | GHgist.search('_USERNAME').links(name='_GISTNAME') 81 | 82 | Other Docs 83 | ^^^^^^^^^^ 84 | 85 | * :doc:`index` 86 | * :doc:`create` 87 | * :doc:`manage` 88 | * :doc:`actions` 89 | * :doc:`comments` 90 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.rst -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | from setuptools import setup 4 | 5 | required = ['requests'] 6 | 7 | 8 | if sys.version_info[:2] < (2,6): 9 | required.append('simplejson') 10 | 11 | setup( 12 | name = 'simplegist', 13 | packages = ['simplegist'], 14 | version = '1.0.1', 15 | install_requires=required, 16 | description = 'Python wrapper for Gist ', 17 | long_description=open('README.rst').read(), 18 | author = 'Varun Malhotra', 19 | author_email = 'varun2902@gmail.com', 20 | url = 'https://github.com/softvar/simplegist', 21 | download_url = 'https://github.com/softvar/simplegist/tarball/1.0.1', 22 | keywords = ['gist', 'github', 'API'], 23 | license = 'MIT', 24 | classifiers = ( 25 | "Programming Language :: Python", 26 | "Programming Language :: Python :: 2.5", 27 | "Programming Language :: Python :: 2.6", 28 | "Programming Language :: Python :: 2.7", 29 | ), 30 | ) -------------------------------------------------------------------------------- /simplegist/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | GistApi-Wrapper-python -- A python wrapper for GitHub's Gist API 3 | with advanced support to easily copy-paste the url, script,clone link 4 | without manually looking for it on GitHub 5 | (c) 2013 Varun Malhotra. MIT License 6 | """ 7 | 8 | from simplegist import * 9 | 10 | __author__ = 'Varun Malhotra' 11 | __version__ = '1.0.1' 12 | __license__ = 'MIT' -------------------------------------------------------------------------------- /simplegist/comments.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | from config import BASE_URL, GIST_URL 4 | 5 | class Comments: 6 | def __init__(self, gist): 7 | self.gist = gist 8 | 9 | 10 | def getMyID(self,gist_name): 11 | ''' 12 | Getting gistID of a gist in order to make the workflow 13 | easy and uninterrupted. 14 | ''' 15 | r = requests.get( 16 | '%s'%BASE_URL+'/users/%s/gists' % self.user, 17 | headers=self.gist.header 18 | ) 19 | if (r.status_code == 200): 20 | r_text = json.loads(r.text) 21 | limit = len(r.json()) 22 | 23 | for g,no in zip(r_text, range(0,limit)): 24 | for ka,va in r.json()[no]['files'].iteritems(): 25 | if str(va['filename']) == str(gist_name): 26 | return r.json()[no]['id'] 27 | return 0 28 | 29 | raise Exception('Username not found') 30 | 31 | 32 | def listall(self, **args): 33 | if 'user' in args: 34 | self.user = args['user'] 35 | 36 | else: 37 | self.user = self.gist.username 38 | 39 | self.gist_name = '' 40 | if 'name' in args: 41 | self.gist_name = args['name'] 42 | self.gist_id = self.getMyID(self.gist_name) 43 | elif 'id' in args: 44 | self.gist_id = args['id'] 45 | else: 46 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 47 | 48 | if self.gist_id: 49 | allcomments = [] 50 | r = requests.get( 51 | '%s'%BASE_URL+'/gists/%s/comments' % self.gist_id, 52 | headers=self.gist.header 53 | ) 54 | r_text = json.loads(r.text) 55 | limit = len(r.json()) 56 | if (r.status_code == 200 ): 57 | for g,no in zip(r_text, range(0,limit)): 58 | allcomments.append(r.json()[no]['body']) 59 | 60 | return allcomments 61 | 62 | raise Exception('Gistname not found') 63 | 64 | def create(self, **args): 65 | if 'body' in args: 66 | self.body = {'body':args['body']} 67 | else: 68 | raise Exception('Comment Body can\'t be empty') 69 | if 'user' in args: 70 | self.user = args['user'] 71 | 72 | else: 73 | self.user = self.gist.username 74 | 75 | self.gist_name = '' 76 | if 'name' in args: 77 | self.gist_name = args['name'] 78 | self.gist_id = self.getMyID(self.gist_name) 79 | elif 'id' in args: 80 | self.gist_id = args['id'] 81 | else: 82 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 83 | 84 | if self.gist_id: 85 | 86 | r = requests.post( 87 | '%s'%BASE_URL+'/gists/%s/comments' % self.gist_id, 88 | headers=self.gist.header, 89 | data=json.dumps(self.body) 90 | ) 91 | if (r.status_code == 201): 92 | response ={ 93 | 'GistID': self.gist_id, 94 | 'CommenID': r.json()['id'], 95 | 'body': self.body['body'], 96 | 'created_at': r.json()['created_at'] 97 | } 98 | return response 99 | 100 | 101 | raise Exception('Comment not created') 102 | 103 | 104 | def delete(self, **args): 105 | 106 | self.user = self.gist.username 107 | 108 | self.gist_name = '' 109 | if 'name' in args: 110 | self.gist_name = args['name'] 111 | self.gist_id = self.getMyID(self.gist_name) 112 | elif 'id' in args: 113 | self.gist_id = args['id'] 114 | else: 115 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 116 | 117 | if 'commentid' in args: 118 | self.commentid = args['commentid'] 119 | else: 120 | raise Exception('CommenID not provided') 121 | 122 | if self.gist_id: 123 | r = requests.delete( 124 | '%s/gists/%s/comments/%s'%(BASE_URL,self.gist_id, self.commentid), 125 | headers=self.gist.header 126 | ) 127 | if (r.status_code == 204): 128 | response ={ 129 | 'deleted': 'True', 130 | 'GistID': self.gist_id, 131 | 'CommentID': self.commentid, 132 | } 133 | return response 134 | else: 135 | response ={ 136 | 'comment' : 'not exists' 137 | } 138 | return response 139 | 140 | raise Exception('Gist/Comment not exits') 141 | 142 | 143 | def get(self, **args): 144 | 145 | self.user = self.gist.username 146 | 147 | self.gist_name = '' 148 | if 'name' in args: 149 | self.gist_name = args['name'] 150 | self.gist_id = self.getMyID(self.gist_name) 151 | elif 'id' in args: 152 | self.gist_id = args['id'] 153 | else: 154 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 155 | 156 | if 'commentid' in args: 157 | self.commentid = args['commentid'] 158 | else: 159 | raise Exception('CommenID not provided') 160 | 161 | if self.gist_id: 162 | r = requests.get( 163 | '%s/gists/%s/comments/%s'%(BASE_URL,self.gist_id, self.commentid), 164 | headers=self.gist.header 165 | ) 166 | if (r.status_code == 200): 167 | response ={ 168 | 'body': r.json()['body'], 169 | 'GistID': self.gist_id, 170 | 'CommentID': self.commentid, 171 | 'created_at': r.json()['created_at'] 172 | } 173 | return response 174 | else: 175 | response ={ 176 | 'comment' : 'not exists' 177 | } 178 | return response 179 | 180 | 181 | raise Exception('Comment not exits/deleted') 182 | 183 | def edit(self, **args): 184 | if 'body' in args: 185 | self.body = {'body':args['body']} 186 | else: 187 | raise Exception('Comment Body can\'t be empty') 188 | if 'user' in args: 189 | self.user = args['user'] 190 | 191 | else: 192 | self.user = self.gist.username 193 | 194 | if 'commentid' in args: 195 | self.commentid = args['commentid'] 196 | else: 197 | raise Exception('CommenID not provided') 198 | 199 | self.gist_name = '' 200 | if 'name' in args: 201 | self.gist_name = args['name'] 202 | self.gist_id = self.getMyID(self.gist_name) 203 | elif 'id' in args: 204 | self.gist_id = args['id'] 205 | else: 206 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 207 | 208 | if self.gist_id: 209 | 210 | r = requests.patch( 211 | '%s/gists/%s/comments/%s'%(BASE_URL,self.gist_id, self.commentid), 212 | headers=self.gist.header, 213 | data=json.dumps(self.body) 214 | ) 215 | if (r.status_code == 200): 216 | response ={ 217 | 'GistID': self.gist_id, 218 | 'CommenID': r.json()['id'], 219 | 'body': self.body['body'], 220 | 'created_at': r.json()['created_at'] 221 | } 222 | return response 223 | else: 224 | response = { 225 | 'comment' : 'not edited' 226 | } 227 | 228 | 229 | raise Exception('Comment not edited') -------------------------------------------------------------------------------- /simplegist/config.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Either configure here or use command line arguments 3 | -U/--username for username eg. -U 'softvar' or --username 'softvar' 4 | _p/--password for password eg. -P 'secret_password' or --password 'secret_password' 5 | ''' 6 | # Your Github username 7 | USERNAME = '' 8 | 9 | # Your Github API TOKEN 10 | API_TOKEN = '' 11 | # By default setting Limit to fetch no of gists of authenticated user 12 | # or use -L/--limit as command-line arguments 13 | # Github API will always return <= 30 recent gists. 14 | LIMIT = None 15 | 16 | BASE_URL = 'https://api.github.com' 17 | GIST_URL = 'https://gist.github.com' -------------------------------------------------------------------------------- /simplegist/do.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | from config import BASE_URL, GIST_URL 4 | 5 | class Do: 6 | def __init__(self, gist): 7 | self.gist = gist 8 | 9 | def getMyID(self,gist_name): 10 | ''' 11 | Getting gistID of a gist in order to make the workflow 12 | easy and uninterrupted. 13 | ''' 14 | r = requests.get( 15 | '%s'%BASE_URL+'/users/%s/gists' % self.gist.username, 16 | headers=self.gist.header 17 | ) 18 | if (r.status_code == 200): 19 | r_text = json.loads(r.text) 20 | limit = len(r.json()) 21 | 22 | for g,no in zip(r_text, range(0,limit)): 23 | for ka,va in r.json()[no]['files'].iteritems(): 24 | if str(va['filename']) == str(gist_name): 25 | return r.json()[no]['id'] 26 | return 0 27 | 28 | def star(self, **args): 29 | ''' 30 | star any gist by providing gistID or gistname(for authenticated user) 31 | ''' 32 | if 'name' in args: 33 | self.gist_name = args['name'] 34 | self.gist_id = self.getMyID(self.gist_name) 35 | elif 'id' in args: 36 | self.gist_id = args['id'] 37 | else: 38 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid to be starred') 39 | 40 | r = requests.put( 41 | '%s'%BASE_URL+'/gists/%s/star' % self.gist_id, 42 | headers=self.gist.header 43 | ) 44 | if (r.status_code == 204): 45 | response = { 46 | 'id': self.gist_id 47 | } 48 | return response 49 | 50 | raise Exception('Gist can\'t be starred') 51 | 52 | def unstar(self, **args): 53 | ''' 54 | unstar any gist by providing gistID or gistname(for authenticated user) 55 | ''' 56 | if 'name' in args: 57 | self.gist_name = args['name'] 58 | self.gist_id = self.getMyID(self.gist_name) 59 | elif 'id' in args: 60 | self.gist_id = args['id'] 61 | else: 62 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid to be unstarred') 63 | 64 | r = requests.delete( 65 | '%s'%BASE_URL+'/gists/%s/star' % self.gist_id, 66 | headers=self.gist.header 67 | ) 68 | if (r.status_code == 204): 69 | response = { 70 | 'id': self.gist_id 71 | } 72 | return response 73 | 74 | raise Exception('Gist can\'t be unstarred') 75 | 76 | def fork(self, **args): 77 | ''' 78 | fork any gist by providing gistID or gistname(for authenticated user) 79 | ''' 80 | if 'name' in args: 81 | self.gist_name = args['name'] 82 | self.gist_id = self.getMyID(self.gist_name) 83 | elif 'id' in args: 84 | self.gist_id = args['id'] 85 | else: 86 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid to be forked') 87 | 88 | r = requests.post( 89 | '%s'%BASE_URL+'/gists/%s/forks' % self.gist_id, 90 | headers=self.gist.header 91 | ) 92 | if (r.status_code == 201): 93 | response = { 94 | 'id': self.gist_id, 95 | 'description': r.json()['description'], 96 | 'public': r.json()['public'], 97 | 'comments': r.json()['comments'] 98 | } 99 | return response 100 | 101 | raise Exception('Gist can\'t be forked') 102 | 103 | def checkifstar(self, **args): 104 | ''' 105 | Check a gist if starred by providing gistID or gistname(for authenticated user) 106 | ''' 107 | 108 | if 'name' in args: 109 | self.gist_name = args['name'] 110 | self.gist_id = self.getMyID(self.gist_name) 111 | elif 'id' in args: 112 | self.gist_id = args['id'] 113 | else: 114 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid to be checked for star') 115 | 116 | r = requests.get( 117 | '%s'%BASE_URL+'/gists/%s/star' % self.gist_id, 118 | headers=self.gist.header 119 | ) 120 | if (r.status_code == 204): 121 | response = { 122 | 'starred': 'True', 123 | 'id': self.gist_id 124 | } 125 | else: 126 | response = { 127 | 'starred': 'False' 128 | } 129 | 130 | return response -------------------------------------------------------------------------------- /simplegist/mygist.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | from config import BASE_URL, GIST_URL 4 | 5 | class Mygist: 6 | def __init__(self, gist, **args): 7 | self.gist = gist 8 | if 'user' in args: 9 | self.user = args['user'] 10 | else: 11 | self.user = self.gist.username 12 | 13 | def listall(self): 14 | ''' 15 | will display all the filenames. 16 | Result can be stored in an array for easy fetching of gistNames 17 | for future purposes. 18 | eg. a = Gist().mygists().listall() 19 | print a[0] #to fetch first gistName 20 | ''' 21 | file_name = [] 22 | r = requests.get( 23 | '%s/users/%s/gists' % (BASE_URL, self.user), 24 | headers=self.gist.header 25 | ) 26 | r_text = json.loads(r.text) 27 | limit = len(r.json()) 28 | if (r.status_code == 200 ): 29 | for g,no in zip(r_text, range(0,limit)): 30 | for key,value in r.json()[no]['files'].iteritems(): 31 | file_name.append(value['filename']) 32 | return file_name 33 | 34 | raise Exception('Username not found') 35 | 36 | def list(self, offset): 37 | ''' 38 | will display only the required no. of filenames but in order. 39 | Result can be stored in an array for easy fetching of gistNames 40 | for future purposes. 41 | eg. a = Gist().mygists().listall() 42 | print a[0] #to fetch first gistName 43 | ''' 44 | file_name = [] 45 | r = requests.get( 46 | '%s/users/%s/gists' %(BASE_URL,self.user), 47 | headers=self.gist.header 48 | ) 49 | if (r.status_code == 200 ): 50 | r_text = json.loads(r.text) 51 | limit = offset if (offset <= len(r.json()) ) else len(r.json()) 52 | 53 | for g,no in zip(r_text, range(0,limit)): 54 | for key,value in r.json()[no]['files'].iteritems(): 55 | file_name.append(value['filename']) 56 | return file_name 57 | raise Exception('Username not found') 58 | 59 | def getMyID(self,gist_name): 60 | ''' 61 | Getting gistID of a gist in order to make the workflow 62 | easy and uninterrupted. 63 | ''' 64 | r = requests.get( 65 | '%s'%BASE_URL+'/users/%s/gists' % self.user, 66 | headers=self.gist.header 67 | ) 68 | if (r.status_code == 200): 69 | r_text = json.loads(r.text) 70 | limit = len(r.json()) 71 | 72 | for g,no in zip(r_text, range(0,limit)): 73 | for ka,va in r.json()[no]['files'].iteritems(): 74 | if str(va['filename']) == str(gist_name): 75 | return r.json()[no]['id'] 76 | return 0 77 | 78 | def content(self, **args): 79 | ''' 80 | Doesn't require manual fetching of gistID of a gist 81 | passing gistName will return the content of gist. In case, 82 | names are ambigious, provide GistID or it will return the contents 83 | of recent ambigious gistname 84 | ''' 85 | self.gist_name = '' 86 | if 'name' in args: 87 | self.gist_name = args['name'] 88 | self.gist_id = self.getMyID(self.gist_name) 89 | elif 'id' in args: 90 | self.gist_id = args['id'] 91 | else: 92 | raise Exception('Either provide authenticated user\'s Unambigious Gistname or any unique Gistid') 93 | 94 | 95 | if self.gist_id: 96 | r = requests.get( 97 | '%s'%BASE_URL+'/gists/%s' %self.gist_id, 98 | headers=self.gist.header 99 | ) 100 | if (r.status_code == 200): 101 | r_text = json.loads(r.text) 102 | if self.gist_name!='': 103 | content = r.json()['files'][self.gist_name]['content'] 104 | else: 105 | for key,value in r.json()['files'].iteritems(): 106 | content = r.json()['files'][value['filename']]['content'] 107 | return content 108 | 109 | raise Exception('No such gist found') 110 | 111 | def getgist(self, **args): 112 | 113 | if 'id' in args: 114 | self.gist_id = args['id'] 115 | else: 116 | raise Exception('Gist ID must be provided') 117 | 118 | if self.gist_id: 119 | r = requests.get( 120 | '%s/gists/%s'%(BASE_URL,self.gist_id), 121 | headers=self.gist.header, 122 | ) 123 | if (r.status_code == 200): 124 | 125 | for key,value in r.json()['files'].iteritems(): 126 | content = value['filename'] 127 | return content 128 | 129 | raise Exception('No such gist found') 130 | 131 | 132 | def edit(self, **args): 133 | ''' 134 | Doesn't require manual fetching of gistID of a gist 135 | passing gistName will return edit the gist 136 | ''' 137 | self.gist_name = '' 138 | if 'description' in args: 139 | self.description = args['description'] 140 | else: 141 | self.description = '' 142 | 143 | 144 | if 'name' in args and 'id' in args: 145 | self.gist_name = args['name'] 146 | self.gist_id = args['id'] 147 | elif 'name' in args: 148 | self.gist_name = args['name'] 149 | self.gist_id = self.getMyID(self.gist_name) 150 | elif 'id' in args: 151 | self.gist_id = args['id'] 152 | else: 153 | raise Exception('Gist Name/ID must be provided') 154 | 155 | if 'content' in args: 156 | self.content = args['content'] 157 | else: 158 | raise Exception('Gist content can\'t be empty') 159 | 160 | if (self.gist_name == ''): 161 | self.gist_name = self.getgist(id=self.gist_id) 162 | data = {"description": self.description, 163 | "files": { 164 | self.gist_name: { 165 | "content": self.content 166 | } 167 | } 168 | } 169 | else: 170 | data = {"description": self.description, 171 | "files": { 172 | self.gist_name: { 173 | "content": self.content 174 | } 175 | } 176 | } 177 | 178 | 179 | if self.gist_id: 180 | r = requests.patch( 181 | '%s/gists/%s'%(BASE_URL,self.gist_id), 182 | headers=self.gist.header, 183 | data=json.dumps(data), 184 | ) 185 | if (r.status_code == 200): 186 | r_text = json.loads(r.text) 187 | response = { 188 | 'updated_content': self.content, 189 | 'created_at': r.json()['created_at'], 190 | 'comments':r.json()['comments'] 191 | } 192 | 193 | return response 194 | 195 | raise Exception('No such gist found') 196 | 197 | 198 | def delete(self, **args): 199 | ''' 200 | Delete a gist by gistname/gistID 201 | ''' 202 | 203 | if 'name' in args: 204 | self.gist_name = args['name'] 205 | self.gist_id = self.getMyID(self.gist_name) 206 | elif 'id' in args: 207 | self.gist_id = args['id'] 208 | else: 209 | raise Exception('Provide GistName to delete') 210 | 211 | url = 'gists' 212 | if self.gist_id: 213 | r = requests.delete( 214 | '%s/%s/%s'%(BASE_URL,url,self.gist_id), 215 | headers=self.gist.header 216 | ) 217 | if (r.status_code == 204): 218 | response = { 219 | 'id': self.gist_id, 220 | } 221 | return response 222 | 223 | raise Exception('Can not delete gist') 224 | 225 | 226 | def starred(self, **args): 227 | ''' 228 | List the authenticated user's starred gists 229 | ''' 230 | ids =[] 231 | r = requests.get( 232 | '%s/gists/starred'%BASE_URL, 233 | headers=self.gist.header 234 | ) 235 | 236 | if 'limit' in args: 237 | limit = args['limit'] 238 | else: 239 | limit = len(r.json()) 240 | 241 | if (r.status_code == 200): 242 | for g in range(0,limit ): 243 | ids.append('%s/%s/%s' %(GIST_URL,r.json()[g]['user']['login'],r.json()[g]['id'])) 244 | return ids 245 | 246 | raise Exception('Username not found') 247 | 248 | def links(self,**args): 249 | ''' 250 | Return Gist URL-Link, Clone-Link and Script-Link to embed 251 | ''' 252 | if 'name' in args: 253 | self.gist_name = args['name'] 254 | self.gist_id = self.getMyID(self.gist_name) 255 | elif 'id' in args: 256 | self.gist_id = args['id'] 257 | else: 258 | raise Exception('Gist Name/ID must be provided') 259 | if self.gist_id: 260 | r = requests.get( 261 | '%s/gists/%s'%(BASE_URL,self.gist_id), 262 | headers=self.gist.header, 263 | ) 264 | if (r.status_code == 200): 265 | 266 | content = { 267 | 'Github-User': r.json()['user']['login'], 268 | 'GistID': r.json()['id'], 269 | 'Gist-Link': '%s/%s/%s' %(GIST_URL,self.gist.username,r.json()['id']), 270 | 'Clone-Link': '%s/%s.git' %(GIST_URL,r.json()['id']), 271 | 'Embed-Script': '' %(GIST_URL,self.username,r.json()['id']), 99 | 'id': r.json()['id'], 100 | 'created_at': r.json()['created_at'], 101 | 102 | } 103 | return response 104 | raise Exception('Gist not created: server response was [%s] %s' % (r.status_code, r.text)) 105 | 106 | --------------------------------------------------------------------------------