Skip to content

Commit

Permalink
Move HTTPClient adapter from Faraday
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Jul 4, 2021
1 parent d7646c5 commit f9d5df5
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 148 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,51 @@
name: CI

on:
pull_request:
push:
branches: [main, setup-ci]
schedule:
- cron: '0 8 * * 1' # At 8:00 on Monday

env:
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Ruby 2.7
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7

- name: Rubocop
run: |
bin/setup
bin/ci-lint
test:
needs: [lint]
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['2.5', '2.6', '2.7', '3.0']

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Build
run: |
bin/setup
- name: Test
run: |
bin/ci-test
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
@@ -0,0 +1,29 @@
name: Publish

on:
release:
types: [published]

jobs:
build:
name: Publish to Rubygems
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.x

- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build faraday-httpclient.gemspec
gem push faraday-httpclient-*.gem
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
60 changes: 60 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,60 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-packaging
- rubocop-performance

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.4
SuggestExtensions: false
NewCops: enable

Metrics/BlockLength:
Exclude:
- spec/**/*.rb
- examples/**/*.rb

Layout/EmptyLinesAroundAttributeAccessor: # (0.83)
Enabled: true

Layout/LineLength:
Exclude:
- spec/**/*.rb
- examples/**/*.rb

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Lint/DeprecatedOpenSSLConstant: # (0.84)
Enabled: true

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Style/DoubleNegation:
Enabled: false

Style/Documentation:
Exclude:
- 'spec/**/*'
- 'examples/**/*'

Style/ExponentialNotation:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
Style/IfUnlessModifier:
Enabled: false

Style/SlicingWithRange: # (0.83)
Enabled: true

17 changes: 17 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,17 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-07-04 13:33:15 UTC using RuboCop version 1.12.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 37

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 30
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers 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, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at giuffrida.mattia AT gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
72 changes: 48 additions & 24 deletions README.md
@@ -1,38 +1,62 @@
# Faraday Adapter Template
# Faraday HTTPClient adapter

This repo is a template for building [Faraday][faraday] adapters.
This gem is a [Faraday][faraday] adapter for the [HTTPClient][httpclient] library.
Faraday is an HTTP client library that provides a common interface over many adapters.
Every adapter is defined into it's own gem. Use this repository to create your own adapter gem.
Every adapter is defined into its own gem. This gem defines the adapter for HTTPClient.

## Getting Started
## Installation

### Setting up and cloning the repo
Add these lines to your application's Gemfile:

You can start using GitHub's [Use this template][use-template] button.
![Use this template](https://docs.github.com/assets/images/help/repository/use-this-template-button.png)
```ruby
gem 'httpclient', '>= 2.2'
gem 'faraday'
gem 'faraday-httpclient'
```

This will create a repository based off from this template.
After that is created, you can clone it locally to start working on it.
And then execute:

### Refactoring the template
$ bundle install

The next step is for you to find and replace all the "parametrised" names in this template and change them to make it unique.
First of all, you should decide on the name of your adapter.
The current convention (which is by no means mandatory) is to call adapter gems as `faraday-<adapter_name>`.
Here are some examples:
Or install them yourself as:

* `HTTP`: [`faraday-http`][faraday-http]
* `Net::HTTP`: [`faraday-net_http`][faraday-net_http]
$ gem install httpclient -v '>= 2.2'
$ gem install faraday faraday-httpclient

In this template repository, the placeholder for your chosen adapter name is `MyAdapter` (`my_adapter`).
So once you decide on the final name you want to use you should update all occurrences of `MyAdapter` and all files with `my_adapter` in their name with the new name you chose.
## Usage

### Main implementation
Configure your Faraday connection to use this adapter like this:

The bulk of the implementation is in the `Faraday::Adapter::MyAdapter` class.
We've added lots of comments in there to guide you through it, but if you have any doubt/question please don't hesitate to get in touch!
```ruby
connection = Faraday.new(url, conn_options) do |conn|
conn.adapter(:httpclient)
end
```

For more information on how to setup your Faraday connection and adapters usage, please refer to the [Faraday Website][faraday-website].

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

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](rubygems).

## Contributing

Bug reports and pull requests are welcome on [GitHub][repo].

## License

The gem is available as open source under the terms of the [license][license].

## Code of Conduct

Everyone interacting in the Faraday HTTPClient adapter project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].

[faraday]: https://github.com/lostisland/faraday
[faraday-http]: https://github.com/lostisland/faraday-http
[faraday-net_http]: https://github.com/lostisland/faraday-net_http
[use-template]: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template
[faraday-website]: https://lostisland.github.io/faraday
[httpclient]: https://github.com/nahi/httpclient
[rubygems]: https://rubygems.org
[repo]: https://github.com/lostisland/faraday-httpclient
[license]: https://github.com/lostisland/faraday-httpclient/blob/main/LICENSE.md
[code-of-conduct]: https://github.com/lostisland/faraday-httpclient/blob/main/CODE_OF_CONDUCT.md
3 changes: 2 additions & 1 deletion bin/console
Expand Up @@ -2,7 +2,8 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'faraday-my_adapter'
require 'faraday'
require 'faraday/httpclient'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
28 changes: 17 additions & 11 deletions faraday-my_adapter.gemspec → faraday-httpclient.gemspec
@@ -1,28 +1,30 @@
# frozen_string_literal: true

require_relative 'lib/faraday/my_adapter/version'
require_relative 'lib/faraday/httpclient/version'

Gem::Specification.new do |spec|
spec.name = 'faraday-my_adapter'
spec.version = Faraday::MyAdapter::VERSION
spec.authors = ['Your Name']
spec.email = ['your_name@gmail.com']

spec.summary = 'Faraday adapter for MyAdapter'
spec.description = 'Faraday adapter for MyAdapter'
spec.homepage = 'https://github.com/lostisland/faraday-my_adapter'
spec.name = 'faraday-httpclient'
spec.version = Faraday::HTTPClient::VERSION
spec.authors = ['@iMacTia']
spec.email = ['giuffrida.mattia@gmail.com']

spec.summary = 'Faraday adapter for HTTPClient'
spec.description = 'Faraday adapter for HTTPClient'
spec.homepage = 'https://github.com/lostisland/faraday-httpclient'
spec.license = 'MIT'

spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/lostisland/faraday-my_adapter'
spec.metadata['changelog_uri'] = 'https://github.com/lostisland/faraday-my_adapter'
spec.metadata['source_code_uri'] = 'https://github.com/lostisland/faraday-httpclient'
spec.metadata['changelog_uri'] = 'https://github.com/lostisland/faraday-httpclient'

spec.files = Dir.glob('lib/**/*') + %w[README.md LICENSE.md]
spec.require_paths = ['lib']

# TODO: make these normal dependencies when releasing v2.0 together with Faraday v2.0
spec.add_development_dependency 'faraday', '~> 1.0'
spec.add_development_dependency 'httpclient', '>= 2.2'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
Expand All @@ -31,4 +33,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'multipart-parser', '~> 0.1.1'
spec.add_development_dependency 'webmock', '~> 3.4'

spec.add_development_dependency 'rubocop', '~> 1.12.0'
spec.add_development_dependency 'rubocop-packaging', '~> 0.5'
spec.add_development_dependency 'rubocop-performance', '~> 1.0'
end

0 comments on commit f9d5df5

Please sign in to comment.