x 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/bin/console +10 -0
- data/bin/setup +6 -0
- data/lib/x/client.rb +2 -1
- data/lib/x/connection.rb +12 -3
- data/lib/x/redirect_handler.rb +1 -1
- data/lib/x/version.rb +1 -1
- data/sig/x.rbs +4 -2
- metadata +7 -7
- data/.rubocop.yml +0 -54
- data/Gemfile +0 -18
- data/Rakefile +0 -23
- data/Steepfile +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ff134774b6d6b28f3f72c740c74b1f44b11ce94cff63fbfe4eabc0414f600c3
|
4
|
+
data.tar.gz: 9f3b9abd3ca2628979676b5f634781b960adf6afe8a77559cf6f3a96ee738098
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd471d0b216161f5e68832e83b5024a8a89cdda1c815f49543f8361b225776ad46f84690eddf9a9b884cf0ab540924ecae94ebd145f26ac07e44ffdf7c4ff1f2
|
7
|
+
data.tar.gz: 3670666ca95e154a253be800af600cdcaf44195b9dcd3d001e1404d85f27dd5939ce09bd25588cfbe81cefef92ce22bfcd26e105dcb70d813bc4efa221a4360d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,6 +56,8 @@ ads_client = X::Client.new(base_url: "https://ads-api.twitter.com/12/", **x_cred
|
|
56
56
|
ads_client.get("accounts")
|
57
57
|
```
|
58
58
|
|
59
|
+
See other common usage [examples](https://github.com/sferik/x-ruby/tree/main/examples).
|
60
|
+
|
59
61
|
## History and Philosophy
|
60
62
|
|
61
63
|
This library is a rewrite of the [Twitter Ruby library](https://github.com/sferik/twitter). Over 16 years of development, that library ballooned to over 3,000 lines of code (plus 7,500 lines of tests). At the time of writing, this library is about 300 lines of code (plus 200 test lines) and I’d like to keep it that way. That doesn’t mean new features won’t be added over time, but the benefits of more code must be weighted against the benefits of less:
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/x/client.rb
CHANGED
@@ -26,6 +26,7 @@ module X
|
|
26
26
|
open_timeout: Connection::DEFAULT_OPEN_TIMEOUT,
|
27
27
|
read_timeout: Connection::DEFAULT_READ_TIMEOUT,
|
28
28
|
write_timeout: Connection::DEFAULT_WRITE_TIMEOUT,
|
29
|
+
proxy_url: nil,
|
29
30
|
content_type: RequestBuilder::DEFAULT_CONTENT_TYPE,
|
30
31
|
user_agent: RequestBuilder::DEFAULT_USER_AGENT,
|
31
32
|
debug_output: nil,
|
@@ -35,7 +36,7 @@ module X
|
|
35
36
|
|
36
37
|
initialize_authenticator(bearer_token, api_key, api_key_secret, access_token, access_token_secret)
|
37
38
|
@connection = Connection.new(base_url: base_url, open_timeout: open_timeout, read_timeout: read_timeout,
|
38
|
-
write_timeout: write_timeout, debug_output: debug_output)
|
39
|
+
write_timeout: write_timeout, debug_output: debug_output, proxy_url: proxy_url)
|
39
40
|
@request_builder = RequestBuilder.new(content_type: content_type, user_agent: user_agent)
|
40
41
|
@redirect_handler = RedirectHandler.new(@authenticator, @connection, @request_builder,
|
41
42
|
max_redirects: max_redirects)
|
data/lib/x/connection.rb
CHANGED
@@ -20,14 +20,15 @@ module X
|
|
20
20
|
Net::ReadTimeout
|
21
21
|
].freeze
|
22
22
|
|
23
|
-
attr_reader :base_uri, :http_client
|
23
|
+
attr_reader :base_uri, :proxy_uri, :http_client
|
24
24
|
|
25
25
|
def_delegators :@http_client, :open_timeout, :read_timeout, :write_timeout
|
26
26
|
def_delegators :@http_client, :open_timeout=, :read_timeout=, :write_timeout=
|
27
27
|
def_delegator :@http_client, :set_debug_output, :debug_output=
|
28
28
|
|
29
29
|
def initialize(base_url: DEFAULT_BASE_URL, open_timeout: DEFAULT_OPEN_TIMEOUT,
|
30
|
-
read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: nil)
|
30
|
+
read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, proxy_url: nil, debug_output: nil)
|
31
|
+
@proxy_uri = URI(proxy_url) unless proxy_url.nil?
|
31
32
|
self.base_uri = base_url
|
32
33
|
apply_http_client_settings(
|
33
34
|
open_timeout: open_timeout,
|
@@ -77,11 +78,19 @@ module X
|
|
77
78
|
conditionally_apply_http_client_settings do
|
78
79
|
host = @base_uri.host || DEFAULT_HOST
|
79
80
|
port = @base_uri.port || DEFAULT_PORT
|
80
|
-
@http_client =
|
81
|
+
@http_client = build_http_client(host: host, port: port)
|
81
82
|
@http_client.use_ssl = @base_uri.scheme == "https"
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
86
|
+
def build_http_client(host:, port:)
|
87
|
+
if @proxy_uri.nil?
|
88
|
+
Net::HTTP.new(host, port)
|
89
|
+
else
|
90
|
+
Net::HTTP.new(host, port, @proxy_uri&.host, @proxy_uri&.port, @proxy_uri&.user, @proxy_uri&.password)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
85
94
|
def conditionally_apply_http_client_settings
|
86
95
|
if @http_client
|
87
96
|
settings = current_http_client_settings
|
data/lib/x/redirect_handler.rb
CHANGED
@@ -49,7 +49,7 @@ module X
|
|
49
49
|
def send_new_request(new_uri, new_request)
|
50
50
|
@connection = Connection.new(base_url: new_uri, open_timeout: connection.open_timeout,
|
51
51
|
read_timeout: connection.read_timeout, write_timeout: connection.write_timeout,
|
52
|
-
debug_output: connection.debug_output)
|
52
|
+
debug_output: connection.debug_output, proxy_url: connection.proxy_uri)
|
53
53
|
connection.send_request(new_request)
|
54
54
|
end
|
55
55
|
end
|
data/lib/x/version.rb
CHANGED
data/sig/x.rbs
CHANGED
@@ -93,10 +93,11 @@ module X
|
|
93
93
|
@http_client: Net::HTTP
|
94
94
|
|
95
95
|
attr_reader base_uri: URI::Generic
|
96
|
+
attr_reader proxy_uri: URI::Generic?
|
96
97
|
attr_reader open_timeout : Float | Integer
|
97
98
|
attr_reader read_timeout : Float | Integer
|
98
99
|
attr_reader write_timeout : Float | Integer
|
99
|
-
def initialize: (?base_url: URI::Generic | String, ?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?debug_output: IO?) -> void
|
100
|
+
def initialize: (?base_url: URI::Generic | String, ?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?proxy_url: URI::Generic? | String?, ?debug_output: IO?) -> void
|
100
101
|
def send_request: (Net::HTTPRequest request) -> Net::HTTPResponse
|
101
102
|
def base_uri=: (URI::Generic | String base_url) -> void
|
102
103
|
def debug_output: -> IO?
|
@@ -105,6 +106,7 @@ module X
|
|
105
106
|
def apply_http_client_settings: (open_timeout: Float | Integer, read_timeout: Float | Integer, write_timeout: Float | Integer, debug_output: IO?) -> untyped
|
106
107
|
def current_http_client_settings: -> {open_timeout: Float | Integer, read_timeout: Float | Integer, write_timeout: Float | Integer, debug_output: IO?}
|
107
108
|
def update_http_client_settings: -> untyped
|
109
|
+
def build_http_client: (host: String, port: Integer) -> (Net::HTTP)
|
108
110
|
def conditionally_apply_http_client_settings: { -> untyped } -> untyped
|
109
111
|
end
|
110
112
|
|
@@ -168,7 +170,7 @@ module X
|
|
168
170
|
@response_handler: ResponseHandler
|
169
171
|
|
170
172
|
attr_reader base_uri: URI::Generic
|
171
|
-
def initialize: (?bearer_token: String?, ?api_key: String?, ?api_key_secret: String?, ?access_token: String?, ?access_token_secret: String?, ?base_url: URI::Generic | String, ?content_type: String, ?user_agent: String, ?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?debug_output: IO?, ?array_class: Class, ?object_class: Class, ?max_redirects: Integer) -> void
|
173
|
+
def initialize: (?bearer_token: String?, ?api_key: String?, ?api_key_secret: String?, ?access_token: String?, ?access_token_secret: String?, ?base_url: URI::Generic | String, ?content_type: String, ?user_agent: String, ?open_timeout: Float | Integer, ?read_timeout: Float | Integer, ?write_timeout: Float | Integer, ?proxy_url: URI::Generic? | String?, ?debug_output: IO?, ?array_class: Class, ?object_class: Class, ?max_redirects: Integer) -> void
|
172
174
|
def get: (String endpoint) -> Hash[String, untyped]
|
173
175
|
def post: (String endpoint, ?nil body) -> Hash[String, untyped]
|
174
176
|
def put: (String endpoint, ?nil body) -> Hash[String, untyped]
|
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.
|
4
|
+
version: 0.9.0
|
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-
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,13 +17,11 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".rubocop.yml"
|
21
20
|
- CHANGELOG.md
|
22
|
-
- Gemfile
|
23
21
|
- LICENSE.txt
|
24
22
|
- README.md
|
25
|
-
-
|
26
|
-
-
|
23
|
+
- bin/console
|
24
|
+
- bin/setup
|
27
25
|
- lib/x.rb
|
28
26
|
- lib/x/bearer_token_authenticator.rb
|
29
27
|
- lib/x/client.rb
|
@@ -50,10 +48,12 @@ licenses:
|
|
50
48
|
- MIT
|
51
49
|
metadata:
|
52
50
|
allowed_push_host: https://rubygems.org
|
51
|
+
rubygems_mfa_required: 'true'
|
53
52
|
homepage_uri: https://sferik.github.io/x-ruby
|
54
53
|
source_code_uri: https://github.com/sferik/x-ruby
|
55
54
|
changelog_uri: https://github.com/sferik/x-ruby/blob/master/CHANGELOG.md
|
56
|
-
|
55
|
+
bug_tracker_uri: https://github.com/sferik/x-ruby/issues
|
56
|
+
documentation_uri: https://rubydoc.info/gems/x/
|
57
57
|
post_install_message:
|
58
58
|
rdoc_options: []
|
59
59
|
require_paths:
|
data/.rubocop.yml
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- standard
|
3
|
-
- standard-performance
|
4
|
-
- rubocop-minitest
|
5
|
-
- rubocop-performance
|
6
|
-
- rubocop-rake
|
7
|
-
|
8
|
-
AllCops:
|
9
|
-
NewCops: enable
|
10
|
-
TargetRubyVersion: 3.0
|
11
|
-
|
12
|
-
Layout/ArgumentAlignment:
|
13
|
-
Enabled: true
|
14
|
-
EnforcedStyle: with_fixed_indentation
|
15
|
-
|
16
|
-
Layout/ArrayAlignment:
|
17
|
-
Enabled: true
|
18
|
-
EnforcedStyle: with_fixed_indentation
|
19
|
-
|
20
|
-
Layout/EndAlignment:
|
21
|
-
Enabled: true
|
22
|
-
EnforcedStyleAlignWith: variable
|
23
|
-
|
24
|
-
Layout/HashAlignment:
|
25
|
-
Enabled: true
|
26
|
-
EnforcedHashRocketStyle: key
|
27
|
-
EnforcedColonStyle: key
|
28
|
-
EnforcedLastArgumentHashStyle: always_inspect
|
29
|
-
|
30
|
-
Layout/ParameterAlignment:
|
31
|
-
Enabled: true
|
32
|
-
EnforcedStyle: with_fixed_indentation
|
33
|
-
IndentationWidth: ~
|
34
|
-
|
35
|
-
Layout/SpaceInsideHashLiteralBraces:
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
Metrics/ParameterLists:
|
39
|
-
CountKeywordArgs: false
|
40
|
-
|
41
|
-
Style/Alias:
|
42
|
-
Enabled: true
|
43
|
-
EnforcedStyle: prefer_alias_method
|
44
|
-
|
45
|
-
Style/StringLiterals:
|
46
|
-
Enabled: true
|
47
|
-
EnforcedStyle: double_quotes
|
48
|
-
|
49
|
-
Style/StringLiteralsInInterpolation:
|
50
|
-
Enabled: true
|
51
|
-
EnforcedStyle: double_quotes
|
52
|
-
|
53
|
-
Style/FrozenStringLiteralComment:
|
54
|
-
Enabled: false
|
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in x.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem "hashie", ">= 5"
|
7
|
-
gem "minitest", ">= 5.19"
|
8
|
-
gem "rake", ">= 13.0.6"
|
9
|
-
gem "rbs", ">= 3.2.1"
|
10
|
-
gem "rubocop", ">= 1.21"
|
11
|
-
gem "rubocop-minitest", ">= 0.31"
|
12
|
-
gem "rubocop-performance", ">= 1.18"
|
13
|
-
gem "rubocop-rake", ">= 0.6"
|
14
|
-
gem "simplecov", ">= 0.22"
|
15
|
-
gem "standard", ">= 1.30.1"
|
16
|
-
gem "steep", ">= 1.5.3"
|
17
|
-
gem "timecop", ">= 0.9.6"
|
18
|
-
gem "webmock", ">= 3.18.1"
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rake/testtask"
|
3
|
-
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << "test"
|
6
|
-
t.libs << "lib"
|
7
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
-
end
|
9
|
-
|
10
|
-
require "standard/rake"
|
11
|
-
require "rubocop/rake_task"
|
12
|
-
|
13
|
-
RuboCop::RakeTask.new
|
14
|
-
|
15
|
-
require "steep"
|
16
|
-
require "steep/cli"
|
17
|
-
|
18
|
-
desc "Type check with Steep"
|
19
|
-
task :steep do
|
20
|
-
Steep::CLI.new(argv: ["check"], stdout: $stdout, stderr: $stderr, stdin: $stdin).run
|
21
|
-
end
|
22
|
-
|
23
|
-
task default: %i[test rubocop standard steep]
|
data/Steepfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
target :lib do
|
2
|
-
signature "sig"
|
3
|
-
check "lib"
|
4
|
-
library "base64"
|
5
|
-
library "cgi"
|
6
|
-
library "forwardable"
|
7
|
-
library "json"
|
8
|
-
library "net-http"
|
9
|
-
library "openssl"
|
10
|
-
library "securerandom"
|
11
|
-
library "uri"
|
12
|
-
configure_code_diagnostics(Steep::Diagnostic::Ruby.strict)
|
13
|
-
end
|