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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6144425925319954e3223f9621c5a15b37bdde7
4
- data.tar.gz: 05c33f28f3ca7ded8bdce6de7d785bb0cd36de72
3
+ metadata.gz: f15da8cadfc98f548c2da00e94dc548b8832c40a
4
+ data.tar.gz: d8d5f07ff220028dc41a625e50bab2bd614ceb60
5
5
  SHA512:
6
- metadata.gz: d6afe82453cbee37fcba73054286a6d7d3dcef1fa253f00f495489bbdc711171ac28e402a471bf9d8c6eac2a69e1b6c1fae9e9980b69c955b194a82ced171295
7
- data.tar.gz: edd22bb662cc1e3ff67fbee67471f93799a273ed5193b19d4d86a5016c34ba4e433078f300f8d45028eecebb84e134a1b9615778f4eadaee3b63ff63d1d65eb2
6
+ metadata.gz: f7daed40792bb0fd62e2989fe193ad16d3398029f9b5c70a034b551b10ff463432162bf309a6219a5effbfc118341acbc2449c3229faac024d5e52b08296a376
7
+ data.tar.gz: 109fe7e6579b3c59598f4391009d2b18cbe18a8408b79589d0cd50b86eca25c814f757c8262f5d3707a66c70c66785435fde516bf79d555f73c26fc09f705ac1
@@ -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
- build_2_4:
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.3.4
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
- build_2_2:
62
+ build_2_4:
81
63
  docker:
82
- - image: circleci/ruby:2.2.7
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
- build_2_1:
83
+ build_2_3:
102
84
  docker:
103
- - image: circleci/ruby:2.1.10
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
- build_2_0:
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
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.2
3
3
  Exclude:
4
4
  - Rakefile
5
5
  - spec/**/*
@@ -1,3 +1,7 @@
1
+ # 1.1 (2018-05-18)
2
+
3
+ * Make HTTP Errors their own class.
4
+
1
5
  # 1.0.0.rc3 (2018-01-28)
2
6
 
3
7
  * Converted to using a middleware stack for sending requests.
@@ -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 => e
21
- if redirect?(e, env)
22
- handle_redirect(env, e)
20
+ rescue Errors::HTTPError => error
21
+ if redirect?(error, env)
22
+ handle_redirect(env, error)
23
23
  else
24
- raise e
24
+ raise error
25
25
  end
26
26
  end
27
27
 
28
28
  private
29
29
 
30
- def handle_redirect(env, e)
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 = e.response.headers['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?(e, env)
60
+ def redirect?(error, env)
61
61
  return false unless env.config[:follow_redirect].nil? ? true : env.config[:follow_redirect]
62
- REDIRECT_STATUS.include?(e.status)
62
+ REDIRECT_STATUS.include?(error.status)
63
63
  end
64
64
  end
65
65
  end
@@ -24,7 +24,7 @@ module Namira
24
24
  if (200...300).cover?(response.status)
25
25
  final
26
26
  else
27
- raise Errors::HTTPError.new("http_error/#{response.status}", response.status, final)
27
+ raise Errors::HTTPError.create(final)
28
28
  end
29
29
  end
30
30
  end
@@ -11,7 +11,7 @@ module Namira
11
11
  ##
12
12
  # @return [Hash, Array] Parse the response body as JSON
13
13
  def from_json
14
- @json ||= JSON.parse(@backing.body)
14
+ @from_json ||= JSON.parse(@backing.body)
15
15
  end
16
16
 
17
17
  ##
@@ -1,5 +1,5 @@
1
1
  module Namira
2
2
  ##
3
3
  # The current version of Namira
4
- VERSION = '1.0.0'.freeze
4
+ VERSION = '1.1.0'.freeze
5
5
  end
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
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.0'
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.0.0
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-01-29 00:00:00.000000000 Z
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.0'
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.6.13
194
+ rubygems_version: 2.5.2
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: A simple wrapper around HTTP