net-http-ext 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b26da458fd1f2d62e0fc16a68223f53615f93ecdada0ef979ce8af507149c246
4
- data.tar.gz: 1ce8f34c41d3cc5e58490915ab6118c24139e0140f5a227b8d7f86df4bc59c02
3
+ metadata.gz: c90112ab31ec1229abfa8b159437f7d797d1f817dcd6ebb8670f69f24a4ef2f2
4
+ data.tar.gz: 8744a8146cf8f185e217469ee8dd02ac93d3fe6c67e72e11105d0d145de5f3f5
5
5
  SHA512:
6
- metadata.gz: 45dd4238afd0639c6ca112eac1623f6629662ac693c92ac76d4a107105b61159e2ed0e667c17fbfb2ccc401fe6d7b580bf4ae7c2571a594c7c21566eaca48c1e
7
- data.tar.gz: 0b522d8f0d0b1efaa7bcd2ef2dbec07982beb40c4193a51f7256158c4c5107c30402fab90b0332a57ef2844725f458a9cc3374eb30fbc29f33fc4b9cb479cb84
6
+ metadata.gz: ad130f518516b5a3df732cbc06d07645474c4699fafd323d14f3688f4a6d6cb34f2242001e05fbd61a573bab95792613d8da46dfca006047256c4935abd583e7
7
+ data.tar.gz: 89e4e426d5b30b5c1baaf5f0c992ca0aad8c31b6d42503904af7c0a8a2e1a1540ad0078efbabe3a927704c5e2e92705ab76ab90eeafe25e1b2dad2dc06212ec8
data/README.md CHANGED
@@ -1,5 +1,143 @@
1
1
  # net-http-ext
2
2
 
