Sha256: c15dcdec645a45948499427ca590c3d758d3fd614a495f3f422dc28a78357c65

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'travis'
require 'octokit'

module Travis
  module GithubApi
    class ServiceHookError < StandardError; end

    class << self
      def add_service_hook(owner_name, name, oauth_token, data)
        client = Octokit::Client.new(:oauth_token => oauth_token)
        client.subscribe_service_hook("#{owner_name}/#{name}", 'Travis', data)
      rescue Octokit::UnprocessableEntity => e
        # TODO log these events
        raise ServiceHookError, 'error subscribing to the GitHub push event'
      rescue Octokit::Unauthorized => e
        raise ServiceHookError, 'error authorizing with given GitHub OAuth token'
      end

      def remove_service_hook(owner_name, name, oauth_token)
        client = Octokit::Client.new(:oauth_token => oauth_token)
        client.unsubscribe_service_hook("#{owner_name}/#{name}", 'Travis')
      rescue Octokit::UnprocessableEntity => e
        # TODO log this event
        raise ServiceHookError, 'error unsubscribing from the GitHub push event'
      end

      def repositories_for_user(login)
        Octokit.repositories(login)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/travis/github_api.rb