twingly-http 0.4.0 → 0.6.0

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: 573e3beb22fd03c1961fe5b6264b3a2b1ef9f0a5a89b95e0094e1693e76dff7f
4
- data.tar.gz: 30a0dda321f1a3804492fd91e49907456cd3e45494f79ff571c054b648f7725c
3
+ metadata.gz: 8fd022cb30b4e6aea665f8e8bc569a7fa7023c78f1a0cc88b18c4f00793b23ac
4
+ data.tar.gz: 498f19467946922913480c55637baea6871d6895ab2a51ed82d7e6cd6fd4b60c
5
5
  SHA512:
6
- metadata.gz: 9d209c54bbd796f27d38796d6a5449cf961e7de9a351700098ba92f022502a34950dc7652c4c9d16f80d9ae7474fe65bd6d3a60976cf43db65f767d5fb97277e
7
- data.tar.gz: 6e4db092c8893e0539b17af90233d9ac86f2bbb2f51a2ab3b29fbd7c671211861168e30b434b4abdbf209c332861292a71bee37cb47fe4a91f3623b14f67a21f
6
+ metadata.gz: 8658da71b5b0a3d327f81cf8f4c29014606ca3336b2ed3848b234498511fde9152953e841ca920818b2a1daae9024912ce5987b518b0be7204bdf61071a8b115
7
+ data.tar.gz: a397277ad9301bae0b25589e0aeea82beaa11e57a8c228a6d3d8bcc276010b181721b184c230d29fbb41a592c74905a411be68d717ee04e5049a8cd4e6534097
data/README.md CHANGED
@@ -14,7 +14,7 @@ Example "one-liner" usage:
14
14
 
15
15
  ```
16
16
  ruby -rlogger -rtwingly/http -e '\
17
- logger = Logger.new(STDOUT); logger.level = :INFO; \
17
+ logger = Logger.new($stdout); logger.level = :INFO; \
18
18
  puts Twingly::HTTP::Client.new(logger: logger, \
19
19
  base_user_agent: "").get("http://example.org").status'
20
20
  ```
@@ -25,7 +25,7 @@ Example `irb` usage:
25
25
  irb -rlogger -rtwingly/http
26
26
  ```
27
27
  ```ruby
28
- logger = Logger.new(STDOUT); logger.level = :INFO
28
+ logger = Logger.new($stdout); logger.level = :INFO
29
29
  client = Twingly::HTTP::Client.new(logger: logger, base_user_agent: "")
30
30
  client.get("http://example.org").status