3
- Safe defaults, persistent connections, thread safety, and basic logging for Ruby's Net::HTTP library
3
+ [![test](https://github.com/GrantBirki/net-http-ext/actions/workflows/test.yml/badge.svg)](https://github.com/GrantBirki/net-http-ext/actions/workflows/test.yml)
4
+ [![lint](https://github.com/GrantBirki/net-http-ext/actions/workflows/lint.yml/badge.svg)](https://github.com/GrantBirki/net-http-ext/actions/workflows/lint.yml)
5
+ [![acceptance](https://github.com/GrantBirki/net-http-ext/actions/workflows/acceptance.yml/badge.svg)](https://github.com/GrantBirki/net-http-ext/actions/workflows/acceptance.yml)
6
+ [![build](https://github.com/GrantBirki/net-http-ext/actions/workflows/build.yml/badge.svg)](https://github.com/GrantBirki/net-http-ext/actions/workflows/build.yml)
7
+ [![release](https://github.com/GrantBirki/net-http-ext/actions/workflows/release.yml/badge.svg)](https://github.com/GrantBirki/net-http-ext/actions/workflows/release.yml)
4
8
 
5
- A simple wrapper around [`net/http/persistent`](https://github.com/drbrain/net-http-persistent)
9
+ Safe defaults, persistent connections, thread safety, and basic logging for Ruby's Net::HTTP library.
10
+
11
+ A simple wrapper around [`net/http/persistent`](https://github.com/drbrain/net-http-persistent) in pure Ruby.
12
+
13
+ ## About 💡
14
+
15
+ A very simple wrapper around the `net/http/persistent` library (which is a wrapper around `net/http`) that provides a few extra features and safe defaults. It is designed to be a *lite*-batteries-included version of `net/http/persistent` that is easy to use and configure.
16
+
17
+ Should you need anything more complex, check out [`faraday`](https://github.com/lostisland/faraday) + [`araday-net_http_persistent`](https://github.com/lostisland/faraday-net_http_persistent).
18
+
19
+ ### Benefits ⭐
20
+
21
+ 1. Reuse connections for multiple requests
22
+ 2. Thread safe
23
+ 3. Secure defaults
24
+ 4. Basic logging
25
+ 5. Automatically rebuild the connection if it is closed by the server
26
+ 6. Automatically retry requests on connection failures if `max_retries` is set to a value >1
27
+ 7. Easy to use and configure
28
+
29
+ ## Installation 💎
30
+
31
+ You can download this Gem from [GitHub Packages](https://github.com/GrantBirki/net-http-ext/pkgs/rubygems/net-http-ext) or [RubyGems](https://rubygems.org/gems/net-http-ext)
32
+
33
+ Via a Gemfile:
34
+
35
+ ```ruby
36
+ source "https://rubygems.org"
37
+
38
+ gem "net-http-ext", "~> X.X.X" # Replace X.X.X with the latest version
39
+ ```
40
+
41
+ Via the CLI:
42
+
43
+ ```bash
44
+ gem install net-http-ext
45
+ ```
46
+
47
+ ## Usage 💻
48
+
49
+ ## Basic Usage
50
+
51
+ Here is an example using the library in its most basic form:
52
+
53
+ ```ruby
54
+ require "net/http/ext"
55
+
56
+ # initialize the client
57
+ client = Net::HTTP::Ext.new("httpbin.org")
58
+
59
+ # make a request
60
+ response = client.get("/")
61
+
62
+ puts response.code
63
+ puts response.body
64
+ ```
65
+
66
+ ### Extended Usage
67
+
68
+ Here is a more detailed/full usage example:
69
+
70
+ ```ruby
71
+ require "net/http/ext"
72
+
73
+ # Initialize the client
74
+ client = Net::HTTP::Ext.new("httpbin.org")
75
+
76
+ response = client.get("/")
77
+ puts response.code
78
+
79
+ # GET request with headers and query parameters
80
+ response = client.get("/get?param1=value1&param2=value2",
81
+ headers: { "Authorization" => "Bearer token123" }
82
+ )
83
+ puts response.body
84
+
85
+ # GET request using query parameters as a qwarg
86
+ response = client.get("/get",
87
+ params: { param1: "value1kwarg", param2: "value2kwarg" },
88
+ )
89
+ puts response.body
90
+
91
+ # POST request with JSON payload
92
+ response = client.post("/post",
93
+ payload: { name: "John Doe", email: "john@example.com" }
94
+ )
95
+ puts response.body
96
+
97
+ # POST request with JSON payload and custom content type
98
+ response = client.post("/post",
99
+ headers: { "Content-Type" => "application/json+custom" },
100
+ payload: { name: "John Doe", email: "john@example.com" }
101
+ )
102
+ puts response.body
103
+
104
+ # Custom timeouts
105
+ client = Net::HTTP::Ext.new("https://httpbin.org",
106
+ open_timeout: 5, # connection establishment timeout (seconds)
107
+ read_timeout: 10, # response read timeout (seconds)
108
+ idle_timeout: 30, # how long to keep idle connections open (seconds)
109
+ request_timeout: 15 # overall request timeout (seconds)
110
+ )
111
+ response = client.get("/delay/2") # Simulate a delay of 2 seconds
112
+ puts response.code
113
+
114
+ # Default headers on all requests
115
+ client = Net::HTTP::Ext.new("https://httpbin.org",
116
+ default_headers: {
117
+ "User-Agent" => "MyApp/1.0"
118
+ }
119
+ )
120
+ response = client.get("/headers")
121
+ puts response.body
122
+
123
+ # Make a get request and automatically parse it as JSON
124
+ response = client.get_json("/get?param1=value1&param2=value2")
125
+ puts response["args"]["param1"] # => "value1"
126
+ ```
127
+
128
+ > See the full source code at [`lib/net/http/ext.rb`](lib/net/http/ext.rb) for more details on the available options and methods.
129
+
130
+ ## Contributing 🤝
131
+
132
+ 1. Fork the repository
133
+ 2. Bootstrap the project with `script/bootstrap`
134
+ 3. Create a new branch (`git checkout -b feature/your-feature`)
135
+ 4. Write your code
136
+ 5. Run the tests (`script/test`)
137
+ 6. Run the acceptance tests (`script/acceptance`)
138
+ 7. Run the linter (`script/lint -A`)
139
+ 8. Commit your changes (`git commit -m "Add some feature"`)
140
+ 9. Push to the branch (`git push origin feature/your-feature`)
141
+ 10. Create a new Pull Request
142
+ 11. Wait for an approval and passing ci tests
143
+ 12. 🎉
data/lib/net/http/ext.rb CHANGED
@@ -94,6 +94,9 @@ class Net::HTTP::Ext
94
94
  ssl_cert_file: nil,
95
95
  **options
96
96
  )
97
+ # Add "https://" if the endpoint does not include a scheme
98
+ endpoint = "https://#{endpoint}" unless endpoint.start_with?("http://", "https://")
99
+
97
100
  @uri = URI.parse(endpoint)
98
101
  @name = name || ENV.fetch("HTTP_CLIENT_NAME", "http-client")
99
102
  @request_timeout = request_timeout
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NetHTTPExt
4
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Birkinbine