tinybucket 0.1.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.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +35 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +44 -0
  6. data/.travis.yml +10 -0
  7. data/Gemfile +22 -0
  8. data/Guardfile +13 -0
  9. data/LICENSE +21 -0
  10. data/README.md +237 -0
  11. data/Rakefile +39 -0
  12. data/lib/faraday_middleware/follow_oauth_redirects.rb +67 -0
  13. data/lib/tinybucket.rb +61 -0
  14. data/lib/tinybucket/api.rb +20 -0
  15. data/lib/tinybucket/api/base_api.rb +31 -0
  16. data/lib/tinybucket/api/branch_restrictions_api.rb +26 -0
  17. data/lib/tinybucket/api/comments_api.rb +46 -0
  18. data/lib/tinybucket/api/commits_api.rb +26 -0
  19. data/lib/tinybucket/api/diff_api.rb +17 -0
  20. data/lib/tinybucket/api/helper.rb +22 -0
  21. data/lib/tinybucket/api/helper/api_helper.rb +48 -0
  22. data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +27 -0
  23. data/lib/tinybucket/api/helper/comments_helper.rb +49 -0
  24. data/lib/tinybucket/api/helper/commits_helper.rb +27 -0
  25. data/lib/tinybucket/api/helper/diff_helper.rb +29 -0
  26. data/lib/tinybucket/api/helper/pull_requests_helper.rb +44 -0
  27. data/lib/tinybucket/api/helper/repo_helper.rb +29 -0
  28. data/lib/tinybucket/api/helper/repos_helper.rb +21 -0
  29. data/lib/tinybucket/api/helper/team_helper.rb +35 -0
  30. data/lib/tinybucket/api/helper/user_helper.rb +31 -0
  31. data/lib/tinybucket/api/pull_requests_api.rb +49 -0
  32. data/lib/tinybucket/api/repo_api.rb +35 -0
  33. data/lib/tinybucket/api/repos_api.rb +19 -0
  34. data/lib/tinybucket/api/team_api.rb +51 -0
  35. data/lib/tinybucket/api/user_api.rb +44 -0
  36. data/lib/tinybucket/api_factory.rb +21 -0
  37. data/lib/tinybucket/client.rb +95 -0
  38. data/lib/tinybucket/connection.rb +62 -0
  39. data/lib/tinybucket/constants.rb +4 -0
  40. data/lib/tinybucket/error.rb +8 -0
  41. data/lib/tinybucket/error/base_error.rb +12 -0
  42. data/lib/tinybucket/error/service_error.rb +20 -0
  43. data/lib/tinybucket/model.rb +20 -0
  44. data/lib/tinybucket/model/base.rb +54 -0
  45. data/lib/tinybucket/model/branch_restriction.rb +17 -0
  46. data/lib/tinybucket/model/comment.rb +39 -0
  47. data/lib/tinybucket/model/commit.rb +39 -0
  48. data/lib/tinybucket/model/concerns.rb +14 -0
  49. data/lib/tinybucket/model/concerns/reloadable.rb +45 -0
  50. data/lib/tinybucket/model/concerns/repository_keys.rb +43 -0
  51. data/lib/tinybucket/model/error_response.rb +7 -0
  52. data/lib/tinybucket/model/page.rb +65 -0
  53. data/lib/tinybucket/model/profile.rb +37 -0
  54. data/lib/tinybucket/model/pull_request.rb +64 -0
  55. data/lib/tinybucket/model/repository.rb +96 -0
  56. data/lib/tinybucket/model/team.rb +39 -0
  57. data/lib/tinybucket/parser.rb +25 -0
  58. data/lib/tinybucket/parser/base_parser.rb +17 -0
  59. data/lib/tinybucket/parser/branch_restriction_parser.rb +9 -0
  60. data/lib/tinybucket/parser/branch_restrictions_parser.rb +10 -0
  61. data/lib/tinybucket/parser/comment_parser.rb +9 -0
  62. data/lib/tinybucket/parser/comments_parser.rb +10 -0
  63. data/lib/tinybucket/parser/commit_parser.rb +9 -0
  64. data/lib/tinybucket/parser/commits_parser.rb +9 -0
  65. data/lib/tinybucket/parser/profile_parser.rb +9 -0
  66. data/lib/tinybucket/parser/profiles_parser.rb +9 -0
  67. data/lib/tinybucket/parser/pull_request_parser.rb +9 -0
  68. data/lib/tinybucket/parser/pull_requests_parser.rb +10 -0
  69. data/lib/tinybucket/parser/repo_parser.rb +9 -0
  70. data/lib/tinybucket/parser/repos_parser.rb +10 -0
  71. data/lib/tinybucket/parser/team_parser.rb +9 -0
  72. data/lib/tinybucket/parser/teams_parser.rb +9 -0
  73. data/lib/tinybucket/request.rb +55 -0
  74. data/lib/tinybucket/response.rb +7 -0
  75. data/lib/tinybucket/response/error_handler.rb +14 -0
  76. data/lib/tinybucket/version.rb +3 -0
  77. data/spec/fixtures/commit.json +83 -0
  78. data/spec/fixtures/profile.json +29 -0
  79. data/spec/fixtures/pull_request.json +106 -0
  80. data/spec/fixtures/repositories/get.json +78 -0
  81. data/spec/fixtures/repositories/test_owner/get.json +78 -0
  82. data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json +17 -0
  83. data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json +101 -0
  84. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json +38 -0
  85. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json +40 -0
  86. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json +83 -0
  87. data/spec/fixtures/repositories/test_owner/test_repo/commits/get.json +73 -0
  88. data/spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json +21 -0
  89. data/spec/fixtures/repositories/test_owner/test_repo/forks/get.json +78 -0
  90. data/spec/fixtures/repositories/test_owner/test_repo/get.json +71 -0
  91. data/spec/fixtures/repositories/test_owner/test_repo/patch/1/get.json +29 -0
  92. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/delete.json +3 -0
  93. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/post.json +3 -0
  94. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/1/get.json +30 -0
  95. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +44 -0
  96. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +66 -0
  97. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/diff/get.txt +13 -0
  98. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/get.json +164 -0
  99. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +112 -0
  100. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_declined.json +112 -0
  101. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_merged.json +112 -0
  102. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json +112 -0
  103. data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +32 -0
  104. data/spec/fixtures/repository.json +71 -0
  105. data/spec/fixtures/teams/test_team/followers/get.json +36 -0
  106. data/spec/fixtures/teams/test_team/following/get.json +39 -0
  107. data/spec/fixtures/teams/test_team/get.json +32 -0
  108. data/spec/fixtures/teams/test_team/members/get.json +36 -0
  109. data/spec/fixtures/teams/test_team/repositories/get.json +125 -0
  110. data/spec/fixtures/users/test_owner/followers/get.json +65 -0
  111. data/spec/fixtures/users/test_owner/following/get.json +100 -0
  112. data/spec/fixtures/users/test_owner/get.json +29 -0
  113. data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +78 -0
  114. data/spec/lib/tinybucket/api/comments_api_spec.rb +133 -0
  115. data/spec/lib/tinybucket/api/commits_api_spec.rb +63 -0
  116. data/spec/lib/tinybucket/api/diff_api_spec.rb +5 -0
  117. data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +229 -0
  118. data/spec/lib/tinybucket/api/repo_api_spec.rb +100 -0
  119. data/spec/lib/tinybucket/api/repos_api_spec.rb +28 -0
  120. data/spec/lib/tinybucket/api/team_api_spec.rb +87 -0
  121. data/spec/lib/tinybucket/api/user_api_spec.rb +60 -0
  122. data/spec/lib/tinybucket/api_factory_spec.rb +23 -0
  123. data/spec/lib/tinybucket/client_spec.rb +102 -0
  124. data/spec/lib/tinybucket/connection_spec.rb +30 -0
  125. data/spec/lib/tinybucket/model/branch_restriction_spec.rb +29 -0
  126. data/spec/lib/tinybucket/model/comment_spec.rb +31 -0
  127. data/spec/lib/tinybucket/model/commit_spec.rb +62 -0
  128. data/spec/lib/tinybucket/model/page_spec.rb +58 -0
  129. data/spec/lib/tinybucket/model/profile_spec.rb +47 -0
  130. data/spec/lib/tinybucket/model/pull_request_spec.rb +122 -0
  131. data/spec/lib/tinybucket/model/repository_spec.rb +131 -0
  132. data/spec/lib/tinybucket/model/team_spec.rb +53 -0
  133. data/spec/lib/tinybucket_spec.rb +32 -0
  134. data/spec/spec_helper.rb +42 -0
  135. data/spec/support/api_response_macros.rb +30 -0
  136. data/spec/support/model_macros.rb +61 -0
  137. data/tinybucket.gemspec +36 -0
  138. metadata +437 -0
