buildkiterb 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8c74759ca24a01e1c3014a40e390bf0e6856f6f822afbe9b3ec04ce4eedf47a3
4
+ data.tar.gz: 15155f0dd6b2925cd986ca1fe4f800070b14f532b26bdf75dd368c40996afdc0
5
+ SHA512:
6
+ metadata.gz: 6471e3269bedfda857df898a96435d6b71759720880d4707e95ee1e9dd1d1eb54539446c9a05ada092413c7bc67327414781153ffec061dad8136c39d753ae04
7
+ data.tar.gz: 1424178e0527a785d2ac7b63d6632ee02fa7b8e19bae68e2a4a02dc15df3e0b04066395ba7de968a9db24df2c4be6f06dbaeb68a73b444e1fff65aa3cffe41be
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ ACCESS_TOKEN=
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ ko_fi: deanpcmad
@@ -0,0 +1,23 @@
1
+ name: CI
2
+ on: push
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby_version:
10
+ - 2.6
11
+ - 2.7
12
+ - 3.0
13
+ - 3.1
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby_version }}
19
+ bundler: default
20
+ bundler-cache: true
21
+
22
+ - name: Run tests
23
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twitch.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem "dotenv"
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ buildkiterb (0.1.0)
5
+ faraday (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ dotenv (2.7.6)
11
+ faraday (2.7.4)
12
+ faraday-net_http (>= 2.0, < 3.1)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-net_http (3.0.2)
15
+ minitest (5.15.0)
16
+ rake (12.3.3)
17
+ ruby2_keywords (0.0.5)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ buildkiterb!
24
+ dotenv
25
+ minitest (~> 5.0)
26
+ rake (~> 12.0)
27
+
28
+ BUNDLED WITH
29
+ 2.3.21
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Dean Perry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # BuildkiteRB
2
+
3
+ BuiltkiteRB is a Ruby library for the Buildkite API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "buildkiterb"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Set Client Details
16
+
17
+ Firstly you'll need to create an API Token on [Buildkite](https://buildkite.com/user/api-access-tokens)
18
+ and then set it like so:
19
+
20
+ ```ruby
21
+ @client = Buildkite::Client.new(access_token: "")
22
+ ```
23
+
24
+ ### Organizations
25
+
26
+ ```ruby
27
+ # List all of your organizations
28
+ @client.organizations.list
29
+
30
+ # Retrieves an organization
31
+ @client.organizations.get slug: "my-org-slug"
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/buildkiterb.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "buildkite"
5
+
6
+ # Load environment variables from .env file
7
+ require 'dotenv/load'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ @client = Buildkite::Client.new(access_token: ENV["ACCESS_TOKEN"])
17
+
18
+ require "irb"
19
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/buildkite/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "buildkiterb"
5
+ spec.version = Buildkite::VERSION
6
+ spec.authors = ["Dean Perry"]
7
+ spec.email = ["dean@deanpcmad.com"]
8
+
9
+ spec.summary = "A Ruby library for the Buildkite API"
10
+ spec.homepage = "https://deanpcmad.com"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/buildkiterb"
16
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "faraday", "~> 2.0"
28
+ end
@@ -0,0 +1,36 @@
1
+ module Buildkite
2
+ class Client
3
+ BASE_URL = "https://api.buildkite.com/v2"
4
+
5
+ attr_reader :access_token, :adapter
6
+
7
+ def initialize(access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
+ @access_token = access_token
9
+ @adapter = adapter
10
+
11
+ # Test stubs for requests
12
+ @stubs = stubs
13
+ end
14
+
15
+ def organizations
16
+ OrganizationsResource.new(self)
17
+ end
18
+
19
+ def connection
20
+ @connection ||= Faraday.new(BASE_URL) do |conn|
21
+ conn.request :authorization, :Bearer, access_token
22
+
23
+ conn.headers = {
24
+ "User-Agent" => "buildkiterb/v#{VERSION} (github.com/deanpcmad/buildkiterb)"
25
+ }
26
+
27
+ conn.request :json
28
+
29
+ conn.response :json, content_type: "application/json"
30
+
31
+ conn.adapter adapter, @stubs
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module Buildkite
2
+ class Collection
3
+ attr_reader :data, :total
4
+
5
+ def self.from_response(response, type:)
6
+ body = response.body
7
+
8
+ new(
9
+ data: body.map { |attrs| type.new(attrs) },
10
+ total: body.count
11
+ )
12
+ end
13
+
14
+ def initialize(data:, total:)
15
+ @data = data
16
+ @total = total
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Buildkite
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Buildkite
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else # Assumed to be a primitive value
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Buildkite
2
+ class Organization < Object
3
+ end
4
+ end
@@ -0,0 +1,59 @@
1
+ module Buildkite
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response client.connection.post(url, body, headers)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.patch(url, body, headers)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.put(url, body, headers)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.delete(url, params, headers)
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
35
+ when 401
36
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
37
+ when 403
38
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
39
+ when 404
40
+ raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
41
+ when 409
42
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
+ when 422
44
+ raise Error, "Error 422: Unprocessable Entity. '#{response.body["message"]}"
45
+ when 429
46
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
47
+ when 500
48
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
49
+ when 503
50
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
51
+ when 204
52
+ # 204 is a response for success on Twitch's API
53
+ return true
54
+ end
55
+
56
+ response
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ module Buildkite
2
+ class OrganizationsResource < Resource
3
+
4
+ def list
5
+ response = get_request("organizations")
6
+ Collection.from_response(response, type: Organization)
7
+ end
8
+
9
+ def get(slug:)
10
+ Organization.new get_request("organizations/#{slug}").body
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Buildkite
2
+ VERSION = "0.1.0"
3
+ end
data/lib/buildkite.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "buildkite/version"
4
+
5
+ module Buildkite
6
+
7
+ autoload :Client, "buildkite/client"
8
+ autoload :Collection, "buildkite/collection"
9
+ autoload :Error, "buildkite/error"
10
+ autoload :Resource, "buildkite/resource"
11
+ autoload :Object, "buildkite/object"
12
+
13
+
14
+ autoload :OrganizationsResource, "buildkite/resources/organizations"
15
+
16
+ autoload :Organization, "buildkite/objects/organization"
17
+
18
+ end
@@ -0,0 +1 @@
1
+ require "buildkite"
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildkiterb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-02-06 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description:
28
+ email:
29
+ - dean@deanpcmad.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".env.example"
35
+ - ".github/FUNDING.yml"
36
+ - ".github/workflows/ci.yml"
37
+ - ".gitignore"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - buildkiterb.gemspec
46
+ - lib/buildkite.rb
47
+ - lib/buildkite/client.rb
48
+ - lib/buildkite/collection.rb
49
+ - lib/buildkite/error.rb
50
+ - lib/buildkite/object.rb
51
+ - lib/buildkite/objects/organization.rb
52
+ - lib/buildkite/resource.rb
53
+ - lib/buildkite/resources/organizations.rb
54
+ - lib/buildkite/version.rb
55
+ - lib/buildkiterb.rb
56
+ homepage: https://deanpcmad.com
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://deanpcmad.com
61
+ source_code_uri: https://github.com/deanpcmad/buildkiterb
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.3.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.4.6
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A Ruby library for the Buildkite API
81
+ test_files: []