metal_archives 2.2.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +93 -0
  3. data/.gitignore +6 -6
  4. data/.overcommit.yml +35 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +66 -6
  7. data/CHANGELOG.md +33 -0
  8. data/Gemfile +1 -1
  9. data/LICENSE.md +17 -4
  10. data/README.md +65 -86
  11. data/Rakefile +8 -7
  12. data/bin/console +38 -0
  13. data/bin/setup +8 -0
  14. data/config/inflections.rb +7 -0
  15. data/config/initializers/.keep +0 -0
  16. data/docker-compose.yml +23 -0
  17. data/lib/metal_archives.rb +82 -27
  18. data/lib/metal_archives/cache/base.rb +40 -0
  19. data/lib/metal_archives/cache/memory.rb +68 -0
  20. data/lib/metal_archives/cache/null.rb +22 -0
  21. data/lib/metal_archives/cache/redis.rb +49 -0
  22. data/lib/metal_archives/{utils/collection.rb → collection.rb} +3 -5
  23. data/lib/metal_archives/configuration.rb +33 -50
  24. data/lib/metal_archives/{error.rb → errors.rb} +9 -1
  25. data/lib/metal_archives/http_client.rb +45 -44
  26. data/lib/metal_archives/models/artist.rb +90 -45
  27. data/lib/metal_archives/models/band.rb +77 -52
  28. data/lib/metal_archives/models/base.rb +225 -0
  29. data/lib/metal_archives/models/label.rb +14 -15
  30. data/lib/metal_archives/models/release.rb +25 -29
  31. data/lib/metal_archives/parsers/artist.rb +86 -50
  32. data/lib/metal_archives/parsers/band.rb +155 -88
  33. data/lib/metal_archives/parsers/base.rb +14 -0
  34. data/lib/metal_archives/parsers/country.rb +21 -0
  35. data/lib/metal_archives/parsers/date.rb +31 -0
  36. data/lib/metal_archives/parsers/genre.rb +67 -0
  37. data/lib/metal_archives/parsers/label.rb +39 -31
  38. data/lib/metal_archives/parsers/parser.rb +18 -63
  39. data/lib/metal_archives/parsers/release.rb +98 -89
  40. data/lib/metal_archives/parsers/year.rb +31 -0
  41. data/lib/metal_archives/version.rb +12 -1
  42. data/metal_archives.env.example +10 -0
  43. data/metal_archives.gemspec +43 -28
  44. data/nginx/default.conf +60 -0
  45. metadata +179 -74
  46. data/.travis.yml +0 -12
  47. data/lib/metal_archives/middleware/cache_check.rb +0 -20
  48. data/lib/metal_archives/middleware/encoding.rb +0 -16
  49. data/lib/metal_archives/middleware/headers.rb +0 -38
  50. data/lib/metal_archives/middleware/rewrite_endpoint.rb +0 -38
  51. data/lib/metal_archives/models/base_model.rb +0 -215
  52. data/lib/metal_archives/utils/lru_cache.rb +0 -61
  53. data/lib/metal_archives/utils/nil_date.rb +0 -99
  54. data/lib/metal_archives/utils/range.rb +0 -66
  55. data/spec/configuration_spec.rb +0 -96
  56. data/spec/factories/artist_factory.rb +0 -37
  57. data/spec/factories/band_factory.rb +0 -60
  58. data/spec/factories/nil_date_factory.rb +0 -9
  59. data/spec/factories/range_factory.rb +0 -8
  60. data/spec/models/artist_spec.rb +0 -138
  61. data/spec/models/band_spec.rb +0 -164
  62. data/spec/models/base_model_spec.rb +0 -219
  63. data/spec/models/release_spec.rb +0 -133
  64. data/spec/parser_spec.rb +0 -19
  65. data/spec/spec_helper.rb +0 -111
  66. data/spec/support/factory_girl.rb +0 -5
  67. data/spec/support/metal_archives.rb +0 -33
  68. data/spec/utils/collection_spec.rb +0 -72
  69. data/spec/utils/lru_cache_spec.rb +0 -53
  70. data/spec/utils/nil_date_spec.rb +0 -156
  71. data/spec/utils/range_spec.rb +0 -62
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3d67ee1fe72c3fb58bf95f48ee68bda41232857e
4
- data.tar.gz: cfa4704bb7020f4176ad6a14de0b979249e11976
2
+ SHA256:
3
+ metadata.gz: 39ec01fd7f1c69fc54d794cd58693912fd4c1ece0ca6f70c4281ba3b3d7cad4c
4
+ data.tar.gz: d518c8a15a0e5a9fbb26565696aeead06435a06f12dafcd586b54a4c50be5f3e
5
5
  SHA512:
