foucault_http 0.4.10 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/Rakefile +14 -0
- data/foucault_http.gemspec +5 -5
- data/lib/foucault_http/configuration.rb +1 -2
- data/lib/foucault_http/http_connection.rb +7 -6
- data/lib/foucault_http/http_port.rb +19 -15
- data/lib/foucault_http/net.rb +6 -5
- data/lib/foucault_http/version.rb +1 -1
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3a575800d5379ebfccee8f9479c670dfa8bf6d663e6da89b8487b6d206f070
|
4
|
+
data.tar.gz: a5e00f7a22b10c63d5dfe787ee2cae1a0ba3ce368b77900571f21d404ba2aa2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac29c9498e03e672654b0517f2e2758e9b7ece1e13e0e3a565a69bfab78fbdd28e8c76732d578d11efafc07582c712a4f243413fd90bbae578f1068dcc57e0c4
|
7
|
+
data.tar.gz: df22f9316f5997b21c3780f31bc8e084d3b69e270095d4e3b8ecf52698a8f3e3fed67c125e6aff13e8f49d68d71b7c44d3365d01a543961827b4237fcef943b3
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ You provide configuration through the object
|
|
31
31
|
FoucaultHttp::Configuration.configure do |config|
|
32
32
|
config.logger = SomeLogger # Any class that responds to the log level methods with a single param
|
33
33
|
# (a string or hash if you're using a structured log format)
|
34
|
-
config.
|
34
|
+
config.log_formatter = SomeLogFormatter # A class which inherits from Faraday::Logging::Formatter
|
35
35
|
config.logging_level = :info
|
36
36
|
end
|
37
37
|
```
|
@@ -114,6 +114,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
114
114
|
|
115
115
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
116
|
|
117
|
+
To update the gem on RubyGems:
|
118
|
+
|
119
|
+
+ Update the version
|
120
|
+
+ `gem build foucault_http.gemspec`
|
121
|
+
+ `gem push foucault_http-v.v.v.gem`
|
122
|
+
|
117
123
|
## Contributing
|
118
124
|
|
119
125
|
Bug reports and pull requests are welcome on GitHub at https://github.com/wildfauve/foucault_http. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/Rakefile
CHANGED
@@ -4,3 +4,17 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
task :build do |t, args|
|
9
|
+
puts "packaging gem"
|
10
|
+
system "gem build foucault_http.gemspec"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :push, [:version] do |t, args|
|
14
|
+
if args[:version]
|
15
|
+
puts "pushing gem"
|
16
|
+
system "gem push foucault_http-#{args[:version]}.gem"
|
17
|
+
else
|
18
|
+
puts "Please provide version"
|
19
|
+
end
|
20
|
+
end
|
data/foucault_http.gemspec
CHANGED
@@ -30,13 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency 'stoplight'
|
33
|
+
spec.add_dependency 'stoplight', "~> 2.2"
|
34
34
|
spec.add_dependency 'dry-monads', "~> 1.0"
|
35
|
-
spec.add_dependency 'dry-configurable'
|
36
|
-
spec.add_dependency 'funcify'
|
35
|
+
spec.add_dependency 'dry-configurable', "~> 0.11"
|
36
|
+
spec.add_dependency 'funcify', "~> 0.4"
|
37
37
|
spec.add_dependency 'faraday', '~> 1.0'
|
38
|
-
spec.add_dependency "dry-types"
|
39
|
-
spec.add_dependency "dry-struct"
|
38
|
+
spec.add_dependency "dry-types", "~> 1.4"
|
39
|
+
spec.add_dependency "dry-struct", "~> 1.3"
|
40
40
|
|
41
41
|
spec.add_development_dependency "bundler", "~> 2.0"
|
42
42
|
spec.add_development_dependency "rake", "~> 13.0"
|
@@ -10,8 +10,8 @@ module FoucaultHttp
|
|
10
10
|
|
11
11
|
HTTP_CONNECTION_FAILURE = :http_connection_failure
|
12
12
|
|
13
|
-
def connection(address, encoding, cache_store = nil, instrumenter = nil)
|
14
|
-
@http_connection = Try { http_connection(address, encoding, cache_store, instrumenter) }
|
13
|
+
def connection(address, opts, encoding, cache_store = nil, instrumenter = nil)
|
14
|
+
@http_connection = Try { http_connection(address, opts, encoding, cache_store, instrumenter) }
|
15
15
|
self
|
16
16
|
end
|
17
17
|
|
@@ -27,9 +27,10 @@ module FoucaultHttp
|
|
27
27
|
|
28
28
|
def post(hdrs, body)
|
29
29
|
return @http_connection.to_result if @http_connection.failure?
|
30
|
+
return body.to_result if body.failure?
|
30
31
|
Try {
|
31
32
|
@http_connection.value_or.post do |r|
|
32
|
-
r.body = body
|
33
|
+
r.body = body.value_or
|
33
34
|
r.headers = hdrs
|
34
35
|
end
|
35
36
|
}.to_result
|
@@ -46,12 +47,12 @@ module FoucaultHttp
|
|
46
47
|
|
47
48
|
private
|
48
49
|
|
49
|
-
def http_connection(address, encoding, cache_store, instrumenter)
|
50
|
-
faraday_connection = Faraday.new(:
|
50
|
+
def http_connection(address, opts={}, encoding, cache_store, instrumenter)
|
51
|
+
faraday_connection = Faraday.new(opts.merge(url: address)) do |faraday|
|
51
52
|
# faraday.use :http_cache, caching if caching
|
52
53
|
faraday.request encoding if encoding
|
53
54
|
if Configuration.config.logger && Configuration.config.log_formatter
|
54
|
-
faraday.response :logger, Configuration.config.logger, formatter: Configuration.config.
|
55
|
+
faraday.response :logger, Configuration.config.logger, formatter: Configuration.config.log_formatter
|
55
56
|
elsif Configuration.config.logger
|
56
57
|
faraday.response :logger, Configuration.config.logger
|
57
58
|
else
|
@@ -18,39 +18,39 @@ module FoucaultHttp
|
|
18
18
|
class << self
|
19
19
|
|
20
20
|
def post
|
21
|
-
-> correlation, service, resource, hdrs, body_fn, enc, body {
|
21
|
+
-> correlation, service, resource, opts, hdrs, body_fn, enc, body {
|
22
22
|
( Fn.either.(net_ok).(Monad.success).(Monad.failure) <<
|
23
23
|
log_response.(correlation, service, resource, __method__) <<
|
24
24
|
response_value <<
|
25
25
|
run_post.(hdrs, body_fn, body) <<
|
26
|
-
addressed.(service, resource)).(connection.(enc))
|
26
|
+
addressed.(service, resource)).(connection.(opts, enc))
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
30
|
def get
|
31
|
-
-> correlation, service, resource, hdrs, enc, query {
|
31
|
+
-> correlation, service, resource, opts, hdrs, enc, query {
|
32
32
|
( Fn.either.(net_ok).(Monad.success).(Monad.failure) <<
|
33
33
|
log_response.(correlation, service, resource, __method__) <<
|
34
34
|
response_value <<
|
35
35
|
run_get.(hdrs, query) <<
|
36
|
-
addressed.(service, resource)).(connection.(enc))
|
36
|
+
addressed.(service, resource)).(connection.(opts, enc))
|
37
37
|
}
|
38
38
|
end
|
39
39
|
|
40
40
|
def delete
|
41
|
-
-> correlation, service, resource, hdrs {
|
41
|
+
-> correlation, service, resource, opts, hdrs {
|
42
42
|
( Fn.either.(net_ok).(Monad.success).(Monad.failure) <<
|
43
43
|
log_response.([], service, resource, __method__) <<
|
44
44
|
response_value <<
|
45
45
|
run_delete.(hdrs) <<
|
46
|
-
addressed.(service, resource)).(connection.(nil))
|
46
|
+
addressed.(service, resource)).(connection.(opts, nil))
|
47
47
|
}
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
51
|
def run_post
|
52
52
|
-> hdrs, body_fn, body, connection {
|
53
|
-
connection.post(hdrs, body_fn.(body))
|
53
|
+
connection.post(hdrs, Try { body_fn.(body) })
|
54
54
|
}.curry
|
55
55
|
end
|
56
56
|
|
@@ -73,7 +73,7 @@ module FoucaultHttp
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def connection
|
76
|
-
-> encoding, address { HttpConnection.new.connection(address, encoding) }.curry
|
76
|
+
-> opts, encoding, address { HttpConnection.new.connection(address, opts, encoding) }.curry
|
77
77
|
end
|
78
78
|
|
79
79
|
def address
|
@@ -132,7 +132,7 @@ module FoucaultHttp
|
|
132
132
|
-> type {
|
133
133
|
case type
|
134
134
|
when "text/html"
|
135
|
-
|
135
|
+
xml_parser
|
136
136
|
when "text/plain"
|
137
137
|
text_parser
|
138
138
|
when "text/csv"
|
@@ -140,7 +140,7 @@ module FoucaultHttp
|
|
140
140
|
when "application/json"
|
141
141
|
json_parser
|
142
142
|
when "application/xml", "application/soap+xml", "text/xml"
|
143
|
-
|
143
|
+
xml_parser
|
144
144
|
else
|
145
145
|
nil_parser
|
146
146
|
end
|
@@ -148,7 +148,7 @@ module FoucaultHttp
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def returned_response(response)
|
151
|
-
raise(NoContentTypeError.new("Content Type in response is nil")) unless response.value_or.headers["content-type"]
|
151
|
+
raise(NoContentTypeError.new("Content Type in response is nil; body: #{response.value_or.body}")) unless response.value_or.headers["content-type"]
|
152
152
|
OpenStruct.new(
|
153
153
|
status: evalulate_status.(response.value_or.status),
|
154
154
|
code: response.value_or.status,
|
@@ -177,6 +177,10 @@ module FoucaultHttp
|
|
177
177
|
-> response { JSON.parse(response.body) }
|
178
178
|
end
|
179
179
|
|
180
|
+
def xml_parser
|
181
|
+
-> response { Nokogiri::XML(response.body) }
|
182
|
+
end
|
183
|
+
|
180
184
|
def text_parser
|
181
185
|
-> response { response.body }
|
182
186
|
end
|
@@ -196,18 +200,18 @@ module FoucaultHttp
|
|
196
200
|
def structured_log(service, resource, api, response, correlation={})
|
197
201
|
{
|
198
202
|
msg: "Common::Network::Net",
|
199
|
-
context: context_for_log(service, resource, response
|
203
|
+
context: context_for_log(service, resource, response),
|
200
204
|
step: api,
|
201
205
|
status: response.status
|
202
|
-
}
|
206
|
+
}.merge(correlation || {})
|
203
207
|
end
|
204
208
|
|
205
|
-
def context_for_log(service, resource, response
|
209
|
+
def context_for_log(service, resource, response)
|
206
210
|
{
|
207
211
|
http_code: response.code,
|
208
212
|
resource: address.(service, resource),
|
209
213
|
fail_response: log_of_failure(response)
|
210
|
-
}
|
214
|
+
}
|
211
215
|
end
|
212
216
|
|
213
217
|
def log_of_failure(response)
|
data/lib/foucault_http/net.rb
CHANGED
@@ -9,9 +9,10 @@ module FoucaultHttp
|
|
9
9
|
class << self
|
10
10
|
|
11
11
|
# Client interface
|
12
|
+
|
12
13
|
def post
|
13
|
-
-> correlation, service, resource, hdrs, enc, body_fn, body {
|
14
|
-
HttpPort.post.(correlation, service, resource, hdrs, body_fn, enc, body)
|
14
|
+
-> correlation, service, resource, opts, hdrs, enc, body_fn, body {
|
15
|
+
HttpPort.post.(correlation, service, resource, opts, hdrs, body_fn, enc, body)
|
15
16
|
}.curry
|
16
17
|
end
|
17
18
|
|
@@ -30,8 +31,8 @@ module FoucaultHttp
|
|
30
31
|
# Example
|
31
32
|
# > get.(@env[:host], "/userinfo", {authorization: "Bearer <token> }, :url_encoded, {} )
|
32
33
|
def get
|
33
|
-
-> correlation, service, resource, hdrs, enc, query {
|
34
|
-
HttpPort.get.(correlation, service, resource, hdrs, enc, query)
|
34
|
+
-> correlation, service, resource, opts, hdrs, enc, query {
|
35
|
+
HttpPort.get.(correlation, service, resource, opts, hdrs, enc, query)
|
35
36
|
}.curry
|
36
37
|
end
|
37
38
|
|
@@ -82,7 +83,7 @@ module FoucaultHttp
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def json_body_fn
|
85
|
-
-> body { body
|
86
|
+
-> body { JSON.generate(body) }
|
86
87
|
end
|
87
88
|
|
88
89
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foucault_http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Col Perks
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stoplight
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-monads
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: dry-configurable
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.11'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: funcify
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.4'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faraday
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,30 +84,30 @@ dependencies:
|
|
84
84
|
name: dry-types
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.4'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.4'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: dry-struct
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.3'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: bundler
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|