bitbucket-api 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2b45e58455c6226749365b0c4e55ceb4c61aa32daaec5f9d3bc4c6be1b6e5084
4
+ data.tar.gz: aa74fa2ebc788735570420e49a99dda49b5e9db3cc47ba7a2cea6a10c6c6f0c3
5
+ SHA512:
6
+ metadata.gz: 755363c84b8ebf923aceda1151ce38d039bc9d060a45cf2c047019a916156a6327dbaf2313b7dfdba8016704cf9ac63536bd0e4d16fc7211bea70c5144949f84
7
+ data.tar.gz: 0b222fe40dc9de154b8836bc4c080861580bcae7b0a5f43110ae9c698bb97b110c4363efe36403840da40a6749deeeaa04179024231c389c8190ae1829812daa
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+ Copyright (c) 2020 Lokalise team, Ilya Bodrov
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+ The above copyright notice and this permission notice shall be
11
+ included in all copies or substantial portions of the Software.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Bitbucket API
2
+ Bitbucket 2.0 API client
3
+
4
+ WARNING This bitbucket client is under development.
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```
10
+ gem 'bitbucket-api', git: 'git@github.com:rslhdyt/bitbucket-api.git'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install bitbucket-api
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ #### Init the client
28
+
29
+ There is multiple ways to set the config.
30
+
31
+ ```
32
+ BitbucketApi.configure do |config|
33
+ config.username = 'BITBUCKET_USERNAME'
34
+ config.app_password = 'BITBUCKET_APP_PASSWORD'
35
+ end
36
+
37
+ client = BitbucketApi.new
38
+ ```
39
+
40
+ Alternatively, you can configure the BitBucket settings by passing a block:
41
+
42
+ ```
43
+ client = BitbucketApi.new do |config|
44
+ config.username = 'BITBUCKET_USERNAME'
45
+ config.app_password = 'BITBUCKET_APP_PASSWORD'
46
+ end
47
+ ```
48
+
49
+ #### Interact with the interface
50
+
51
+ You can interact with BitBucket interface, for example pull request, by issuing following calls that correspond directly to the BitBucket API hierarchy
52
+
53
+ ```
54
+ response = client.pull_request.all('username/repository_slug', { state: 'OPEN'})
55
+ ```
56
+
57
+ ## Development
58
+ After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
@@ -0,0 +1,11 @@
1
+ module BitbucketApi
2
+ module Api
3
+ class Base
4
+ attr_reader :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module BitbucketApi
2
+ module Api
3
+ class PullRequest < BitbucketApi::Api::Base
4
+ def user(user)
5
+ response = @client.get("pullrequests/#{user}", params = {})
6
+
7
+ BitbucketApi::Collection::Pagination.new(response, BitbucketApi::Model::PullRequest)
8
+ end
9
+
10
+ def commit(repository, commit, params = {})
11
+ response = @client.get("repositories/#{repository}/commit/#{commit}/pullrequests", params)
12
+
13
+ BitbucketApi::Collection::Pagination.new(response, BitbucketApi::Model::PullRequest)
14
+ end
15
+
16
+ def all(repository, params = {})
17
+ response = @client.get("repositories/#{repository}/pullrequests", params)
18
+
19
+ BitbucketApi::Collection::Pagination.new(response, BitbucketApi::Model::PullRequest)
20
+ end
21
+
22
+ def default_reviewers(repository)
23
+ response = @client.get("repositories/#{repository}/default-reviewers")
24
+
25
+ BitbucketApi::Collection::Pagination.new(response, BitbucketApi::Model::Account)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'faraday_middleware'
2
+ # require 'bitbucket-api/middleware/handle_response_exception'
3
+ require 'bitbucket-api/api/base'
4
+ require 'bitbucket-api/model/base'
5
+ require 'bitbucket-api/collection/pagination'
6
+
7
+ require 'bitbucket-api/api/pull_request'
8
+ require 'bitbucket-api/model/pull_request'
9
+ require 'bitbucket-api/model/account'
10
+
11
+ module BitbucketApi
12
+ class Client
13
+ BASE_URL = 'https://api.bitbucket.org/2.0'.freeze
14
+
15
+ def initialize(options = {}, &block)
16
+ config = BitbucketApi::Configuration.new(options)
17
+
18
+ yield config if block_given?
19
+
20
+ @connection = Faraday.new(url: BASE_URL) do |conn|
21
+ conn.request :basic_auth, config.username, config.app_password
22
+ conn.request :json
23
+ conn.response :json
24
+
25
+ # conn.use ::Middleware::HandleResponseException
26
+ conn.adapter Faraday.default_adapter
27
+ end
28
+ end
29
+
30
+ def pull_request
31
+ @pull_request ||= BitbucketApi::Api::PullRequest.new(self)
32
+ end
33
+
34
+ def get(url, params = nil)
35
+ response = @connection.get(url, params)
36
+ response.body
37
+ end
38
+
39
+ def post(url, params)
40
+ response = @connection.post(url, params)
41
+ response.body
42
+ end
43
+
44
+ def patch(url, params)
45
+ response = @connection.patch(url, params)
46
+ response.body
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module BitbucketApi
2
+ module Collection
3
+ class Pagination
4
+ attr_accessor :size,
5
+ :page,
6
+ :pagelen,
7
+ :next,
8
+ :previous
9
+
10
+ def initialize(collection_attributes, model)
11
+ build_collection(collection_attributes, model)
12
+ end
13
+
14
+ def collection
15
+ @collection ||= []
16
+ end
17
+
18
+ private
19
+
20
+ def build_collection(collection_attributes, model)
21
+ @size = collection_attributes['size']
22
+ @page = collection_attributes['page']
23
+ @pagelen = collection_attributes['pagelen']
24
+ @next = collection_attributes['next']
25
+ @previous = collection_attributes['previous']
26
+ @values = collection_attributes['values']
27
+
28
+ @values.each do |value|
29
+ collection << model.new(value)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module BitbucketApi
2
+ class Configuration
3
+ attr_accessor :username,
4
+ :app_password
5
+
6
+ def initialize(**args)
7
+ @username = args[:username]
8
+ @app_password = args[:app_password]
9
+ end
10
+
11
+ def configure
12
+ yield self
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module BitbucketApi
2
+ module Model
3
+ class Account < BitbucketApi::Model::Base
4
+ attr_accessor :id,
5
+ :links,
6
+ :display_name,
7
+ :username,
8
+ :uuid
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module BitbucketApi
2
+ module Model
3
+ class Base
4
+ def initialize(attributes)
5
+ assign_attributes(attributes)
6
+ end
7
+
8
+ private
9
+
10
+ def assign_attributes(attributes)
11
+ raise ArgumentError, "Attributes is empty" if attributes.empty?
12
+
13
+ attributes.each do |key, value|
14
+ assign_attribute(key, value)
15
+ end
16
+ end
17
+
18
+ # Private: Set attribute with only defined resource attribute
19
+ def assign_attribute(key, value)
20
+ setter = :"#{key}="
21
+ public_send(setter, value) if respond_to?(setter)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module BitbucketApi
2
+ module Model
3
+ class PullRequest < BitbucketApi::Model::Base
4
+ attr_accessor :id,
5
+ :links,
6
+ :title,
7
+ :author,
8
+ :summary,
9
+ :state,
10
+ :source,
11
+ :destrination,
12
+ :merge_commit,
13
+ :comment_count,
14
+ :task_count,
15
+ :close_source_branch,
16
+ :closed_by,
17
+ :reason,
18
+ :created_on,
19
+ :updated_on,
20
+ :reviewers,
21
+ :participants
22
+
23
+ def author=(author)
24
+ @author = BitbucketApi::Model::Account.new(author)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module BitbucketApi
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'bitbucket-api/version'
2
+ require 'bitbucket-api/client'
3
+ require 'bitbucket-api/configuration'
4
+
5
+ # require errors
6
+ # require 'bitbucket-api/errors'
7
+
8
+ module BitbucketApi
9
+ class << self
10
+ attr_accessor :client, :config
11
+
12
+ def new(options = {}, &block)
13
+ @client = BitbucketApi::Client.new(options, &block)
14
+ end
15
+
16
+ def config
17
+ @config ||= Configuration.new
18
+ end
19
+
20
+ def reset
21
+ @config = Configuration.new
22
+ end
23
+
24
+ def configure
25
+ yield config
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitbucketApi do
4
+ describe '#new' do
5
+ it 'return alias of BitbucketApi::Client' do
6
+ expect(described_class.new).to be_an described_class::Client
7
+ end
8
+ end
9
+
10
+ describe 'config' do
11
+ context 'when set config using block' do
12
+ it 'return correct value' do
13
+ described_class.configure do |config|
14
+ config.username = 'banana'
15
+ config.app_password = 'secret'
16
+ end
17
+
18
+ expect(described_class.config.username).to eq 'banana'
19
+ expect(described_class.config.app_password).to eq 'secret'
20
+ end
21
+ end
22
+
23
+ # context 'when set config using options' do
24
+ # it 'return correct value' do
25
+ # client = described_class.new({ username: 'bananas', app_password: 'secret' })
26
+
27
+ # expect(described_class.username).to eq 'bananas'
28
+ # expect(described_class.app_password).to eq 'secret'
29
+ # end
30
+ # end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ # require 'webmock/rspec'
5
+ # require 'pry'
6
+ # require 'vcr'
7
+
8
+ require 'bitbucket-api'
9
+
10
+ RSpec.configure do |config|
11
+ config.expect_with :rspec do |expectations|
12
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13
+ # config.mock_with :mocha
14
+ end
15
+
16
+ # config.mock_with :rspec do |mocks|
17
+ # mocks.verify_partial_doubles = true
18
+ # end
19
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitbucket-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Risal Hidayat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: " Ruby wrapper for the BitBucket API "
140
+ email: risalhidayat88@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/bitbucket-api.rb
148
+ - lib/bitbucket-api/api/base.rb
149
+ - lib/bitbucket-api/api/pull_request.rb
150
+ - lib/bitbucket-api/client.rb
151
+ - lib/bitbucket-api/collection/pagination.rb
152
+ - lib/bitbucket-api/configuration.rb
153
+ - lib/bitbucket-api/model/account.rb
154
+ - lib/bitbucket-api/model/base.rb
155
+ - lib/bitbucket-api/model/pull_request.rb
156
+ - lib/bitbucket-api/version.rb
157
+ - spec/bitbucket-api_spec.rb
158
+ - spec/spec_helper.rb
159
+ homepage: https://github.com/rslhdyt/bitbucket-api
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: 2.5.0
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubygems_version: 3.1.4
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Ruby wrapper for the BitBucket API
182
+ test_files: []