31
31
  ```
@@ -13,7 +13,7 @@ module Faraday
13
13
  super(app)
14
14
  @logger = logger || begin
15
15
  require "logger"
16
- ::Logger.new(STDOUT)
16
+ ::Logger.new($stdout)
17
17
  end
18
18
 
19
19
  @filter = []
@@ -26,10 +26,10 @@ module Faraday
26
26
  def call(env)
27
27
  info("request") do
28
28
  log_entry = {
29
- "source": "upstream-request",
30
- "method": env.method.upcase,
31
- "url": apply_filters(env.url.to_s),
32
- "request_id": request_id,
29
+ source: "upstream-request",
30
+ method: env.method.upcase,
31
+ url: apply_filters(env.url.to_s),
32
+ request_id: request_id,
33
33
  }.merge(app_metadata)
34
34
 
35
35
  Twingly::StringUtilities.logfmt(log_entry)
@@ -41,9 +41,9 @@ module Faraday
41
41
  def on_complete(env)
42
42
  info("response") do
43
43
  log_entry = {
44
- "source": "upstream-response",
45
- "status": env.status,
46
- "request_id": request_id,
44
+ source: "upstream-response",
45
+ status: env.status,
46
+ request_id: request_id,
47
47
  }.merge(app_metadata)
48
48
 
49
49
  Twingly::StringUtilities.logfmt(log_entry)
@@ -68,7 +68,7 @@ module Faraday
68
68
 
69
69
  def app_metadata
70
70
  {
71
- "release": Twingly::HTTP::Heroku.release_version,
71
+ release: Twingly::HTTP::Heroku.release_version,
72
72
  }
73
73
  end
74
74
 
@@ -16,7 +16,7 @@ module Faraday
16
16
 
17
17
  if url_bytesize >= @max_size_bytes
18
18
  raise LimitExceededError,
19
- "Expected URL below #{@max_size_bytes} bytes, "\
19
+ "Expected URL below #{@max_size_bytes} bytes, " \
20
20
  "was #{url_bytesize} bytes"
21
21
  end
22
22
 
@@ -20,7 +20,7 @@ module Twingly
20
20
  end
21
21
 
22
22
  def self.review_app?
23
- parent_name = ENV.fetch("HEROKU_PARENT_APP_NAME") {}
23
+ parent_name = ENV.fetch("HEROKU_PARENT_APP_NAME") { nil }
24
24
 
25
25
  return false unless parent_name
26
26
 
data/lib/twingly/http.rb CHANGED
@@ -46,9 +46,10 @@ module Twingly
46
46
  attr_accessor :logger
47
47
  attr_accessor :retryable_exceptions
48
48
 
49
- def initialize(base_user_agent:, logger: default_logger)
49
+ def initialize(base_user_agent:, logger: default_logger, user_agent: nil)
50
50
  @base_user_agent = base_user_agent
51
51
  @logger = logger
52
+ @user_agent = user_agent
52
53
 
53
54
  initialize_defaults
54
55
  end
@@ -97,7 +98,8 @@ module Twingly
97
98
 
98
99
  Response.new(headers: response.headers.to_h,
99
100
  status: response.status,
100
- body: response.body)
101
+ body: response.body,
102
+ final_url: response.env.url.to_s)
101
103
  rescue *(@retryable_exceptions + TIMEOUT_EXCEPTIONS)
102
104
  raise ConnectionError
103
105
  rescue Faraday::UrlSizeLimit::LimitExceededError => error
@@ -231,7 +233,7 @@ module Twingly
231
233
  end
232
234
 
233
235
  def user_agent
234
- format(
236
+ @user_agent || format(
235
237
  "%<base>s (Release/%<release>s; Commit/%<commit>s)",
236
238
  base: @base_user_agent,
237
239
  release: Heroku.release_version,
@@ -241,9 +243,9 @@ module Twingly
241
243
 
242
244
  def app_metadata
243
245
  {
244
- "dyno_id": Heroku.dyno_id,
245
- "release": Heroku.release_version,
246
- "git_head": Heroku.slug_commit,
246
+ dyno_id: Heroku.dyno_id,
247
+ release: Heroku.release_version,
248
+ git_head: Heroku.slug_commit,
247
249
  }
248
250
  end
249
251
 
@@ -258,13 +260,16 @@ module Twingly
258
260
  attr_reader :headers
259
261
  attr_reader :status
260
262
  attr_reader :body
263
+ attr_reader :final_url
261
264
 
262
265
  def initialize(headers: nil,
263
266
  status: nil,
264
- body: nil)
267
+ body: nil,
268
+ final_url: nil)
265
269
  @headers = headers
266
270
  @status = status
267
271
  @body = body
272
+ @final_url = final_url
268
273
  end
269
274
  end
270
275
  end
@@ -12,7 +12,7 @@ module Twingly
12
12
  return unless string
13
13
 
14
14
  if string[0] == char
15
- string[1..-1]
15
+ string[1..]
16
16
  else
17
17
  string
18
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Twingly
4
4
  module HTTP
5
- VERSION = "0.4.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twingly-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twingly AB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,118 +44,6 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.0.0
47
- - !ruby/object:Gem::Dependency
48
- name: climate_control
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.1'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.1'
61
- - !ruby/object:Gem::Dependency
62
- name: rake
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '12'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '12'
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '3'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '3'
89
- - !ruby/object:Gem::Dependency
90
- name: rubocop
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: 0.77.0
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 0.77.0
103
- - !ruby/object:Gem::Dependency
104
- name: rubocop-rspec
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '1.36'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '1.36'
117
- - !ruby/object:Gem::Dependency
118
- name: toxiproxy
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - "~>"
122
- - !ruby/object:Gem::Version
123
- version: '1.0'
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - "~>"
129
- - !ruby/object:Gem::Version
130
- version: '1.0'
131
- - !ruby/object:Gem::Dependency
132
- name: vcr
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '5.0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: '5.0'
145
- - !ruby/object:Gem::Dependency
146
- name: webmock
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '3.7'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: '3.7'
159
47
  description: Robust HTTP client tailored by Twingly
160
48
  email:
161
49
  - support@twingly.com
@@ -177,7 +65,8 @@ files:
177
65
  homepage: http://github.com/twingly/twingly-http
178
66
  licenses:
179
67
  - MIT
180
- metadata: {}
68
+ metadata:
69
+ rubygems_mfa_required: 'true'
181
70
  post_install_message:
182
71
  rdoc_options: []
183
72
  require_paths:
@@ -193,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
82
  - !ruby/object:Gem::Version
194
83
  version: '0'
195
84
  requirements: []
196
- rubygems_version: 3.1.6
85
+ rubygems_version: 3.4.10
197
86
  signing_key:
198
87
  specification_version: 4
199
88
  summary: Robust HTTP client