opdb 0.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 +7 -0
- data/.github/workflows/main.yml +70 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +87 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/opdb.rb +8 -0
- data/lib/opdb/api_exceptions.rb +17 -0
- data/lib/opdb/client.rb +133 -0
- data/lib/opdb/http_status_codes.rb +12 -0
- data/lib/opdb/version.rb +5 -0
- data/opdb.gemspec +41 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 619de4cfb632eba4c24a9f8b1fcf0c7461e11a7dafcb7642878eb3a09452776e
|
4
|
+
data.tar.gz: 8f430d3f170f772b5acf14bf77a5146008e7053b8a4a0698bda900e1998d6a44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5eba5ffc5dc0e6a13d81f3a513de601d586ee3205a0fa80d4e11c77968084c681276ad08dd3b55b08134720cfb8b91c12ffc51ba35ab735bc4466f49d413ee16
|
7
|
+
data.tar.gz: 290004b9fd5c1bf4e0d7b77dad049e4277897e2cb8dc3f96b869da3fd1d4eb40a1877cefca6368c626f6aa60ca7eb68cb39849ebec52be4d260fbeb315835a07
|
@@ -0,0 +1,70 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
tags:
|
9
|
+
- v*
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby:
|
18
|
+
- 2.5
|
19
|
+
- 2.6
|
20
|
+
- 2.7
|
21
|
+
- 3.0
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: actions/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
architecture: 'x64'
|
31
|
+
|
32
|
+
- name: Setup bundler
|
33
|
+
run: |
|
34
|
+
gem install bundler --no-doc
|
35
|
+
bundle config path vendor/bundle
|
36
|
+
- name: Bundler cache
|
37
|
+
uses: actions/cache@v2
|
38
|
+
with:
|
39
|
+
path: vendor/bundle
|
40
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
41
|
+
restore-keys: |
|
42
|
+
${{ runner.os }}-gems-
|
43
|
+
- name: Setup gems
|
44
|
+
run: bundle install --jobs 4
|
45
|
+
|
46
|
+
- name: Rubocop
|
47
|
+
run: bundle exec rubocop
|
48
|
+
|
49
|
+
- name: RSpec
|
50
|
+
run: bundle exec rspec
|
51
|
+
|
52
|
+
publish:
|
53
|
+
if: contains(github.ref, 'refs/tags/v')
|
54
|
+
needs: build
|
55
|
+
runs-on: ubuntu-latest
|
56
|
+
|
57
|
+
steps:
|
58
|
+
- uses: actions/checkout@v2
|
59
|
+
|
60
|
+
- name: Release Gem
|
61
|
+
|
62
|
+
run: |
|
63
|
+
mkdir -p $HOME/.gem
|
64
|
+
touch $HOME/.gem/credentials
|
65
|
+
chmod 0600 $HOME/.gem/credentials
|
66
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
67
|
+
gem build *.gemspec
|
68
|
+
gem push *.gem
|
69
|
+
env:
|
70
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
Gemspec/DateAssignment: # (new in 1.10)
|
17
|
+
Enabled: true
|
18
|
+
Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
|
19
|
+
Enabled: true
|
20
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
21
|
+
Enabled: true
|
22
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
23
|
+
Enabled: true
|
24
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
25
|
+
Enabled: true
|
26
|
+
Lint/DuplicateBranch: # (new in 1.3)
|
27
|
+
Enabled: true
|
28
|
+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
29
|
+
Enabled: true
|
30
|
+
Lint/EmptyBlock: # (new in 1.1)
|
31
|
+
Enabled: true
|
32
|
+
Lint/EmptyClass: # (new in 1.3)
|
33
|
+
Enabled: true
|
34
|
+
Lint/EmptyInPattern: # (new in 1.16)
|
35
|
+
Enabled: true
|
36
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
37
|
+
Enabled: true
|
38
|
+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
39
|
+
Enabled: true
|
40
|
+
Lint/NumberedParameterAssignment: # (new in 1.9)
|
41
|
+
Enabled: true
|
42
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
43
|
+
Enabled: true
|
44
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
45
|
+
Enabled: true
|
46
|
+
Lint/SymbolConversion: # (new in 1.9)
|
47
|
+
Enabled: true
|
48
|
+
Lint/ToEnumArguments: # (new in 1.1)
|
49
|
+
Enabled: true
|
50
|
+
Lint/TripleQuotes: # (new in 1.9)
|
51
|
+
Enabled: true
|
52
|
+
Lint/UnexpectedBlockArity: # (new in 1.5)
|
53
|
+
Enabled: true
|
54
|
+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
55
|
+
Enabled: true
|
56
|
+
Naming/InclusiveLanguage: # (new in 1.18)
|
57
|
+
Enabled: true
|
58
|
+
Style/ArgumentsForwarding: # (new in 1.1)
|
59
|
+
Enabled: true
|
60
|
+
Style/CollectionCompact: # (new in 1.2)
|
61
|
+
Enabled: true
|
62
|
+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
63
|
+
Enabled: true
|
64
|
+
Style/EndlessMethod: # (new in 1.8)
|
65
|
+
Enabled: true
|
66
|
+
Style/HashConversion: # (new in 1.10)
|
67
|
+
Enabled: true
|
68
|
+
Style/HashExcept: # (new in 1.7)
|
69
|
+
Enabled: true
|
70
|
+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
71
|
+
Enabled: true
|
72
|
+
Style/InPatternThen: # (new in 1.16)
|
73
|
+
Enabled: true
|
74
|
+
Style/MultilineInPatternThen: # (new in 1.16)
|
75
|
+
Enabled: true
|
76
|
+
Style/NegatedIfElseCondition: # (new in 1.2)
|
77
|
+
Enabled: true
|
78
|
+
Style/NilLambda: # (new in 1.3)
|
79
|
+
Enabled: true
|
80
|
+
Style/QuotedSymbols: # (new in 1.16)
|
81
|
+
Enabled: true
|
82
|
+
Style/RedundantArgument: # (new in 1.4)
|
83
|
+
Enabled: true
|
84
|
+
Style/StringChars: # (new in 1.12)
|
85
|
+
Enabled: true
|
86
|
+
Style/SwapValues: # (new in 1.1)
|
87
|
+
Enabled: true
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
opdb (0.1.0)
|
5
|
+
faraday (~> 1.5.0)
|
6
|
+
faraday_middleware (~> 1.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
coderay (1.1.3)
|
15
|
+
crack (0.4.5)
|
16
|
+
rexml
|
17
|
+
diff-lcs (1.4.4)
|
18
|
+
faraday (1.5.1)
|
19
|
+
faraday-em_http (~> 1.0)
|
20
|
+
faraday-em_synchrony (~> 1.0)
|
21
|
+
faraday-excon (~> 1.1)
|
22
|
+
faraday-httpclient (~> 1.0.1)
|
23
|
+
faraday-net_http (~> 1.0)
|
24
|
+
faraday-net_http_persistent (~> 1.1)
|
25
|
+
faraday-patron (~> 1.0)
|
26
|
+
multipart-post (>= 1.2, < 3)
|
27
|
+
ruby2_keywords (>= 0.0.4)
|
28
|
+
faraday-em_http (1.0.0)
|
29
|
+
faraday-em_synchrony (1.0.0)
|
30
|
+
faraday-excon (1.1.0)
|
31
|
+
faraday-httpclient (1.0.1)
|
32
|
+
faraday-net_http (1.0.1)
|
33
|
+
faraday-net_http_persistent (1.2.0)
|
34
|
+
faraday-patron (1.0.0)
|
35
|
+
faraday_middleware (1.1.0)
|
36
|
+
faraday (~> 1.0)
|
37
|
+
hashdiff (1.0.1)
|
38
|
+
method_source (1.0.0)
|
39
|
+
multipart-post (2.1.1)
|
40
|
+
parallel (1.20.1)
|
41
|
+
parser (3.0.2.0)
|
42
|
+
ast (~> 2.4.1)
|
43
|
+
pry (0.14.1)
|
44
|
+
coderay (~> 1.1)
|
45
|
+
method_source (~> 1.0)
|
46
|
+
public_suffix (4.0.6)
|
47
|
+
rainbow (3.0.0)
|
48
|
+
rake (13.0.6)
|
49
|
+
regexp_parser (2.1.1)
|
50
|
+
rexml (3.2.5)
|
51
|
+
rspec (3.10.0)
|
52
|
+
rspec-core (~> 3.10.0)
|
53
|
+
rspec-expectations (~> 3.10.0)
|
54
|
+
rspec-mocks (~> 3.10.0)
|
55
|
+
rspec-core (3.10.1)
|
56
|
+
rspec-support (~> 3.10.0)
|
57
|
+
rspec-expectations (3.10.1)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.10.0)
|
60
|
+
rspec-mocks (3.10.2)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-support (3.10.2)
|
64
|
+
rubocop (1.18.4)
|
65
|
+
parallel (~> 1.10)
|
66
|
+
parser (>= 3.0.0.0)
|
67
|
+
rainbow (>= 2.2.2, < 4.0)
|
68
|
+
regexp_parser (>= 1.8, < 3.0)
|
69
|
+
rexml
|
70
|
+
rubocop-ast (>= 1.8.0, < 2.0)
|
71
|
+
ruby-progressbar (~> 1.7)
|
72
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
73
|
+
rubocop-ast (1.8.0)
|
74
|
+
parser (>= 3.0.1.1)
|
75
|
+
ruby-progressbar (1.11.0)
|
76
|
+
ruby2_keywords (0.0.5)
|
77
|
+
unicode-display_width (2.0.0)
|
78
|
+
webmock (3.13.0)
|
79
|
+
addressable (>= 2.3.6)
|
80
|
+
crack (>= 0.3.2)
|
81
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
82
|
+
|
83
|
+
PLATFORMS
|
84
|
+
x86_64-darwin-20
|
85
|
+
|
86
|
+
DEPENDENCIES
|
87
|
+
opdb!
|
88
|
+
pry (~> 0.14)
|
89
|
+
rake (~> 13.0)
|
90
|
+
rspec (~> 3.0)
|
91
|
+
rubocop (~> 1.7)
|
92
|
+
webmock (~> 3.13)
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.2.16
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Mollemoll
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Opdb
|
2
|
+
|
3
|
+
This gem is a simple API wrapper for the [Open Pinball Database API](https://opdb.org/api) for ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opdb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install opdb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
By initializing a Opdb::Client without a api_token you will gain access to the public endpoints like Opdb typeahead_search and changelog.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
opdb_client = Opdb::Client.new
|
27
|
+
|
28
|
+
opdb_client.typeahead_search(q: "Metallica")
|
29
|
+
|
30
|
+
opdb_client.changelog
|
31
|
+
```
|
32
|
+
|
33
|
+
To access the full Open Pinball Database you will have to sign up for an account at their webpage [https://opdb.org/api](https://opdb.org/api) and initialize the client with your api_token:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
opdb_client = Opdb::Client.new(api_token: "your-valid-token") //Remember to put your token in an env variable/secrets
|
37
|
+
|
38
|
+
opdb_client.search_machines(q: "Metallica (PRO LED)")
|
39
|
+
|
40
|
+
opdb_client.get_machine_info(opdb_id: "GRBE4-MQK1Z-A9Yn1")
|
41
|
+
|
42
|
+
opdb_client.get_machine_info_by_ipdb_id(ipdb_id: 6179)
|
43
|
+
|
44
|
+
opdb_client.export_machines //Note: This endpoint is rate limited and you will only be able to request the export once per hour.
|
45
|
+
|
46
|
+
opdb_client.export_machine_groups
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mollemoll/opdb.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "opdb"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/opdb.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiExceptions
|
4
|
+
class ApiExceptionError < StandardError; end
|
5
|
+
|
6
|
+
class BadRequestError < ApiExceptionError; end
|
7
|
+
|
8
|
+
class UnauthorizedError < ApiExceptionError; end
|
9
|
+
|
10
|
+
class ForbiddenError < ApiExceptionError; end
|
11
|
+
|
12
|
+
class NotFoundError < ApiExceptionError; end
|
13
|
+
|
14
|
+
class UnprocessableEntityError < ApiExceptionError; end
|
15
|
+
|
16
|
+
class ApiError < ApiExceptionError; end
|
17
|
+
end
|
data/lib/opdb/client.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "faraday_middleware"
|
5
|
+
require "opdb/http_status_codes"
|
6
|
+
require "opdb/api_exceptions"
|
7
|
+
|
8
|
+
module Opdb
|
9
|
+
# Client wrapping the Open Pinball Database API
|
10
|
+
class Client # rubocop:disable Metrics/ClassLength
|
11
|
+
include ApiExceptions
|
12
|
+
include HttpStatusCodes
|
13
|
+
|
14
|
+
API_BASE_URI = "https://opdb.org/api"
|
15
|
+
|
16
|
+
attr_reader :api_token
|
17
|
+
|
18
|
+
def initialize(api_token: nil)
|
19
|
+
@api_token = api_token
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public Requests
|
23
|
+
def changelog
|
24
|
+
request(
|
25
|
+
http_method: :get,
|
26
|
+
endpoint: "changelog"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def typeahead_search(q:, include_groups: "0", include_aliases: "1") # rubocop:disable Naming/MethodParameterName
|
31
|
+
request(
|
32
|
+
http_method: :get,
|
33
|
+
endpoint: "search/typeahead",
|
34
|
+
params: {
|
35
|
+
q: q,
|
36
|
+
include_groups: include_groups,
|
37
|
+
include_aliases: include_aliases
|
38
|
+
}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Requests that require a valid api_token
|
43
|
+
def search_machines(q:, require_opdb: "1", include_groups: "0", include_aliases: "1", include_grouping_entries: "0") # rubocop:disable Naming/MethodParameterName, Metrics/MethodLength
|
44
|
+
private_request(
|
45
|
+
http_method: :get,
|
46
|
+
endpoint: "search",
|
47
|
+
params: {
|
48
|
+
q: q,
|
49
|
+
require_opdb: require_opdb,
|
50
|
+
include_groups: include_groups,
|
51
|
+
include_aliases: include_aliases,
|
52
|
+
include_grouping_entries: include_grouping_entries
|
53
|
+
}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_machine_info(opdb_id:)
|
58
|
+
private_request(
|
59
|
+
http_method: :get,
|
60
|
+
endpoint: "machines/#{opdb_id}"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_machine_info_by_ipdb_id(ipdb_id:)
|
65
|
+
private_request(
|
66
|
+
http_method: :get,
|
67
|
+
endpoint: "machines/ipdb/#{ipdb_id}"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def export_machines
|
72
|
+
private_request(
|
73
|
+
http_method: :get,
|
74
|
+
endpoint: "export"
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def export_machine_groups
|
79
|
+
private_request(
|
80
|
+
http_method: :get,
|
81
|
+
endpoint: "export/groups"
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def client
|
88
|
+
@client ||= Faraday.new(API_BASE_URI) do |client|
|
89
|
+
client.response :json
|
90
|
+
client.headers["Accept"] = "application/json"
|
91
|
+
client.headers["User-Agent"] = "opdb ruby client #{Opdb::VERSION}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def request(http_method:, endpoint:, params: {})
|
96
|
+
response = client.public_send(http_method, endpoint, params)
|
97
|
+
|
98
|
+
return response.body if response.status == HTTP_OK_CODE
|
99
|
+
|
100
|
+
raise error_class(response.status), response.body.to_json
|
101
|
+
end
|
102
|
+
|
103
|
+
def private_request(http_method:, endpoint:, params: {})
|
104
|
+
raise "Api key not set" unless @api_token
|
105
|
+
|
106
|
+
params.merge!(
|
107
|
+
{ api_token: api_token }
|
108
|
+
)
|
109
|
+
request(
|
110
|
+
http_method: http_method,
|
111
|
+
endpoint: endpoint,
|
112
|
+
params: params
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
def error_class(response_status) # rubocop:disable Metrics/MethodLength
|
117
|
+
case response_status
|
118
|
+
when HTTP_BAD_REQUEST_CODE
|
119
|
+
BadRequestError
|
120
|
+
when HTTP_UNAUTHORIZED_CODE
|
121
|
+
UnauthorizedError
|
122
|
+
when HTTP_FORBIDDEN_CODE
|
123
|
+
ForbiddenError
|
124
|
+
when HTTP_NOT_FOUND_CODE
|
125
|
+
NotFoundError
|
126
|
+
when HTTP_UNPROCESSABLE_ENTITY_CODE
|
127
|
+
UnprocessableEntityError
|
128
|
+
else
|
129
|
+
ApiError
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# HTTP status codes
|
4
|
+
module HttpStatusCodes
|
5
|
+
HTTP_OK_CODE = 200
|
6
|
+
|
7
|
+
HTTP_BAD_REQUEST_CODE = 400
|
8
|
+
HTTP_UNAUTHORIZED_CODE = 401
|
9
|
+
HTTP_FORBIDDEN_CODE = 403
|
10
|
+
HTTP_NOT_FOUND_CODE = 404
|
11
|
+
HTTP_UNPROCESSABLE_ENTITY_CODE = 429
|
12
|
+
end
|
data/lib/opdb/version.rb
ADDED
data/opdb.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/opdb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "opdb"
|
7
|
+
spec.version = Opdb::VERSION
|
8
|
+
spec.authors = ["Mollemoll"]
|
9
|
+
spec.email = ["jm@jmol.se"]
|
10
|
+
|
11
|
+
spec.summary = "A ruby api-wrapper for the open pinball database"
|
12
|
+
spec.homepage = "https://github.com/Mollemoll/opdb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/Mollemoll/opdb"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/Mollemoll/opdb/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
# Uncomment to register a new dependency of your gem
|
30
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
31
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "rubocop", "~> 1.7"
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.13"
|
35
|
+
|
36
|
+
spec.add_dependency "faraday", "~> 1.5.0"
|
37
|
+
spec.add_dependency "faraday_middleware", "~> 1.1.0"
|
38
|
+
|
39
|
+
# For more information and examples about making a new gem, checkout our
|
40
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mollemoll
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.5.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.5.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.0
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- jm@jmol.se
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".github/workflows/main.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".ruby-version"
|
123
|
+
- CHANGELOG.md
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- lib/opdb.rb
|
132
|
+
- lib/opdb/api_exceptions.rb
|
133
|
+
- lib/opdb/client.rb
|
134
|
+
- lib/opdb/http_status_codes.rb
|
135
|
+
- lib/opdb/version.rb
|
136
|
+
- opdb.gemspec
|
137
|
+
homepage: https://github.com/Mollemoll/opdb
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata:
|
141
|
+
homepage_uri: https://github.com/Mollemoll/opdb
|
142
|
+
source_code_uri: https://github.com/Mollemoll/opdb
|
143
|
+
changelog_uri: https://github.com/Mollemoll/opdb/CHANGELOG.md
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.5.0
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubygems_version: 3.1.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: A ruby api-wrapper for the open pinball database
|
163
|
+
test_files: []
|