better-faraday 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/better-faraday.gemspec +17 -0
- data/lib/better-faraday.rb +62 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bdd3e8a61f80ccc5c84fa20f45f761e71e087fb7413995a5a5808a116063613b
|
4
|
+
data.tar.gz: 796dcaca5f06c2be9f18e12735562f38febd2f5d67a49963c71170f25d4fadd6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d2c46facc2824bc2f921928d1f37c41978e8e953fa9ecc222c2f986f04557f07a923d25a2ee1ea083b4023997c447e60f09cbb5b7ad792282d966a7b5eab9ef
|
7
|
+
data.tar.gz: 9fd3e5ebc2a4a40df2df61e34c446c8a2e75e2adcf0ff6df59aef0b330b09bc1fe07cc23191cc2dcb3c84d3ca60291092d0b722b3bdd8e89d45ff59580caca2f
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Yaroslav Konoplov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# better-faraday
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "better-faraday"
|
6
|
+
s.version = "1.0.0"
|
7
|
+
s.author = "Yaroslav Konoplov"
|
8
|
+
s.email = "eahome00@gmail.com"
|
9
|
+
s.summary = "Extends Faraday with useful features."
|
10
|
+
s.description = "Extends Faraday (popular Ruby HTTP client) with useful features without breaking anything."
|
11
|
+
s.homepage = "https://github.com/yivo/better-faraday"
|
12
|
+
s.license = "MIT"
|
13
|
+
s.files = `git ls-files -z`.split("\x0")
|
14
|
+
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.add_dependency "faraday", "~> 0.12"
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "faraday"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
Module.new do
|
8
|
+
def run_request(method, url, body, headers, &block)
|
9
|
+
super.tap { |response| response.env.instance_variable_set(:@request_body, body) }
|
10
|
+
end
|
11
|
+
end.tap { |m| Faraday::Connection.send(:prepend, m) }
|
12
|
+
|
13
|
+
module Faraday
|
14
|
+
class Env
|
15
|
+
attr_reader :request_body
|
16
|
+
end
|
17
|
+
|
18
|
+
class Response
|
19
|
+
def assert_2xx!
|
20
|
+
return self if status >= 200 && status <= 299
|
21
|
+
raise Faraday::HTTP422, describe if status == 422
|
22
|
+
raise Faraday::HTTP4xx, describe if status >= 400 && status <= 499
|
23
|
+
raise Faraday::Error, describe
|
24
|
+
end
|
25
|
+
|
26
|
+
alias ok! assert_2xx! # Short name.
|
27
|
+
alias assert_success! assert_2xx! # Compatibility.
|
28
|
+
|
29
|
+
def describe
|
30
|
+
[ "",
|
31
|
+
"-- #{status} #{reason_phrase} --",
|
32
|
+
"",
|
33
|
+
"-- Request URL --",
|
34
|
+
env.url.to_s,
|
35
|
+
"",
|
36
|
+
"-- Request method --",
|
37
|
+
env.method.to_s.upcase,
|
38
|
+
"",
|
39
|
+
"-- Request headers --",
|
40
|
+
::JSON.generate(env.request_headers.tap { |x| x["Authorization"] = "SECRET" if x.key?("Authorization") }),
|
41
|
+
"",
|
42
|
+
"-- Request body --",
|
43
|
+
env.request_body.to_s,
|
44
|
+
"",
|
45
|
+
"-- Response headers --",
|
46
|
+
::Hash === env.response_headers ? ::JSON.generate(env.response_headers) : "",
|
47
|
+
"",
|
48
|
+
"-- Response body --",
|
49
|
+
env.body.to_s,
|
50
|
+
""
|
51
|
+
].join("\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class HTTP4xx < Error
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class HTTP422 < HTTP4xx
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: better-faraday
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yaroslav Konoplov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
description: Extends Faraday (popular Ruby HTTP client) with useful features without
|
28
|
+
breaking anything.
|
29
|
+
email: eahome00@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".ruby-version"
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- better-faraday.gemspec
|
39
|
+
- lib/better-faraday.rb
|
40
|
+
homepage: https://github.com/yivo/better-faraday
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.7.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Extends Faraday with useful features.
|
64
|
+
test_files: []
|