lhc 5.1.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lhc.gemspec +1 -2
- data/lib/lhc.rb +109 -20
- data/lib/lhc/concerns/lhc/{basic_methods.rb → basic_methods_concern.rb} +1 -1
- data/lib/lhc/concerns/lhc/configuration_concern.rb +18 -0
- data/lib/lhc/concerns/lhc/{formats.rb → formats_concern.rb} +2 -2
- data/lib/lhc/error.rb +0 -1
- data/lib/lhc/formats.rb +3 -0
- data/lib/lhc/formats/json.rb +28 -26
- data/lib/lhc/request.rb +1 -1
- data/lib/lhc/response.rb +2 -1
- data/lib/lhc/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6908fdbe476007a57296f9b09e4b59b10eb640a5
|
4
|
+
data.tar.gz: e10412be6e7a72ad83d1ef790ed1eec197614bc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c140419daea4fd88e36392d0f553abca3c158005a51876f8f6ecfe91e19afb680090050e719802bc4acf01789ae9a48a07c8147c4820125ec7893af94db90b6e
|
7
|
+
data.tar.gz: fdc55b10cc865a2f83e456dfddf3d7063598e218f33e2577c0519981f1018103a4b588ec877d048f273d776c9118129787cabf0a9e9f911c57c9641722e9c5c9
|
data/lhc.gemspec
CHANGED
@@ -14,8 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.description = 'Rails gem for HTTP: Wraps typhoeus and provides additional features (like interceptors)'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
18
|
-
`git ls-files -- non_rails_spec/*`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
18
|
s.require_paths = ['lib']
|
20
19
|
|
21
20
|
s.requirements << 'Ruby >= 2.0.0'
|
data/lib/lhc.rb
CHANGED
@@ -1,24 +1,113 @@
|
|
1
|
-
Dir[File.dirname(__FILE__) + '/lhc/concerns/lhc/*.rb'].sort.each { |file| require file }
|
2
|
-
|
3
1
|
module LHC
|
4
|
-
|
5
|
-
|
2
|
+
autoload :BasicMethodsConcern,
|
3
|
+
'lhc/concerns/lhc/basic_methods_concern'
|
4
|
+
autoload :ConfigurationConcern,
|
5
|
+
'lhc/concerns/lhc/configuration_concern'
|
6
|
+
autoload :FormatsConcern,
|
7
|
+
'lhc/concerns/lhc/formats_concern'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
include BasicMethodsConcern
|
10
|
+
include ConfigurationConcern
|
11
|
+
include FormatsConcern
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
autoload :Auth,
|
14
|
+
'lhc/interceptors/auth'
|
15
|
+
autoload :Caching,
|
16
|
+
'lhc/interceptors/caching'
|
17
|
+
autoload :Config,
|
18
|
+
'lhc/config'
|
19
|
+
autoload :Endpoint,
|
20
|
+
'lhc/endpoint'
|
21
|
+
|
22
|
+
autoload :Error,
|
23
|
+
'lhc/error'
|
24
|
+
autoload :ClientError,
|
25
|
+
'lhc/errors/client_error'
|
26
|
+
autoload :BadRequest,
|
27
|
+
'lhc/errors/client_error'
|
28
|
+
autoload :Unauthorized,
|
29
|
+
'lhc/errors/client_error'
|
30
|
+
autoload :PaymentRequired,
|
31
|
+
'lhc/errors/client_error'
|
32
|
+
autoload :Forbidden,
|
33
|
+
'lhc/errors/client_error'
|
34
|
+
autoload :Forbidden,
|
35
|
+
'lhc/errors/client_error'
|
36
|
+
autoload :NotFound,
|
37
|
+
'lhc/errors/client_error'
|
38
|
+
autoload :MethodNotAllowed,
|
39
|
+
'lhc/errors/client_error'
|
40
|
+
autoload :NotAcceptable,
|
41
|
+
'lhc/errors/client_error'
|
42
|
+
autoload :ProxyAuthenticationRequired,
|
43
|
+
'lhc/errors/client_error'
|
44
|
+
autoload :RequestTimeout,
|
45
|
+
'lhc/errors/client_error'
|
46
|
+
autoload :Conflict,
|
47
|
+
'lhc/errors/client_error'
|
48
|
+
autoload :Gone,
|
49
|
+
'lhc/errors/client_error'
|
50
|
+
autoload :LengthRequired,
|
51
|
+
'lhc/errors/client_error'
|
52
|
+
autoload :PreconditionFailed,
|
53
|
+
'lhc/errors/client_error'
|
54
|
+
autoload :RequestEntityTooLarge,
|
55
|
+
'lhc/errors/client_error'
|
56
|
+
autoload :RequestUriToLong,
|
57
|
+
'lhc/errors/client_error'
|
58
|
+
autoload :UnsupportedMediaType,
|
59
|
+
'lhc/errors/client_error'
|
60
|
+
autoload :RequestedRangeNotSatisfiable,
|
61
|
+
'lhc/errors/client_error'
|
62
|
+
autoload :ExpectationFailed,
|
63
|
+
'lhc/errors/client_error'
|
64
|
+
autoload :UnprocessableEntity,
|
65
|
+
'lhc/errors/client_error'
|
66
|
+
autoload :Locked,
|
67
|
+
'lhc/errors/client_error'
|
68
|
+
autoload :FailedDependency,
|
69
|
+
'lhc/errors/client_error'
|
70
|
+
autoload :UpgradeRequired,
|
71
|
+
'lhc/errors/client_error'
|
72
|
+
autoload :ParserError,
|
73
|
+
'lhc/errors/parser_error'
|
74
|
+
autoload :ServerError,
|
75
|
+
'lhc/errors/server_error'
|
76
|
+
autoload :InternalServerError,
|
77
|
+
'lhc/errors/server_error'
|
78
|
+
autoload :NotImplemented,
|
79
|
+
'lhc/errors/server_error'
|
80
|
+
autoload :BadGateway,
|
81
|
+
'lhc/errors/server_error'
|
82
|
+
autoload :ServiceUnavailable,
|
83
|
+
'lhc/errors/server_error'
|
84
|
+
autoload :GatewayTimeout,
|
85
|
+
'lhc/errors/server_error'
|
86
|
+
autoload :HttpVersionNotSupported,
|
87
|
+
'lhc/errors/server_error'
|
88
|
+
autoload :InsufficientStorage,
|
89
|
+
'lhc/errors/server_error'
|
90
|
+
autoload :NotExtended,
|
91
|
+
'lhc/errors/server_error'
|
92
|
+
autoload :Timeout,
|
93
|
+
'lhc/errors/timeout'
|
94
|
+
autoload :UnknownError,
|
95
|
+
'lhc/errors/unknown_error'
|
16
96
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
97
|
+
autoload :Interceptor,
|
98
|
+
'lhc/interceptor'
|
99
|
+
autoload :InterceptorProcessor,
|
100
|
+
'lhc/interceptor_processor'
|
101
|
+
autoload :Formats,
|
102
|
+
'lhc/formats'
|
103
|
+
autoload :Monitoring,
|
104
|
+
'lhc/interceptors/monitoring'
|
105
|
+
autoload :Request,
|
106
|
+
'lhc/request'
|
107
|
+
autoload :Response,
|
108
|
+
'lhc/response'
|
109
|
+
autoload :Rollbar,
|
110
|
+
'lhc/interceptors/rollbar'
|
111
|
+
|
112
|
+
require 'lhc/railtie' if defined?(Rails)
|
113
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module LHC
|
4
|
+
module ConfigurationConcern
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def config
|
9
|
+
LHC::Config.instance
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
LHC::Config.instance.reset
|
14
|
+
yield config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/lhc/error.rb
CHANGED
data/lib/lhc/formats.rb
ADDED
data/lib/lhc/formats/json.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module LHC::Formats
|
2
|
+
class JSON
|
3
|
+
include LHC::BasicMethodsConcern
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def self.request(options)
|
6
|
+
options[:headers] ||= {}
|
7
|
+
options[:headers]['Content-Type'] = 'application/json'
|
8
|
+
options[:headers]['Accept'] = 'application/json'
|
9
|
+
options[:format] = new
|
10
|
+
super(options)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def as_json(response)
|
14
|
+
parse(response, Hash)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def as_open_struct(response)
|
18
|
+
parse(response, OpenStruct)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def to_s
|
22
|
+
'json'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def to_sym
|
26
|
+
to_s.to_sym
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
+
private
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def parse(response, object_class)
|
32
|
+
::JSON.parse(response.body, object_class: object_class)
|
33
|
+
rescue ::JSON::ParserError => e
|
34
|
+
raise LHC::ParserError.new(e.message, response)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
data/lib/lhc/request.rb
CHANGED
@@ -18,7 +18,7 @@ class LHC::Request
|
|
18
18
|
generate_url_from_template!
|
19
19
|
self.iprocessor = LHC::InterceptorProcessor.new(self)
|
20
20
|
self.raw = create_request
|
21
|
-
self.format = options.delete('format') ||
|
21
|
+
self.format = options.delete('format') || LHC::Formats::JSON.new
|
22
22
|
iprocessor.intercept(:before_request, self)
|
23
23
|
raw.run if self_executing && !response
|
24
24
|
end
|
data/lib/lhc/response.rb
CHANGED
@@ -4,6 +4,7 @@ require 'active_support/core_ext/module'
|
|
4
4
|
# The response contains the raw response (typhoeus)
|
5
5
|
# and provides functionality to access response data.
|
6
6
|
class LHC::Response
|
7
|
+
autoload :Data, 'lhc/response/data'
|
7
8
|
|
8
9
|
attr_accessor :request, :body_replacement
|
9
10
|
|
@@ -38,7 +39,7 @@ class LHC::Response
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def format
|
41
|
-
return
|
42
|
+
return LHC::Formats::JSON.new if request.nil?
|
42
43
|
request.format
|
43
44
|
end
|
44
45
|
|
data/lib/lhc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -172,8 +172,9 @@ files:
|
|
172
172
|
- docs/response.md
|
173
173
|
- lhc.gemspec
|
174
174
|
- lib/lhc.rb
|
175
|
-
- lib/lhc/concerns/lhc/
|
176
|
-
- lib/lhc/concerns/lhc/
|
175
|
+
- lib/lhc/concerns/lhc/basic_methods_concern.rb
|
176
|
+
- lib/lhc/concerns/lhc/configuration_concern.rb
|
177
|
+
- lib/lhc/concerns/lhc/formats_concern.rb
|
177
178
|
- lib/lhc/config.rb
|
178
179
|
- lib/lhc/endpoint.rb
|
179
180
|
- lib/lhc/error.rb
|
@@ -182,6 +183,7 @@ files:
|
|
182
183
|
- lib/lhc/errors/server_error.rb
|
183
184
|
- lib/lhc/errors/timeout.rb
|
184
185
|
- lib/lhc/errors/unknown_error.rb
|
186
|
+
- lib/lhc/formats.rb
|
185
187
|
- lib/lhc/formats/json.rb
|
186
188
|
- lib/lhc/interceptor.rb
|
187
189
|
- lib/lhc/interceptor_processor.rb
|