Skip to content

Commit

Permalink
Support Faraday 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed May 31, 2024
1 parent aaed5dc commit f0d80da
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ["2.4", "2.5", "2.6", "2.7", "3.0"]
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
gemfile: ["faraday-1", "faraday-2"]

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
BUNDLE_PATH_RELATIVE_TO_CWD: true

steps:
- uses: actions/checkout@master
Expand Down
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 2.7
8 changes: 8 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
appraise "faraday-1" do
gem "faraday", "~> 1.10"
gem "base64", "~> 0.2.0"
end

appraise "faraday-2" do
gem "faraday", "~> 2.0"
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gemspec
gem "rake"
gem "minitest", ">= 5.0.5"
gem "standard"
gem "appraisal"
12 changes: 12 additions & 0 deletions gemfiles/faraday_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rake"
gem "minitest", ">= 5.0.5"
gem "standard"
gem "appraisal"
gem "faraday", "~> 1.10"
gem "base64", "~> 0.2.0"

gemspec path: "../"
102 changes: 102 additions & 0 deletions gemfiles/faraday_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
PATH
remote: ..
specs:
vultr (1.0.0)
faraday (>= 1.0, < 3.0)

GEM
remote: https://rubygems.org/
specs:
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
base64 (0.2.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
json (2.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.23.1)
multipart-post (2.4.1)
parallel (1.24.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
standard (1.36.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.63.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
strscan (3.1.0)
thor (1.3.1)
unicode-display_width (2.5.0)

PLATFORMS
ruby
x86_64-darwin-23

DEPENDENCIES
appraisal
base64 (~> 0.2.0)
faraday (~> 1.10)
minitest (>= 5.0.5)
rake
standard
vultr!

BUNDLED WITH
2.5.10
11 changes: 11 additions & 0 deletions gemfiles/faraday_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rake"
gem "minitest", ">= 5.0.5"
gem "standard"
gem "appraisal"
gem "faraday", "~> 2.0"

gemspec path: "../"
82 changes: 82 additions & 0 deletions gemfiles/faraday_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
PATH
remote: ..
specs:
vultr (1.0.0)
faraday (>= 1.0, < 3.0)

GEM
remote: https://rubygems.org/
specs:
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
net-http
json (2.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.23.1)
net-http (0.4.1)
uri
parallel (1.24.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
standard (1.36.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.63.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
strscan (3.1.0)
thor (1.3.1)
unicode-display_width (2.5.0)
uri (0.13.0)

PLATFORMS
ruby
x86_64-darwin-23

DEPENDENCIES
appraisal
faraday (~> 2.0)
minitest (>= 5.0.5)
rake
standard
vultr!

BUNDLED WITH
2.5.10
6 changes: 4 additions & 2 deletions lib/vultr.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "faraday"
require "faraday_middleware"
require "vultr/version"
require "faraday"

module Vultr
autoload :Client, "vultr/client"
autoload :Collection, "vultr/collection"
autoload :Error, "vultr/error"
autoload :Middleware, "vultr/middleware"
autoload :Resource, "vultr/resource"
autoload :Object, "vultr/object"

Expand Down Expand Up @@ -54,4 +54,6 @@ module Vultr
autoload :SshKey, "vultr/objects/ssh_key"
autoload :StartupScript, "vultr/objects/startup_script"
autoload :User, "vultr/objects/user"

Faraday::Response.register_middleware vultr: Middleware
end
2 changes: 1 addition & 1 deletion lib/vultr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def connection
conn.request :authorization, :Bearer, api_key
conn.request :json

conn.response :dates
conn.response :vultr
conn.response :json, content_type: "application/json"

conn.adapter adapter, @stubs
Expand Down
32 changes: 32 additions & 0 deletions lib/vultr/middleware.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "time"

module Vultr
class Middleware < Faraday::Middleware
ISO_DATE_FORMAT = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|((\+|-)\d{2}:?\d{2}))\Z/xm

# This method will be called when the response is being processed.
# You can alter it as you like, accessing things like response_body, response_headers, and more.
# Refer to Faraday::Env for a list of accessible fields:
# https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
#
# @param env [Faraday::Env] the environment of the response being processed.
def on_complete(env)
parse_dates! env[:body]
end

private

def parse_dates!(value)
case value
when Hash
value.each { |key, element| value[key] = parse_dates!(element) }
when Array
value.each_with_index { |element, index| value[index] = parse_dates!(element) }
when ISO_DATE_FORMAT
Time.parse(value)
else
value
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vultr/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Vultr
class Object < OpenStruct
def initialize(attributes)
super to_ostruct(attributes)
super(to_ostruct(attributes))
end

def to_ostruct(obj)
Expand Down
8 changes: 3 additions & 5 deletions vultr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ require "vultr/version"
Gem::Specification.new do |s|
s.name = "vultr"
s.version = Vultr::VERSION
s.authors = ["Gao Jiangmiao"]
s.email = ["[email protected]"]
s.authors = ["Gao Jiangmiao", "Chris Oliver"]
s.email = ["[email protected]", "[email protected]"]
s.summary = "Ruby bindings for VULTR API."
s.description = "Ruby bindings for VULTR API. VULTR APIs can be found here: https://www.vultr.com/api/"
s.homepage = "https://github.com/tolbkni/vultr.rb"
s.license = "MIT"

s.files = `git ls-files -z`.split("\x0")
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.require_paths = ["lib"]

s.required_ruby_version = ">= 2.4"

s.add_dependency "faraday", "~> 1.7"
s.add_dependency "faraday_middleware", "~> 1.1"
s.add_dependency "faraday", ">= 1.0", "< 3.0"
end

0 comments on commit f0d80da

Please sign in to comment.