# Path: flask_github/client/messages.py
# class Ref(msgs.Message):
#   sha = msgs.StringField(1)
#   ref = msgs.StringField(2)
#   force = msgs.BooleanField(3, default=False)
# 
# Path: flask_github/client/requests.py
# class RefResponse(msgs.Message):
#   response = msgs.MessageField('Ref', 1)
# 
# Path: flask_github/client/requests.py
# class RefListResponse(msgs.Message):
#   response = msgs.MessageField('Ref', 1, repeated=True)


from ..messages import Ref
from ..requests import RefResponse
from ..requests import RefListResponse

class GitDataRefs:
  def __init__(self, client):
    self.client = client

  def list(self, repo, subnamespace=None, user=None):
    url = 'repos/%s/%s/git/refs' % (repo, self.client.user(user))
    if subnamespace:
      if subnamespace[0] == '/':
        url += subnamespace
      else:
        url += subnamespace
    return self.client.get(url, msg_type=RefListResponse)

  def get(self, repo, ref, user=None):
    return self.client.get(
      'repos/%s/%s/git/refs/%s' % (
        self.client.user(user), repo, ref), msg_type=RefResponse)

  def create(self, repo, ref, sha, user=None):
    msg = Ref(
      ref=ref,
      sha=sha)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/git/refs' % (
        self.client.user(user), repo), data=msg, msg_type=RefResponse)

  def edit(self, repo, sha, force=False, user=None):

# Path: flask_github/client/messages.py
# class Ref(msgs.Message):
#   sha = msgs.StringField(1)
#   ref = msgs.StringField(2)
#   force = msgs.BooleanField(3, default=False)
# 
# Path: flask_github/client/requests.py
# class RefResponse(msgs.Message):
#   response = msgs.MessageField('Ref', 1)
# 
# Path: flask_github/client/requests.py
# class RefListResponse(msgs.Message):
#   response = msgs.MessageField('Ref', 1, repeated=True)


# Path: flask_github/client/gitdata/gitdatarefs.py
from ..messages import Ref
from ..requests import RefResponse
from ..requests import RefListResponse

class GitDataRefs:
  def __init__(self, client):
    self.client = client

  def list(self, repo, subnamespace=None, user=None):
    url = 'repos/%s/%s/git/refs' % (repo, self.client.user(user))
    if subnamespace:
      if subnamespace[0] == '/':
        url += subnamespace
      else:
        url += subnamespace
    return self.client.get(url, msg_type=RefListResponse)

  def get(self, repo, ref, user=None):
    return self.client.get(
      'repos/%s/%s/git/refs/%s' % (
        self.client.user(user), repo, ref), msg_type=RefResponse)

  def create(self, repo, ref, sha, user=None):
    msg = Ref(
      ref=ref,
      sha=sha)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/git/refs' % (
        self.client.user(user), repo), data=msg, msg_type=RefResponse)

  def edit(self, repo, sha, force=False, user=None):

    msg = Ref(
