# Path: flask_github/client/messages.py
# class Hook(msgs.Message):
#   id = msgs.IntegerField(1, default=0)
#   name = msgs.StringField(2)
#   events = msgs.StringField(3, repeated=True)
#   add_events = msgs.StringField(4, repeated=True)
#   remove_events = msgs.StringField(5, repeated=True)
#   active = msgs.BooleanField(6, default=True)
#   config = msgs.MessageField('HookConfig', 7)
# 
# class HookConfig(msgs.Message):
#   url = msgs.StringField(1)
#   insecure_ssl = msgs.StringField(2)
#   content_type = msgs.StringField(3, default='json')
# 
# Path: flask_github/client/requests.py
# class HookResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1)
# 
# Path: flask_github/client/requests.py
# class HookTestResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1)
# 
# Path: flask_github/client/requests.py
# class HookListResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1, repeated=True)


from ..messages import Hook, HookConfig
from ..requests import HookResponse
from ..requests import HookTestResponse
from ..requests import HookListResponse

from __future__ import unicode_literals

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

  def list(self, repo, user=None):
    return self.client.get(
      'repos/%s/%s/hooks' % (
        self.client.user(user), repo), msg_type=HookListResponse)

  def get(self, repo, id, user=None):
    return self.client.get(
      'repos/%s/%s/hooks/%s' % (
        self.client.user(user), repo, id), msg_type=HookResponse)

  def create(self, repo, name, url, events=None, active=True,
      user=None):
    msg = Hook(
      name=name,
      config=HookConfig(
        url=url),
      events=events,
      active=active)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/hooks' % (

# Path: flask_github/client/messages.py
# class Hook(msgs.Message):
#   id = msgs.IntegerField(1, default=0)
#   name = msgs.StringField(2)
#   events = msgs.StringField(3, repeated=True)
#   add_events = msgs.StringField(4, repeated=True)
#   remove_events = msgs.StringField(5, repeated=True)
#   active = msgs.BooleanField(6, default=True)
#   config = msgs.MessageField('HookConfig', 7)
# 
# class HookConfig(msgs.Message):
#   url = msgs.StringField(1)
#   insecure_ssl = msgs.StringField(2)
#   content_type = msgs.StringField(3, default='json')
# 
# Path: flask_github/client/requests.py
# class HookResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1)
# 
# Path: flask_github/client/requests.py
# class HookTestResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1)
# 
# Path: flask_github/client/requests.py
# class HookListResponse(msgs.Message):
#   response = msgs.MessageField('Hook', 1, repeated=True)


# Path: flask_github/client/repos/reposhooks.py
from ..messages import Hook, HookConfig
from ..requests import HookResponse
from ..requests import HookTestResponse
from ..requests import HookListResponse

from __future__ import unicode_literals

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

  def list(self, repo, user=None):
    return self.client.get(
      'repos/%s/%s/hooks' % (
        self.client.user(user), repo), msg_type=HookListResponse)

  def get(self, repo, id, user=None):
    return self.client.get(
      'repos/%s/%s/hooks/%s' % (
        self.client.user(user), repo, id), msg_type=HookResponse)

  def create(self, repo, name, url, events=None, active=True,
      user=None):
    msg = Hook(
      name=name,
      config=HookConfig(
        url=url),
      events=events,
      active=active)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/hooks' % (

        self.client.user(user), repo), data=msg, msg_type=HookResponse)
