x 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b97ab44334b647867e9fdd400531d6e925a10533fb51be399c669c28d441c67
4
- data.tar.gz: 03e6b5b78f62cdef778dea21128e8ea1b56955a1077c5ea040b6640694e7577a
3
+ metadata.gz: 81a5b12497937f06eb22779e6c78ef9dc18d5e9c5b049c96b4da461b058c6998
4
+ data.tar.gz: 96f4e02f93df2e39589095f12d5a1e790f17159f932cc1ab72330e301815bda4
5
5
  SHA512:
6
- metadata.gz: 47b47a9e6f98e6a61933d7f8f53d2477b2e921206894b2907171f04c2d94da05ebdbb25b501824240997d07c935cc0d2ea1269c6082e7488800c6c7d141f9c0e
7
- data.tar.gz: a642eb6fa5e9b61b3cbcf7fff91506e7f44c6b5b5e7a7f16c4cc5ce7ed57d8d19191583fad4bd2bc174c8e9f010546c34d8c83a1b46444de3685805a4b6471dc
6
+ metadata.gz: f8540864206f44e6863653ec538d076d4f1c696dab4fff2b8eeb33b587603301d2d62faedb163c59cc9366439b28a29acff4068876b4013a05bf88090c61042f
7
+ data.tar.gz: ef425363ab320f922e9f05f28f4d21a8090b763ef0d2468dfcd0ff7b9d0c456efa7f0a21b034fc750e5d927aafd5c4ae1b9407696d242512a44c7114e4efda4a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.1] - 2023-09-20
4
+
5
+ - Fix bug where setting Connection#base_uri= doesn't update the HTTP client (d5a89db)
6
+
3
7
  ## [0.8.0] - 2023-09-14
4
8
 
5
9
  - Add (back) bearer token authentication (62e141d)
data/README.md CHANGED
@@ -74,6 +74,20 @@ The tests for the previous version of this library executed in about 2 seconds.
74
74
 
75
75
  This code is not littered with comments that are intended to generate documentation. Rather, this code is intended to be simple enough to serve as its own documentation. If you want to understand how something works, don’t read the documentation—it might be wrong—read the code. The code is always right.
76
76
 
77
+ ## Sponsorship
78
+
79
+ The X gem is free to use, but with X API pricing tiers, it actually costs money to develop and maintain. By contributing to the project, you help us:
80
+
81
+ 1. Maintain the library: Keeping it up-to-date and secure.
82
+ 2. Add new features: Enhancements that make your life easier.
83
+ 3. Provide support: Faster responses to issues and feature requests.
84
+
85
+ ⭐️ Bonus: Sponsors will get priority support and influence over the project roadmap. We will also list your name or your company's logo on our GitHub page.
86
+
87
+ Building and maintaining an open-source project like this takes a considerable amount of time and effort. Your sponsorship can help sustain this project. Even a small monthly donation makes a huge difference!
88
+
89
+ [Click here to sponsor this project.](https://github.com/sponsors/sferik)
90
+
77
91
  ## Development
78
92
 
79
93
  1. Checkout and repo:
data/lib/x/connection.rb CHANGED
@@ -9,6 +9,8 @@ module X
9
9
  extend Forwardable
10
10
 
11
11
  DEFAULT_BASE_URL = "https://api.twitter.com/2/".freeze
12
+ DEFAULT_HOST = "https://api.twitter.com".freeze
13
+ DEFAULT_PORT = 443
12
14
  DEFAULT_OPEN_TIMEOUT = 60 # seconds
13
15
  DEFAULT_READ_TIMEOUT = 60 # seconds
14
16
  DEFAULT_WRITE_TIMEOUT = 60 # seconds
@@ -18,7 +20,7 @@ module X
18
20
  Net::ReadTimeout
19
21
  ].freeze
20
22
 
21
- attr_reader :base_uri
23
+ attr_reader :base_uri, :http_client
22
24
 
23
25
  def_delegators :@http_client, :open_timeout, :read_timeout, :write_timeout
24
26
  def_delegators :@http_client, :open_timeout=, :read_timeout=, :write_timeout=
@@ -27,12 +29,12 @@ module X
27
29
  def initialize(base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT,
28
30
  read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: nil)
29
31
  self.base_uri = base_url
30
- @http_client = Net::HTTP.new(base_uri.host, base_uri.port) if base_uri.host
31
- @http_client.use_ssl = base_uri.scheme == "https"
32
- @http_client.open_timeout = open_timeout
33
- @http_client.read_timeout = read_timeout
34
- @http_client.write_timeout = write_timeout
35
- @http_client.set_debug_output(debug_output) if debug_output
32
+ apply_http_client_settings(
33
+ open_timeout: open_timeout,
34
+ read_timeout: read_timeout,
35
+ write_timeout: write_timeout,
36
+ debug_output: debug_output
37
+ )
36
38
  end
