htb 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad35da07fd9b2867d488dbf3559f26f7a4d892accd93f7787ef318e0c6ab4d6d
4
- data.tar.gz: 77ae561b2b972ca331fe42b1dacfda49909bbd177d6f92406b659f19079974e2
3
+ metadata.gz: 1c61e897e5256a77995c2c6b07d1990805855cc59495576e5925d13196192b92
4
+ data.tar.gz: 686ab280f44de1aa5d59ef2b6bd28607b3aefdbd9db3807152f89d3533f22ca5
5
5
  SHA512:
6
- metadata.gz: 8af38c52092bf0738dc64d9752624bd4b996389e730561a6a4c54809e3752350847aabb8a16a4ff120e8e6132ea9fd8ea15b95518b7ef4fc8f5cfa02bebe2ba1
7
- data.tar.gz: dc43a9683115267a1d0e9f2370cf69ed0c7d329ad2d09bafd50487a33a8fdb7f479484dad4f2e2404198bdd6c7ad03c2a7e6fac46a08da8c40c1cdd0acc6b948
6
+ metadata.gz: 1ff67688442edf583e9d1b81961199e078ebfa9425efc981c23e254af7cc26ddfd08fcfffca5dac4f3eea380cac20c8bf55720fdf4bf5109428d1c949243de25
7
+ data.tar.gz: e1a7c7efb65dbff32c972a040c83db23041665d7df32f610c8497f209bfe93ef933f32ec3f7a451b5fae4fadc96f37e0e909bad83c8f6e007b2c2fd45d81ca8c
@@ -7,9 +7,11 @@ module HTB
7
7
  true
8
8
  end
9
9
 
10
- desc "list", "List all active machines"
10
+ desc "list", "List machines"
11
11
  option :retired, type: :boolean, desc: "Show retired machines instead"
12
12
  option :sp, type: :boolean, desc: "Show Starting Point machines"
13
+ option :unsolved, type: :boolean, desc: "Show only unsolved machines"
14
+ option :difficulty, type: :string, desc: "Filter by difficulty (Easy, Medium, Hard, Insane)"
13
15
  def list
14
16
  client = CLI.client
15
17
 
@@ -24,23 +26,42 @@ module HTB
24
26
  end
25
27
 
26
28
  if machines && machines["info"]
27
- rows = machines["info"].map do |m|
29
+ machine_list = machines["info"]
30
+
31
+ if options[:unsolved]
32
+ machine_list = machine_list.reject do |m|
33
+ m["authUserInUserOwns"] && m["authUserInRootOwns"]
34
+ end
35
+ end
36
+
37
+ if options[:difficulty]
38
+ diff = options[:difficulty].downcase
39
+ machine_list = machine_list.select do |m|
40
+ (m["difficultyText"] || "").downcase == diff
41
+ end
42
+ end
43
+
44
+ rows = machine_list.map do |m|
28
45
  difficulty = m["difficultyText"] || m["difficulty"] || "N/A"
29
46
  os = m["os"] || "N/A"
47
+ user_own = m["authUserInUserOwns"] ? CLI.pastel.green("Y") : CLI.pastel.red("-")
48
+ root_own = m["authUserInRootOwns"] ? CLI.pastel.green("Y") : CLI.pastel.red("-")
30
49
  [
31
50
  m["id"],
32
51
  m["name"],
33
52
  os,
34
53
  difficulty,
35
- m["user_owns_count"] || 0,
36
- m["root_owns_count"] || 0,
37
- m["release"] || "N/A"
54
+ user_own,
55
+ root_own,
56
+ m["release"]&.slice(0, 10) || "N/A"
38
57
  ]
39
58
  end
40
59
 
