pigeon-http 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pigeon/core.rb +7 -14
- data/lib/pigeon/http.rb +11 -7
- data/lib/pigeon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b7eedde8b0c9fb75e25872962fbda47a2425927c94995bcf99b5d6b2515c23
|
4
|
+
data.tar.gz: 81d2864272ffb24191949f132fd53964548391d561cf7b00057bc916b1a56d56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b66e8bb1b3f1acad749742d6759af5aa0ad2eaac4ec144fcb5f956a93a44cba79745e3331c12587fdeb2041adc9f454448b2de7cb421c698ddb52ac078711c
|
7
|
+
data.tar.gz: 39939f3c8160246dea3c00e3c992474b175e79b266b62aafc3bb3925257063baf842edc1118c8107c0ea0533ec50760cfb8dc68d81361f29f65bd6237287bcdb
|
data/Gemfile.lock
CHANGED
data/lib/pigeon/core.rb
CHANGED
@@ -77,49 +77,42 @@ module Pigeon
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def get url, args = {}
|
80
|
-
start = Time.now
|
81
80
|
response = http(:get, url, args)
|
82
|
-
Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
|
83
|
-
|
84
|
-
response
|
85
81
|
rescue => e
|
86
82
|
@callbacks[:HttpError]&.call(e)
|
87
83
|
end
|
88
84
|
|
89
85
|
def post url, args = {}
|
90
|
-
start = Time.now
|
91
86
|
response = http(:post, url, args)
|
92
|
-
Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
|
93
|
-
|
94
|
-
response
|
95
87
|
rescue => e
|
96
88
|
@callbacks[:HttpError]&.call(e)
|
97
89
|
end
|
98
90
|
|
99
91
|
def put url, args = {}
|
100
|
-
start = Time.now
|
101
92
|
response = http(:put, url, args)
|
102
|
-
Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
|
103
|
-
|
104
|
-
response
|
105
93
|
rescue => e
|
106
94
|
@callbacks[:HttpError]&.call(e)
|
107
95
|
end
|
108
96
|
|
109
97
|
def delete url, args = {}
|
110
|
-
http(:delete, url, args)
|
98
|
+
response = http(:delete, url, args)
|
111
99
|
rescue => e
|
112
100
|
@callbacks[:HttpError]&.call(e)
|
113
101
|
end
|
114
102
|
|
115
103
|
def http method, url, args = {}
|
104
|
+
start = Time.now
|
116
105
|
args.merge({
|
117
106
|
read_timeout: @options[:request_timeout],
|
118
107
|
open_timeout: @options[:request_open_timeout],
|
119
108
|
ssl_verify: @options[:ssl_verify]
|
120
109
|
})
|
121
110
|
response = Pigeon::Http::Request.new(method, url, args).execute
|
122
|
-
|
111
|
+
|
112
|
+
uri = URI.parse(url)
|
113
|
+
Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: ["host:#{uri.host}"]).capture(action: :histogram, count: (Time.now - start))
|
114
|
+
Pigeon::Statsd.new(@options[:request_name] + '_througput', tags: ["host:#{uri.host}"]).capture
|
115
|
+
Pigeon::Statsd.new(@options[:request_name] + '_status', tags: ["host:#{uri.host}", "http:#{response.code}"]).capture
|
123
116
|
|
124
117
|
response
|
125
118
|
end
|
data/lib/pigeon/http.rb
CHANGED
@@ -17,7 +17,7 @@ module Pigeon
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class Request
|
20
|
-
VALID_PARAMETERS = %w[headers query body auth timeout open_timeout ssl_timeout read_timeout max_redirects ssl_verify]
|
20
|
+
VALID_PARAMETERS = %w[headers query body form auth timeout open_timeout ssl_timeout read_timeout max_redirects ssl_verify]
|
21
21
|
DEFAULT_HEADERS = { 'User-Agent' => 'HTTP Client API/1.0' }
|
22
22
|
VALID_VERBS = [GET, HEAD, PUT, POST, DELETE, OPTIONS, TRACE]
|
23
23
|
VALID_SSL_VERIFICATIONS = [SSL_VERIFY_NONE, SSL_VERIFY_PEER]
|
@@ -81,24 +81,28 @@ module Pigeon
|
|
81
81
|
klass = find_delegate_class(verb)
|
82
82
|
headers = DEFAULT_HEADERS.merge(args.fetch(:headers, {}))
|
83
83
|
body = args[:body]&.to_json
|
84
|
+
form = args[:form]&.transform_keys(&:to_s)
|
84
85
|
query = args[:query]
|
85
86
|
uri = uri.dup
|
86
87
|
delegate = klass.new(uri, headers)
|
87
88
|
|
89
|
+
delegate.content_type = 'application/json'
|
90
|
+
|
88
91
|
if body
|
89
92
|
raise Error::Argument, "#{verb} cannot have body" unless klass.const_get(:REQUEST_HAS_BODY)
|
90
|
-
delegate.
|
91
|
-
|
93
|
+
delegate.body = body
|
94
|
+
elsif form
|
95
|
+
raise Error::Argument, "#{verb} cannot have form" unless klass.const_get(:REQUEST_HAS_BODY)
|
96
|
+
delegate.content_type = 'multipart/form-data'
|
97
|
+
delegate.set_form(form, 'multipart/form-data')
|
92
98
|
elsif query
|
93
99
|
if klass.const_get(:REQUEST_HAS_BODY)
|
94
|
-
delegate =
|
100
|
+
delegate.content_type = 'application/x-www-form-urlencoded'
|
95
101
|
delegate.set_form_data(query)
|
96
102
|
else
|
97
103
|
uri.query = URI.encode_www_form(query)
|
98
|
-
delegate
|
104
|
+
delegate = klass.new(uri, headers)
|
99
105
|
end
|
100
|
-
else
|
101
|
-
delegate = klass.new(uri, headers)
|
102
106
|
end
|
103
107
|
|
104
108
|
delegate
|
data/lib/pigeon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigeon-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fitra Aditya
|
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
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: circuitbox
|