generated from mattbrictson/gem
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop Faraday dependency and use plain Net::HTTP instead (#22)
One less runtime dependency. 🎉
- Loading branch information
1 parent
983b32e
commit 359c040
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "net/http" | ||
require "uri" | ||
|
||
module BundleUpdateInteractive | ||
module HTTP | ||
module Success | ||
def success? | ||
code.start_with?("2") | ||
end | ||
end | ||
|
||
class << self | ||
def get(url) | ||
http(:get, url) | ||
end | ||
|
||
def head(url) | ||
http(:head, url) | ||
end | ||
|
||
private | ||
|
||
def http(method, url_string) | ||
uri = URI(url_string) | ||
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme.end_with?("s")) do |http| | ||
http.public_send(method, uri.request_uri) | ||
end | ||
response.extend(Success) | ||
end | ||
end | ||
end | ||
end |