# Path: nbx/nbmanager/tagged_gist/gisthub.py
# def gisthub(user, password):
#     g = github.Github(user, password, user_agent="nbx")
#     return GistHub(g)
# 
# def _hashtags(desc):
#     if not desc:
#         return []
#     tags = [tag for tag in desc.split(" ") if tag.startswith("#")]
#     return tags


import github
import nbformat
import nbx.compat as compat
from .gisthub import gisthub, _hashtags
        out = "NotebookGist(name={name}, active={active}, " + \
               "public={public}, tags={tags})"
        return out.format(public=self.public, name=self.name,
                          tags=self.tags, active=self.active)

    def strip_gist_id(self, key_name):
        " small util to remove gist_id suffix "
        # really we're assuming this will only match once, seems fine
        return key_name.replace(' '+self.suffix, '')

class NotebookGistHub(object):
    def __init__(self, gisthub):
        self.gisthub = gisthub

    def _wrap_results(self, results):
        wrapped = {}
        for key, gists in results.items():
            # convert to NotebookGist
            items = [NotebookGist(gist, self) for gist in gists]
            # index by key_name
            items = dict([(gist.key_name, gist) for gist in items])
            wrapped[key] = items
        return wrapped

    def query(self, *args, **kwargs):
        kwargs['filter_tag'] = '#notebook'
        results = self.gisthub.query(*args, **kwargs)
        return self._wrap_results(results)

    def refresh_gist(self, gist):

# Path: nbx/nbmanager/tagged_gist/gisthub.py
# def gisthub(user, password):
#     g = github.Github(user, password, user_agent="nbx")
#     return GistHub(g)
# 
# def _hashtags(desc):
#     if not desc:
#         return []
#     tags = [tag for tag in desc.split(" ") if tag.startswith("#")]
#     return tags


# Path: nbx/nbmanager/tagged_gist/notebook_gisthub.py
import github
import nbformat
import nbx.compat as compat
from .gisthub import gisthub, _hashtags

        out = "NotebookGist(name={name}, active={active}, " + \
               "public={public}, tags={tags})"
        return out.format(public=self.public, name=self.name,
                          tags=self.tags, active=self.active)

    def strip_gist_id(self, key_name):
        " small util to remove gist_id suffix "
        # really we're assuming this will only match once, seems fine
        return key_name.replace(' '+self.suffix, '')

class NotebookGistHub(object):
    def __init__(self, gisthub):
        self.gisthub = gisthub

    def _wrap_results(self, results):
        wrapped = {}
        for key, gists in results.items():
            # convert to NotebookGist
            items = [NotebookGist(gist, self) for gist in gists]
            # index by key_name
            items = dict([(gist.key_name, gist) for gist in items])
            wrapped[key] = items
        return wrapped

    def query(self, *args, **kwargs):
        kwargs['filter_tag'] = '#notebook'
        results = self.gisthub.query(*args, **kwargs)
        return self._wrap_results(results)

    def refresh_gist(self, gist):

        return self.gisthub.refresh_gist(gist)