6
- metadata.gz: be9295ee982e7600ad2aba6f5a9ae60fdcdcb5db1039e51a76c18a2fedc53e7899e3ee3c068763c171a3a7a232cbca325d3885d07f1598c4852f73ba7c4b5e17
7
- data.tar.gz: 7a121ab78954206854de8d73d1131030684864dccc68c53429ddc2054cb6cc836b7014b5f8044778992bcd27317caa2f8da0f6c020c4a7f72ae848fd1b84aa39
6
+ metadata.gz: 15cf3a9ae549ff1a43aae068a83b16287c7a70ad95ee176e41dbccac78fe0884031bfff6ec1a4cdda098b7dcbcc7b720b1087cfd9fa3a6da39a766b805321720
7
+ data.tar.gz: f4738548bd36c4af3e97e6a666df23861a3a2bc969a1148d66fccf9cd2d404593f1fb77b3a63a61fa9f1a0325dd754173a7763424653c271abdbefcf201f2817
@@ -0,0 +1,93 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ tags:
8
+ - '*'
9
+ schedule:
10
+ - cron: '0 7 * * 1'
11
+
12
+ jobs:
13
+ build:
14
+ name: Continuous Integration
15
+ runs-on: ubuntu-20.04
16
+ strategy:
17
+ matrix:
18
+ ruby: [ "2.6", "2.7", "3.0" ]
19
+
20
+ container:
21
+ image: ruby:3.0-alpine
22
+
23
+ services:
24
+ redis:
25
+ image: redis:alpine
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+
30
+ - name: Install dependencies
31
+ run: |
32
+ apk add build-base git cmake openssl-dev
33
+ apk add tar
34
+
35
+ - name: Cache Gems
36
+ uses: actions/cache@v2.1.3
37
+ with:
38
+ path: vendor/bundle
39
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
40
+ restore-keys: |
41
+ ${{ runner.os }}-${{ matrix.ruby }}-gem-
42
+
43
+ - name: Install Gems
44
+ run: |
45
+ gem install bundler
46
+ bundle config path vendor/bundle
47
+ bundle install --jobs 4 --retry 3
48
+
49
+ - name: Test
50
+ env:
51
+ MA_ENDPOINT: ${{ secrets.MA_ENDPOINT }}
52
+ MA_ENDPOINT_USER: ${{ secrets.MA_ENDPOINT_USER }}
53
+ MA_ENDPOINT_PASSWORD: ${{ secrets.MA_ENDPOINT_PASSWORD }}
54
+ WEBMOCK_ALLOW_HOST: ${{ secrets.WEBMOCK_ALLOW_HOST }}
55
+ REDIS_URL: "redis://redis:6379/"
56
+ run: bundle exec rspec --profile 10 --format progress
57
+
58
+ - name: Lint
59
+ run: bundle exec rubocop --parallel --display-cop-names
60
+
61
+ release:
62
+ name: Release application
63
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
64
+ runs-on: ubuntu-20.04
65
+ needs: build
66
+
67
+ steps:
68
+ - uses: actions/checkout@v2
69
+
70
+ - name: Set version
71
+ run: |
72
+ echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
73
+
74
+ - name: Publish to RubyGems
75
+ run: |
76
+ mkdir -p ~/.gem
77
+ touch ~/.gem/credentials
78
+ chmod 0600 ~/.gem/credentials
79
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > ~/.gem/credentials
80
+ gem build *.gemspec
81
+ gem push *.gem
82
+ env:
83
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
84
+
85
+ - name: Create Github Release
86
+ uses: actions/create-release@v1
87
+ env:
88
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89
+ with:
90
+ tag_name: ${{ github.ref }}
91
+ release_name: ${{ github.ref }}
92
+ body: |
93
+ Gem ${{ github.event.repository.name }} ${{ env.VERSION }} was released
data/.gitignore CHANGED
@@ -1,6 +1,3 @@
1
- Gemfile.lock
2
- .idea
3
-
4
1
  *.tar.gz
