binford 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: 0dfd0dfb86159566e6cbe5043afb5a91a44c379c02c87460199d8a5c77a2ac5a
4
+ data.tar.gz: 137580e9dcd75fb98e3cb3ad134c2b46eb0d1c828f3a0274ccb0d10b8db0925f
5
+ SHA512:
6
+ metadata.gz: a8bdd2ee5f374d2cfe9fa3dd698691e67b3db6fa02a54b6c435f8568d9e88128c4dfc50008780c8e8e9241d2598668994abb449a0edb8c44f46088c5962a558a
7
+ data.tar.gz: 0eaf224f80a8890be5b795309f2524d5619cf4379d938887ff3119378f4f54079af0685e6339c72fd1d41c69ed98d599940daf4696771cecc243e8226ec67eb4
@@ -0,0 +1,25 @@
1
+ name: Ruby
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ ruby-version: ['2.6', '2.7', '3.0']
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
18
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
19
+ # uses: ruby/setup-ruby@v1
20
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
24
+ - name: Run tests
25
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
15
+
16
+ Style/Documentation:
17
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-05-03
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ing.ezcurdia@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in binford.gemspec
6
+ gemspec
7
+
8
+ gem "minitest", "~> 5.0"
9
+ gem "rake", "~> 13.0"
10
+ gem "rubocop"
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ binford (0.1.0)
5
+ faraday (~> 1.0)
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ faraday (1.4.1)
13
+ faraday-excon (~> 1.1)
14
+ faraday-net_http (~> 1.0)
15
+ faraday-net_http_persistent (~> 1.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ ruby2_keywords (>= 0.0.4)
18
+ faraday-excon (1.1.0)
19
+ faraday-net_http (1.0.1)
20
+ faraday-net_http_persistent (1.1.0)
21
+ mini_portile2 (2.5.1)
22
+ minitest (5.14.4)
23
+ multipart-post (2.1.1)
24
+ nokogiri (1.11.3)
25
+ mini_portile2 (~> 2.5.0)
26
+ racc (~> 1.4)
27
+ parallel (1.20.1)
28
+ parser (3.0.1.1)
29
+ ast (~> 2.4.1)
30
+ racc (1.5.2)
31
+ rainbow (3.0.0)
32
+ rake (13.0.3)
33
+ regexp_parser (2.1.1)
34
+ rexml (3.2.5)
35
+ rubocop (1.13.0)
36
+ parallel (~> 1.10)
37
+ parser (>= 3.0.0.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8, < 3.0)
40
+ rexml
41
+ rubocop-ast (>= 1.2.0, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 3.0)
44
+ rubocop-ast (1.5.0)
45
+ parser (>= 3.0.1.1)
46
+ ruby-progressbar (1.11.0)
47
+ ruby2_keywords (0.0.4)
48
+ unicode-display_width (2.0.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+ x86_64-darwin-19
53
+ x86_64-darwin-20
54
+
55
+ DEPENDENCIES
56
+ binford!
57
+ minitest (~> 5.0)
58
+ rake (~> 13.0)
59
+ rubocop
60
+
61
+ BUNDLED WITH
62
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Luis Ezcurdia
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,43 @@
1
+ # Binford
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/binford`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'binford'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install binford
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/binford. 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]/binford/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Binford project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/binford/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "binford"
6
+
7
+ # (If you use this, don't forget to add pry to your Gemfile!)
8
+ # require "pry"
9
+ # Pry.start
10
+
11
+ require "irb"
12
+ IRB.start(__FILE__)
data/bin/gemfile_stats ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "binford"
6
+
7
+ if ARGV.empty?
8
+ puts "Gemfile.lock must be given"
9
+ exit(1)
10
+ end
11
+
12
+ puts Binford::GemfileStats.new(ARGV[0]).stats.to_json
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/bindford.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/binford/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "binford"
7
+ spec.version = Binford::VERSION
8
+ spec.authors = ["Luis Ezcurdia"]
9
+ spec.email = ["ing.ezcurdia@gmail.com"]
10
+
11
+ spec.summary = "The Toolkit with more power!"
12
+ spec.description = "Toolkit with more power for github"
13
+ spec.homepage = "https://github.com/3zcurdia/binford"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/3zcurdia/binford"
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "faraday", "~> 1.0"
33
+ spec.add_dependency "nokogiri"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
data/lib/binford.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "binford/version"
4
+ require_relative "binford/serializers/json"
5
+ require_relative "binford/serializers/html"
6
+ require_relative "binford/web_service"
7
+ require_relative "binford/github"
8
+ require_relative "binford/ruby_toolbox"
9
+ require_relative "binford/ruby_gems"
10
+ require_relative "binford/gemfile_stats"
11
+
12
+ module Binford
13
+ class Error < StandardError; end
14
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binford
4
+ class GemfileStats
5
+ def initialize(file_path)
6
+ @file_path = file_path
7
+ end
8
+
9
+ def stats
10
+ gems.map do |gem, version|
11
+ Thread.new { analyze(gem, version) }
12
+ end.map(&:value)
13
+ end
14
+
15
+ def gems
16
+ @gems ||= parse_gems
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :file_path
22
+
23
+ def parse_gems
24
+ out = {}
25
+ File.open(file_path).each do |line|
26
+ out[Regexp.last_match(1).tr(" ", "")] = Regexp.last_match(2) if line =~ /(.*)\s\(([\d.]*)\)/
27
+ end
28
+ out
29
+ end
30
+
31
+ def analyze(gem, version)
32
+ fibers = []
33
+ fibers << Fiber.new { ruby_toolbox_data(gem) }
34
+ fibers << Fiber.new { rubygems_data(gem, version) }
35
+ fibers.map(&:resume).inject({}, &:merge!)
36
+ end
37
+
38
+ def ruby_toolbox_data(gem)
39
+ RubyToolbox.new(gem).data
40
+ end
41
+
42
+ def rubygems_data(gem, version)
43
+ rubygems = RubyGems.new(gem)
44
+ rubygems.data.merge(current: rubygems.current(version))
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Binford
6
+ class Github < WebService
7
+ def initialize(token:)
8
+ super("https://api.github.com", serializer: Serializers::Json.new)
9
+ @token = token
10
+ end
11
+
12
+ def projects(owner, repo)
13
+ get("repos/#{owner}/#{repo}/projects")
14
+ end
15
+
16
+ def project_columns(project_id)
17
+ get("/projects/#{project_id}/columns")
18
+ end
19
+
20
+ def project_cards(column_id)
21
+ get("/projects/columns/#{column_id}/cards")
22
+ end
23
+
24
+ def project_story_points(column_id)
25
+ regex = /SP:\s*(\d+\.*\d*)/
26
+ project_cards(column_id)&.map do |data|
27
+ (data[:note] || get(data[:content_url].sub(base_url, ""))[:body]).scan(regex).flatten.first
28
+ end&.compact
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :token
34
+
35
+ def default_headers
36
+ {
37
+ "Content-Type" => "application/json",
38
+ "Accept" => "application/vnd.github.inertia-preview+json",
39
+ "Authorization" => "token #{token}"
40
+ }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binford
4
+ class RubyGems < WebService
5
+ attr_reader :gem
6
+
7
+ def initialize(gem)
8
+ super("https://rubygems.org/", serializer: Serializers::HTML.new)
9
+ @gem = gem
10
+ end
11
+
12
+ def data
13
+ {
14
+ name: gem,
15
+ versions: versions,
16
+ dependencies: dependencies,
17
+ rails_dependencies: rails_dependencies
18
+ }
19
+ end
20
+
21
+ def current(version)
22
+ {
23
+ version: version,
24
+ released_at: (versions ? versions[version] : nil)
25
+ }
26
+ end
27
+
28
+ def versions
29
+ @versions ||= versions_document&.css(".t-list__items")&.css("li.gem__version-wrap")&.map do |node|
30
+ parse_node_version(node)
31
+ end&.to_h
32
+ end
33
+
34
+ def dependencies
35
+ @dependencies ||= document&.css(".dependencies")&.css(".t-list__items")&.map do |node|
36
+ parse_node_dependency(node)
37
+ end
38
+ end
39
+
40
+ def rails_dependencies
41
+ dependencies&.select { |dependency, _| rails_gems.include?(dependency) }
42
+ end
43
+
44
+ private
45
+
46
+ def parse_node_version(node)
47
+ version = node.css(".t-list__item")&.text
48
+ date = node.css("small.gem__version__date")&.text&.sub("- ", "")
49
+ [version, date]
50
+ end
51
+
52
+ def parse_node_dependency(node)
53
+ item = node.css(".t-list__item")
54
+ dependency = item&.css("strong")&.text
55
+ version = item&.text&.sub(dependency.to_s, "")
56
+ [dependency.strip, version.strip.gsub("\n", "")]
57
+ end
58
+
59
+ def document
60
+ @document ||= get("gems/#{gem}")
61
+ end
62
+
63
+ def versions_document
64
+ @versions_document ||= get("gems/#{gem}/versions")
65
+ end
66
+
67
+ def rails_gems
68
+ @rails_gems ||= %w[actionpack actionview actioncable actionmailer activerecord
69
+ active_model_serializers activejob activesupport activemodel activestorage activeadmin]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binford
4
+ class RubyToolbox < WebService
5
+ attr_reader :gem
6
+
7
+ def initialize(gem)
8
+ super("https://www.ruby-toolbox.com/", serializer: Serializers::HTML.new)
9
+ @gem = gem
10
+ end
11
+
12
+ def data
13
+ {
14
+ name: gem,
15
+ score: score,
16
+ description: description
17
+ }
18
+ end
19
+
20
+ def score
21
+ @score ||= document&.xpath("/html/body/section/div/section/div/div[1]/div[2]/div[1]/span[2]")&.text&.to_f
22
+ end
23
+
24
+ def description
25
+ @description ||= document&.xpath("/html/body/section/div/section/div/div[4]/div")&.text
26
+ end
27
+
28
+ def document
29
+ @document ||= get("/projects/#{gem}")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+
5
+ module Binford
6
+ module Serializers
7
+ class HTML
8
+ def call(content)
9
+ Nokogiri::HTML(content)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Binford
6
+ module Serializers
7
+ class Json
8
+ def call(content)
9
+ JSON.parse(content, symbolize_names: true)
10
+ rescue JSON::ParserError
11
+ nil
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binford
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Binford
6
+ class WebService
7
+ def initialize(base_url, serializer:)
8
+ @base_url = base_url
9
+ @serializer = serializer
10
+ end
11
+
12
+ def get(path)
13
+ response = conn.get(path)
14
+ return unless response.success?
15
+
16
+ serializer.call(response.body)
17
+ end
18
+
19
+ protected
20
+
21
+ attr_reader :base_url, :serializer
22
+
23
+ def conn
24
+ @conn ||= Faraday.new(url: base_url, headers: default_headers)
25
+ end
26
+
27
+ def default_headers
28
+ {}
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binford
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luis Ezcurdia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
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
+ description: Toolkit with more power for github
42
+ email:
43
+ - ing.ezcurdia@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/main.yml"
49
+ - ".gitignore"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/gemfile_stats
60
+ - bin/setup
61
+ - bindford.gemspec
62
+ - lib/binford.rb
63
+ - lib/binford/gemfile_stats.rb
64
+ - lib/binford/github.rb
65
+ - lib/binford/ruby_gems.rb
66
+ - lib/binford/ruby_toolbox.rb
67
+ - lib/binford/serializers/html.rb
68
+ - lib/binford/serializers/json.rb
69
+ - lib/binford/version.rb
70
+ - lib/binford/web_service.rb
71
+ homepage: https://github.com/3zcurdia/binford
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/3zcurdia/binford
76
+ source_code_uri: https://github.com/3zcurdia/binford
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.2.15
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: The Toolkit with more power!
96
+ test_files: []