Class: ExtremeOverclockingClient::Service
- Inherits:
-
Object
- Object
- ExtremeOverclockingClient::Service
- Defined in:
- lib/extreme_overclocking_client/service.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(project_url:, project_name:, project_version:) ⇒ Service
constructor
A new instance of Service.
- #team(id:) ⇒ Object
- #teams(ids:) ⇒ Object
- #user(id:, name: nil, team_id: nil) ⇒ Object
- #users(ids: nil, hashes: nil) ⇒ Object
Constructor Details
#initialize(project_url:, project_name:, project_version:) ⇒ Service
Returns a new instance of Service.
7 8 9 10 11 12 13 |
# File 'lib/extreme_overclocking_client/service.rb', line 7 def initialize(project_url:, project_name:, project_version:) @config = Config.new( project_url:, project_name:, project_version: ) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/extreme_overclocking_client/service.rb', line 5 def config @config end |
Instance Method Details
#team(id:) ⇒ Object
15 16 17 18 19 |
# File 'lib/extreme_overclocking_client/service.rb', line 15 def team(id:) raise ArgumentError, 'Required: id' unless id Team.new(config: @config, id:) end |
#teams(ids:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/extreme_overclocking_client/service.rb', line 21 def teams(ids:) raise ArgumentError, 'Required: ids' unless ids ids.map do |id| rate_limit if id.is_a?(Integer) begin Team.new(config: @config, id:) rescue StandardError => e { id:, error: e } end else { error: "Ids entry is not an integer: #{id}" } end end end |
#user(id:, name: nil, team_id: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/extreme_overclocking_client/service.rb', line 39 def user(id:, name: nil, team_id: nil) if id User.new(config: @config, id:) elsif name && team_id User.new(config: @config, name:, team_id:) else raise ArgumentError, 'Required: id or (name and team_id) of user' end end |
#users(ids: nil, hashes: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/extreme_overclocking_client/service.rb', line 49 def users(ids: nil, hashes: nil) if ids ids.map do |item| rate_limit id = nil if item.is_a?(Integer) id = item else symbol_hash = item.transform_keys(&:to_sym) if item.is_a?(Hash) id = symbol_hash[:id] if symbol_hash end if id User.new(config: @config, id:) else { error: "Could not find id: #{item}" } end rescue StandardError => e { id:, error: e } end elsif hashes hashes.map do |hash| rate_limit if hash.is_a?(Hash) symbol_hash = hash.transform_keys(&:to_sym) User.new( config: @config, name: symbol_hash[:name], team_id: symbol_hash[:team_id] ) else { error: "Hashes entry is not a hash: #{hash}" } end rescue StandardError => e { id:, error: e } end else raise ArgumentError, 'Required: ids or hashes' end end |