BigW Consortium Gitlab

client.rb 1.39 KB
Newer Older
1 2
module Bitbucket
  class Client
3 4
    attr_reader :connection

5
    def initialize(options = {})
6
      @connection = Connection.new(options)
7 8
    end

9
    def issues(repo)
10
      path = "/repositories/#{repo}/issues"
11
      get_collection(path, :issue)
12 13
    end

14 15
    def issue_comments(repo, issue_id)
      path = "/repositories/#{repo}/issues/#{issue_id}/comments"
16
      get_collection(path, :comment)
17 18
    end

19
    def pull_requests(repo)
20
      path = "/repositories/#{repo}/pullrequests?state=ALL"
21
      get_collection(path, :pull_request)
22
    end
23

Stan Hu committed
24
    def pull_request_comments(repo, pull_request)
25
      path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments"
26
      get_collection(path, :pull_request_comment)
Stan Hu committed
27 28
    end

29
    def pull_request_diff(repo, pull_request)
30 31
      path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff"
      connection.get(path)
32 33
    end

34 35 36 37 38
    def repo(name)
      parsed_response = connection.get("/repositories/#{name}")
      Representation::Repo.new(parsed_response)
    end

39
    def repos
40
      path = "/repositories?role=member"
41
      get_collection(path, :repo)
42 43
    end

44
    def user
45 46 47 48
      @user ||= begin
        parsed_response = connection.get('/user')
        Representation::User.new(parsed_response)
      end
49 50
    end

51 52
    private

53 54 55 56
    def get_collection(path, type)
      paginator = Paginator.new(connection, path, type)
      Collection.new(paginator)
    end
57 58
  end
end