rubytoolbox-api 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: 074f746fd6ec2589d1b6ec6b494ce814c469bc2dcc3ef47171f9ae6f184f254e
4
+ data.tar.gz: cbdf7c4df218fd0ae0bffbf7ec4875f0df07f7a23187388415563b51a540d38d
5
+ SHA512:
6
+ metadata.gz: 13acb59c9172b2d00479e2195ce1a259af0756f00f745d94935f46fb7197a6e430b61264160384e984e58735ad51569cd78a143bf8b0795d2b07e3d502d728d1
7
+ data.tar.gz: c5119e50a5f4129c29151843429ecc7463c4c187351086b967369bf10238dbc505a86490822e5d7214820d6f15bd90034aee5157526249b46e726b4031fdc74b
@@ -0,0 +1,29 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby:
15
+ - '2.7'
16
+ - '2.6'
17
+ - '2.5'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: "${{matrix.ruby}}"
25
+ - name: Install dependencies and run RSpec
26
+ run: |
27
+ gem install bundler
28
+ bundle install --jobs 4 --retry 3
29
+ bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order random
data/.rubocop ADDED
@@ -0,0 +1,3 @@
1
+ --display-cop-names
2
+ --display-style-guide
3
+ --extra-details
data/.rubocop.yml ADDED
@@ -0,0 +1,67 @@
1
+ #
2
+ # Our adjustments to rubocop default code policies.
3
+ #
4
+ # See http://rubocop.readthedocs.io/en/latest/ for detailed configuration options documentation
5
+
6
+ # Additional cops for working with RSpec. See https://github.com/backus/rubocop-rspec
7
+ require:
8
+ - rubocop-performance
9
+ - rubocop-rspec
10
+
11
+ AllCops:
12
+ Exclude:
13
+ - 'tmp/**/*.rb'
14
+ # See https://qiita.com/ozhaan/items/40ea864757162e931be1
15
+ - 'vendor/**/*'
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ # The default guard-rspec config fails this, but it's ok.
20
+ - 'Guardfile'
21
+ - 'spec/**/*_spec.rb'
22
+
23
+ # Big screens are common :)
24
+ Layout/LineLength:
25
+ Max: 120
26
+
27
+ # We use RSpec as a format linter, so no specific classes under test neccessarily :)
28
+ RSpec/DescribeClass:
29
+ Enabled: false
30
+
31
+ # Prefer to use the up-front message expectations
32
+ RSpec/MessageSpies:
33
+ Enabled: false
34
+
35
+ # Prefer structure over small indentation
36
+ RSpec/NestedGroups:
37
+ Max: 5
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+
42
+ # Prefer to create "real" booleans using double negation
43
+ Style/DoubleNegation:
44
+ Enabled: false
45
+
46
+ Style/StringLiterals:
47
+ EnforcedStyle: double_quotes
48
+
49
+ Style/TrailingCommaInArrayLiteral:
50
+ EnforcedStyleForMultiline: comma
51
+
52
+ Style/TrailingCommaInHashLiteral:
53
+ EnforcedStyleForMultiline: comma
54
+
55
+ # I actually use this a lot with `private :foo=`
56
+ Style/AccessModifierDeclarations:
57
+ Enabled: false
58
+
59
+ RSpec/ExampleLength:
60
+ Max: 10
61
+
62
+ Style/HashEachMethods:
63
+ Enabled: true
64
+ Style/HashTransformKeys:
65
+ Enabled: true
66
+ Style/HashTransformValues:
67
+ Enabled: true
data/.simplecov ADDED
@@ -0,0 +1,4 @@
1
+ SimpleCov.start :rails do
2
+ enable_coverage :branch
3
+ minimum_coverage line: 100, branch: 94.5 unless ENV["SKIP_COVERAGE"]
4
+ end
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,73 @@
1
+ # The Ruby Toolbox - Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at team@ruby-toolbox.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rubytoolbox-api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,122 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubytoolbox-api (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ ast (2.4.0)
12
+ coderay (1.1.2)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ docile (1.3.2)
17
+ ffi (1.12.2)
18
+ formatador (0.2.5)
19
+ guard (2.16.2)
20
+ formatador (>= 0.2.4)
21
+ listen (>= 2.7, < 4.0)
22
+ lumberjack (>= 1.0.12, < 2.0)
23
+ nenv (~> 0.1)
24
+ notiffany (~> 0.0)
25
+ pry (>= 0.9.12)
26
+ shellany (~> 0.0)
27
+ thor (>= 0.18.1)
28
+ guard-bundler (3.0.0)
29
+ bundler (>= 2.1, < 3)
30
+ guard (~> 2.2)
31
+ guard-compat (~> 1.1)
32
+ guard-compat (1.2.1)
33
+ guard-rspec (4.7.3)
34
+ guard (~> 2.1)
35
+ guard-compat (~> 1.1)
36
+ rspec (>= 2.99.0, < 4.0)
37
+ guard-rubocop (1.3.0)
38
+ guard (~> 2.0)
39
+ rubocop (~> 0.20)
40
+ hashdiff (1.0.1)
41
+ jaro_winkler (1.5.4)
42
+ listen (3.2.1)
43
+ rb-fsevent (~> 0.10, >= 0.10.3)
44
+ rb-inotify (~> 0.9, >= 0.9.10)
45
+ lumberjack (1.2.4)
46
+ method_source (1.0.0)
47
+ nenv (0.3.0)
48
+ notiffany (0.1.3)
49
+ nenv (~> 0.1)
50
+ shellany (~> 0.0)
51
+ parallel (1.19.1)
52
+ parser (2.7.0.5)
53
+ ast (~> 2.4.0)
54
+ pry (0.13.0)
55
+ coderay (~> 1.1)
56
+ method_source (~> 1.0)
57
+ public_suffix (4.0.3)
58
+ rainbow (3.0.0)
59
+ rake (12.3.3)
60
+ rb-fsevent (0.10.3)
61
+ rb-inotify (0.10.1)
62
+ ffi (~> 1.0)
63
+ rexml (3.2.4)
64
+ rspec (3.9.0)
65
+ rspec-core (~> 3.9.0)
66
+ rspec-expectations (~> 3.9.0)
67
+ rspec-mocks (~> 3.9.0)
68
+ rspec-core (3.9.1)
69
+ rspec-support (~> 3.9.1)
70
+ rspec-expectations (3.9.1)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.9.0)
73
+ rspec-mocks (3.9.1)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.9.0)
76
+ rspec-support (3.9.2)
77
+ rubocop (0.80.1)
78
+ jaro_winkler (~> 1.5.1)
79
+ parallel (~> 1.10)
80
+ parser (>= 2.7.0.1)
81
+ rainbow (>= 2.2.2, < 4.0)
82
+ rexml
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (>= 1.4.0, < 1.7)
85
+ rubocop-performance (1.5.2)
86
+ rubocop (>= 0.71.0)
87
+ rubocop-rspec (1.38.1)
88
+ rubocop (>= 0.68.1)
89
+ ruby-progressbar (1.10.1)
90
+ safe_yaml (1.0.5)
91
+ shellany (0.0.1)
92
+ simplecov (0.18.5)
93
+ docile (~> 1.1)
94
+ simplecov-html (~> 0.11)
95
+ simplecov-html (0.12.2)
96
+ thor (1.0.1)
97
+ unicode-display_width (1.6.1)
98
+ vcr (5.1.0)
99
+ webmock (3.8.3)
100
+ addressable (>= 2.3.6)
101
+ crack (>= 0.3.2)
102
+ hashdiff (>= 0.4.0, < 2.0.0)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ guard-bundler
109
+ guard-rspec
110
+ guard-rubocop
111
+ rake (~> 12.0)
112
+ rspec (>= 3.9)
113
+ rubocop
114
+ rubocop-performance
115
+ rubocop-rspec
116
+ rubytoolbox-api!
117
+ simplecov (>= 0.18.5)
118
+ vcr (>= 5.1.0)
119
+ webmock (>= 3.8.3)
120
+
121
+ BUNDLED WITH
122
+ 2.1.4
data/Guardfile ADDED
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ guard :bundler do
21
+ require "guard/bundler"
22
+ require "guard/bundler/verify"
23
+ helper = Guard::Bundler::Verify.new
24
+
25
+ files = ["Gemfile"]
26
+ files += Dir["*.gemspec"] if files.any? { |f| helper.uses_gemspec?(f) }
27
+
28
+ # Assume files are symlinked from somewhere
29
+ files.each { |file| watch(helper.real_path(file)) }
30
+ end
31
+
32
+ # Note: The cmd option is now required due to the increasing number of ways
33
+ # rspec may be run, below are examples of the most common uses.
34
+ # * bundler: 'bundle exec rspec'
35
+ # * bundler binstubs: 'bin/rspec'
36
+ # * spring: 'bin/rspec' (This will use spring if running and you have
37
+ # installed the spring binstubs per the docs)
38
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
39
+ # * 'just' rspec: 'rspec'
40
+
41
+ guard :rspec, cmd: "bundle exec rspec" do
42
+ require "guard/rspec/dsl"
43
+ dsl = Guard::RSpec::Dsl.new(self)
44
+
45
+ # Feel free to open issues for suggestions and improvements
46
+
47
+ # RSpec files
48
+ rspec = dsl.rspec
49
+ watch(rspec.spec_helper) { rspec.spec_dir }
50
+ watch(rspec.spec_support) { rspec.spec_dir }
51
+ watch(rspec.spec_files)
52
+
53
+ # Ruby files
54
+ ruby = dsl.ruby
55
+ dsl.watch_spec_files_for(ruby.lib_files)
56
+
57
+ # Rails files
58
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
59
+ dsl.watch_spec_files_for(rails.app_files)
60
+ dsl.watch_spec_files_for(rails.views)
61
+
62
+ watch(rails.controllers) do |m|
63
+ [
64
+ rspec.spec.call("routing/#{m[1]}_routing"),
65
+ rspec.spec.call("controllers/#{m[1]}_controller"),
66
+ rspec.spec.call("acceptance/#{m[1]}"),
67
+ ]
68
+ end
69
+
70
+ # Rails config changes
71
+ watch(rails.spec_helper) { rspec.spec_dir }
72
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
73
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
74
+
75
+ # Capybara features specs
76
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
77
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
78
+
79
+ # Turnip features and steps
80
+ watch(%r{^spec/acceptance/(.+)\.feature$})
81
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
82
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
83
+ end
84
+ end
85
+
86
+ rubocop_cli_args = []
87
+
88
+ if ENV["AUTOCORRECT"]
89
+ puts "*" * 80, "Rubocop auto-correct mode enabled", "*" * 80
90
+ rubocop_cli_args << "--auto-correct"
91
+ else
92
+ puts "*" * 80
93
+ puts "You can set Rubocop to auto-correct fixable offenses by setting ENV['AUTOCORRECT']"
94
+ puts "e.g. `$ AUTOCORRECT=yesplease guard`"
95
+ puts "*" * 80
96
+ end
97
+
98
+ guard :rubocop, run_on_start: true, cli: rubocop_cli_args.join(" ") do
99
+ watch(/.+\.rb$/)
100
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
101
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Christoph Olszowka
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,48 @@
1
+ <div align="center">
2
+ <img src="https://github.com/rubytoolbox/rubytoolbox/raw/master/app/assets/images/logo/regular.svg?sanitize=true" width="400px" alt="The Ruby Toolbox"/>
3
+
4
+ ![CI](https://github.com/rubytoolbox/rubytoolbox-api/workflows/CI/badge.svg)
5
+
6
+ **This is a simple ruby APi client for the [Ruby Toolbox API](https://www.ruby-toolbox.com/pages/docs/api/projects)**
7
+ </div>
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rubytoolbox-api'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rubytoolbox-api
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ Rubytoolbox::Api.new.compare "rails", "sinatra", "hanami"
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubytoolbox-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rubytoolbox-api/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the Rubytoolbox::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rubytoolbox-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rubytoolbox/api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubytoolbox/api/version"
4
+ require "uri"
5
+ require "json"
6
+ require "net/http"
7
+ require "rubytoolbox/api/response_wrapper"
8
+ require "rubytoolbox/api/category"
9
+ require "rubytoolbox/api/category_group"
10
+ require "rubytoolbox/api/project"
11
+ require "rubytoolbox/api/health"
12
+ require "rubytoolbox/api/rubygem"
13
+ require "rubytoolbox/api/github_repo"
14
+
15
+ module Rubytoolbox
16
+ class Api
17
+ class RequestError < StandardError; end
18
+
19
+ DEFAULT_URL = "https://www.ruby-toolbox.com/api/"
20
+
21
+ attr_accessor :endpoint_url
22
+ private :endpoint_url=
23
+
24
+ def initialize(url: DEFAULT_URL)
25
+ self.endpoint_url = url.clone.freeze
26
+ end
27
+
28
+ def compare(*names)
29
+ url = URI(File.join(endpoint_url, "projects", "compare", names.join(",")))
30
+
31
+ data = handle_response! Net::HTTP.get_response(url)
32
+
33
+ data.fetch("projects").map do |project_data|
34
+ Project.new project_data
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def handle_response!(response)
41
+ case response.code.to_i
42
+ when 200
43
+ JSON.parse(response.body)
44
+ else
45
+ raise RequestError, error_message_for_response(response)
46
+ end
47
+ end
48
+
49
+ def error_message_for_response(response)
50
+ data = JSON.parse(response.body)
51
+
52
+ "Unexpected response status #{response.code}! #{data['message']}"
53
+ rescue JSON::ParserError
54
+ "Unexpected response status #{response.code}! #{response.body}"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ class Category < ResponseWrapper
6
+ class UrlSet < ResponseWrapper
7
+ field :toolbox_url
8
+ end
9
+
10
+ field :permalink
11
+ field :name
12
+ field :description
13
+ field :category_group do |category_group|
14
+ CategoryGroup.new category_group
15
+ end
16
+ field :urls do |urls|
17
+ UrlSet.new urls
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ class CategoryGroup < ResponseWrapper
6
+ field :permalink
7
+ field :name
8
+ field :description
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+
5
+ module Rubytoolbox
6
+ class Api
7
+ class GithubRepo < ResponseWrapper
8
+ class Stats < ResponseWrapper
9
+ field :stargazers_count
10
+ field :forks_count
11
+ field :watchers_count
12
+ end
13
+
14
+ class Issues < ResponseWrapper
15
+ field :url
16
+ field :open_count
17
+ field :closed_count
18
+ field :total_count
19
+ field :closure_rate, &:to_f
20
+ end
21
+
22
+ class PullRequests < ResponseWrapper
23
+ field :url
24
+ field :open_count
25
+ field :closed_count
26
+ field :merged_count
27
+ field :total_count
28
+ field :acceptance_rate, &:to_f
29
+ end
30
+
31
+ field :path
32
+ field :average_recent_committed_at do |time|
33
+ Time.parse(time)
34
+ end
35
+ field :description
36
+ field :is_archived
37
+ field :is_fork
38
+ field :is_mirror
39
+ field :license
40
+ field :primary_language
41
+
42
+ field :repo_pushed_at do |time|
43
+ Time.parse(time)
44
+ end
45
+
46
+ field :url
47
+ field :wiki_url
48
+
49
+ field :stats do |stats|
50
+ Stats.new stats
51
+ end
52
+
53
+ field :issues do |issues|
54
+ Issues.new issues
55
+ end
56
+
57
+ field :pull_requests do |pull_requests|
58
+ PullRequests.new pull_requests
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ class Health < ResponseWrapper
6
+ class Status < ResponseWrapper
7
+ field :key
8
+ field :icon
9
+ field :label
10
+ field :level
11
+ end
12
+
13
+ field :overall_level
14
+ field :statuses do |statuses|
15
+ statuses.map do |status|
16
+ Status.new status
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ class Project < ResponseWrapper
6
+ class UrlSet < ResponseWrapper
7
+ field :bug_tracker_url
8
+ field :changelog_url
9
+ field :documentation_url
10
+ field :homepage_url
11
+ field :mailing_list_url
12
+ field :source_code_url
13
+ field :toolbox_url
14
+ field :wiki_url
15
+ end
16
+
17
+ field :description
18
+ field :name
19
+ field :permalink
20
+ field :score, &:to_f
21
+
22
+ field :categories do |categories|
23
+ categories.map { |category| Category.new category }
24
+ end
25
+
26
+ field :github_repo do |github_repo|
27
+ GithubRepo.new github_repo
28
+ end
29
+
30
+ field :health do |health|
31
+ Health.new health
32
+ end
33
+
34
+ field :rubygem do |rubygem|
35
+ Rubygem.new rubygem
36
+ end
37
+
38
+ field :urls do |urls|
39
+ UrlSet.new urls
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ #
6
+ # A simple base class for data wrapper objects / structs. Libraries like
7
+ # dry-struct are normally very handy for these things but to keep dependencies
8
+ # minimal we roll our own simple utility here.
9
+ #
10
+ # Usage:
11
+ #
12
+ # class Foo < Rubytoolbox::Api::ResponseWrapper
13
+ # field :foo
14
+ # field :bar, &:reverse
15
+ # end
16
+ #
17
+ # Foo.new(foo: "foo", bar: "bar").bar # => "rab"
18
+ #
19
+ class ResponseWrapper
20
+ class << self
21
+ def field(name, &block)
22
+ fields << name.to_s
23
+
24
+ block ||= ->(value) { value }
25
+
26
+ define_method "#{name}=" do |value|
27
+ instance_variable_set "@#{name}", block.call(value)
28
+ end
29
+
30
+ attr_reader name
31
+ private "#{name}="
32
+ end
33
+
34
+ def fields
35
+ @fields ||= []
36
+ end
37
+ end
38
+
39
+ def initialize(data)
40
+ self.class.fields.each do |name|
41
+ value = data.key?(name.to_s) ? data[name.to_s] : data[name.to_sym]
42
+
43
+ send "#{name}=", value unless value.nil?
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubytoolbox
4
+ class Api
5
+ class Rubygem < ResponseWrapper
6
+ class Stats < ResponseWrapper
7
+ field :downloads
8
+ field :reverse_dependencies_count
9
+ field :releases_count
10
+
11
+ field :quarterly_release_counts
12
+ end
13
+
14
+ field :name
15
+ field :current_version
16
+ field :first_release_on do |date|
17
+ Date.parse(date)
18
+ end
19
+ field :latest_release_on do |date|
20
+ Date.parse(date)
21
+ end
22
+ field :licenses
23
+ field :url
24
+
25
+ field :stats do |stats|
26
+ Stats.new stats
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://github.com/colszowka/simplecov/issues/557#issuecomment-410126627
4
+ # :nocov:
5
+ module Rubytoolbox
6
+ class Api
7
+ VERSION = "0.1.0"
8
+ end
9
+ end
10
+ # :nocov:
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rubytoolbox/api/version"
4
+
5
+ # rubocop:disable Metrics/BlockLength
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubytoolbox-api"
8
+ spec.version = Rubytoolbox::Api::VERSION
9
+ spec.authors = ["Christoph Olszowka"]
10
+ spec.email = ["christoph at olszowka de"]
11
+
12
+ spec.summary = "A simple, dependency-free API client for The Ruby Toolbox"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://www.ruby-toolbox.com"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/rubytoolbox/rubytoolbox-api"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "rubocop-performance"
32
+ spec.add_development_dependency "rubocop-rspec"
33
+
34
+ spec.add_development_dependency "guard-bundler"
35
+ spec.add_development_dependency "guard-rspec"
36
+ spec.add_development_dependency "guard-rubocop"
37
+
38
+ spec.add_development_dependency "rspec", ">= 3.9"
39
+ spec.add_development_dependency "simplecov", ">= 0.18.5"
40
+
41
+ spec.add_development_dependency "vcr", ">= 5.1.0"
42
+ spec.add_development_dependency "webmock", ">= 3.8.3"
43
+ end
44
+ # rubocop:enable Metrics/BlockLength
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubytoolbox-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Olszowka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rubocop-performance
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rubocop-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: guard-bundler
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: guard-rspec
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: guard-rubocop
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: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '3.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '3.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 0.18.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.18.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 5.1.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 5.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 3.8.3
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 3.8.3
153
+ description: A simple, dependency-free API client for The Ruby Toolbox
154
+ email:
155
+ - christoph at olszowka de
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".github/workflows/ruby.yml"
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".rubocop"
164
+ - ".rubocop.yml"
165
+ - ".simplecov"
166
+ - ".travis.yml"
167
+ - CODE_OF_CONDUCT.md
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - Guardfile
171
+ - MIT-LICENSE
172
+ - README.md
173
+ - Rakefile
174
+ - bin/console
175
+ - bin/setup
176
+ - lib/rubytoolbox/api.rb
177
+ - lib/rubytoolbox/api/category.rb
178
+ - lib/rubytoolbox/api/category_group.rb
179
+ - lib/rubytoolbox/api/github_repo.rb
180
+ - lib/rubytoolbox/api/health.rb
181
+ - lib/rubytoolbox/api/project.rb
182
+ - lib/rubytoolbox/api/response_wrapper.rb
183
+ - lib/rubytoolbox/api/rubygem.rb
184
+ - lib/rubytoolbox/api/version.rb
185
+ - rubytoolbox-api.gemspec
186
+ homepage: https://www.ruby-toolbox.com
187
+ licenses:
188
+ - MIT
189
+ metadata:
190
+ homepage_uri: https://www.ruby-toolbox.com
191
+ source_code_uri: https://github.com/rubytoolbox/rubytoolbox-api
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 2.3.0
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubygems_version: 3.1.2
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: A simple, dependency-free API client for The Ruby Toolbox
211
+ test_files: []