Skip to content

Commit

Permalink
Moving over Excon adapter and tests from Faraday (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Apr 12, 2021
1 parent 1a6662b commit 8a34b8d
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 149 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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@v1

- 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@v1

- 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish

on:
release:
types: [published]

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

steps:
- uses: actions/checkout@master

- 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-excon.gemspec
gem push faraday-excon-*.gem
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
58 changes: 58 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-packaging
- rubocop-performance

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.4

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-04-11 16:21:00 UTC using RuboCop version 0.91.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: 1
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 32

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Max: 23
69 changes: 45 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
# Faraday Adapter Template
# Faraday Excon adapter

This repo is a template for building [Faraday][faraday] adapters.
This gem is a [Faraday][faraday] adapter for the [Excon][excon] 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 Excon.

## Getting Started
## Installation

### Setting up and cloning the repo
Add this line 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 'faraday-excon'
```

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 it yourself as:

* `HTTP`: [`faraday-http`][faraday-http]
* `Net::HTTP`: [`faraday-net_http`][faraday-net_http]
$ gem install faraday-excon

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(:excon)
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 Excon 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
[excon]: https://github.com/excon/excon
[rubygems]: https://rubygems.org
[repo]: https://github.com/lostisland/faraday-excon
[license]: https://github.com/lostisland/faraday-excon/blob/main/LICENSE.md
[code-of-conduct]: https://github.com/lostisland/faraday-excon/blob/main/CODE_OF_CONDUCT.md
3 changes: 2 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# frozen_string_literal: true

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

# 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
29 changes: 17 additions & 12 deletions faraday-my_adapter.gemspec → faraday-excon.gemspec
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
# frozen_string_literal: true

require_relative 'lib/faraday/my_adapter/version'
require_relative 'lib/faraday/excon/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-excon'
spec.version = Faraday::Excon::VERSION
spec.authors = ['Mattia Giuffrida']
spec.email = ['giuffrida.mattia@gmail.com']

spec.summary = 'Faraday adapter for Excon'
spec.description = 'Faraday adapter for Excon'
spec.homepage = 'https://github.com/lostisland/faraday-excon'
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-excon'
spec.metadata['changelog_uri'] = 'https://github.com/lostisland/faraday-excon'

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

spec.add_development_dependency 'faraday', '~> 1.0'
spec.add_dependency 'excon', '>= 0.27.4'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'faraday', '~> 1.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'simplecov', '~> 0.19.0'

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

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

0 comments on commit 8a34b8d

Please sign in to comment.