extreme_overclocking_client 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/.rspec +3 -0
- data/.rubocop.yml +39 -0
- data/.ruby-version +1 -0
- data/LICENSE +21 -0
- data/README.md +139 -0
- data/Rakefile +8 -0
- data/extreme_overclocking_client.gemspec +36 -0
- data/lib/extreme_overclocking_client/config.rb +19 -0
- data/lib/extreme_overclocking_client/request.rb +35 -0
- data/lib/extreme_overclocking_client/service.rb +100 -0
- data/lib/extreme_overclocking_client/team.rb +89 -0
- data/lib/extreme_overclocking_client/user.rb +103 -0
- data/lib/extreme_overclocking_client/version.rb +5 -0
- data/lib/extreme_overclocking_client.rb +12 -0
- metadata +87 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bad0128705a8beafab93b7af85d186c1ba2d91c7a9f9be28f74c8879ecbce994
|
|
4
|
+
data.tar.gz: 9d5c0ebebd3e8692bb3acd6450a9b6fac7eb2f98893ff52a977b0009fc4a5c0d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b2fcf604c3957733e0b5a1c1aaaf71ba22da409ee679e256e112bae520a03242112471919d84fc442fe09f3dc6fd031e33c967b156748dbe4bd9978aa2dbd900
|
|
7
|
+
data.tar.gz: 8dd0b2c58be9dfa69f2fe931cbdcee9eaa07f00b110c675bc926e53a4fc693d2c15b4101d369456b5ce2da13098169fb10de192d41dce98f6e0644e7c60bd2c6
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Docs: https://docs.rubocop.org/rubocop/configuration
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
NewCops: enable
|
|
5
|
+
TargetRubyVersion: 3.1
|
|
6
|
+
|
|
7
|
+
Layout/ArgumentAlignment:
|
|
8
|
+
EnforcedStyle: 'with_fixed_indentation'
|
|
9
|
+
Enabled: true
|
|
10
|
+
|
|
11
|
+
Metrics/MethodLength:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
Metrics/AbcSize:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Metrics/BlockLength:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
Metrics/ClassLength:
|
|
21
|
+
Enabled: false
|
|
22
|
+
|
|
23
|
+
Metrics/CyclomaticComplexity:
|
|
24
|
+
Enabled: false
|
|
25
|
+
|
|
26
|
+
Metrics/ParameterLists:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Metrics/PerceivedComplexity:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
Style/Documentation:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
Style/HashConversion:
|
|
36
|
+
Enabled: false
|
|
37
|
+
|
|
38
|
+
Style/TrailingCommaInHashLiteral:
|
|
39
|
+
EnforcedStyleForMultiline: 'consistent_comma'
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.1.0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Blake Gearin
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# extreme_overclocking_client
|
|
2
|
+
|
|
3
|
+
Ruby client for [Extreme Overclocking's Folding@home Data Export](https://folding.extremeoverclocking.com/?nav=XML)
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
Install and add to Gemfile:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bundle add extreme_overclocking_client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Install without bundler:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install extreme_overclocking_client
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Please read the full [usage statement](https://folding.extremeoverclocking.com/?nav=XML) from Extreme Overclocking before using. This client has some simplistic rate limiting built-in, but ultimately it's up to consumers of the gem to prevent excessive queries and abuse. Neglecting to do so may result in your IP being blocked.
|
|
22
|
+
|
|
23
|
+
- [Service](#service)
|
|
24
|
+
- [Config](#config)
|
|
25
|
+
- [User](#user)
|
|
26
|
+
- [Team](#team)
|
|
27
|
+
|
|
28
|
+
Data can be retrieved via the `Service` class or individual classes with a configuration parameter.
|
|
29
|
+
|
|
30
|
+
### Service
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
service = ExtremeOverclockingClient::Service.new(
|
|
34
|
+
project_url: "https://github.com/blakegearin/extreme_overclocking_client",
|
|
35
|
+
project_name: "ExtremeOverclockingClientTesting",
|
|
36
|
+
project_version: "0.0.1",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
user_id = 32334
|
|
40
|
+
name = "EOC_Jason"
|
|
41
|
+
team_id = 11314
|
|
42
|
+
|
|
43
|
+
# User
|
|
44
|
+
|
|
45
|
+
user = service.user(id: user_id)
|
|
46
|
+
user = service.user(name: name, team_id: team_id)
|
|
47
|
+
|
|
48
|
+
# Users
|
|
49
|
+
|
|
50
|
+
users = service.users(ids: [32334, 811139])
|
|
51
|
+
hashes = [
|
|
52
|
+
{ name: name, team_id: team_id},
|
|
53
|
+
{ name: name, team_id: team_id},
|
|
54
|
+
]
|
|
55
|
+
users = service.users(hashes: hashes)
|
|
56
|
+
|
|
57
|
+
# Team
|
|
58
|
+
|
|
59
|
+
team = service.team(id: team_id)
|
|
60
|
+
|
|
61
|
+
# Teams
|
|
62
|
+
|
|
63
|
+
teams = service.teams(ids: [11314, 223518])
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Config
|
|
67
|
+
|
|
68
|
+
Provide a `project_url` and `project_name` to let Extreme Overclocking know what your project is. These values populate referer and user-agent metadata sent with each request.
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
config = ExtremeOverclockingClient::Config.new(
|
|
72
|
+
project_url: "https://github.com/blakegearin/extreme_overclocking_client",
|
|
73
|
+
project_name: "ExtremeOverclockingClientTesting",
|
|
74
|
+
project_version: "0.0.1",
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### User
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
user_id = 32334
|
|
82
|
+
name = "EOC_Jason"
|
|
83
|
+
team_id = 11314
|
|
84
|
+
config = ExtremeOverclockingClient::Config.new(
|
|
85
|
+
project_url: "https://github.com/blakegearin/extreme_overclocking_client",
|
|
86
|
+
project_name: "ExtremeOverclockingClientTesting",
|
|
87
|
+
project_version: "0.0.1",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Fetch a user by id
|
|
91
|
+
# Required: config, id
|
|
92
|
+
user = ExtremeOverclockingClient::User.new(config: config, id: user_id)
|
|
93
|
+
|
|
94
|
+
# Fetch a user with a name and team_id
|
|
95
|
+
# Required: config, name, team_id
|
|
96
|
+
user = ExtremeOverclockingClient::User.new(config: config, name: name, team_id: team_id)
|
|
97
|
+
|
|
98
|
+
## Update a user with the latest stats
|
|
99
|
+
user.refresh
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Team
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
id = 11314
|
|
106
|
+
config = ExtremeOverclockingClient::Config.new(
|
|
107
|
+
project_url: "https://github.com/blakegearin/extreme_overclocking_client",
|
|
108
|
+
project_name: "ExtremeOverclockingClientTesting",
|
|
109
|
+
project_version: "0.0.1",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Fetch a team by id
|
|
113
|
+
team = ExtremeOverclockingClient::Team.new(config: config, id: id)
|
|
114
|
+
|
|
115
|
+
## Update a team with the latest stats
|
|
116
|
+
team.refresh
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
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.
|
|
122
|
+
|
|
123
|
+
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).
|
|
124
|
+
|
|
125
|
+
## Contributing
|
|
126
|
+
|
|
127
|
+
Bug reports, feature requests, and pull requests are welcome.
|
|
128
|
+
|
|
129
|
+
## Links
|
|
130
|
+
|
|
131
|
+
- [Folding@home](https://foldingathome.org)
|
|
132
|
+
|
|
133
|
+
- [Folding@home Download](https://foldingathome.org/start-folding)
|
|
134
|
+
|
|
135
|
+
- [Folding@home Stats](https://stats.foldingathome.org)
|
|
136
|
+
|
|
137
|
+
- [EXTREME Overclocking (EOC) Stats](https://folding.extremeoverclocking.com/aggregate_summary.php)
|
|
138
|
+
|
|
139
|
+
- [EXTREME Overclocking (EOC) Stats Export Info](https://folding.extremeoverclocking.com/?nav=XML)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/extreme_overclocking_client/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'extreme_overclocking_client'
|
|
7
|
+
spec.version = ExtremeOverclockingClient::VERSION
|
|
8
|
+
|
|
9
|
+
spec.authors = ['Blake Gearin']
|
|
10
|
+
spec.email = 'hello@blakeg.me'
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Ruby client for Extreme Overclocking'
|
|
13
|
+
spec.description = 'Ruby client for Extreme Overclocking'
|
|
14
|
+
spec.homepage = 'https://github.com/blakegearin/extreme_overclocking_client'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
17
|
+
|
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/blakegearin/extreme_overclocking_client'
|
|
20
|
+
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
spec.bindir = 'exe'
|
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ['lib']
|
|
32
|
+
|
|
33
|
+
spec.add_dependency 'activesupport', '~> 7.1'
|
|
34
|
+
spec.add_dependency 'nokogiri', '~> 1.16'
|
|
35
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
36
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ExtremeOverclockingClient
|
|
4
|
+
class Config
|
|
5
|
+
attr_reader :referer, :user_agent
|
|
6
|
+
|
|
7
|
+
def initialize(project_url:, project_name:, project_version:)
|
|
8
|
+
raise ArgumentError, "Param 'project_url' must be defined" unless project_url && !project_url.empty?
|
|
9
|
+
|
|
10
|
+
raise ArgumentError, "Param 'project_name' must be defined" unless project_name && !project_name.empty?
|
|
11
|
+
|
|
12
|
+
raise ArgumentError, "Param 'project_version' must be defined" unless project_version && !project_version.empty?
|
|
13
|
+
|
|
14
|
+
@referer = project_url
|
|
15
|
+
@user_agent = "#{project_name}/#{project_version} ExtremeOverclockingClient/" \
|
|
16
|
+
"#{ExtremeOverclockingClient::VERSION} Ruby/#{RUBY_VERSION}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: false
|
|
2
|
+
|
|
3
|
+
require 'active_support/all'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'nokogiri'
|
|
6
|
+
|
|
7
|
+
ActiveSupport::XmlMini.backend = 'Nokogiri'
|
|
8
|
+
|
|
9
|
+
module ExtremeOverclockingClient
|
|
10
|
+
module Request
|
|
11
|
+
FEED_URL = 'https://folding.extremeoverclocking.com'.freeze
|
|
12
|
+
|
|
13
|
+
def request(config:, endpoint:, base_url: FEED_URL, params: {})
|
|
14
|
+
unless config.is_a?(ExtremeOverclockingClient::Config)
|
|
15
|
+
raise ArgumentError, "Param 'config' must be an instance of ExtremeOverclockingClient::Config"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
url = URI.join(base_url, endpoint)
|
|
19
|
+
url.query = URI.encode_www_form(params) unless params.empty?
|
|
20
|
+
|
|
21
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
22
|
+
http.use_ssl = true
|
|
23
|
+
|
|
24
|
+
request = Net::HTTP::Get.new(url.request_uri)
|
|
25
|
+
request['Referer'] = config.referer
|
|
26
|
+
request['User-Agent'] = config.user_agent
|
|
27
|
+
|
|
28
|
+
response = http.request(request)
|
|
29
|
+
|
|
30
|
+
raise StandardError, response.body unless response.code == '200'
|
|
31
|
+
|
|
32
|
+
Hash.from_xml(response.body)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ExtremeOverclockingClient
|
|
4
|
+
class Service
|
|
5
|
+
attr_reader :config
|
|
6
|
+
|
|
7
|
+
def initialize(project_url:, project_name:, project_version:)
|
|
8
|
+
@config = Config.new(
|
|
9
|
+
project_url:,
|
|
10
|
+
project_name:,
|
|
11
|
+
project_version:
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def team(id:)
|
|
16
|
+
raise ArgumentError, 'Required: id' unless id
|
|
17
|
+
|
|
18
|
+
Team.new(config: @config, id:)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def teams(ids:)
|
|
22
|
+
raise ArgumentError, 'Required: ids' unless ids
|
|
23
|
+
|
|
24
|
+
ids.map do |id|
|
|
25
|
+
rate_limit
|
|
26
|
+
|
|
27
|
+
if id.is_a?(Integer)
|
|
28
|
+
begin
|
|
29
|
+
Team.new(config: @config, id:)
|
|
30
|
+
rescue StandardError => e
|
|
31
|
+
{ id:, error: e }
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
{ error: "Ids entry is not an integer: #{id}" }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def user(id:, name: nil, team_id: nil)
|
|
40
|
+
if id
|
|
41
|
+
User.new(config: @config, id:)
|
|
42
|
+
elsif name && team_id
|
|
43
|
+
User.new(config: @config, name:, team_id:)
|
|
44
|
+
else
|
|
45
|
+
raise ArgumentError, 'Required: id or (name and team_id) of user'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def users(ids: nil, hashes: nil)
|
|
50
|
+
if ids
|
|
51
|
+
ids.map do |item|
|
|
52
|
+
rate_limit
|
|
53
|
+
|
|
54
|
+
id = nil
|
|
55
|
+
|
|
56
|
+
if item.is_a?(Integer)
|
|
57
|
+
id = item
|
|
58
|
+
else
|
|
59
|
+
symbol_hash = item.transform_keys(&:to_sym) if item.is_a?(Hash)
|
|
60
|
+
id = symbol_hash[:id] if symbol_hash
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if id
|
|
64
|
+
User.new(config: @config, id:)
|
|
65
|
+
else
|
|
66
|
+
{ error: "Could not find id: #{item}" }
|
|
67
|
+
end
|
|
68
|
+
rescue StandardError => e
|
|
69
|
+
{ id:, error: e }
|
|
70
|
+
end
|
|
71
|
+
elsif hashes
|
|
72
|
+
hashes.map do |hash|
|
|
73
|
+
rate_limit
|
|
74
|
+
|
|
75
|
+
if hash.is_a?(Hash)
|
|
76
|
+
symbol_hash = hash.transform_keys(&:to_sym)
|
|
77
|
+
User.new(
|
|
78
|
+
config: @config,
|
|
79
|
+
name: symbol_hash[:name],
|
|
80
|
+
team_id: symbol_hash[:team_id]
|
|
81
|
+
)
|
|
82
|
+
else
|
|
83
|
+
{ error: "Hashes entry is not a hash: #{hash}" }
|
|
84
|
+
end
|
|
85
|
+
rescue StandardError => e
|
|
86
|
+
{ id:, error: e }
|
|
87
|
+
end
|
|
88
|
+
else
|
|
89
|
+
raise ArgumentError, 'Required: ids or hashes'
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def rate_limit
|
|
96
|
+
# Limit to 2 calls per second
|
|
97
|
+
sleep(0.5)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ExtremeOverclockingClient
|
|
4
|
+
class Team
|
|
5
|
+
include Request
|
|
6
|
+
|
|
7
|
+
attr_reader :id,
|
|
8
|
+
:name,
|
|
9
|
+
:users,
|
|
10
|
+
:rank,
|
|
11
|
+
:points,
|
|
12
|
+
:wus,
|
|
13
|
+
:updated_at,
|
|
14
|
+
:retrieved_at
|
|
15
|
+
|
|
16
|
+
def initialize(params = {})
|
|
17
|
+
unless params[:belongs_to_user]
|
|
18
|
+
config = params[:config] || nil
|
|
19
|
+
|
|
20
|
+
unless config.is_a?(ExtremeOverclockingClient::Config)
|
|
21
|
+
raise ArgumentError, "Param 'config' must be an instance of ExtremeOverclockingClient::Config"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
id = params[:id] || nil
|
|
25
|
+
|
|
26
|
+
raise ArgumentError, 'Required: id of team' unless id.present?
|
|
27
|
+
|
|
28
|
+
params = fetch(config:, id:)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
build(params:)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def refresh
|
|
35
|
+
time_difference_in_hours = (Time.now.utc - Time.parse(@retrieved_at)) / 3600
|
|
36
|
+
|
|
37
|
+
return unless time_difference_in_hours >= 3.0
|
|
38
|
+
|
|
39
|
+
params = fetch(config: @config, id: @id)
|
|
40
|
+
build(params:)
|
|
41
|
+
|
|
42
|
+
self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def fetch(config:, id:)
|
|
48
|
+
params = { t: id }
|
|
49
|
+
response = request(
|
|
50
|
+
config:,
|
|
51
|
+
endpoint: '/xml/team_summary.php',
|
|
52
|
+
params:
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
stats_hash = response['EOC_Folding_Stats']
|
|
56
|
+
params = stats_hash['team']
|
|
57
|
+
params[:updated_at] = Time.at(stats_hash['status']['Last_Update_Unix_TimeStamp']&.to_i).utc.to_s
|
|
58
|
+
|
|
59
|
+
params
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def build(params:)
|
|
63
|
+
@id = params['TeamID']&.to_i
|
|
64
|
+
@name = params['Team_Name']
|
|
65
|
+
@users = {
|
|
66
|
+
active: params['Users_Active']&.to_i,
|
|
67
|
+
total: params['Users']&.to_i,
|
|
68
|
+
}
|
|
69
|
+
@rank = {
|
|
70
|
+
total: params['Rank']&.to_i,
|
|
71
|
+
day_change: params['Change_Rank_24hr']&.to_i,
|
|
72
|
+
week_change: params['Change_Rank_7days']&.to_i,
|
|
73
|
+
}
|
|
74
|
+
@points = {
|
|
75
|
+
day_average: params['Points_24hr_Avg']&.to_i,
|
|
76
|
+
last_day: params['Points_Last_24hr']&.to_i,
|
|
77
|
+
last_week: params['Points_Last_7days']&.to_i,
|
|
78
|
+
update: params['Points_Update']&.to_i,
|
|
79
|
+
today: params['Points_Today']&.to_i,
|
|
80
|
+
week: params['Points_Week']&.to_i,
|
|
81
|
+
total: params['Points']&.to_i,
|
|
82
|
+
}
|
|
83
|
+
@wus = params['WUs']&.to_i
|
|
84
|
+
|
|
85
|
+
@updated_at = params[:updated_at]
|
|
86
|
+
@retrieved_at = Time.now.utc.to_s
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ExtremeOverclockingClient
|
|
4
|
+
class User
|
|
5
|
+
include Request
|
|
6
|
+
|
|
7
|
+
attr_reader :id,
|
|
8
|
+
:name,
|
|
9
|
+
:rank,
|
|
10
|
+
:points,
|
|
11
|
+
:wus,
|
|
12
|
+
:team,
|
|
13
|
+
:created_at,
|
|
14
|
+
:updated_at,
|
|
15
|
+
:retrieved_at
|
|
16
|
+
|
|
17
|
+
def initialize(
|
|
18
|
+
config:,
|
|
19
|
+
id: nil,
|
|
20
|
+
name: nil,
|
|
21
|
+
team_id: nil
|
|
22
|
+
)
|
|
23
|
+
unless config.is_a?(ExtremeOverclockingClient::Config)
|
|
24
|
+
raise ArgumentError, "Param 'config' must be an instance of ExtremeOverclockingClient::Config"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
params = fetch(config:, id:, name:, team_id:)
|
|
28
|
+
build(params:)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def refresh
|
|
32
|
+
time_difference_in_hours = (Time.now.utc - Time.parse(@retrieved_at)) / 3600
|
|
33
|
+
|
|
34
|
+
return unless time_difference_in_hours >= 3.0
|
|
35
|
+
|
|
36
|
+
params = fetch(config: @config, id: @id)
|
|
37
|
+
build(params:)
|
|
38
|
+
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def fetch(config:, id: nil, name: nil, team_id: nil)
|
|
45
|
+
params = {}
|
|
46
|
+
|
|
47
|
+
if id
|
|
48
|
+
params = { u: id }
|
|
49
|
+
elsif name && team_id
|
|
50
|
+
params = {
|
|
51
|
+
t: team_id,
|
|
52
|
+
un: name,
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
raise ArgumentError, 'Required: id or (name and team_id) of user'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
response = request(
|
|
59
|
+
config:,
|
|
60
|
+
endpoint: '/xml/user_summary.php',
|
|
61
|
+
params:
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
stats_hash = response['EOC_Folding_Stats']
|
|
65
|
+
params = stats_hash['user']
|
|
66
|
+
params[:updated_at] = Time.at(stats_hash['status']['Last_Update_Unix_TimeStamp']&.to_i).utc.to_s
|
|
67
|
+
params[:team] = stats_hash['team']
|
|
68
|
+
|
|
69
|
+
params
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build(params:)
|
|
73
|
+
@id = params['UserID']&.to_i
|
|
74
|
+
@name = params['User_Name']
|
|
75
|
+
@rank = {
|
|
76
|
+
team: params['Team_Rank']&.to_i,
|
|
77
|
+
overall: params['Overall_Rank']&.to_i,
|
|
78
|
+
day_change: params['Change_Rank_24hr']&.to_i,
|
|
79
|
+
week_change: params['Change_Rank_7days']&.to_i,
|
|
80
|
+
}
|
|
81
|
+
@points = {
|
|
82
|
+
day_average: params['Points_24hr_Avg']&.to_i,
|
|
83
|
+
last_day: params['Points_Last_24hr']&.to_i,
|
|
84
|
+
last_week: params['Points_Last_7days']&.to_i,
|
|
85
|
+
update: params['Points_Update']&.to_i,
|
|
86
|
+
today: params['Points_Today']&.to_i,
|
|
87
|
+
week: params['Points_Week']&.to_i,
|
|
88
|
+
total: params['Points']&.to_i,
|
|
89
|
+
}
|
|
90
|
+
@wus = params['WUs']&.to_i
|
|
91
|
+
|
|
92
|
+
@created_at = Time.parse(params['First_Record']).utc.to_s
|
|
93
|
+
@updated_at = params[:updated_at]
|
|
94
|
+
@retrieved_at = Time.now.utc.to_s
|
|
95
|
+
|
|
96
|
+
team_hash = params[:team]
|
|
97
|
+
team_hash[:updated_at] = @updated_at
|
|
98
|
+
team_hash[:belongs_to_user] = true
|
|
99
|
+
|
|
100
|
+
@team = Team.new(**team_hash)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'extreme_overclocking_client/version'
|
|
4
|
+
|
|
5
|
+
# Helpers
|
|
6
|
+
require_relative 'extreme_overclocking_client/config'
|
|
7
|
+
require_relative 'extreme_overclocking_client/request'
|
|
8
|
+
|
|
9
|
+
# Classes
|
|
10
|
+
require_relative 'extreme_overclocking_client/service'
|
|
11
|
+
require_relative 'extreme_overclocking_client/team'
|
|
12
|
+
require_relative 'extreme_overclocking_client/user'
|
metadata
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: extreme_overclocking_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Blake Gearin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '7.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: nokogiri
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.16'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.16'
|
|
41
|
+
description: Ruby client for Extreme Overclocking
|
|
42
|
+
email: hello@blakeg.me
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- ".rspec"
|
|
48
|
+
- ".rubocop.yml"
|
|
49
|
+
- ".ruby-version"
|
|
50
|
+
- LICENSE
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- extreme_overclocking_client.gemspec
|
|
54
|
+
- lib/extreme_overclocking_client.rb
|
|
55
|
+
- lib/extreme_overclocking_client/config.rb
|
|
56
|
+
- lib/extreme_overclocking_client/request.rb
|
|
57
|
+
- lib/extreme_overclocking_client/service.rb
|
|
58
|
+
- lib/extreme_overclocking_client/team.rb
|
|
59
|
+
- lib/extreme_overclocking_client/user.rb
|
|
60
|
+
- lib/extreme_overclocking_client/version.rb
|
|
61
|
+
homepage: https://github.com/blakegearin/extreme_overclocking_client
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
homepage_uri: https://github.com/blakegearin/extreme_overclocking_client
|
|
66
|
+
source_code_uri: https://github.com/blakegearin/extreme_overclocking_client
|
|
67
|
+
rubygems_mfa_required: 'true'
|
|
68
|
+
post_install_message:
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 3.1.0
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubygems_version: 3.3.3
|
|
84
|
+
signing_key:
|
|
85
|
+
specification_version: 4
|
|
86
|
+
summary: Ruby client for Extreme Overclocking
|
|
87
|
+
test_files: []
|