lhc 5.1.1 → 6.0.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
  SHA1:
3
- metadata.gz: 6cd6400bfee103b70bc5e305da3dc67b97e4a24a
4
- data.tar.gz: 3a703ca1c8134923bb9a932eea73ce40617cce17
3
+ metadata.gz: 6908fdbe476007a57296f9b09e4b59b10eb640a5
4
+ data.tar.gz: e10412be6e7a72ad83d1ef790ed1eec197614bc0
5
5
  SHA512:
6
- metadata.gz: a2c1a046ff9b60c2bc85f676c09b1750bf0bba0404120323c31d8fd60c27944abc2f5cf9d46f7596e10873ba2ce8cea5d8c3e9d5818bb7fe348343ee237cd2e7
7
- data.tar.gz: d9236773084de2c7ecff22c280d3087ac737baf11ba19ee3b0f82e775870538f2acb36077df0cb8af416f4b8b45e07f43ed1a69e342c944bdb0cc065284d38c0
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
- include BasicMethods
5
- include Formats
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
- def self.config
8
- LHC::Config.instance
9
- end
9
+ include BasicMethodsConcern
10
+ include ConfigurationConcern
11
+ include FormatsConcern
10
12
 
11
- def self.configure
12
- LHC::Config.instance.reset
13
- yield config
14
- end
15
- end
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
- Gem.find_files('lhc/**/*.rb')
18
- .sort
19
- .reject do |path|
20
- (!defined?(Rails) && File.basename(path).include?('railtie.rb')) || # don't require railtie if Rails is not around
21
- path.match(%r{\/test\/.*_helper}) # don't require test helper (as we ask people to explicitly require if needed)
22
- end.each do |path|
23
- require path
24
- end
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
@@ -1,7 +1,7 @@
1
1
  require 'active_support'
2
2
 
3
3
  module LHC
4
- module BasicMethods
4
+ module BasicMethodsConcern
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  module ClassMethods
@@ -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
@@ -1,10 +1,10 @@
1
1
  module LHC
2
- module Formats
2
+ module FormatsConcern
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
6
  def json
7
- JsonFormat
7
+ LHC::Formats::JSON
8
8
  end
9
9
  end
10
10
  end
data/lib/lhc/error.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  class LHC::Error < StandardError
2
-
3
2
  attr_accessor :response, :_message
4
3
 
5
4
  def self.map
@@ -0,0 +1,3 @@
1
+ module LHC::Formats
2
+ autoload :JSON, 'lhc/formats/json'
3
+ end
@@ -1,35 +1,37 @@
1
- class JsonFormat
2
- include LHC::BasicMethods
1
+ module LHC::Formats
2
+ class JSON
3
+ include LHC::BasicMethodsConcern
3
4
 
4
- def self.request(options)
5
- options[:headers] ||= {}
6
- options[:headers]['Content-Type'] = 'application/json'
7
- options[:headers]['Accept'] = 'application/json'
8
- options[:format] = new
9
- super(options)
10
- end
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
- def as_json(response)
13
- parse(response, Hash)
14
- end
13
+ def as_json(response)
14
+ parse(response, Hash)
15
+ end
15
16
 
16
- def as_open_struct(response)
17
- parse(response, OpenStruct)
18
- end
17
+ def as_open_struct(response)
18
+ parse(response, OpenStruct)
19
+ end
19
20
 
20
- def to_s
21
- 'json'
22
- end
21
+ def to_s
22
+ 'json'
23
+ end
23
24
 
24
- def to_sym
25
- to_s.to_sym
26
- end
25
+ def to_sym
26
+ to_s.to_sym
27
+ end
27
28
 
28
- private
29
+ private
29
30
 
30
- def parse(response, object_class)
31
- JSON.parse(response.body, object_class: object_class)
32
- rescue JSON::ParserError => e
33
- raise LHC::ParserError.new(e.message, response)
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') || JsonFormat.new
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 JsonFormat.new if request.nil?
42
+ return LHC::Formats::JSON.new if request.nil?
42
43
  request.format
43
44
  end
44
45
 
data/lib/lhc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION ||= "5.1.1"
2
+ VERSION ||= "6.0.0"
3
3
  end
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: 5.1.1
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-16 00:00:00.000000000 Z
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/basic_methods.rb
176
- - lib/lhc/concerns/lhc/formats.rb
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