torn_ruby 0.1.0.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +12 -0
- data/lib/torn_ruby/base.rb +15 -0
- data/lib/torn_ruby/client.rb +47 -0
- data/lib/torn_ruby/company.rb +11 -0
- data/lib/torn_ruby/endpoints/base.rb +62 -0
- data/lib/torn_ruby/endpoints/company.rb +25 -0
- data/lib/torn_ruby/endpoints/faction.rb +29 -0
- data/lib/torn_ruby/endpoints/market.rb +22 -0
- data/lib/torn_ruby/endpoints/property.rb +32 -0
- data/lib/torn_ruby/endpoints/user.rb +32 -0
- data/lib/torn_ruby/faction.rb +11 -0
- data/lib/torn_ruby/market.rb +11 -0
- data/lib/torn_ruby/property.rb +18 -0
- data/lib/torn_ruby/user.rb +12 -0
- data/lib/torn_ruby/utils.rb +32 -0
- data/lib/torn_ruby/version.rb +5 -0
- data/lib/torn_ruby.rb +8 -0
- data/sig/torn_ruby.rbs +4 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7162049ee394009ba45845e00e4ea788d30b96eab42f647d21f170d577f3ce3a
|
4
|
+
data.tar.gz: 6974bf77a223845a7769d151af60b196707f44841418d80732731d7563eb4766
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf6f4abd4fadc268a8a63b9561daa535578468261beec520957944456255e6fdc0d9c077e4c802d0a3c79aa7e4af0a2cd28d9e03ad4f723ae465e7593ac0cb99
|
7
|
+
data.tar.gz: 2682eea306e9fb276d522ef4d79f8171278987514bbef87b70e157423ffc4007cff72cd03cb895f6bc4e34820a23cf0f0d61bbcca3c5bda3cd0e1d192fc82f47
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.1
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
RSpec/ExampleLength:
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Bram
|
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,38 @@
|
|
1
|
+
# TornRuby
|
2
|
+
|
3
|
+
An implementation of the [Torn](https://www.torn.com/api.html) V2 API using Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add torn_ruby
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install torn_ruby
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
To use the TornRuby gem, you’ll need a valid Torn API key.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
api_key = "Valid Torn Api Key"
|
24
|
+
client = TornRuby::Client.new(api_key:)
|
25
|
+
user = client.user
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ibramsterdam/torn_ruby.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
35
|
+
|
36
|
+
## Code of Conduct
|
37
|
+
|
38
|
+
Everyone interacting in the TornRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ibramsterdam/torn_ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TornRuby
|
4
|
+
# A base class for models that encapsulates data and handles the initialization of attributes.
|
5
|
+
class Base
|
6
|
+
def initialize(data)
|
7
|
+
symbolized_data = TornRuby::Utils.deep_symbolize_keys(data)
|
8
|
+
|
9
|
+
symbolized_data.each do |key, value|
|
10
|
+
define_singleton_method(key) { instance_variable_get("@#{key}") } unless respond_to?(key)
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "endpoints/user"
|
4
|
+
require_relative "endpoints/property"
|
5
|
+
require_relative "endpoints/faction"
|
6
|
+
require_relative "endpoints/company"
|
7
|
+
require_relative "endpoints/market"
|
8
|
+
require_relative "user"
|
9
|
+
require_relative "property"
|
10
|
+
require_relative "faction"
|
11
|
+
require_relative "company"
|
12
|
+
require_relative "market"
|
13
|
+
|
14
|
+
module TornRuby
|
15
|
+
# Responsible for interacting with the Torn API
|
16
|
+
# and providing an interface to access various endpoints.
|
17
|
+
class Client
|
18
|
+
def initialize(api_key:)
|
19
|
+
@api_key = api_key
|
20
|
+
end
|
21
|
+
|
22
|
+
def user(id: nil, selections: nil)
|
23
|
+
data = TornRuby::Endpoints::User.new(@api_key).fetch(id: id, selections: selections)
|
24
|
+
TornRuby::User.new(data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def property(id: nil, selections: nil)
|
28
|
+
data = TornRuby::Endpoints::Property.new(@api_key).fetch(id: id, selections: selections)
|
29
|
+
TornRuby::Property.new(data)
|
30
|
+
end
|
31
|
+
|
32
|
+
def faction(id: nil, selections: nil)
|
33
|
+
data = TornRuby::Endpoints::Faction.new(@api_key).fetch(id: id, selections: selections)
|
34
|
+
TornRuby::Faction.new(data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def company(id: nil, selections: nil)
|
38
|
+
data = TornRuby::Endpoints::Company.new(@api_key).fetch(id: id, selections: selections)
|
39
|
+
TornRuby::Company.new(data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def market(id: nil, selections: nil)
|
43
|
+
data = TornRuby::Endpoints::Market.new(@api_key).fetch(id: id, selections: selections)
|
44
|
+
TornRuby::Market.new(data)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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 a company in the Torn City game.
|
8
|
+
# It encapsulates company data retrieved from the Torn City API
|
9
|
+
class Company < Base
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TornRuby
|
8
|
+
module Endpoints
|
9
|
+
# Base class for all endpoints
|
10
|
+
class Base
|
11
|
+
BASE_URL = "https://api.torn.com/v2"
|
12
|
+
|
13
|
+
def initialize(api_key)
|
14
|
+
@api_key = api_key
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(id: nil, selections: nil)
|
18
|
+
selections = [] if selections.nil?
|
19
|
+
|
20
|
+
raise TornRuby::Error, "Invalid fields selected" if respond_to?(:valid_fields?) && !valid_fields?(selections)
|
21
|
+
|
22
|
+
params = build_params(selections)
|
23
|
+
path = build_path(id)
|
24
|
+
handle_response(make_request(build_uri(path, params)))
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_fields?(fields)
|
28
|
+
raise NotImplementedError, "#{self.class} must implement #valid_fields?"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def build_params(selections)
|
34
|
+
params = ["key=#{@api_key}"]
|
35
|
+
params << "selections=#{selections.join(",")}" if selections
|
36
|
+
params
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_uri(path, params)
|
40
|
+
URI("#{BASE_URL}#{path}?#{params.join("&")}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_path(id)
|
44
|
+
path = "/#{self.class.name.split("::").last.downcase}"
|
45
|
+
path += "/#{id}" if id
|
46
|
+
path
|
47
|
+
end
|
48
|
+
|
49
|
+
def make_request(uri)
|
50
|
+
Net::HTTP.get_response(uri)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handle_response(response)
|
54
|
+
unless response.is_a?(Net::HTTPSuccess)
|
55
|
+
raise TornRuby::Error, "API request failed: #{response.code} #{response.message}"
|
56
|
+
end
|
57
|
+
|
58
|
+
JSON.parse(response.body)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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 company endpoint.
|
11
|
+
# It provides methods to fetch faction data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
|
+
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
|
+
class Company < Base
|
15
|
+
AVAILABLE_FIELDS = %w[
|
16
|
+
companies lookup profile timestamp applications detailed
|
17
|
+
employees news stock
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
def valid_fields?(fields)
|
21
|
+
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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 faction endpoint.
|
11
|
+
# It provides methods to fetch faction data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
|
+
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
|
+
class Faction < Base
|
15
|
+
AVAILABLE_FIELDS = %w[
|
16
|
+
applications armor armorynews attacknews attacks attacksfull balance basic
|
17
|
+
boosters caches cesium chain chainreport chains contributors crimeexp
|
18
|
+
crimenews crimes currency donations drugs fundsnews hof lookup mainnews
|
19
|
+
medical members membershipnews news positions rankedwarreport rankedwars
|
20
|
+
reports revives revivesfull stats temporary territory territorynews
|
21
|
+
timestamp upgrades wars weapons
|
22
|
+
].freeze
|
23
|
+
|
24
|
+
def valid_fields?(fields)
|
25
|
+
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 market endpoint.
|
11
|
+
# It provides methods to fetch market data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
|
+
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
|
+
class Market < Base
|
15
|
+
AVAILABLE_FIELDS = %w[bazaar itemmarket lookup pointsmarket timestamp].freeze
|
16
|
+
|
17
|
+
def valid_fields?(fields)
|
18
|
+
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 user endpoint.
|
11
|
+
# It provides methods to fetch user data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
|
+
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
|
+
class Property < Base
|
15
|
+
AVAILABLE_FIELDS = %w[property].freeze
|
16
|
+
|
17
|
+
def valid_fields?(fields)
|
18
|
+
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def handle_response(response)
|
24
|
+
unless response.is_a?(Net::HTTPSuccess)
|
25
|
+
raise TornRuby::Error, "API request failed: #{response.code} #{response.message}"
|
26
|
+
end
|
27
|
+
|
28
|
+
JSON.parse(response.body)["property"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 user endpoint.
|
11
|
+
# It provides methods to fetch user data based on an API key, along with optional selections
|
12
|
+
# for specific fields to retrieve. The class ensures that only valid fields are requested
|
13
|
+
# from the API and handles the response by parsing the JSON data into a usable format.
|
14
|
+
class User < Base
|
15
|
+
AVAILABLE_FIELDS = %w[
|
16
|
+
ammo attacks attacksfull bars basic battlestats bazaar
|
17
|
+
calendar cooldowns crimes criminalrecord discord display
|
18
|
+
education enlistedcars equipment events factionBalance forumfeed
|
19
|
+
forumfriends forumposts forumsubscribedthreads forumthreads gym hof
|
20
|
+
honors icons inventory itemmarket jobpoints list log lookup
|
21
|
+
medals merits messages missions money networth newevents
|
22
|
+
newmessages notifications organizedCrime perks personalstats profile
|
23
|
+
properties races refills reports revives revivesfull skills stocks
|
24
|
+
timestamp travel weaponexp workstats
|
25
|
+
].freeze
|
26
|
+
|
27
|
+
def valid_fields?(fields)
|
28
|
+
fields.all? { |field| AVAILABLE_FIELDS.include?(field) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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 a Faction in the Torn City game.
|
8
|
+
# It encapsulates user data retrieved from the Torn City API
|
9
|
+
class Faction < 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 market in the Torn City game.
|
8
|
+
# It encapsulates market data retrieved from the Torn City API
|
9
|
+
class Market < Base
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
require_relative "base"
|
5
|
+
|
6
|
+
module TornRuby
|
7
|
+
# Responsible for representing a property in the Torn City game.
|
8
|
+
# It encapsulates property data retrieved from the Torn City API
|
9
|
+
class Property < Base
|
10
|
+
def living_user_ids
|
11
|
+
users_living.split(",").map(&:to_i)
|
12
|
+
end
|
13
|
+
|
14
|
+
def rented?
|
15
|
+
rented.is_a?(Hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
require_relative "base"
|
5
|
+
|
6
|
+
module TornRuby
|
7
|
+
# Responsible for representing a user in the Torn City game.
|
8
|
+
# It encapsulates user data retrieved from the Torn City API and provides access
|
9
|
+
# to the various attributes of the user
|
10
|
+
class User < Base
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TornRuby
|
4
|
+
# Utility methods for common operations used within the TornRuby gem
|
5
|
+
module Utils
|
6
|
+
# Thank you ActiveSupport for this great method :-)
|
7
|
+
def deep_symbolize_keys(obj)
|
8
|
+
case obj
|
9
|
+
when Hash
|
10
|
+
symbolize_hash(obj)
|
11
|
+
when Array
|
12
|
+
obj.map { |e| deep_symbolize_keys(e) }
|
13
|
+
else
|
14
|
+
obj
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def symbolize_hash(hash)
|
19
|
+
hash.each_with_object({}) do |(k, v), result|
|
20
|
+
key = symbolize_key(k)
|
21
|
+
result[key] = deep_symbolize_keys(v)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def symbolize_key(key)
|
26
|
+
# Only convert key to symbol if it's a non-numeric string
|
27
|
+
key.is_a?(String) && key !~ /^\d+$/ ? key.to_sym : key
|
28
|
+
end
|
29
|
+
|
30
|
+
module_function :deep_symbolize_keys, :symbolize_hash, :symbolize_key
|
31
|
+
end
|
32
|
+
end
|
data/lib/torn_ruby.rb
ADDED
data/sig/torn_ruby.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torn_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bram
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-04-19 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: pry
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0.15'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0.15'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: fiddle
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.1'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
description: A Ruby gem that provides a convenient wrapper around the Torn City API.Ideal
|
41
|
+
for developers looking to integrate Torn City data into Ruby applications.
|
42
|
+
email:
|
43
|
+
- bramjanssen@hey.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- CHANGELOG.md
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/torn_ruby.rb
|
56
|
+
- lib/torn_ruby/base.rb
|
57
|
+
- lib/torn_ruby/client.rb
|
58
|
+
- lib/torn_ruby/company.rb
|
59
|
+
- lib/torn_ruby/endpoints/base.rb
|
60
|
+
- lib/torn_ruby/endpoints/company.rb
|
61
|
+
- lib/torn_ruby/endpoints/faction.rb
|
62
|
+
- lib/torn_ruby/endpoints/market.rb
|
63
|
+
- lib/torn_ruby/endpoints/property.rb
|
64
|
+
- lib/torn_ruby/endpoints/user.rb
|
65
|
+
- lib/torn_ruby/faction.rb
|
66
|
+
- lib/torn_ruby/market.rb
|
67
|
+
- lib/torn_ruby/property.rb
|
68
|
+
- lib/torn_ruby/user.rb
|
69
|
+
- lib/torn_ruby/utils.rb
|
70
|
+
- lib/torn_ruby/version.rb
|
71
|
+
- sig/torn_ruby.rbs
|
72
|
+
homepage: https://github.com/ibramsterdam/torn_ruby
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
allowed_push_host: https://rubygems.org
|
77
|
+
homepage_uri: https://github.com/ibramsterdam/torn_ruby
|
78
|
+
source_code_uri: https://github.com/ibramsterdam/torn_ruby
|
79
|
+
changelog_uri: https://github.com/ibramsterdam/torn_ruby/blob/main/CHANGELOG.md
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 3.1.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.6.3
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Ruby gem for interacting with the Torn City API, providing easy access
|
97
|
+
togame data and functionality.
|
98
|
+
test_files: []
|