5
2
  *.gem
6
3
  *.rbc
@@ -13,9 +10,12 @@ Gemfile.lock
13
10
  /test/tmp/
14
11
  /test/version_tmp/
15
12
  /tmp/
13
+ nginx/*.key
14
+ nginx/*.pem
16
15
 
17
16
  # Used by dotenv library to load environment variables.
18
17
  # .env
18
+ *.env
19
19
 
20
20
  ## Specific to RubyMotion:
21
21
  .dat*
@@ -46,9 +46,9 @@ build-iPhoneSimulator/
46
46
 
47
47
  # for a library or gem, you might want to ignore these files since the code is
48
48
  # intended to run in multiple environments; otherwise, check them in:
49
- # Gemfile.lock
50
- # .ruby-version
51
- # .ruby-gemset
49
+ Gemfile.lock
50
+ .ruby-version
51
+ .ruby-gemset
52
52
 
53
53
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
54
  .rvmrc
data/.overcommit.yml ADDED
@@ -0,0 +1,35 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/sds/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/sds/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ PreCommit:
19
+ Fasterer:
20
+ enabled: true
21
+
22
+ Flay:
23
+ enabled: true
24
+
25
+ Pronto:
26
+ enabled: true
27
+
28
+ Reek:
29
+ enabled: true
30
+
31
+ RuboCop:
32
+ enabled: true
33
+
34
+ RubySyntax:
35
+ enabled: true
data/.rspec CHANGED
@@ -1 +1,3 @@
1
+ --color
2
+ --fail-fast
1
3
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,5 +1,34 @@
1
- Metrics/LineLength:
2
- Max: 120
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 2.6
8
+
9
+ Layout/LineLength:
10
+ Enabled: false
11
+
12
+ Layout/MultilineMethodCallIndentation:
13
+ EnforcedStyle: indented
14
+
15
+ Layout/ParameterAlignment:
16
+ EnforcedStyle: with_fixed_indentation
17
+
18
+ Lint/AssignmentInCondition:
19
+ AllowSafeAssignment: true
20
+
21
+ Lint/SafeNavigationWithEmpty:
22
+ Enabled: false
23
+
24
+ Metrics/AbcSize:
25
+ Enabled: false
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Enabled: false
29
+
30
+ Metrics/BlockLength:
31
+ Enabled: false
3
32
 
4
33
  Metrics/ClassLength:
5
34
  Enabled: false
@@ -7,11 +36,42 @@ Metrics/ClassLength:
7
36
  Metrics/MethodLength:
8
37
  Enabled: false
9
38
 
10
- Metrics/BlockLength:
39
+ Metrics/PerceivedComplexity:
11
40
  Enabled: false
12
41
 
13
- Style/HashSyntax:
14
- EnforcedStyle: hash_rockets
42
+ RSpec/ExampleLength:
43
+ Enabled: false
44
+
45
+ RSpec/FilePath:
46
+ Exclude:
47
+ - spec/metal_archives/models/*
15
48
 
16
- Style/NestedParenthesizedCalls:
49
+ RSpec/MultipleExpectations:
17
50
  Enabled: false
51
+
52
+ Style/FrozenStringLiteralComment:
53
+ Enabled: true
54
+
55
+ Style/PercentLiteralDelimiters:
56
+ PreferredDelimiters:
57
+ default: "()"
58
+ "%i": "()"
59
+ "%I": "()"
60
+ "%r": "()"
61
+ "%w": "()"
62
+ "%W": "()"
63
+
64
+ Style/StringLiterals:
65
+ EnforcedStyle: double_quotes
66
+
67
+ Style/SymbolArray:
68
+ EnforcedStyle: brackets
69
+
70
+ Style/TrailingCommaInArguments:
71
+ EnforcedStyleForMultiline: consistent_comma
72
+
73
+ Style/TrailingCommaInArrayLiteral:
74
+ EnforcedStyleForMultiline: consistent_comma
75
+
76
+ Style/TrailingCommaInHashLiteral:
77
+ EnforcedStyleForMultiline: consistent_comma
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.1.1
4
+
5
+ - Fix some invalid parsing
6
+
7
+ ## 3.1.0
8
+
9
+ - Add members property on band
10
+
11
+ ## 3.0.0
12
+
13
+ - Dropped support for Ruby < 2.5
14
+ - `MetalArchives::Errors::APIError` changed
15
+ - Dropped support for Faraday middleware
16
+ - Added support for basic authentication
17
+
18
+ ## 2.2.0
19
+
20
+ - Add `Release` model
21
+
22
+ ## 2.1.1
23
+
24
+ - Fix UTF-8 conversion errors
25
+ - Don't `load!` unconditionally on `find!` and `find_by!`
26
+
27
+ ## 2.1.0
28
+
29
+ - Added Ruby compatibility down to 2.1
30
+ - Band and Label: return `NilDate`
31
+
32
+ ## 2.0.0
33
+
34
+ - Artist returns `NilDate`s
35
+
3
36
  ## 1.0.0
4
37
 
5
38
  - Add `Artist#photo`
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
data/LICENSE.md CHANGED
@@ -1,7 +1,20 @@
1
- Copyright (c) 2016 Florian Dejonckheere
1
+ Copyright 2020 Florian Dejonckheere
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
4
10
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
6
13
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,45 +1,54 @@
1
- # Metal Archives Web Service Wrapper [![Travis](https://travis-ci.org/floriandejonckheere/metal_archives.svg?branch=master)](https://travis-ci.org/floriandejonckheere/metal_archives) [![Coverage Status](https://coveralls.io/repos/github/floriandejonckheere/metal_archives/badge.svg)](https://coveralls.io/github/floriandejonckheere/metal_archives)
1
+ # Metal Archives Ruby API
2
+
3
+ ![Continuous Integration](https://github.com/floriandejonckheere/metal_archives/workflows/Continuous%20Integration/badge.svg)
4
+ ![Release](https://img.shields.io/github/v/release/floriandejonckheere/metal_archives?label=Latest%20release)
5
+
6
+
7
+ MetalArchives is a Ruby API that transparently wraps, caches and normalizes the [Metal Archives](https://www.metal-archives.com) website.
2
8
 
3
9
  ## Installation
4
10
 
5
- ```shell
6
- $ gem install metal_archives
11
+ Add this line to your application's Gemfile.
12
+
13
+ ```ruby
14
+ gem "metal_archives"
7
15
  ```
8
16
 
9
- or add it to your Gemfile
17
+ And then execute:
10
18
 
11
- ```ruby
12
- gem 'metal_archives'
19
+ ```sh
20
+ bundle
13
21
  ```
14
22
 
15
- ```shell
16
- $ bundle install
23
+ Or install it yourself as:
24
+
25
+ ```sh
26
+ gem install metal_archives
17
27
  ```
18
28
 
19
29
  ## Configuration
20
30
 
31
+ Configure MetalArchives before using it:
32
+
21
33
  ```ruby
22
34
  MetalArchives.configure do |c|
23
35
  ## Application identity (required)
24
- c.app_name = 'My App'
25
- c.app_version = '1.0'
26
- c.app_contact = 'support@mymusicapp.com'
27
-
28
- ## Request throttling (optional, overrides defaults)
29
- c.request_rate = 1
30
- c.request_timeout = 3
31
-
32
- ## Connect additional Faraday middleware
33
- # c.middleware = [MyMiddleware, MyOtherMiddleware]
34
-
35
- ## Custom cache size per object class (optional, overrides defaults)
36
- c.cache_size = 100
36
+ c.app_name = "My App"
37
+ c.app_version = "1.0"
38
+ c.app_contact = "support@mymusicapp.com"
39
+
40
+ ## Enable Redis as caching backend (optional, overrides default memory cache)
41
+ ## Available cache strategies: :memory, :redis or :null (disable caching)
42
+ # c.cache_strategy = :redis
43
+ # c.cache_options = { url: "redis://redis:6379", ttl: 1.month.to_i }
37
44
 
38
45
  ## Metal Archives endpoint (optional, overrides default)
39
- # c.endpoint = 'http://www.metal-archives.com/'
46
+ # c.endpoint = "https://www.metal-archives.com/"
47
+ # c.endpoint_user = "my_user"
48
+ # c.endpoint_password = "my_password"
40
49
 
41
50
  ## Custom logger (optional)
42
- c.logger = Logger.new File.new('metal_archives.log')
51
+ c.logger = Logger.new File.new("metal_archives.log")
43
52
  c.logger.level = Logger::INFO
44
53
  end
45
54
  ```
@@ -47,24 +56,24 @@ end
47
56
  ## Usage
48
57
 
49
58
  ```ruby
50
- require 'metal_archives'
59
+ require "metal_archives"
51
60
 
52
61
  # Search for bands
53
- @alquimia_list = MetalArchives::Band.search('Alquimia')
62
+ @alquimia_list = MetalArchives::Band.search("Alquimia")
54
63
 
55
64
  # Find bands by name
56
- @iron_maiden = MetalArchives::Band.find_by(:name => 'Iron Maiden')
65
+ @iron_maiden = MetalArchives::Band.find_by(name: "Iron Maiden")
57
66
 
58
67
  # Find bands by attributes
59
- require 'countries'
68
+ require "countries"
60
69
 
61
- @bands_in_belgium = MetalArchives::Band.search_by :country => ISO3166::Country['BE']
62
- @bands_formed_in_1990 = MetalArchives::Band.search_by :year => Range.new(Date.new(1990))
70
+ @bands_in_belgium = MetalArchives::Band.search_by(country: ISO3166::Country["BE"])
71
+ @bands_formed_in_1990 = MetalArchives::Band.search_by(year: 1990..)
63
72
 
64
73
  # Metal Archives' usual tips apply
65
74
 
66
- @bands_containing_hell = MetalArchives::Band.search_by :name => '*hell*'
67
- @non_melodic_death_bands = MetalArchives::Band.search_by :genre => 'death -melodic'
75
+ @bands_containing_hell = MetalArchives::Band.search_by name: "*hell*"
76
+ @non_melodic_death_bands = MetalArchives::Band.search_by genre: "death -melodic"
68
77
 
69
78
  # Methods returning multiple results return a MetalArchives::Collection.
70
79
  # Collection wraps a paginated resource, and can be used to iterate over huge queries.
@@ -77,79 +86,49 @@ Refer to the model's [RDoc documentation](https://floriandejonckheere.github.io/
77
86
 
78
87
  ## Lazy loading
79
88
 
80
- By default when an model (Artist, Band, ...) is created, no data is fetched. This leads to instantiation of a model with an invalid ID not throwing any errors. Calling any attribute other than `id` will cause all data to be fetched and any errors to be thrown. Refer to the respective methods to find out what errors are thrown in what circumstances.
89
+ By default when an model (Artist, Band, ...) is created, no data is fetched.
90
+ This leads to instantiation of a model with an invalid ID not throwing any errors.
91
+ Calling any attribute other than `id` will cause all data to be fetched and any errors to be thrown.
92
+ Refer to the respective methods to find out what errors are thrown in what circumstances.
81
93
 
82
- Models can be forced to load all data by calling the `:load!` method.
94
+ Models can be forced to load all data by calling the `load!` method.
83
95
 
84
96
  ## Cache
85
97
 
86
- In order not to stress the Metal Archives server, you can quickly set up a local proxy that caches the requests. For NGINX, adjust the following configuration:
87
-
88
- ```
89
- # Set cache dir
90
- proxy_cache_path /var/cache/nginx/metal_archives levels=1:2 keys_zone=metal_archives:10m;
91
-
92
- # Set cache key to include identifying components
93
- proxy_cache_key $scheme$proxy_host$request_uri;
94
-
95
- # Add cache status to log
96
- log_format cache '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" cs=$upstream_cache_status';
97
-
98
- server {
99
- server_name metal-archives.myhost.com;
100
- listen 443 ssl;
101
- listen [::]:443 ssl;
102
-
103
- ssl_certificate /path/to/ssl_certificate.crt;
104
- ssl_certificate_key /path/to/ssl_certificate_key.key;
98
+ The gem has builtin caching functionality.
99
+ By default, an in-memory cache is used that evicts cache entries using an LRU-based algorithm.
100
+ However, it is also possible to use Redis as a caching backend.
101
+ Don't forget to include the `redis` gem in your application bundle if you wish to use Redis caching.
105
102
 
106
- access_log /var/log/nginx/metal_archives_access.log;
107
- error_log /var/log/nginx/metal_archives_error.log;
103
+ In order not to stress the Metal Archives server, you can quickly set up a local HTTP proxy that caches the requests.
108
104
 
109
- # Limit HTTP requests
110
- limit_req_zone $binary_remote_addr zone=ma_limit_req:10m rate=2r/s;
111
-
112
- location / {
113
- proxy_redirect off;
114
- proxy_set_header Host www.metal-archives.com;
115
- proxy_set_header X-Forwarded-Host $host;
116
- proxy_set_header X-Forwarded-Server $host;
117
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
118
- proxy_set_header X-Real-IP $remote_addr;
119
-
120
- proxy_pass https://www.metal-archives.com/;
105
+ ```
106
+ # Generate TLS client certificates for NGINX
107
+ openssl req -nodes -new -x509 -keyout nginx/client.key -out nginx/client.pem
121
108
 
122
- limit_req zone=ma_limit_req burst=5;
123
109
 
124
- proxy_ignore_headers X-Accel-Expires;
125
- proxy_ignore_headers Expires;
126
- proxy_ignore_headers Cache-Control;
127
- proxy_ignore_headers Set-Cookie;
110
+ # Start proxy server
111
+ docker-compose up -d
112
+ ```
128
113
 
129
- proxy_hide_header Set-Cookie;
130
- proxy_hide_header Pragma;
114
+ A caching proxy server is now available on `http://localhost:8080/`.
131
115
 
132
- # Cache valid responses for 30 days
133
- proxy_cache metal_archives;
134
- proxy_cache_valid 200 301 302 30d;
135
- proxy_cache_valid 404 7d;
136
- expires 30d;
137
- }
116
+ ## Testing
138
117
 
139
- add_header X-Cache-Status $upstream_cache_status;
140
- }
141
- ```
118
+ Run tests:
142
119
 
143
- ## Testing
144
120
  ```
145
- $ bundle exec rake test
121
+ bundle exec rake test
146
122
  ```
147
123
 
148
124
  ## Documentation
125
+
126
+ Generate documentation:
127
+
149
128
  ```
150
129
  $ bundle exec rake rdoc
151
130
  ```
152
131
 
153
- ## Copyright
132
+ ## License
154
133
 
155
- Copyright 2016 Florian Dejonckheere. All content acquired through the usage of this API is copyrighted by the respective owner.
134
+ See [LICENSE.md](LICENSE.md).