Class: Tinybucket::Api::CommentsApi

Inherits:
BaseApi
  • Object
show all
Includes:
Helper::CommentsHelper
Defined in:
lib/tinybucket/api/comments_api.rb

Overview

Comments Api client

Constant Summary

Constants included from Connection

Connection::DEFAULT_USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connection

#caching?, #clear_cache, #connection

Instance Attribute Details

#commented_toTinybucket::Model::Commit, Tinybucket::Model::PullRequest



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tinybucket/api/comments_api.rb', line 13

class CommentsApi < BaseApi
  include Tinybucket::Api::Helper::CommentsHelper

  attr_accessor :repo_owner, :repo_slug

  attr_accessor :commented_to

  # Send 'GET a list of comments' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of commit comments}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of pull request comments}.
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    list = get_path(path_to_list,
                    options,
                    get_parser(:collection, Tinybucket::Model::Comment))

    associate_with_target(list)
    list
  end

  # Send 'GET a individual comment' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual commit comment}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual pull request comment}.
  #
  # @param comment_id [String] comment identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::Comment]
  def find(comment_id, options = {})
    comment = get_path(path_to_find(comment_id),
                       options,
                       get_parser(:object, Tinybucket::Model::Comment))

    associate_with_target(comment)
    comment
  end

  private

  def associate_with_target(result)
    case result
    when Tinybucket::Model::Comment
      result.commented_to = commented_to
    when Tinybucket::Model::Page
      result.items.map { |m| m.commented_to = commented_to }
    else
      raise ArgumentError, "Invalid result: #{result.inspect}"
    end

    result
  end
end

#repo_ownerString

Returns repository owner name.

Returns:

  • (String)

    repository owner name.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tinybucket/api/comments_api.rb', line 13

class CommentsApi < BaseApi
  include Tinybucket::Api::Helper::CommentsHelper

  attr_accessor :repo_owner, :repo_slug

  attr_accessor :commented_to

  # Send 'GET a list of comments' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of commit comments}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of pull request comments}.
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    list = get_path(path_to_list,
                    options,
                    get_parser(:collection, Tinybucket::Model::Comment))

    associate_with_target(list)
    list
  end

  # Send 'GET a individual comment' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual commit comment}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual pull request comment}.
  #
  # @param comment_id [String] comment identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::Comment]
  def find(comment_id, options = {})
    comment = get_path(path_to_find(comment_id),
                       options,
                       get_parser(:object, Tinybucket::Model::Comment))

    associate_with_target(comment)
    comment
  end

  private

  def associate_with_target(result)
    case result
    when Tinybucket::Model::Comment
      result.commented_to = commented_to
    when Tinybucket::Model::Page
      result.items.map { |m| m.commented_to = commented_to }
    else
      raise ArgumentError, "Invalid result: #{result.inspect}"
    end

    result
  end
end

#repo_slugString

Returns repository slug.

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tinybucket/api/comments_api.rb', line 13

class CommentsApi < BaseApi
  include Tinybucket::Api::Helper::CommentsHelper

  attr_accessor :repo_owner, :repo_slug

  attr_accessor :commented_to

  # Send 'GET a list of comments' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of commit comments}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
  #   GET a list of pull request comments}.
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    list = get_path(path_to_list,
                    options,
                    get_parser(:collection, Tinybucket::Model::Comment))

    associate_with_target(list)
    list
  end

  # Send 'GET a individual comment' request.
  #
  # This method send different request depend on 'commented_to' attribute.
  #
  # @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual commit comment}.
  # @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
  #   this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
  #   GET an individual pull request comment}.
  #
  # @param comment_id [String] comment identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::Comment]
  def find(comment_id, options = {})
    comment = get_path(path_to_find(comment_id),
                       options,
                       get_parser(:object, Tinybucket::Model::Comment))

    associate_with_target(comment)
    comment
  end

  private

  def associate_with_target(result)
    case result
    when Tinybucket::Model::Comment
      result.commented_to = commented_to
    when Tinybucket::Model::Page
      result.items.map { |m| m.commented_to = commented_to }
    else
      raise ArgumentError, "Invalid result: #{result.inspect}"
    end

    result
  end
end

Instance Method Details

#find(comment_id, options = {}) ⇒ Tinybucket::Model::Comment

Note:

When ‘commented_to’ is Model::Commit instance, this method send GET an individual commit comment.

Note:

When ‘commented_to’ is Model::PullRequest instance, this method send GET an individual pull request comment.

Send ‘GET a individual comment’ request.

This method send different request depend on ‘commented_to’ attribute.

Parameters:

  • comment_id (String)

    comment identifier

  • options (Hash) (defaults to: {})

Returns:



56
57
58
59
60
61
62
63
# File 'lib/tinybucket/api/comments_api.rb', line 56

def find(comment_id, options = {})
  comment = get_path(path_to_find(comment_id),
                     options,
                     get_parser(:object, Tinybucket::Model::Comment))

  associate_with_target(comment)
  comment
end

#list(options = {}) ⇒ Tinybucket::Model::Page

Note:

When ‘commented_to’ is Model::Commit instance, this method send GET a list of commit comments.

Note:

When ‘commented_to’ is Model::PullRequest instance, this method send GET a list of pull request comments.

Send ‘GET a list of comments’ request.

This method send different request depend on ‘commented_to’ attribute.

Parameters:

  • options (Hash) (defaults to: {})

Returns:



33
34
35
36
37
38
39
40
# File 'lib/tinybucket/api/comments_api.rb', line 33

def list(options = {})
  list = get_path(path_to_list,
                  options,
                  get_parser(:collection, Tinybucket::Model::Comment))

  associate_with_target(list)
  list
end