37
39
 
38
40
  def send_request(request)
@@ -46,10 +48,48 @@ module X
46
48
  raise ArgumentError, "Invalid base URL" unless base_uri.is_a?(URI::HTTPS) || base_uri.is_a?(URI::HTTP)
47
49
 
48
50
  @base_uri = base_uri
51
+ update_http_client_settings
49
52
  end
50
53
 
51
54
  def debug_output
52
55
  @http_client.instance_variable_get(:@debug_output)
53
56
  end
57
+
58
+ private
59
+
60
+ def apply_http_client_settings(open_timeout:, read_timeout:, write_timeout:, debug_output:)
61
+ @http_client.open_timeout = open_timeout
62
+ @http_client.read_timeout = read_timeout
63
+ @http_client.write_timeout = write_timeout
64
+ @http_client.set_debug_output(debug_output) if debug_output
65
+ end
66
+
67
+ def current_http_client_settings
68
+ {
69
+ open_timeout: @http_client.open_timeout,
70
+ read_timeout: @http_client.read_timeout,
71
+ write_timeout: @http_client.write_timeout,
72
+ debug_output: debug_output
73
+ }
74
+ end
75
+
76
+ def update_http_client_settings
77
+ conditionally_apply_http_client_settings do
78
+ host = @base_uri.host || DEFAULT_HOST
79
+ port = @base_uri.port || DEFAULT_PORT
80
+ @http_client = Net::HTTP.new(host, port)
81
+ @http_client.use_ssl = @base_uri.scheme == "https"
82
+ end
83
+ end
84
+
85
+ def conditionally_apply_http_client_settings
86
+ if @http_client
87
+ settings = current_http_client_settings
88
+ yield
89
+ apply_http_client_settings(**settings)
90
+ else
91
+ yield
92
+ end
93
+ end
54
94
  end
55
95
  end
data/lib/x/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "rubygems/version"
2
2
 
3
3
  module X
4
- VERSION = Gem::Version.create("0.8.0")
4
+ VERSION = Gem::Version.create("0.8.1")
5
5
  end
data/sig/x.rbs CHANGED
@@ -82,23 +82,30 @@ module X
82
82
  end
83
83
 
84
84
  class Connection
85
- extend Forwardable
86
-
87
85
  DEFAULT_BASE_URL: String
86
+ DEFAULT_HOST: String
87
+ DEFAULT_PORT: Integer
88
88
  DEFAULT_OPEN_TIMEOUT: Integer
89
89
  DEFAULT_READ_TIMEOUT: Integer
90
90
  DEFAULT_WRITE_TIMEOUT: Integer
91
91
  NETWORK_ERRORS: Array[(singleton(::Errno::ECONNREFUSED) | singleton(::Net::OpenTimeout) | singleton(::Net::ReadTimeout))]
92
+ extend Forwardable
92
93
  @http_client: Net::HTTP
93
94
 
94
95
  attr_reader base_uri: URI::Generic
95
- attr_reader open_timeout: Float | Integer
96
- attr_reader read_timeout: Float | Integer
97
- attr_reader write_timeout: Float | Integer
96
+ attr_reader open_timeout : Float | Integer
97
+ attr_reader read_timeout : Float | Integer
98
+ attr_reader write_timeout : Float | Integer
98
99
  def initialize: (?base_url: URI::Generic | String, ?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?debug_output: IO?) -> void
99
100
  def send_request: (Net::HTTPRequest request) -> Net::HTTPResponse
100
- def base_uri=: (URI::Generic | String base_url) -> URI::Generic
101
+ def base_uri=: (URI::Generic | String base_url) -> void
101
102
  def debug_output: -> IO?
103
+
104
+ private
105
+ def apply_http_client_settings: (open_timeout: Float | Integer, read_timeout: Float | Integer, write_timeout: Float | Integer, debug_output: IO?) -> untyped
106
+ def current_http_client_settings: -> {open_timeout: Float | Integer, read_timeout: Float | Integer, write_timeout: Float | Integer, debug_output: IO?}
107
+ def update_http_client_settings: -> untyped
108
+ def conditionally_apply_http_client_settings: { -> untyped } -> untyped
102
109
  end
103
110
 
104
111
  class RequestBuilder
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Berlin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.4.18
72
+ rubygems_version: 3.4.19
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: A Ruby interface to the X API.