torn_ruby 0.1.0.beta → 1.0.1.beta
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/.github/workflows/main.yml +27 -0
- data/.gitignore +11 -0
- data/CHANGELOG.md +14 -2
- data/Gemfile +25 -0
- data/Gemfile.lock +95 -0
- data/README.md +12 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/torn_ruby/client.rb +32 -11
- data/lib/torn_ruby/endpoints/base.rb +7 -7
- data/lib/torn_ruby/endpoints/company.rb +1 -5
- data/lib/torn_ruby/endpoints/faction.rb +1 -5
- data/lib/torn_ruby/endpoints/forum.rb +17 -0
- data/lib/torn_ruby/endpoints/market.rb +1 -5
- data/lib/torn_ruby/endpoints/property.rb +1 -5
- data/lib/torn_ruby/endpoints/racing.rb +18 -0
- data/lib/torn_ruby/endpoints/torn.rb +21 -0
- data/lib/torn_ruby/endpoints/user.rb +1 -5
- data/lib/torn_ruby/forum.rb +10 -0
- data/lib/torn_ruby/racing.rb +11 -0
- data/lib/torn_ruby/torn.rb +11 -0
- data/lib/torn_ruby/version.rb +1 -1
- data/spec/spec_helper.rb +18 -0
- data/spec/torn_ruby/base_spec.rb +73 -0
- data/spec/torn_ruby/client_spec.rb +336 -0
- data/spec/torn_ruby/company_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/company_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/faction_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/forum_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/market_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/property_spec.rb +34 -0
- data/spec/torn_ruby/endpoints/racing_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/torn_spec.rb +3 -0
- data/spec/torn_ruby/endpoints/user_spec.rb +3 -0
- data/spec/torn_ruby/faction_spec.rb +3 -0
- data/spec/torn_ruby/forum_spec.rb +3 -0
- data/spec/torn_ruby/market_spec.rb +3 -0
- data/spec/torn_ruby/property_spec.rb +44 -0
- data/spec/torn_ruby/racing_spec.rb +3 -0
- data/spec/torn_ruby/torn_spec.rb +3 -0
- data/spec/torn_ruby/user_spec.rb +3 -0
- data/spec/torn_ruby/utils_spec.rb +32 -0
- data/spec/torn_ruby_spec.rb +1 -0
- data/torn_ruby.gemspec +48 -0
- metadata +45 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf1168a05ee032a581d00e8188c2f53ab677a02c828cf6ec8320b68e48b4c220
|
4
|
+
data.tar.gz: 33188bb3d07fb5c107dfb9c7ca9a84d476f7f2389e4a2f976dff5677fca0565c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2fc12525e4c16a927c0772301572906098f611fcca87433998e954e1f31cb4dab5b92b653f396560825e17de875e3ffab4b4557f294dfeac416cf2d62e82a6
|
7
|
+
data.tar.gz: 15942273fcc790da47b136513824d9c8dfb84e27c98f1bbb18b562b6cc8acda2433281a9de0c0cbfaf6be6d60d15afbc71c4c1d1668df0d402735adf55b4a697
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '3.3.5'
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v4
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
- name: Run the default task
|
27
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.1.0] - 2025-04-18
|
3
|
+
## [0.1.0.beta] - 2025-04-18
|
4
4
|
|
5
|
-
- Initial release
|
5
|
+
- Initial Beta release
|
6
|
+
- Published gem to RubyGems
|
7
|
+
- Added `User`, `Faction`, `Property`, `Market` and `Company` endpoints
|
8
|
+
- Introduced `valid_fields?` method for field validation in endpoints
|
9
|
+
- Setup versioning and pre-release (beta) for early testing
|
10
|
+
|
11
|
+
## [1.0.0.beta] - 2025-04-18
|
12
|
+
|
13
|
+
- Fully implemented support for Torn API v2 endpoints
|
14
|
+
- Added `Racing`, `Forum` , `Torn` endpoint
|
15
|
+
- Improved internal architecture by extracting common logic to `Base` endpoint class
|
16
|
+
- Added comprehensive test coverage for all v2 endpoints
|
17
|
+
- Refactored and documented code for maintainability and clarity
|
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in torn_ruby.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
gem "rubocop-rspec", "~> 3.6"
|
15
|
+
|
16
|
+
gem "rubocop-rake", "~> 0.7.1"
|
17
|
+
|
18
|
+
group :development, :test do
|
19
|
+
gem "pry"
|
20
|
+
gem "pry-byebug"
|
21
|
+
end
|
22
|
+
|
23
|
+
group :test do
|
24
|
+
gem "simplecov", require: false
|
25
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
torn_ruby (0.1.0.beta)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.3)
|
10
|
+
byebug (12.0.0)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.6.1)
|
13
|
+
docile (1.4.1)
|
14
|
+
fiddle (1.1.2)
|
15
|
+
json (2.10.2)
|
16
|
+
language_server-protocol (3.17.0.4)
|
17
|
+
lint_roller (1.1.0)
|
18
|
+
method_source (1.1.0)
|
19
|
+
parallel (1.27.0)
|
20
|
+
parser (3.3.8.0)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
racc
|
23
|
+
prism (1.4.0)
|
24
|
+
pry (0.15.2)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
pry-byebug (3.11.0)
|
28
|
+
byebug (~> 12.0)
|
29
|
+
pry (>= 0.13, < 0.16)
|
30
|
+
racc (1.8.1)
|
31
|
+
rainbow (3.1.1)
|
32
|
+
rake (13.2.1)
|
33
|
+
regexp_parser (2.10.0)
|
34
|
+
rspec (3.13.0)
|
35
|
+
rspec-core (~> 3.13.0)
|
36
|
+
rspec-expectations (~> 3.13.0)
|
37
|
+
rspec-mocks (~> 3.13.0)
|
38
|
+
rspec-core (3.13.3)
|
39
|
+
rspec-support (~> 3.13.0)
|
40
|
+
rspec-expectations (3.13.3)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.13.0)
|
43
|
+
rspec-mocks (3.13.2)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.13.0)
|
46
|
+
rspec-support (3.13.2)
|
47
|
+
rubocop (1.75.2)
|
48
|
+
json (~> 2.3)
|
49
|
+
language_server-protocol (~> 3.17.0.2)
|
50
|
+
lint_roller (~> 1.1.0)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.3.0.2)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
55
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
58
|
+
rubocop-ast (1.44.1)
|
59
|
+
parser (>= 3.3.7.2)
|
60
|
+
prism (~> 1.4)
|
61
|
+
rubocop-rake (0.7.1)
|
62
|
+
lint_roller (~> 1.1)
|
63
|
+
rubocop (>= 1.72.1)
|
64
|
+
rubocop-rspec (3.6.0)
|
65
|
+
lint_roller (~> 1.1)
|
66
|
+
rubocop (~> 1.72, >= 1.72.1)
|
67
|
+
ruby-progressbar (1.13.0)
|
68
|
+
simplecov (0.22.0)
|
69
|
+
docile (~> 1.1)
|
70
|
+
simplecov-html (~> 0.11)
|
71
|
+
simplecov_json_formatter (~> 0.1)
|
72
|
+
simplecov-html (0.13.1)
|
73
|
+
simplecov_json_formatter (0.1.4)
|
74
|
+
unicode-display_width (3.1.4)
|
75
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
76
|
+
unicode-emoji (4.0.4)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
x86_64-linux
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
fiddle (~> 1.1)
|
84
|
+
pry
|
85
|
+
pry-byebug
|
86
|
+
rake (~> 13.0)
|
87
|
+
rspec (~> 3.0)
|
88
|
+
rubocop (~> 1.21)
|
89
|
+
rubocop-rake (~> 0.7.1)
|
90
|
+
rubocop-rspec (~> 3.6)
|
91
|
+
simplecov
|
92
|
+
torn_ruby!
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.6.3
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# TornRuby
|
2
|
+
[](https://badge.fury.io/rb/torn_ruby)
|
2
3
|
|
3
4
|
An implementation of the [Torn](https://www.torn.com/api.html) V2 API using Ruby.
|
4
5
|
|
@@ -20,9 +21,20 @@ gem install torn_ruby
|
|
20
21
|
To use the TornRuby gem, you’ll need a valid Torn API key.
|
21
22
|
|
22
23
|
```ruby
|
24
|
+
require "torn_ruby"
|
25
|
+
|
23
26
|
api_key = "Valid Torn Api Key"
|
24
27
|
client = TornRuby::Client.new(api_key:)
|
28
|
+
|
29
|
+
# Fetch basic data
|
25
30
|
user = client.user
|
31
|
+
puts user.name # => "YourTornName"
|
32
|
+
|
33
|
+
# Fetch specific selections by passing symbols
|
34
|
+
user = client.user(selections: [:profile])
|
35
|
+
|
36
|
+
# Some endpoints require you to specify a path
|
37
|
+
racing = client.racing(path: :carupgrades)
|
26
38
|
```
|
27
39
|
|
28
40
|
## Contributing
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/torn_ruby/client.rb
CHANGED
@@ -5,11 +5,17 @@ require_relative "endpoints/property"
|
|
5
5
|
require_relative "endpoints/faction"
|
6
6
|
require_relative "endpoints/company"
|
7
7
|
require_relative "endpoints/market"
|
8
|
+
require_relative "endpoints/torn"
|
9
|
+
require_relative "endpoints/racing"
|
10
|
+
require_relative "endpoints/forum"
|
8
11
|
require_relative "user"
|
9
12
|
require_relative "property"
|
10
13
|
require_relative "faction"
|
11
14
|
require_relative "company"
|
12
15
|
require_relative "market"
|
16
|
+
require_relative "torn"
|
17
|
+
require_relative "racing"
|
18
|
+
require_relative "forum"
|
13
19
|
|
14
20
|
module TornRuby
|
15
21
|
# Responsible for interacting with the Torn API
|
@@ -19,29 +25,44 @@ module TornRuby
|
|
19
25
|
@api_key = api_key
|
20
26
|
end
|
21
27
|
|
22
|
-
def user(
|
23
|
-
data = TornRuby::Endpoints::User.new(@api_key).fetch(
|
28
|
+
def user(path: nil, selections: nil)
|
29
|
+
data = TornRuby::Endpoints::User.new(@api_key).fetch(path:, selections:)
|
24
30
|
TornRuby::User.new(data)
|
25
31
|
end
|
26
32
|
|
27
|
-
def property(
|
28
|
-
data = TornRuby::Endpoints::Property.new(@api_key).fetch(
|
33
|
+
def property(path: nil, selections: nil)
|
34
|
+
data = TornRuby::Endpoints::Property.new(@api_key).fetch(path:, selections:)
|
29
35
|
TornRuby::Property.new(data)
|
30
36
|
end
|
31
37
|
|
32
|
-
def faction(
|
33
|
-
data = TornRuby::Endpoints::Faction.new(@api_key).fetch(
|
38
|
+
def faction(path: nil, selections: nil)
|
39
|
+
data = TornRuby::Endpoints::Faction.new(@api_key).fetch(path:, selections:)
|
34
40
|
TornRuby::Faction.new(data)
|
35
41
|
end
|
36
42
|
|
37
|
-
def company(
|
38
|
-
data = TornRuby::Endpoints::Company.new(@api_key).fetch(
|
43
|
+
def company(path: nil, selections: nil)
|
44
|
+
data = TornRuby::Endpoints::Company.new(@api_key).fetch(path:, selections:)
|
39
45
|
TornRuby::Company.new(data)
|
40
46
|
end
|
41
47
|
|
42
|
-
def market(
|
43
|
-
data = TornRuby::Endpoints::Market.new(@api_key).fetch(
|
44
|
-
TornRuby::
|
48
|
+
def market(path: nil, selections: nil)
|
49
|
+
data = TornRuby::Endpoints::Market.new(@api_key).fetch(path:, selections:)
|
50
|
+
TornRuby::Company.new(data)
|
51
|
+
end
|
52
|
+
|
53
|
+
def torn(path: nil, selections: nil)
|
54
|
+
data = TornRuby::Endpoints::Torn.new(@api_key).fetch(path:, selections:)
|
55
|
+
TornRuby::Torn.new(data)
|
56
|
+
end
|
57
|
+
|
58
|
+
def racing(path: nil, selections: nil)
|
59
|
+
data = TornRuby::Endpoints::Racing.new(@api_key).fetch(path:, selections:)
|
60
|
+
TornRuby::Racing.new(data)
|
61
|
+
end
|
62
|
+
|
63
|
+
def forum(path: nil, selections: nil)
|
64
|
+
data = TornRuby::Endpoints::Forum.new(@api_key).fetch(path:, selections:)
|
65
|
+
TornRuby::Forum.new(data)
|
45
66
|
end
|
46
67
|
end
|
47
68
|
end
|
@@ -14,18 +14,18 @@ module TornRuby
|
|
14
14
|
@api_key = api_key
|
15
15
|
end
|
16
16
|
|
17
|
-
def fetch(
|
17
|
+
def fetch(path: nil, selections: nil)
|
18
18
|
selections = [] if selections.nil?
|
19
19
|
|
20
20
|
raise TornRuby::Error, "Invalid fields selected" if respond_to?(:valid_fields?) && !valid_fields?(selections)
|
21
21
|
|
22
22
|
params = build_params(selections)
|
23
|
-
path = build_path(
|
23
|
+
path = build_path(path)
|
24
24
|
handle_response(make_request(build_uri(path, params)))
|
25
25
|
end
|
26
26
|
|
27
27
|
def valid_fields?(fields)
|
28
|
-
|
28
|
+
fields.all? { |field| self.class::AVAILABLE_FIELDS.include?(field) }
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -40,10 +40,10 @@ module TornRuby
|
|
40
40
|
URI("#{BASE_URL}#{path}?#{params.join("&")}")
|
41
41
|
end
|
42
42
|
|
43
|
-
def build_path(
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
def build_path(path)
|
44
|
+
full_path = "/#{self.class.name.split("::").last.downcase}"
|
45
|
+
full_path += "/#{path}" if path
|
46
|
+
full_path
|
47
47
|
end
|
48
48
|
|
49
49
|
def make_request(uri)
|
@@ -12,14 +12,10 @@ module TornRuby
|
|
12
12
|
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
13
|
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
14
|
class Company < Base
|
15
|
-
AVAILABLE_FIELDS = %
|
15
|
+
AVAILABLE_FIELDS = %i[
|
16
16
|
companies lookup profile timestamp applications detailed
|
17
17
|
employees news stock
|
18
18
|
].freeze
|
19
|
-
|
20
|
-
def valid_fields?(fields)
|
21
|
-
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
22
|
-
end
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -12,7 +12,7 @@ module TornRuby
|
|
12
12
|
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
13
|
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
14
|
class Faction < Base
|
15
|
-
AVAILABLE_FIELDS = %
|
15
|
+
AVAILABLE_FIELDS = %i[
|
16
16
|
applications armor armorynews attacknews attacks attacksfull balance basic
|
17
17
|
boosters caches cesium chain chainreport chains contributors crimeexp
|
18
18
|
crimenews crimes currency donations drugs fundsnews hof lookup mainnews
|
@@ -20,10 +20,6 @@ module TornRuby
|
|
20
20
|
reports revives revivesfull stats temporary territory territorynews
|
21
21
|
timestamp upgrades wars weapons
|
22
22
|
].freeze
|
23
|
-
|
24
|
-
def valid_fields?(fields)
|
25
|
-
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
26
|
-
end
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
require_relative "base"
|
7
|
+
|
8
|
+
module TornRuby
|
9
|
+
module Endpoints
|
10
|
+
# Responsible for interacting with the Torn City API's racing endpoint.
|
11
|
+
# It provides methods to fetch racing-related data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve.
|
13
|
+
class Forum < Base
|
14
|
+
AVAILABLE_FIELDS = %i[categories posts thread threads timestamp].freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -12,11 +12,7 @@ module TornRuby
|
|
12
12
|
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
13
|
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
14
|
class Market < Base
|
15
|
-
AVAILABLE_FIELDS = %
|
16
|
-
|
17
|
-
def valid_fields?(fields)
|
18
|
-
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
19
|
-
end
|
15
|
+
AVAILABLE_FIELDS = %i[bazaar itemmarket lookup pointsmarket timestamp].freeze
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
@@ -12,11 +12,7 @@ module TornRuby
|
|
12
12
|
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
13
|
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
14
|
class Property < Base
|
15
|
-
AVAILABLE_FIELDS = %
|
16
|
-
|
17
|
-
def valid_fields?(fields)
|
18
|
-
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
19
|
-
end
|
15
|
+
AVAILABLE_FIELDS = %i[property].freeze
|
20
16
|
|
21
17
|
private
|
22
18
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
require_relative "base"
|
7
|
+
|
8
|
+
module TornRuby
|
9
|
+
module Endpoints
|
10
|
+
# Responsible for interacting with the Torn City API's racing endpoint.
|
11
|
+
# It provides methods to fetch racing-related data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve.
|
13
|
+
class Racing < Base
|
14
|
+
AVAILABLE_FIELDS = %i[ cars carupgrades race races records
|
15
|
+
tracks lookup timestamp ].freeze
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
require_relative "base"
|
7
|
+
|
8
|
+
module TornRuby
|
9
|
+
module Endpoints
|
10
|
+
# Responsible for interacting with the Torn City API's torn endpoint.
|
11
|
+
class Torn < Base
|
12
|
+
AVAILABLE_FIELDS = %i[
|
13
|
+
attacklog bounties calendar crimes hof itemammo itemmods subcrimes rankedwarreport rankedwars
|
14
|
+
bank cards chainreport cityshops companies competition dirtybombs education factionhof factiontree
|
15
|
+
gyms honors itemdetails items itemstats logcategories logtypes lookup medals organisedcrimes pawnshop
|
16
|
+
pokertables properties rackets raidreport raids rockpaperscissors searchforcash shoplifting stats
|
17
|
+
stocks territory territorynames territorywarreport territorywars timestamp
|
18
|
+
].freeze
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -12,7 +12,7 @@ module TornRuby
|
|
12
12
|
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
13
|
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
14
|
class User < Base
|
15
|
-
AVAILABLE_FIELDS = %
|
15
|
+
AVAILABLE_FIELDS = %i[
|
16
16
|
ammo attacks attacksfull bars basic battlestats bazaar
|
17
17
|
calendar cooldowns crimes criminalrecord discord display
|
18
18
|
education enlistedcars equipment events factionBalance forumfeed
|
@@ -23,10 +23,6 @@ module TornRuby
|
|
23
23
|
properties races refills reports revives revivesfull skills stocks
|
24
24
|
timestamp travel weaponexp workstats
|
25
25
|
].freeze
|
26
|
-
|
27
|
-
def valid_fields?(fields)
|
28
|
-
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
29
|
-
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
require_relative "base"
|
5
|
+
|
6
|
+
module TornRuby
|
7
|
+
# Responsible for representing the racing information in the Torn City game.
|
8
|
+
# It encapsulates racing data retrieved from the Torn City API
|
9
|
+
class Racing < Base
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
require_relative "base"
|
5
|
+
|
6
|
+
module TornRuby
|
7
|
+
# Responsible for representing the general torn ingormation in the Torn City game.
|
8
|
+
# It encapsulates torn api data retrieved from the Torn City API
|
9
|
+
class Torn < Base
|
10
|
+
end
|
11
|
+
end
|
data/lib/torn_ruby/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start
|
5
|
+
require "torn_ruby"
|
6
|
+
require "pry"
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# Enable flags like --only-failures and --next-failure
|
10
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
11
|
+
|
12
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe TornRuby::Base do
|
6
|
+
describe "#initialize" do
|
7
|
+
subject(:model) { described_class.new(input_data) }
|
8
|
+
|
9
|
+
let(:input_data) do
|
10
|
+
{
|
11
|
+
"name" => "Bram",
|
12
|
+
"level" => 37,
|
13
|
+
"life" => {
|
14
|
+
"current" => 1725,
|
15
|
+
"maximum" => 1725
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:symbolized_data) do
|
21
|
+
{
|
22
|
+
name: "Bram",
|
23
|
+
level: 37,
|
24
|
+
life: {
|
25
|
+
current: 1725,
|
26
|
+
maximum: 1725
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(TornRuby::Utils).to receive(:deep_symbolize_keys).with(input_data).and_return(symbolized_data)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "symbolizes the keys using TornRuby::Utils.deep_symbolize_keys" do
|
36
|
+
model # trigger the call
|
37
|
+
expect(TornRuby::Utils).to have_received(:deep_symbolize_keys).with(input_data)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "creates accessor methods for each top-level key" do
|
41
|
+
expect(model).to have_attributes(
|
42
|
+
name: "Bram",
|
43
|
+
level: 37,
|
44
|
+
life: hash_including(
|
45
|
+
current: 1725,
|
46
|
+
maximum: 1725
|
47
|
+
)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "sets instance variables for each key" do
|
52
|
+
expect({
|
53
|
+
name: model.instance_variable_get("@name"),
|
54
|
+
level: model.instance_variable_get("@level"),
|
55
|
+
life: model.instance_variable_get("@life")
|
56
|
+
}).to eq({
|
57
|
+
name: "Bram",
|
58
|
+
level: 37,
|
59
|
+
life: { current: 1725, maximum: 1725 }
|
60
|
+
})
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not override existing methods" do
|
64
|
+
class << model
|
65
|
+
def name
|
66
|
+
"Overridden"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
expect(model.name).to eq("Overridden")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|