@@ -0,0 +1,27 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module CommitsHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_list
10
+ build_path(base_path, 'commits')
11
+ end
12
+
13
+ def path_to_find(revision)
14
+ build_path(base_path,
15
+ 'commit',
16
+ [revision, 'revision'])
17
+ end
18
+
19
+ def base_path
20
+ build_path('/repositories',
21
+ [repo_owner, 'repo_owner'],
22
+ [repo_slug, 'repo_slug'])
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module DiffHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_find(spec)
10
+ build_path(base_path,
11
+ 'diff',
12
+ [spec, 'spec'])
13
+ end
14
+
15
+ def path_to_patch(spec)
16
+ build_path(base_path,
17
+ 'patch',
18
+ [spec, 'spec'])
19
+ end
20
+
21
+ def base_path
22
+ build_path('/repositories',
23
+ [repo_owner, 'repo_owner'],
24
+ [repo_slug, 'repo_slug'])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module PullRequestsHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_list
10
+ base_path
11
+ end
12
+
13
+ def path_to_find(pr_id)
14
+ build_path(base_path,
15
+ [pr_id, 'pullrequest_id'])
16
+ end
17
+
18
+ def path_to_commits(pr_id)
19
+ build_path(base_path,
20
+ [pr_id, 'pullrequest_id'],
21
+ 'commits')
22
+ end
23
+
24
+ def path_to_approve(pr_id)
25
+ build_path(base_path,
26
+ [pr_id, 'pullrequest_id'],
27
+ 'approve')
28
+ end
29
+
30
+ def path_to_diff(pr_id)
31
+ build_path(path_to_find(pr_id),
32
+ 'diff')
33
+ end
34
+
35
+ def base_path
36
+ build_path('/repositories',
37
+ [repo_owner, 'repo_owner'],
38
+ [repo_slug, 'repo_slug'],
39
+ 'pullrequests')
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module RepoHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_find
10
+ base_path
11
+ end
12
+
13
+ def path_to_watchers
14
+ build_path(base_path, '/watchers')
15
+ end
16
+
17
+ def path_to_forks
18
+ build_path(base_path, '/forks')
19
+ end
20
+
21
+ def base_path
22
+ build_path('/repositories',
23
+ [repo_owner, 'repo_owner'],
24
+ [repo_slug, 'repo_slug'])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module ReposHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_list(options)
10
+ owner = options[:owner]
11
+ return base_path if owner.blank?
12
+ build_path(base_path, [owner, 'owner'])
13
+ end
14
+
15
+ def base_path
16
+ '/repositories'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module TeamHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_find(name)
10
+ base_path(name)
11
+ end
12
+
13
+ def path_to_members(name)
14
+ build_path(base_path(name), 'members')
15
+ end
16
+
17
+ def path_to_followers(name)
18
+ build_path(base_path(name), 'followers')
19
+ end
20
+
21
+ def path_to_following(name)
22
+ build_path(base_path(name), 'following')
23
+ end
24
+
25
+ def path_to_repos(name)
26
+ build_path(base_path(name), 'repositories')
27
+ end
28
+
29
+ def base_path(name)
30
+ build_path('/teams', [name, 'teamname'])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module UserHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_find
10
+ base_path
11
+ end
12
+
13
+ def path_to_followers
14
+ build_path(base_path, 'followers')
15
+ end
16
+
17
+ def path_to_following
18
+ build_path(base_path, 'following')
19
+ end
20
+
21
+ def path_to_repos
22
+ build_path('/repositories', [username, 'username'])
23
+ end
24
+
25
+ def base_path
26
+ build_path('/users', [username, 'username'])
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ module Tinybucket
2
+ module Api
3
+ class PullRequestsApi < BaseApi
4
+ include Tinybucket::Api::Helper::PullRequestsHelper
5
+
6
+ attr_accessor :repo_owner, :repo_slug
7
+
8
+ def list(options = {})
9
+ list = get_path(path_to_list,
10
+ options,
11
+ Tinybucket::Parser::PullRequestsParser)
12
+
13
+ list.next_proc = next_proc(:list, options)
14
+ inject_api_config(list)
15
+ end
16
+
17
+ def find(pr_id, options = {})
18
+ m = get_path(path_to_find(pr_id),
19
+ options,
20
+ Tinybucket::Parser::PullRequestParser)
21
+
22
+ inject_api_config(m)
23
+ end
24
+
25
+ def commits(pr_id, options = {})
26
+ list = get_path(path_to_commits(pr_id),
27
+ options,
28
+ Tinybucket::Parser::CommitsParser)
29
+
30
+ list.next_proc = next_proc(:commits, options)
31
+ inject_api_config(list)
32
+ end
33
+
34
+ def approve(pr_id, options = {})
35
+ result = post_path(path_to_approve(pr_id), options)
36
+ (result['approved'] == true)
37
+ end
38
+
39
+ def unapprove(pr_id, options = {})
40
+ result = delete_path(path_to_approve(pr_id), options)
41
+ (result['approved'] == false)
42
+ end
43
+
44
+ def diff(pr_id, options = {})
45
+ get_path(path_to_diff(pr_id), options)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ module Tinybucket
2
+ module Api
3
+ class RepoApi < BaseApi
4
+ include Tinybucket::Api::Helper::RepoHelper
5
+
6
+ attr_accessor :repo_owner, :repo_slug
7
+
8
+ def find(options = {})
9
+ repo = get_path(path_to_find,
10
+ options,
11
+ Tinybucket::Parser::RepoParser)
12
+
13
+ inject_api_config(repo)
14
+ end
15
+
16
+ def watchers(options = {})
17
+ list = get_path(path_to_watchers,
18
+ options,
19
+ Tinybucket::Parser::ProfilesParser)
20
+
21
+ list.next_proc = next_proc(:watchers, options)
22
+ inject_api_config(list)
23
+ end
24
+
25
+ def forks(options = {})
26
+ list = get_path(path_to_forks,
27
+ options,
28
+ Tinybucket::Parser::ReposParser)
29
+
30
+ list.next_proc = next_proc(:forks, options)
31
+ inject_api_config(list)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ module Tinybucket
2
+ module Api
3
+ class ReposApi < BaseApi
4
+ include Tinybucket::Api::Helper::ReposHelper
5
+
6
+ def list(options = {})
7
+ opts = options.clone
8
+ opts.delete(:owner)
9
+
10
+ list = get_path(path_to_list(options),
11
+ opts,
12
+ Tinybucket::Parser::ReposParser)
13
+
14
+ list.next_proc = next_proc(:list, options)
15
+ inject_api_config(list)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ module Tinybucket
2
+ module Api
3
+ class TeamApi < BaseApi
4
+ include Tinybucket::Api::Helper::TeamHelper
5
+
6
+ def find(name, options = {})
7
+ m = get_path(path_to_find(name),
8
+ options,
9
+ Tinybucket::Parser::TeamParser)
10
+
11
+ inject_api_config(m)
12
+ end
13
+
14
+ def members(name, options = {})
15
+ list = get_path(path_to_members(name),
16
+ options,
17
+ Tinybucket::Parser::TeamsParser)
18
+
19
+ list.next_proc = next_proc(:members, options)
20
+ inject_api_config(list)
21
+ end
22
+
23
+ def followers(name, options = {})
24
+ list = get_path(path_to_followers(name),
25
+ options,
26
+ Tinybucket::Parser::TeamsParser)
27
+
28
+ list.next_proc = next_proc(:followers, options)
29
+ inject_api_config(list)
30
+ end
31
+
32
+ def following(name, options = {})
33
+ list = get_path(path_to_following(name),
34
+ options,
35
+ Tinybucket::Parser::TeamsParser)
36
+
37
+ list.next_proc = next_proc(:following, options)
38
+ inject_api_config(list)
39
+ end
40
+
41
+ def repos(name, options = {})
42
+ list = get_path(path_to_repos(name),
43
+ options,
44
+ Tinybucket::Parser::ReposParser)
45
+
46
+ list.next_proc = next_proc(:repos, options)
47
+ inject_api_config(list)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ module Tinybucket
2
+ module Api
3
+ class UserApi < BaseApi
4
+ include Tinybucket::Api::Helper::UserHelper
5
+
6
+ attr_accessor :username
7
+
8
+ def profile(options = {})
9
+ m = get_path(path_to_find,
10
+ options,
11
+ Tinybucket::Parser::ProfileParser)
12
+
13
+ inject_api_config(m)
14
+ end
15
+
16
+ def followers(options = {})
17
+ list = get_path(path_to_followers,
18
+ options,
19
+ Tinybucket::Parser::ProfilesParser)
20
+
21
+ list.next_proc = next_proc(:followers, options)
22
+ inject_api_config(list)
23
+ end
24
+
25
+ def following(options = {})
26
+ list = get_path(path_to_following,
27
+ options,
28
+ Tinybucket::Parser::ProfilesParser)
29
+
30
+ list.next_proc = next_proc(:following, options)
31
+ inject_api_config(list)
32
+ end
33
+
34
+ def repos(options = {})
35
+ list = get_path(path_to_repos,
36
+ options,
37
+ Tinybucket::Parser::ReposParser)
38
+
39
+ list.next_proc = next_proc(:repos, options)
40
+ inject_api_config(list)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ module Tinybucket
2
+ class ApiFactory
3
+ class << self
4
+ def create_instance(klass_name, config, options)
5
+ options.symbolize_keys!
6
+
7
+ klass =
8
+ begin
9
+ name = "#{klass_name}Api".intern
10
+ (Tinybucket::Api).const_get name
11
+ rescue => e
12
+ # TODO: log exception
13
+ Tinybucket.logger.error e
14
+ raise ArgumentError, 'must provide klass to be instantiated'
15
+ end
16
+
17
+ klass.new config, options
18
+ end
19
+ end
20
+ end
21
+ end