namira 1.0.0 → 1.1.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/.circleci/config.yml +12 -31
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/lib/namira/errors/http_error.rb +74 -0
- data/lib/namira/middleware/redirector.rb +8 -8
- data/lib/namira/middleware/responder.rb +1 -1
- data/lib/namira/response.rb +1 -1
- data/lib/namira/version.rb +1 -1
- data/namira.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15da8cadfc98f548c2da00e94dc548b8832c40a
|
4
|
+
data.tar.gz: d8d5f07ff220028dc41a625e50bab2bd614ceb60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7daed40792bb0fd62e2989fe193ad16d3398029f9b5c70a034b551b10ff463432162bf309a6219a5effbfc118341acbc2449c3229faac024d5e52b08296a376
|
7
|
+
data.tar.gz: 109fe7e6579b3c59598f4391009d2b18cbe18a8408b79589d0cd50b86eca25c814f757c8262f5d3707a66c70c66785435fde516bf79d555f73c26fc09f705ac1
|
data/.circleci/config.yml
CHANGED
@@ -8,6 +8,9 @@ jobs:
|
|
8
8
|
working_directory: ~/repo
|
9
9
|
steps:
|
10
10
|
- checkout
|
11
|
+
- run:
|
12
|
+
name: ruby version
|
13
|
+
command: ruby --version
|
11
14
|
- run:
|
12
15
|
name: Setup Code Climate test-reporter
|
13
16
|
command: |
|
@@ -35,30 +38,9 @@ jobs:
|
|
35
38
|
./cc-test-reporter upload-coverage
|
36
39
|
- store_artifacts:
|
37
40
|
path: coverage/coverage.json
|
38
|
-
|
39
|
-
docker:
|
40
|
-
- image: circleci/ruby:2.4.2
|
41
|
-
working_directory: ~/repo
|
42
|
-
steps:
|
43
|
-
- checkout
|
44
|
-
- restore_cache:
|
45
|
-
keys:
|
46
|
-
- v1-gems-{{ checksum "namira.gemspec" }}
|
47
|
-
- v1-gems-
|
48
|
-
- run:
|
49
|
-
name: install gems
|
50
|
-
command: |
|
51
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
52
|
-
- save_cache:
|
53
|
-
key: v1-gems-{{ checksum "namira.gemspec" }}
|
54
|
-
paths:
|
55
|
-
- ./vendor/bundle
|
56
|
-
- run:
|
57
|
-
name: Run Specs
|
58
|
-
command: bundle exec rspec spec/**/*.rb
|
59
|
-
build_2_3:
|
41
|
+
build_2_5:
|
60
42
|
docker:
|
61
|
-
- image: circleci/ruby:2.
|
43
|
+
- image: circleci/ruby:2.5
|
62
44
|
working_directory: ~/repo
|
63
45
|
steps:
|
64
46
|
- checkout
|
@@ -77,9 +59,9 @@ jobs:
|
|
77
59
|
- run:
|
78
60
|
name: Run Specs
|
79
61
|
command: bundle exec rspec spec/**/*.rb
|
80
|
-
|
62
|
+
build_2_4:
|
81
63
|
docker:
|
82
|
-
- image: circleci/ruby:2.2
|
64
|
+
- image: circleci/ruby:2.4.2
|
83
65
|
working_directory: ~/repo
|
84
66
|
steps:
|
85
67
|
- checkout
|
@@ -98,9 +80,9 @@ jobs:
|
|
98
80
|
- run:
|
99
81
|
name: Run Specs
|
100
82
|
command: bundle exec rspec spec/**/*.rb
|
101
|
-
|
83
|
+
build_2_3:
|
102
84
|
docker:
|
103
|
-
- image: circleci/ruby:2.
|
85
|
+
- image: circleci/ruby:2.3.4
|
104
86
|
working_directory: ~/repo
|
105
87
|
steps:
|
106
88
|
- checkout
|
@@ -119,9 +101,9 @@ jobs:
|
|
119
101
|
- run:
|
120
102
|
name: Run Specs
|
121
103
|
command: bundle exec rspec spec/**/*.rb
|
122
|
-
|
104
|
+
build_2_2:
|
123
105
|
docker:
|
124
|
-
- image: circleci/ruby:2
|
106
|
+
- image: circleci/ruby:2.2.7
|
125
107
|
working_directory: ~/repo
|
126
108
|
steps:
|
127
109
|
- checkout
|
@@ -144,9 +126,8 @@ workflows:
|
|
144
126
|
version: 2
|
145
127
|
specs:
|
146
128
|
jobs:
|
147
|
-
- build_2_0
|
148
|
-
- build_2_1
|
149
129
|
- build_2_2
|
150
130
|
- build_2_3
|
151
131
|
- build_2_4
|
132
|
+
- build_2_5
|
152
133
|
- latest
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -24,6 +24,80 @@ module Namira
|
|
24
24
|
@response = response
|
25
25
|
super(msg)
|
26
26
|
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
##
|
30
|
+
# Returns a new HTTP Error based on the status
|
31
|
+
def create(response)
|
32
|
+
klass_for_status(response.status).new("http_error/#{response.status}", response.status, response)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def klass_for_status(status)
|
38
|
+
name = STATUS_MAPPING[status.to_i.to_s]
|
39
|
+
return HTTPError if name.nil?
|
40
|
+
klass_name = "#{name.tr(' ', '')}Error"
|
41
|
+
begin
|
42
|
+
HTTPError.const_get(klass_name)
|
43
|
+
rescue NameError
|
44
|
+
klass = Class.new(HTTPError) {}
|
45
|
+
HTTPError.const_set(klass_name, klass)
|
46
|
+
retry
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
STATUS_MAPPING = {
|
52
|
+
'300' => 'Multiple Choices',
|
53
|
+
'301' => 'Moved Permanently',
|
54
|
+
'302' => 'Found',
|
55
|
+
'303' => 'See Other',
|
56
|
+
'304' => 'Not Modified',
|
57
|
+
'305' => 'Use Proxy',
|
58
|
+
'306' => 'Switch Proxy',
|
59
|
+
'307' => 'Temporary Redirect',
|
60
|
+
'308' => 'Permanent Redirect',
|
61
|
+
'400' => 'Bad Request',
|
62
|
+
'401' => 'Unauthorized',
|
63
|
+
'402' => 'Payment Required',
|
64
|
+
'403' => 'Foridden',
|
65
|
+
'404' => 'Not Found',
|
66
|
+
'405' => 'Method Not Allowed',
|
67
|
+
'406' => 'Not Acceptable',
|
68
|
+
'407' => 'Proxy Authentication Required',
|
69
|
+
'408' => 'Request Timeout',
|
70
|
+
'409' => 'Conflict',
|
71
|
+
'410' => 'Gone',
|
72
|
+
'411' => 'Length Required',
|
73
|
+
'412' => 'Precondition Failed',
|
74
|
+
'413' => 'Payload Too Large',
|
75
|
+
'414' => 'URI Too Long',
|
76
|
+
'415' => 'Unsupported Media Type',
|
77
|
+
'416' => 'Range Not Satisfiable',
|
78
|
+
'417' => 'Expectation Failed',
|
79
|
+
'418' => "Im A Teapot",
|
80
|
+
'421' => 'Misdirected Request',
|
81
|
+
'422' => 'Unprocessable Entity',
|
82
|
+
'423' => 'Locked',
|
83
|
+
'424' => 'Failed Dependency',
|
84
|
+
'426' => 'Upgrade Required',
|
85
|
+
'428' => 'Precondition Required',
|
86
|
+
'429' => 'Too Man Requests',
|
87
|
+
'431' => 'Request Header Fields Too Large',
|
88
|
+
'451' => 'Unavailable For Legal Reasons',
|
89
|
+
'500' => 'Internal Server Error',
|
90
|
+
'501' => 'Not Implemented',
|
91
|
+
'502' => 'Bad Gateway',
|
92
|
+
'503' => 'Service Unavailable',
|
93
|
+
'504' => 'Gateway Timeout',
|
94
|
+
'505' => 'HTTP Version Not Supported',
|
95
|
+
'506' => 'Variant Also Negotiates',
|
96
|
+
'507' => 'Insufficient Storage',
|
97
|
+
'508' => 'Loop Detected',
|
98
|
+
'510' => 'Not Extended',
|
99
|
+
'511' => 'Network Authentication Required'
|
100
|
+
}.freeze
|
27
101
|
end
|
28
102
|
end
|
29
103
|
end
|
@@ -17,20 +17,20 @@ module Namira
|
|
17
17
|
# @param env [Namira::Env] The request environment
|
18
18
|
def call(env)
|
19
19
|
@app.call(env)
|
20
|
-
rescue Errors::HTTPError =>
|
21
|
-
if redirect?(
|
22
|
-
handle_redirect(env,
|
20
|
+
rescue Errors::HTTPError => error
|
21
|
+
if redirect?(error, env)
|
22
|
+
handle_redirect(env, error)
|
23
23
|
else
|
24
|
-
raise
|
24
|
+
raise error
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def handle_redirect(env,
|
30
|
+
def handle_redirect(env, error)
|
31
31
|
count = env.redirect_count
|
32
32
|
redirect_count_error(env) if count >= max_redirect(env)
|
33
|
-
location =
|
33
|
+
location = error.response.headers['Location']
|
34
34
|
redirect_location_error(env) if location.nil?
|
35
35
|
env.uri = Addressable::URI.parse(location)
|
36
36
|
env.redirect_count += 1
|
@@ -57,9 +57,9 @@ module Namira
|
|
57
57
|
)
|
58
58
|
end
|
59
59
|
|
60
|
-
def redirect?(
|
60
|
+
def redirect?(error, env)
|
61
61
|
return false unless env.config[:follow_redirect].nil? ? true : env.config[:follow_redirect]
|
62
|
-
REDIRECT_STATUS.include?(
|
62
|
+
REDIRECT_STATUS.include?(error.status)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/lib/namira/response.rb
CHANGED
data/lib/namira/version.rb
CHANGED
data/namira.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'namira/version'
|
4
4
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.2'
|
22
22
|
|
23
23
|
spec.add_dependency 'http', '>= 2.0.0', '< 4.0'
|
24
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: namira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skylar Schipper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
183
|
requirements:
|
184
184
|
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: '2.
|
186
|
+
version: '2.2'
|
187
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
188
|
requirements:
|
189
189
|
- - ">="
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.5.2
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: A simple wrapper around HTTP
|