togetajob 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9306a243ae6571b7b91b972f0698d014c58187a9ac210b36966e4b130eadda6a
4
+ data.tar.gz: f8ecfbfe47726636b486e1a1432bb878b2004a157dfbf722950b39e1ad8d131b
5
+ SHA512:
6
+ metadata.gz: c31bfdc25bf909e895e420627fb6d46e20bc05f28eef0aae66d662ac91c5f84d63023041c7a2b45062c3f4a54cde2388c9e8a34b8b70ad75b0eadf3b818ccd17
7
+ data.tar.gz: a120ca8ee5ecd12eaff2d56639dc95157fc878fdef27d030373375fe50384785efd48c2c09596308d7775278dbb6948d24ca1ec425c538be992d29d8b67dcdb1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DH
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,86 @@
1
+ # togetajob
2
+
3
+ The official Ruby client for [togetajob.com](https://togetajob.com), a free,
4
+ independent guide to New York City government jobs and civil service exams.
5
+
6
+ No account, no key, no signup. Public reads are rate-limited to 100 requests
7
+ a minute per caller; a free API key raises that to 600 a minute.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ gem install togetajob
13
+ ```
14
+
15
+ Requires Ruby 3.0 or newer. No runtime dependencies (net/http and json from
16
+ the standard library).
17
+
18
+ Or in a Gemfile:
19
+
20
+ ```ruby
21
+ gem "togetajob", "~> 1.0"
22
+ ```
23
+
24
+ ## Use
25
+
26
+ ```ruby
27
+ require "togetajob"
28
+
29
+ client = Togetajob::Client.new
30
+
31
+ health = client.health
32
+ puts "last refresh: #{health["lastRefresh"]}"
33
+
34
+ exams = client.exams
35
+ exams["exams"].each do |e|
36
+ puts "#{e["number"]} #{e["title"]} — filing closes #{e["filingCloses"]}"
37
+ end
38
+
39
+ jobs = client.jobs
40
+ puts "#{jobs.rows.length} open postings"
41
+
42
+ posting = client.posting("808867")
43
+ puts "#{posting["title"]} at #{posting["agency"]}"
44
+ ```
45
+
46
+ ## API keys
47
+
48
+ A key is optional and free, and it only raises the rate limit. Create one
49
+ with no sign-in:
50
+
51
+ ```ruby
52
+ key = client.create_key
53
+ puts key["key"] # shown once; only its hash is stored server-side
54
+ ```
55
+
56
+ Then pass it to the client:
57
+
58
+ ```ruby
59
+ client = Togetajob::Client.new(api_key: "tj_live_...")
60
+ ```
61
+
62
+ Keys expire a year after creation and can be revoked:
63
+
64
+ ```ruby
65
+ client.revoke_key("tj_live_...")
66
+ ```
67
+
68
+ ## What the client wraps
69
+
70
+ | Method | Endpoint | Returns |
71
+ | --- | --- | --- |
72
+ | `health` | `GET /api/health` | API status and last data refresh |
73
+ | `exams` | `GET /data/exams.json` | Civil service exam calendar |
74
+ | `guides` | `GET /data/guides.json` | Step-by-step job guides |
75
+ | `jobs` | `GET /jobs/index.json` | Every open posting, easiest first |
76
+ | `posting(id)` | `GET /api/posting?id=` | One open posting by city job ID |
77
+ | `create_key` | `POST /api/keys` | A free API key, shown once |
78
+ | `revoke_key(key)` | `DELETE /api/keys` | Revokes a key |
79
+
80
+ The full API contract is at https://togetajob.com/data/openapi.json and the
81
+ developer docs at https://togetajob.com/developers. The MCP server lives at
82
+ https://togetajob.com/mcp.
83
+
84
+ ## License
85
+
86
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Togetajob
8
+ # Client talks to the togetajob public API and data feeds.
9
+ class Client
10
+ # @param base_url [String] the site to talk to (default: the public site)
11
+ # @param api_key [String, nil] an optional free API key, sent as X-Api-Key.
12
+ # Without one the client reads as an anonymous caller (100 requests a
13
+ # minute); with one the limit is 600 a minute. Create one with #create_key.
14
+ def initialize(base_url: Togetajob::DEFAULT_BASE_URL, api_key: nil)
15
+ @base_url = base_url.sub(%r{/+\z}, "")
16
+ @api_key = api_key
17
+ end
18
+
19
+ # Health reports whether the API is up and the date of the last refresh.
20
+ # @return [Hash] {"ok" => true, "lastRefresh" => "2026-11-16"}
21
+ def health
22
+ get("/api/health")
23
+ end
24
+
25
+ # Exams returns the civil service exam calendar: every exam with its
26
+ # filing window, fee, and waivers.
27
+ # @return [Hash] {"exams" => [Exam, ...], ...}
28
+ def exams
29
+ get("/data/exams.json")
30
+ end
31
+
32
+ # Guides returns the step-by-step job guides: what each entry-level city
33
+ # title pays, whether it needs an exam, and the exact steps to get hired.
34
+ # @return [Hash] {"guides" => [Guide, ...], ...}
35
+ def guides
36
+ get("/data/guides.json")
37
+ end
38
+
39
+ # Jobs returns the open-postings index: every open city job posting,
40
+ # sorted easiest to get first.
41
+ # @return [JobsIndex]
42
+ def jobs
43
+ JobsIndex.from_json(get("/jobs/index.json"))
44
+ end
45
+
46
+ # Posting looks up one open posting by its city job ID (the number in the
47
+ # official posting URL, e.g. "808867").
48
+ # @return [Hash] the posting
49
+ # @raise [NotFoundError] when no open posting has that ID
50
+ def posting(job_id)
51
+ body = get("/api/posting?id=#{URI.encode_www_form_component(job_id.to_s)}")
52
+ raise NotFoundError, "no open posting with id #{job_id}" unless body["found"]
53
+
54
+ body
55
+ end
56
+
57
+ # CreateKey mints a free, anonymous API key (no sign-in). The key is
58
+ # returned once, in full; only its hash is stored server-side, so keep it
59
+ # somewhere safe. It raises the rate limit from 100 to 600 requests a
60
+ # minute and expires a year after creation. At most 5 keys an hour can be
61
+ # created from one caller.
62
+ # @return [Hash] {"key" => "tj_live_...", "limit" => 600, ...}
63
+ def create_key
64
+ post("/api/keys")
65
+ end
66
+
67
+ # RevokeKey deletes the key. After revocation the caller falls back to
68
+ # the anonymous 100-requests-a-minute limit. Revoking an unknown key
69
+ # raises a 404 APIError.
70
+ def revoke_key(key)
71
+ delete("/api/keys", api_key: key)
72
+ end
73
+
74
+ private
75
+
76
+ def get(path, api_key: @api_key)
77
+ request(:get, path, api_key: api_key)
78
+ end
79
+
80
+ def post(path, api_key: @api_key)
81
+ request(:post, path, api_key: api_key)
82
+ end
83
+
84
+ def delete(path, api_key: @api_key)
85
+ request(:delete, path, api_key: api_key)
86
+ end
87
+
88
+ def request(method, path, api_key:)
89
+ uri = URI(@base_url + path)
90
+ req = case method
91
+ when :get then Net::HTTP::Get.new(uri)
92
+ when :post then Net::HTTP::Post.new(uri)
93
+ when :delete then Net::HTTP::Delete.new(uri)
94
+ end
95
+ req["X-Api-Key"] = api_key if api_key && !api_key.empty?
96
+ req["Content-Type"] = "application/json" if method == :post
97
+ # Net::HTTP.start (not Net::HTTP.new + bare request): the bare form
98
+ # drops chunked SSL responses mid-body on this site (EOFError), while
99
+ # the start block reads them cleanly.
100
+ resp = Net::HTTP.start(uri.host, uri.port,
101
+ use_ssl: uri.scheme == "https",
102
+ open_timeout: 10, read_timeout: 30) do |http|
103
+ http.request(req)
104
+ end
105
+ body = resp.body.to_s
106
+ unless resp.is_a?(Net::HTTPSuccess)
107
+ parsed = begin
108
+ JSON.parse(body)
109
+ rescue JSON::ParserError
110
+ {}
111
+ end
112
+ message = parsed["error"] || body.strip
113
+ message = resp.message if message.empty?
114
+ message += ": #{parsed['resolution']}" if parsed["resolution"]
115
+ raise APIError.new(status: resp.code.to_i, code: parsed["code"], message: message)
116
+ end
117
+ JSON.parse(body)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Togetajob
4
+ # Job is one open city job posting, decoded from the compact positional rows
5
+ # of /jobs/index.json (see fromIndexRow in the site's src/lib/jobrow.js).
6
+ #
7
+ # Row positions: 0 slug, 1 title, 2 agency, 3 salary_text, 4 pay_sort_key,
8
+ # 5 tier, 6 category_indexes, 7 tags, 8 borough_label, 9 full_time (1/0),
9
+ # 10 exam_required (1/0/nil), 11 title_code, 12 closes_at, 13 posted_at,
10
+ # 14 positions, 15 job_id, 16 pay_frequency (1=annual), 17 keywords.
11
+ class Job
12
+ attr_reader :slug, :title, :agency, :salary_text, :pay_sort_key, :tier,
13
+ :category_indexes, :tags, :borough_label, :full_time,
14
+ :exam_required, :title_code, :closes_at, :posted_at,
15
+ :positions, :job_id, :pay_frequency, :keywords
16
+
17
+ def self.from_row(row)
18
+ new(
19
+ slug: row[0],
20
+ title: row[1],
21
+ agency: row[2],
22
+ salary_text: row[3],
23
+ pay_sort_key: row[4],
24
+ tier: row[5],
25
+ category_indexes: row[6],
26
+ tags: row[7],
27
+ borough_label: row[8],
28
+ full_time: row[9] != 0,
29
+ exam_required: row[10].nil? ? nil : row[10] == 1,
30
+ title_code: row[11],
31
+ closes_at: row[12],
32
+ posted_at: row[13],
33
+ positions: row[14],
34
+ job_id: row[15] || "",
35
+ pay_frequency: row[16] == 1 ? "annual" : nil,
36
+ keywords: row[17] || ""
37
+ )
38
+ end
39
+
40
+ def initialize(**attrs)
41
+ attrs.each { |k, v| instance_variable_set(:"@#{k}", v) }
42
+ end
43
+ end
44
+
45
+ # JobsIndex is the /jobs/index.json feed: every open posting, sorted easiest
46
+ # to get first, plus the category list, the guide summaries, and the date
47
+ # the data was checked.
48
+ class JobsIndex
49
+ attr_reader :as_of, :categories, :rows, :guides
50
+
51
+ def self.from_json(body)
52
+ new(
53
+ as_of: body["asOf"],
54
+ categories: body["categories"],
55
+ rows: (body["rows"] || []).map { |r| Job.from_row(r) },
56
+ guides: body["guides"] || []
57
+ )
58
+ end
59
+
60
+ def initialize(as_of:, categories:, rows:, guides:)
61
+ @as_of = as_of
62
+ @categories = categories
63
+ @rows = rows
64
+ @guides = guides
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Togetajob
4
+ VERSION = "1.0.0"
5
+ end
data/lib/togetajob.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "togetajob/version"
4
+ require_relative "togetajob/client"
5
+ require_relative "togetajob/types"
6
+
7
+ # Togetajob is the official Ruby client for togetajob.com, a free,
8
+ # independent guide to New York City government jobs and civil service exams.
9
+ #
10
+ # The public API needs no account and no key. Public reads are rate-limited
11
+ # to 100 requests a minute per caller; a free API key (created with
12
+ # Client#create_key, no sign-in) raises that to 600 a minute.
13
+ module Togetajob
14
+ # The public togetajob site.
15
+ DEFAULT_BASE_URL = "https://togetajob.com"
16
+
17
+ class Error < StandardError; end
18
+
19
+ # A non-2xx response from the API. The body is JSON
20
+ # ({"error": "...", "code": "..."}) and both fields are carried here.
21
+ class APIError < Error
22
+ attr_reader :status, :code
23
+
24
+ def initialize(status:, code:, message:)
25
+ @status = status
26
+ @code = code
27
+ super(message)
28
+ end
29
+ end
30
+
31
+ # A posting that does not exist (the API said found: false).
32
+ class NotFoundError < APIError
33
+ def initialize(message)
34
+ super(status: 404, code: "not_found", message: message)
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: togetajob
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - DH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ description: 'Read the togetajob.com public API and open data feeds: the civil service
42
+ exam calendar, step-by-step job guides, and every open New York City government
43
+ job posting. No account, no key, no signup; a free API key raises the rate limit
44
+ from 100 to 600 requests a minute.'
45
+ email:
46
+ - auth@togetajob.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - LICENSE
52
+ - README.md
53
+ - lib/togetajob.rb
54
+ - lib/togetajob/client.rb
55
+ - lib/togetajob/types.rb
56
+ - lib/togetajob/version.rb
57
+ homepage: https://togetajob.com
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://togetajob.com
62
+ source_code_uri: https://github.com/DoctorHammer/togetajob-ruby
63
+ documentation_uri: https://togetajob.com/developers
64
+ bug_tracker_uri: https://github.com/DoctorHammer/togetajob-ruby/issues
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.4.20
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Official Ruby client for togetajob.com, the free guide to NYC government
84
+ jobs
85
+ test_files: []