gitearb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d09aacbbd7cbe3fe90fe4c799eef4354569a61296bfcc9617cb6d006b9e66f29
4
+ data.tar.gz: 3ac9fb06ee56ced9d0570c2ceb2681cca204d5cfaa03f14583bef9089961bc32
5
+ SHA512:
6
+ metadata.gz: 215c6241bf98977c093769522368af10539b18a917e4da3ffa28b44d8f7ee063586a5b03f81f5559e6fe33d04d6f3d32cfd80bd08ce668dcad2c0a3f8ba41076
7
+ data.tar.gz: 0d8f12f039ad28ca772f3c0a41959dcffcc4e9cbcedc2c20ad22efaa4033ffc08c58ce2bbaebee2c163f6a3ed2eebd290a48574029b3e7303fc93ce4b8b42dc3
data/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ GITEA_URL=
2
+ 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
+ gitearb (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
+ dotenv
24
+ gitearb!
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,41 @@
1
+ # GiteaRB
2
+
3
+ GiteaRB is a Ruby library for the Gitea API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "gitearb"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Set URL and Access Token
16
+
17
+ Firstly, you'll need to set the URL and Access Token like so:
18
+
19
+ ```ruby
20
+ @client = Gitea::Client.new(url: "https://my-gitea-server.com", access_token: "")
21
+ ```
22
+
23
+ ### User
24
+
25
+ Retrieve details about the currently authenticated user.
26
+
27
+ ```ruby
28
+ # Retrieves details about the current user
29
+ @client.user.get
30
+
31
+ # List all of your email addresses
32
+ @client.user.emails
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/gitearb.
38
+
39
+ ## License
40
+
41
+ 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 "gitea"
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 = Gitea::Client.new(url: ENV["GITEA_URL"], 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
data/gitearb.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/gitea/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "gitearb"
5
+ spec.version = Gitea::VERSION
6
+ spec.authors = ["Dean Perry"]
7
+ spec.email = ["dean@deanpcmad.com"]
8
+
9
+ spec.summary = "A Ruby library for the Gitea 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/gitearb"
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,39 @@
1
+ module Gitea
2
+ class Client
3
+ # BASE_URL = "https://api.buildkite.com/v2"
4
+
5
+ attr_reader :url, :access_token, :adapter
6
+
7
+ def initialize(url:, access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
+ @url = url
9
+ @access_token = access_token
10
+ @adapter = adapter
11
+
12
+ # Test stubs for requests
13
+ @stubs = stubs
14
+ end
15
+
16
+ def user
17
+ UserResource.new(self)
18
+ end
19
+
20
+ def connection
21
+ full_url = [url, "api/v1"].join("/")
22
+
23
+ @connection ||= Faraday.new(full_url) do |conn|
24
+ conn.request :authorization, :token, access_token
25
+
26
+ conn.headers = {
27
+ "User-Agent" => "gitearb/v#{VERSION} (github.com/deanpcmad/gitearb)"
28
+ }
29
+
30
+ conn.request :json
31
+
32
+ conn.response :json, content_type: "application/json"
33
+
34
+ conn.adapter adapter, @stubs
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module Gitea
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 Gitea
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Gitea
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 Gitea
2
+ class Email < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gitea
2
+ class User < Object
3
+ end
4
+ end
@@ -0,0 +1,59 @@
1
+ module Gitea
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 Gitea
2
+ class UserResource < Resource
3
+
4
+ def get
5
+ User.new get_request("user").body
6
+ end
7
+
8
+ def emails
9
+ response = get_request("user/emails")
10
+ Collection.from_response(response, type: Email)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Gitea
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gitea.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "gitea/version"
4
+
5
+ module Gitea
6
+
7
+ autoload :Client, "gitea/client"
8
+ autoload :Collection, "gitea/collection"
9
+ autoload :Error, "gitea/error"
10
+ autoload :Resource, "gitea/resource"
11
+ autoload :Object, "gitea/object"
12
+
13
+
14
+ autoload :UserResource, "gitea/resources/user"
15
+
16
+ autoload :User, "gitea/objects/user"
17
+ autoload :Email, "gitea/objects/email"
18
+
19
+ end
data/lib/gitearb.rb ADDED
@@ -0,0 +1 @@
1
+ require "gitea"
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitearb
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
+ - gitearb.gemspec
46
+ - lib/gitea.rb
47
+ - lib/gitea/client.rb
48
+ - lib/gitea/collection.rb
49
+ - lib/gitea/error.rb
50
+ - lib/gitea/object.rb
51
+ - lib/gitea/objects/email.rb
52
+ - lib/gitea/objects/user.rb
53
+ - lib/gitea/resource.rb
54
+ - lib/gitea/resources/user.rb
55
+ - lib/gitea/version.rb
56
+ - lib/gitearb.rb
57
+ homepage: https://deanpcmad.com
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://deanpcmad.com
62
+ source_code_uri: https://github.com/deanpcmad/gitearb
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.3.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.4.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A Ruby library for the Gitea API
82
+ test_files: []