heroics 0.0.23 → 0.1.2

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
- SHA1:
3
- metadata.gz: aa136b8dba59b471d2f401a6a1feced2da9aabd3
4
- data.tar.gz: 7cec9ec603b4093a4c1c65888d2533eeb3920f0f
2
+ SHA256:
3
+ metadata.gz: 935d4099ef19b7d1edd7f04bd8545d0f2a9d0a3dea2433005148854654a9efb9
4
+ data.tar.gz: afb94092e02a8ee403c4e2b2b7b0326c59f310376ce1175db13a18f185a56bdc
5
5
  SHA512:
6
- metadata.gz: 3c949d3e1bd3743f76c81f32483f2ad68417a54f34421b7dac7256bb086c7fef773800b766ccbc5cef61f64d5017e2d993f8bf75cac19ca207c8ac4a0979a439
7
- data.tar.gz: be86626f66f368408ca0887a3561982995c3e778801a882b4cfa6ffadee5156f57411c8f8b5326bf720b5d04c1f611d0c61187d20838ae13bc1684e8722d7856
6
+ metadata.gz: aa084cff8f5819cc23375f0764c878a44113bd094d1b47997438b2fa8e89e24f56e5ac1fa5dab9341fae077cc329e3d1fac4a5ec26a74e859bfeec50e2951a6b
7
+ data.tar.gz: 7417de326cf4f11b9f7dc73df4d4397fcfde7f130a34ed4b287226d1c0a536fee1e2f013a15ddb4c596453fc49167d6a218d630ac54059890ad0411e7d32412d
@@ -0,0 +1,12 @@
1
+ name: Check Changelog
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v1
10
+ - name: Check that CHANGELOG is touched
11
+ run: |
12
+ cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
@@ -0,0 +1,11 @@
1
+ ## 0.1.2
2
+
3
+ - Add support for Ruby 3.0 (https://github.com/interagent/heroics/pull/101)
4
+
5
+ ## 0.1.1
6
+
7
+ - Add status codes configuration (https://github.com/interagent/heroics/pull/96)
8
+
9
+ ## 0.1.0
10
+
11
+ - Introduced rate throttling integration point (https://github.com/interagent/heroics/pull/95)
data/Rakefile CHANGED
@@ -3,7 +3,6 @@ require "rake/testtask"
3
3
 
4
4
  Rake::TestTask.new do |task|
5
5
  task.verbose = true
6
- task.ruby_opts << '-r turn/autorun'
7
6
  task.ruby_opts << '-I test'
8
7
  task.test_files = FileList['test/**/*_test.rb', 'test/**/*_spec.rb']
9
8
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'heroics'
4
4
  require 'netrc'
5
+ require 'moneta'
5
6
 
6
7
  netrc = Netrc.read
7
8
  username, token = netrc['api.heroku.com']
@@ -20,16 +20,16 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep('^(test|spec|features)/')
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'minitest', '4.7.5'
25
- spec.add_development_dependency 'moneta'
26
25
  spec.add_development_dependency 'netrc'
27
26
  spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'turn'
29
27
  spec.add_development_dependency 'yard'
30
28
  spec.add_development_dependency 'pry'
31
29
 
32
30
  spec.add_dependency 'erubis', '~> 2.0'
33
31
  spec.add_dependency 'excon'
34
32
  spec.add_dependency 'multi_json', '>= 1.9.2'
33
+ spec.add_dependency 'moneta'
34
+ spec.add_dependency 'webrick'
35
35
  end
@@ -4,6 +4,7 @@ require 'erubis'
4
4
  require 'excon'
5
5
  require 'multi_json'
6
6
  require 'uri'
7
+ require 'webrick'
7
8
  require 'zlib'
8
9
 
9
10
  # Heroics is an HTTP client for an API described by a JSON schema.
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heroics
4
+ module NullRateLimit
5
+ def self.call
6
+ yield
7
+ end
8
+ end
9
+
4
10
  # Attempts to load configuration, provides defaults, and provide helpers to access that data
5
11
  class Configuration
6
12
  attr_reader :base_url,
@@ -22,7 +28,8 @@ module Heroics
22
28
  @options = {}
23
29
  @options[:cache] = 'Moneta.new(:Memory)'
24
30
  @options[:default_headers] = {}
25
-
31
+ @options[:rate_throttle] = NullRateLimit
32
+ @options[:status_codes] = []
26
33
  @ruby_name_replacement_patterns = { /[\s-]+/ => '_' }
27
34
 
28
35
  yield self if block_given?
@@ -57,5 +64,13 @@ module Heroics
57
64
  raise "Must provide a hash of replacements" unless patterns.is_a?(Hash)
58
65
  @ruby_name_replacement_patterns = patterns
59
66
  end
67
+
68
+ def rate_throttle=(rate_throttle)
69
+ @options[:rate_throttle] = rate_throttle
70
+ end
71
+
72
+ def acceptable_status_codes=(status_codes)
73
+ @options[:status_codes] = status_codes
74
+ end
60
75
  end
61
76
  end
@@ -18,6 +18,8 @@ module Heroics
18
18
  @link_schema = link_schema
19
19
  @default_headers = options[:default_headers] || {}
20
20
  @cache = options[:cache] || {}
21
+ @rate_throttle = options[:rate_throttle] || Heroics::Configuration.defaults.options[:rate_throttle]
22
+ @status_codes = options[:status_codes] || Heroics::Configuration.defaults.options[:status_codes]
21
23
  end
22
24
 
23
25
  # Make a request to the server.
@@ -103,12 +105,18 @@ module Heroics
103
105
 
104
106
  def request_with_cache(connection, options)
105
107
  options[:expects] << 304
108
+ @status_codes.each do |code|
109
+ options[:expects] << code
110
+ end
106
111
  cache_key = "#{options[:path]}:#{options[:headers].hash}"
107
112
  if options[:method] == :get
108
113
  etag = @cache["etag:#{cache_key}"]
109
114
  options[:headers] = options[:headers].merge({'If-None-Match' => etag}) if etag
110
115
  end
111
- response = connection.request(options)
116
+
117
+ response = @rate_throttle.call do
118
+ connection.request(options)
119
+ end
112
120
 
113
121
  if response.status == 304
114
122
  body = @cache["data:#{cache_key}"]
@@ -244,7 +244,7 @@ module Heroics
244
244
  [value['$ref'], key]
245
245
  end]
246
246
  parameters.map do |parameter|
247
- definition_name = URI.unescape(parameter[2..-3])
247
+ definition_name = ::URI::DEFAULT_PARSER.unescape(parameter[2..-3])
248
248
  if definitions.has_key?(definition_name)
249
249
  definitions[definition_name]
250
250
  else
@@ -273,7 +273,7 @@ module Heroics
273
273
  def resolve_parameter_details(parameters)
274
274
  parameters.map do |parameter|
275
275
  # URI decode parameters and strip the leading '{(' and trailing ')}'.
276
- parameter = URI.unescape(parameter[2..-3])
276
+ parameter = ::URI::DEFAULT_PARSER.unescape(parameter[2..-3])
277
277
 
278
278
  # Split the path into components and discard the leading '#' that
279
279
  # represents the root of the schema.
@@ -334,7 +334,7 @@ module Heroics
334
334
  # @return [String] The formatted parameter.
335
335
  def format_parameter(parameter)
336
336
  formatted_parameter = parameter.instance_of?(Time) ? iso_format(parameter) : parameter.to_s
337
- URI.escape formatted_parameter
337
+ WEBrick::HTTPUtils.escape formatted_parameter
338
338
  end
339
339
 
340
340
  # Convert a time to an ISO 8601 combined data and time format.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Heroics
3
- VERSION = '0.0.23'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -9,6 +9,7 @@
9
9
 
10
10
  require 'heroics'
11
11
  require 'uri'
12
+ require 'moneta'
12
13
 
13
14
  module <%= @module_name %>
14
15
  # Get a Client configured to use HTTP Basic or header-based authentication.
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus
8
8
  - jkakar
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-19 00:00:00.000000000 Z
12
+ date: 2021-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.3'
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.3'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 4.7.5
42
42
  - !ruby/object:Gem::Dependency
43
- name: moneta
43
+ name: netrc
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: netrc
57
+ name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,7 +68,7 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rake
71
+ name: yard
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: turn
85
+ name: pry
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,27 +96,27 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: yard
99
+ name: erubis
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
104
+ version: '2.0'
105
+ type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '2.0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: pry
113
+ name: excon
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
- type: :development
119
+ type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
@@ -124,21 +124,21 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: erubis
127
+ name: multi_json
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "~>"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: '2.0'
132
+ version: 1.9.2
133
133
  type: :runtime
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "~>"
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: '2.0'
139
+ version: 1.9.2
140
140
  - !ruby/object:Gem::Dependency
141
- name: excon
141
+ name: moneta
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - ">="
@@ -152,19 +152,19 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: multi_json
155
+ name: webrick
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- version: 1.9.2
160
+ version: '0'
161
161
  type: :runtime
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
- version: 1.9.2
167
+ version: '0'
168
168
  description: A Ruby client generator for HTTP APIs described with a JSON schema
169
169
  email:
170
170
  - geemus@gmail.com
@@ -175,8 +175,10 @@ executables:
175
175
  extensions: []
176
176
  extra_rdoc_files: []
177
177
  files:
178
+ - ".github/workflows/check_changelog.yml"
178
179
  - ".gitignore"
179
180
  - ".travis.yml"
181
+ - CHANGELOG.md
180
182
  - CONTRIBUTING.md
181
183
  - CONTRIBUTORS.md
182
184
  - Gemfile
@@ -205,7 +207,7 @@ homepage: https://github.com/interagent/heroics
205
207
  licenses:
206
208
  - MIT
207
209
  metadata: {}
208
- post_install_message:
210
+ post_install_message:
209
211
  rdoc_options: []
210
212
  require_paths:
211
213
  - lib
@@ -220,9 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
222
  - !ruby/object:Gem::Version
221
223
  version: '0'
222
224
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.6.8
225
- signing_key:
225
+ rubygems_version: 3.1.4
226
+ signing_key:
226
227
  specification_version: 4
227
228
  summary: A Ruby client generator for HTTP APIs described with a JSON schema
228
229
  test_files: []