tinybucket2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +86 -0
- data/Gemfile +32 -0
- data/LICENSE +21 -0
- data/README.md +387 -0
- data/Rakefile +47 -0
- data/lib/faraday_middleware/follow_oauth_redirects.rb +71 -0
- data/lib/tinybucket.rb +76 -0
- data/lib/tinybucket/api.rb +26 -0
- data/lib/tinybucket/api/base_api.rb +44 -0
- data/lib/tinybucket/api/branch_restrictions_api.rb +51 -0
- data/lib/tinybucket/api/branches_api.rb +48 -0
- data/lib/tinybucket/api/build_status_api.rb +69 -0
- data/lib/tinybucket/api/comments_api.rb +81 -0
- data/lib/tinybucket/api/commits_api.rb +97 -0
- data/lib/tinybucket/api/diff_api.rb +40 -0
- data/lib/tinybucket/api/helper.rb +27 -0
- data/lib/tinybucket/api/helper/api_helper.rb +39 -0
- data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +29 -0
- data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
- data/lib/tinybucket/api/helper/build_status_helper.rb +46 -0
- data/lib/tinybucket/api/helper/comments_helper.rb +51 -0
- data/lib/tinybucket/api/helper/commits_helper.rb +42 -0
- data/lib/tinybucket/api/helper/diff_helper.rb +31 -0
- data/lib/tinybucket/api/helper/issues_helper.rb +29 -0
- data/lib/tinybucket/api/helper/projects_helper.rb +28 -0
- data/lib/tinybucket/api/helper/pull_requests_helper.rb +58 -0
- data/lib/tinybucket/api/helper/repo_helper.rb +31 -0
- data/lib/tinybucket/api/helper/repos_helper.rb +23 -0
- data/lib/tinybucket/api/helper/team_helper.rb +45 -0
- data/lib/tinybucket/api/helper/user_helper.rb +33 -0
- data/lib/tinybucket/api/issues_api.rb +48 -0
- data/lib/tinybucket/api/projects_api.rb +26 -0
- data/lib/tinybucket/api/pull_requests_api.rb +117 -0
- data/lib/tinybucket/api/repo_api.rb +56 -0
- data/lib/tinybucket/api/repos_api.rb +28 -0
- data/lib/tinybucket/api/team_api.rb +91 -0
- data/lib/tinybucket/api/user_api.rb +66 -0
- data/lib/tinybucket/api_factory.rb +21 -0
- data/lib/tinybucket/client.rb +107 -0
- data/lib/tinybucket/config.rb +10 -0
- data/lib/tinybucket/connection.rb +84 -0
- data/lib/tinybucket/constants.rb +7 -0
- data/lib/tinybucket/enumerator.rb +47 -0
- data/lib/tinybucket/error.rb +12 -0
- data/lib/tinybucket/error/base_error.rb +14 -0
- data/lib/tinybucket/error/conflict.rb +8 -0
- data/lib/tinybucket/error/not_found.rb +8 -0
- data/lib/tinybucket/error/service_error.rb +26 -0
- data/lib/tinybucket/iterator.rb +79 -0
- data/lib/tinybucket/model.rb +25 -0
- data/lib/tinybucket/model/base.rb +45 -0
- data/lib/tinybucket/model/branch.rb +48 -0
- data/lib/tinybucket/model/branch_restriction.rb +46 -0
- data/lib/tinybucket/model/build_status.rb +57 -0
- data/lib/tinybucket/model/comment.rb +67 -0
- data/lib/tinybucket/model/commit.rb +114 -0
- data/lib/tinybucket/model/concerns.rb +19 -0
- data/lib/tinybucket/model/concerns/acceptable_attributes.rb +34 -0
- data/lib/tinybucket/model/concerns/api_callable.rb +21 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +20 -0
- data/lib/tinybucket/model/concerns/reloadable.rb +41 -0
- data/lib/tinybucket/model/concerns/repository_keys.rb +45 -0
- data/lib/tinybucket/model/error_response.rb +24 -0
- data/lib/tinybucket/model/issue.rb +48 -0
- data/lib/tinybucket/model/page.rb +45 -0
- data/lib/tinybucket/model/profile.rb +70 -0
- data/lib/tinybucket/model/project.rb +44 -0
- data/lib/tinybucket/model/pull_request.rb +160 -0
- data/lib/tinybucket/model/repository.rb +219 -0
- data/lib/tinybucket/model/team.rb +96 -0
- data/lib/tinybucket/null_logger.rb +37 -0
- data/lib/tinybucket/parser.rb +15 -0
- data/lib/tinybucket/parser/collection_parser.rb +17 -0
- data/lib/tinybucket/parser/object_parser.rb +17 -0
- data/lib/tinybucket/request.rb +59 -0
- data/lib/tinybucket/resource.rb +75 -0
- data/lib/tinybucket/resource/base.rb +35 -0
- data/lib/tinybucket/resource/branch_restrictions.rb +47 -0
- data/lib/tinybucket/resource/branches.rb +35 -0
- data/lib/tinybucket/resource/commit/base.rb +14 -0
- data/lib/tinybucket/resource/commit/build_statuses.rb +50 -0
- data/lib/tinybucket/resource/commit/comments.rb +34 -0
- data/lib/tinybucket/resource/commits.rb +46 -0
- data/lib/tinybucket/resource/forks.rb +24 -0
- data/lib/tinybucket/resource/issues.rb +35 -0
- data/lib/tinybucket/resource/projects.rb +49 -0
- data/lib/tinybucket/resource/pull_request/base.rb +20 -0
- data/lib/tinybucket/resource/pull_request/comments.rb +32 -0
- data/lib/tinybucket/resource/pull_request/commits.rb +19 -0
- data/lib/tinybucket/resource/pull_requests.rb +50 -0
- data/lib/tinybucket/resource/repos.rb +40 -0
- data/lib/tinybucket/resource/team/base.rb +24 -0
- data/lib/tinybucket/resource/team/followers.rb +15 -0
- data/lib/tinybucket/resource/team/following.rb +15 -0
- data/lib/tinybucket/resource/team/members.rb +15 -0
- data/lib/tinybucket/resource/team/repos.rb +15 -0
- data/lib/tinybucket/resource/teams.rb +22 -0
- data/lib/tinybucket/resource/user/base.rb +26 -0
- data/lib/tinybucket/resource/user/followers.rb +15 -0
- data/lib/tinybucket/resource/user/following.rb +15 -0
- data/lib/tinybucket/resource/user/repos.rb +15 -0
- data/lib/tinybucket/resource/watchers.rb +24 -0
- data/lib/tinybucket/response.rb +9 -0
- data/lib/tinybucket/response/handler.rb +23 -0
- data/lib/tinybucket/version.rb +5 -0
- data/tinybucket.gemspec +30 -0
- metadata +248 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
# Commit Resource
|
|
6
|
+
#
|
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit
|
|
8
|
+
# Commit Resource
|
|
9
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits
|
|
10
|
+
# Commits Resource
|
|
11
|
+
#
|
|
12
|
+
# @!attribute [rw] hash
|
|
13
|
+
# @return [String]
|
|
14
|
+
# @!attribute [rw] links
|
|
15
|
+
# @return [Hash]
|
|
16
|
+
# @!attribute [rw] repository
|
|
17
|
+
# @return [Hash]
|
|
18
|
+
# @!attribute [rw] author
|
|
19
|
+
# @return [Hash]
|
|
20
|
+
# @!attribute [rw] parents
|
|
21
|
+
# @return [Array]
|
|
22
|
+
# @!attribute [rw] date
|
|
23
|
+
# @return [String]
|
|
24
|
+
# @!attribute [rw] message
|
|
25
|
+
# @return [String]
|
|
26
|
+
# @!attribute [rw] participants
|
|
27
|
+
# @return [Array]
|
|
28
|
+
# @!attribute [rw] uuid
|
|
29
|
+
# @return [NillClass]
|
|
30
|
+
# @!attribute [rw] type
|
|
31
|
+
# @return [String]
|
|
32
|
+
class Commit < Base
|
|
33
|
+
include Tinybucket::Model::Concerns::RepositoryKeys
|
|
34
|
+
include Tinybucket::Constants
|
|
35
|
+
|
|
36
|
+
acceptable_attributes \
|
|
37
|
+
:hash, :links, :repository, :author, :parents, :date,
|
|
38
|
+
:message, :participants, :uuid, :type
|
|
39
|
+
|
|
40
|
+
# Get comments which associate with this commit.
|
|
41
|
+
#
|
|
42
|
+
# @param options [Hash]
|
|
43
|
+
# @return [Tinybucket::Resource::Commit::Comments]
|
|
44
|
+
def comments(options = {})
|
|
45
|
+
comments_resource(options)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Get the specific commit comment which associate with this commit.
|
|
49
|
+
#
|
|
50
|
+
# @param comment_id [String] comment id
|
|
51
|
+
# @param options [Hash]
|
|
52
|
+
# @return [Tinybucket::Model::Comment]
|
|
53
|
+
def comment(comment_id, options = {})
|
|
54
|
+
comments_resource.find(comment_id, options)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Give approval on this commit.
|
|
58
|
+
#
|
|
59
|
+
# @param options [Hash]
|
|
60
|
+
# @return [true]
|
|
61
|
+
# @return [false]
|
|
62
|
+
def approve(options = {})
|
|
63
|
+
commit_api.approve(hash, options)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Revoke approval on this commit.
|
|
67
|
+
#
|
|
68
|
+
# @param options [Hash]
|
|
69
|
+
# @return [true]
|
|
70
|
+
# @return [false]
|
|
71
|
+
def unapprove(options = {})
|
|
72
|
+
commit_api.unapprove(hash, options)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Get build status resource
|
|
76
|
+
#
|
|
77
|
+
# @param options [Hash]
|
|
78
|
+
# @return [Tinybucket::Resource::Commit::BuildStatuses]
|
|
79
|
+
def build_statuses(options = {})
|
|
80
|
+
build_statuses_resource(options)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Get the specific build status which associate with key.
|
|
84
|
+
#
|
|
85
|
+
# @param key [String]
|
|
86
|
+
# @param options [Hash]
|
|
87
|
+
# @return [Tinybucket::Model::BuildStatus]
|
|
88
|
+
# @return [nil] when build_status does not found.
|
|
89
|
+
def build_status(key, options = {})
|
|
90
|
+
build_statuses_resource.find(key, options)
|
|
91
|
+
rescue Tinybucket::Error::NotFound
|
|
92
|
+
nil
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def comments_resource(options = {})
|
|
98
|
+
Tinybucket::Resource::Commit::Comments.new(self, options)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def build_statuses_resource(options = {})
|
|
102
|
+
Tinybucket::Resource::Commit::BuildStatuses.new(self, options)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def commit_api
|
|
106
|
+
create_api('Commits', repo_keys)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def load_model
|
|
110
|
+
commit_api.find(hash)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
extend ActiveSupport::Autoload
|
|
7
|
+
|
|
8
|
+
[
|
|
9
|
+
:AcceptableAttributes,
|
|
10
|
+
:ApiCallable,
|
|
11
|
+
:Enumerable,
|
|
12
|
+
:RepositoryKeys,
|
|
13
|
+
:Reloadable
|
|
14
|
+
].each do |mod_name|
|
|
15
|
+
autoload mod_name
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
module AcceptableAttributes
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
def self.acceptable_attributes(*attrs)
|
|
11
|
+
@_acceptable_attributes = attrs.map(&:intern)
|
|
12
|
+
|
|
13
|
+
attr_accessor(*attrs)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.acceptable_attribute?(key)
|
|
17
|
+
return false if @_acceptable_attributes.nil?
|
|
18
|
+
@_acceptable_attributes.include?(key.intern)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def acceptable_attribute?(key)
|
|
24
|
+
self.class.acceptable_attribute?(key)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def acceptable_attributes
|
|
28
|
+
self.class.instance_variable_get(:@_acceptable_attributes) || []
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
module ApiCallable
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def create_api(name, keys = {})
|
|
10
|
+
api = ApiFactory.create_instance(name)
|
|
11
|
+
return api if keys.empty?
|
|
12
|
+
|
|
13
|
+
api.tap do |m|
|
|
14
|
+
m.repo_owner = keys[:repo_owner]
|
|
15
|
+
m.repo_slug = keys[:repo_slug]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
module Enumerable
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
protected
|
|
11
|
+
|
|
12
|
+
def enumerator(api_client, method, *args, &block)
|
|
13
|
+
iter = Tinybucket::Iterator.new(api_client, method, *args)
|
|
14
|
+
Tinybucket::Enumerator.new(iter, block)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
module Reloadable
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
def load
|
|
11
|
+
return true if @_loaded
|
|
12
|
+
|
|
13
|
+
self.attributes = load_model.attributes
|
|
14
|
+
@_loaded = true
|
|
15
|
+
rescue => e
|
|
16
|
+
@_loaded = false
|
|
17
|
+
Tinybucket.logger.error e
|
|
18
|
+
raise e
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def loaded?
|
|
22
|
+
@_loaded
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def reload
|
|
26
|
+
@_loaded = false
|
|
27
|
+
# rubocop:disable all
|
|
28
|
+
self.load
|
|
29
|
+
# rubocop:enable all
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def load_model
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
module Concerns
|
|
6
|
+
module RepositoryKeys
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
attr_accessor :repo_owner, :repo_slug
|
|
11
|
+
|
|
12
|
+
def repo_keys?
|
|
13
|
+
repo_owner.present? && repo_slug.present?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def repo_keys
|
|
17
|
+
{ repo_owner: repo_owner, repo_slug: repo_slug }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def repo_keys=(keys)
|
|
21
|
+
self.repo_owner = keys[:repo_owner]
|
|
22
|
+
self.repo_slug = keys[:repo_slug]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def inject_repo_keys(result)
|
|
28
|
+
case result
|
|
29
|
+
when Tinybucket::Model::Page
|
|
30
|
+
result.items.map do |m|
|
|
31
|
+
next unless m.class.concern_included?(:RepositoryKeys)
|
|
32
|
+
m.repo_keys = repo_keys
|
|
33
|
+
end
|
|
34
|
+
when Tinybucket::Model::Base
|
|
35
|
+
result.repo_keys = repo_keys \
|
|
36
|
+
if result.class.concern_included?(:RepositoryKeys)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
result
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
# ErrorResponse
|
|
6
|
+
#
|
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/meta/uri-uuid#stand-error
|
|
8
|
+
# Standardized error responses
|
|
9
|
+
#
|
|
10
|
+
# @!attribute [rw] message
|
|
11
|
+
# @return [String]
|
|
12
|
+
# @!attribute [rw] fields
|
|
13
|
+
# @return [Hash]
|
|
14
|
+
# @!attribute [rw] detail
|
|
15
|
+
# @return [String]
|
|
16
|
+
# @!attribute [rw] id
|
|
17
|
+
# @return [String]
|
|
18
|
+
# @!attribute [rw] uuid
|
|
19
|
+
# @return [NillClass]
|
|
20
|
+
class ErrorResponse
|
|
21
|
+
acceptable_attributes :message, :fields, :detail, :id, :uuid
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
# Branch
|
|
6
|
+
#
|
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/branches
|
|
8
|
+
# Branch Resource
|
|
9
|
+
#
|
|
10
|
+
# @!attribute [rw] links
|
|
11
|
+
# @return [Hash]
|
|
12
|
+
# @!attribute [rw] type
|
|
13
|
+
# @return [String]
|
|
14
|
+
# @!attribute [rw] name
|
|
15
|
+
# @return [String]
|
|
16
|
+
# @!attribute [rw] repository
|
|
17
|
+
# @return [Hash]
|
|
18
|
+
# @!attribute [rw] target
|
|
19
|
+
# @return [Hash]
|
|
20
|
+
class Issue < Base
|
|
21
|
+
include Tinybucket::Model::Concerns::RepositoryKeys
|
|
22
|
+
|
|
23
|
+
acceptable_attributes :links, :type, :name, :repository, :target
|
|
24
|
+
|
|
25
|
+
# Returns the commits available for the specific branch
|
|
26
|
+
#
|
|
27
|
+
# @param options [Hash]
|
|
28
|
+
# @return [Tinybucket::Resource::Commits]
|
|
29
|
+
def commits(options = {})
|
|
30
|
+
commits_resource.issue(name, options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def commits_resource(options = {})
|
|
36
|
+
Tinybucket::Resource::Commits.new(self, options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def issues_api
|
|
40
|
+
create_api('Issues', repo_keys)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def load_model
|
|
44
|
+
issues_api.find(name, {})
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
# Page
|
|
6
|
+
#
|
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/meta/pagination
|
|
8
|
+
# Paging through object collections
|
|
9
|
+
#
|
|
10
|
+
# @!attribute [r] attrs
|
|
11
|
+
# This attribute is a Hash object which contains
|
|
12
|
+
# 'size', 'page', 'pagelen', 'next', 'previous' key/value pairs.
|
|
13
|
+
# @return [Hash]
|
|
14
|
+
# @!attribute [r] items
|
|
15
|
+
# This attribute is a array of model instance created with
|
|
16
|
+
# 'values' attribute in json.
|
|
17
|
+
class Page
|
|
18
|
+
attr_reader :attrs
|
|
19
|
+
attr_reader :items
|
|
20
|
+
|
|
21
|
+
# Initialize with json and Model class.
|
|
22
|
+
#
|
|
23
|
+
# @param json [Hash]
|
|
24
|
+
# @param item_klass [Class]
|
|
25
|
+
def initialize(json, item_klass)
|
|
26
|
+
@attrs = parse_attrs(json)
|
|
27
|
+
@items = parse_values(json, item_klass)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def parse_attrs(json)
|
|
33
|
+
%w(size page pagelen next previous).map do |attr|
|
|
34
|
+
{ attr.to_sym => json[attr] }
|
|
35
|
+
end.reduce(&:merge)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def parse_values(json, item_klass)
|
|
39
|
+
return [] if json['values'].nil? || !json['values'].is_a?(Array)
|
|
40
|
+
|
|
41
|
+
json['values'].map { |hash| item_klass.new(hash) }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tinybucket
|
|
4
|
+
module Model
|
|
5
|
+
# Profile
|
|
6
|
+
#
|
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D
|
|
8
|
+
# users Endpoint
|
|
9
|
+
#
|
|
10
|
+
# @!attribute [rw] username
|
|
11
|
+
# @return [String]
|
|
12
|
+
# @!attribute [rw] kind
|
|
13
|
+
# @return [NillClass]
|
|
14
|
+
# @!attribute [rw] website
|
|
15
|
+
# @return [String]
|
|
16
|
+
# @!attribute [rw] display_name
|
|
17
|
+
# @return [String]
|
|
18
|
+
# @!attribute [rw] links
|
|
19
|
+
# @return [Hash]
|
|
20
|
+
# @!attribute [rw] created_on
|
|
21
|
+
# @return [String]
|
|
22
|
+
# @!attribute [rw] location
|
|
23
|
+
# @return [String]
|
|
24
|
+
# @!attribute [rw] type
|
|
25
|
+
# @return [String]
|
|
26
|
+
# @!attribute [rw] uuid
|
|
27
|
+
# @return [String]
|
|
28
|
+
class Profile < Base
|
|
29
|
+
acceptable_attributes \
|
|
30
|
+
:username, :kind, :website, :display_name,
|
|
31
|
+
:links, :created_on, :location, :type, :uuid
|
|
32
|
+
|
|
33
|
+
# Get this user's followers
|
|
34
|
+
#
|
|
35
|
+
# @param options [Hash]
|
|
36
|
+
# @return [Tinybucket::Resource::User::Followers]
|
|
37
|
+
def followers(options = {})
|
|
38
|
+
Tinybucket::Resource::User::Followers.new(username, options)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Get users which this user is following
|
|
42
|
+
#
|
|
43
|
+
# @param options [Hash]
|
|
44
|
+
# @return [Tinybucket::Resource::User::Following]
|
|
45
|
+
def following(options = {})
|
|
46
|
+
Tinybucket::Resource::User::Following.new(username, options)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Get this user's repositories
|
|
50
|
+
#
|
|
51
|
+
# @param options [Hash]
|
|
52
|
+
# @return [Tinybucket::Resource::User::Repos]
|
|
53
|
+
def repos(options = {})
|
|
54
|
+
Tinybucket::Resource::User::Repos.new(username, options)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def user_api
|
|
60
|
+
create_api('User').tap do |api|
|
|
61
|
+
api.username = username
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def load_model
|
|
66
|
+
user_api.profile
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|