41
- puts CLI.pastel.bold("\nMachines:")
60
+ label = options[:retired] ? "Retired" : options[:sp] ? "Starting Point" : "Active"
61
+ label += " (unsolved)" if options[:unsolved]
62
+ puts CLI.pastel.bold("\n#{label} Machines:")
42
63
  CLI.print_table(
43
- ["ID", "Name", "OS", "Difficulty", "User Owns", "Root Owns", "Released"],
64
+ ["ID", "Name", "OS", "Difficulty", "User", "Root", "Released"],
44
65
  rows
45
66
  )
46
67
  puts "\nTotal: #{rows.size} machines"
data/lib/htb/machines.rb CHANGED
@@ -6,10 +6,16 @@ module HTB
6
6
  @client = client
7
7
  end
8
8
 
9
- # List all machines
10
- # GET /api/v4/machine/list
9
+ # List active machines (current season)
10
+ # GET /api/v4/machine/paginated
11
11
  def list
12
- @client.get("/machine/list")
12
+ paginate("/machine/paginated")
13
+ end
14
+
15
+ # List all retired machines (full VIP+ back catalog)
16
+ # GET /api/v4/machine/list/retired/paginated
17
+ def retired
18
+ paginate("/machine/list/retired/paginated")
13
19
  end
14
20
 
15
21
  # Get machine profile by ID or name
@@ -38,9 +44,6 @@ module HTB
38
44
 
39
45
  # Submit flag for machine ownership
40
46
  # POST /api/v4/machine/own
41
- # @param machine_id [Integer] Machine ID
42
- # @param flag [String] The flag to submit
43
- # @param difficulty [Integer] Difficulty rating (10-100)
44
47
  def own(machine_id:, flag:, difficulty: 50)
45
48
  @client.post("/machine/own", {
46
49
  id: machine_id,
@@ -87,10 +90,6 @@ module HTB
87
90
 
88
91
  # Submit machine review
89
92
  # POST /api/v4/machine/review
90
- # @param machine_id [Integer] Machine ID
91
- # @param stars [Integer] Star rating (1-5)
92
- # @param headline [String] Review headline
93
- # @param review [String] Review text
94
93
  def review(machine_id:, stars:, headline:, review:)
95
94
  @client.post("/machine/review", {
96
95
  id: machine_id,
@@ -112,31 +111,37 @@ module HTB
112
111
  @client.get("/machine/spawned")
113
112
  end
114
113
 
115
- # Get retired machines
116
- # GET /api/v4/machine/list/retired
117
- def retired
118
- @client.get("/machine/list/retired")
119
- end
120
-
121
114
  # Get starting point machines
122
115
  # GET /api/v4/machine/list/sp
123
116
  def starting_point
124
117
  @client.get("/machine/list/sp")
125
118
  end
126
119
 
127
- # Get paginated machine list
128
- # GET /api/v4/machine/paginated
129
- def paginated(page: 1, per_page: 20, sort_by: nil, sort_type: nil)
130
- params = { page: page, per_page: per_page }
131
- params[:sort_by] = sort_by if sort_by
132
- params[:sort_type] = sort_type if sort_type
133
- @client.get("/machine/paginated", params)
134
- end
135
-
136
120
  # Search machines
137
121
  # GET /api/v4/search/fetch?query={query}&tags=[]
138
122
  def search(query, tags: [])
139
123
  @client.get("/search/fetch", { query: query, tags: tags })
140
124
  end
125
+
126
+ private
127
+
128
+ # Fetch all pages from a paginated endpoint and return unified hash
129
+ # with "info" key for CLI compatibility
130
+ def paginate(path)
131
+ all_machines = []
132
+ page = 1
133
+ loop do
134
+ result = @client.get(path, { page: page, per_page: 100 })
135
+ data = result["data"] || []
136
+ break if data.empty?
137
+
138
+ all_machines.concat(data)
139
+ last_page = result.dig("meta", "last_page") || 1
140
+ break if page >= last_page
141
+
142
+ page += 1
143
+ end
144
+ { "info" => all_machines }
145
+ end
141
146
  end
142
147
  end
data/lib/htb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTB
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegj00
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-17 00:00:00.000000000 Z
11
+ date: 2026-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday