crawlbase 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a1ccd286be2a6973c23cc8c9dc84a292af4d49910995054312a68e9beca6761
4
- data.tar.gz: 0da3a67ba36a2151d6b982f7a9dc961adae4a1a58f0aac311d089e2dfd99cce9
3
+ metadata.gz: 42efa911e98c21bc83337c2fd34524b205a04520ae7f13d8c90efd8832cadbee
4
+ data.tar.gz: a031d03c6ed8994135a50ae81279a866918e7feba128e630e22f7908d62c6dee
5
5
  SHA512:
6
- metadata.gz: 4d4b9ce783a5fa43cb0dab14550f01f2fcaed958b31bceeab91a9540456361a226f18fb41e11ae874f7d20862ba49d62088ab492b44c8a9b73c96c5812b8d4f3
7
- data.tar.gz: 39ce7ce6996726bb7a3043277b1170fbc06b05f4cebf2903dc1db242bb4ae865de7a5a7a5eaa5af9f7861fcbccbfff92cce8227f5b2ed7df284c47d4c9f7cbe0
6
+ metadata.gz: ffcd59a906f655aff0010147ab1db09544137344aa987617c544a058d14a3771694a0cf9e641c46cadc36fc42976156a2e1611af9742acc11119a362e4f694b8
7
+ data.tar.gz: 48cddc484f162578332f974b34b1921e7f5429b909bf71389134ec96cf6b0bf54deccd6301371f5680af20394a4b89192194f35986ab70543532d8351dec511c
data/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.2.0] - 2026-07-15
9
+
10
+ ### Added
11
+
12
+ - `cb_status` as the preferred public attribute for Crawlbase status on `Crawlbase::API` (and subclasses) and `Crawlbase::StorageAPI`.
13
+ - Status resolution prefers the `cb_status` response header or JSON field, then falls back to `pc_status` when `cb_status` is absent.
14
+
15
+ ### Deprecated
16
+
17
+ - `pc_status` is deprecated but still supported and returns the same resolved value as `cb_status`. A one-time deprecation warning is emitted when `pc_status` is accessed. Prefer `cb_status`. Removal is planned for a future major release.
18
+
19
+ ### Migration
20
+
21
+ ```ruby
22
+ # Before (deprecated)
23
+ response.pc_status
24
+
25
+ # After (preferred)
26
+ response.cb_status
27
+ ```
data/README.md CHANGED
@@ -56,7 +56,7 @@ begin
56
56
  response = api.get('https://www.facebook.com/britneyspears')
57
57
  puts response.status_code
58
58
  puts response.original_status
59
- puts response.pc_status
59
+ puts response.cb_status
60
60
  puts response.body
61
61
  rescue => exception
62
62
  puts exception.backtrace
@@ -125,17 +125,32 @@ response = api.get('https://www.freelancer.com', options: { page_wait: 5000 })
125
125
  puts response.status_code
126
126
  ```
127
127
 
128
- ## Original status
128
+ ## Original status and Crawlbase status
129
129
 
130
- You can always get the original status and crawlbase status from the response. Read the [Crawlbase documentation](https://crawlbase.com/dashboard/docs) to learn more about those status.
130
+ You can always get the original status and Crawlbase status from the response. Read the [Crawlbase documentation](https://crawlbase.com/dashboard/docs) to learn more about those statuses.
131
+
132
+ Prefer `cb_status` for the Crawlbase status. `pc_status` is deprecated but still supported temporarily and returns the same resolved value.
131
133
 
132
134
  ```ruby
133
135
  response = api.get('https://sfbay.craigslist.org/')
134
136
 
135
137
  puts response.original_status
136
- puts response.pc_status
138
+ puts response.cb_status # preferred
139
+ # puts response.pc_status # deprecated; same value as cb_status
137
140
  ```
138
141
 
142
+ ### Migrating from `pc_status` to `cb_status`
143
+
144
+ ```ruby
145
+ # Before (deprecated)
146
+ response.pc_status
147
+
148
+ # After (preferred)
149
+ response.cb_status
150
+ ```
151
+
152
+ The library reads `cb_status` from the API response first, then falls back to `pc_status` if `cb_status` is not present.
153
+
139
154
  ## Scraper API usage
140
155
 
141
156
  Initialize the Scraper API using your normal token and call the `get` method.
@@ -254,7 +269,7 @@ Pass the [url](https://crawlbase.com/docs/storage-api/parameters/#url) that you
254
269
  begin
255
270
  response = storage_api.get('https://www.apple.com')
256
271
  puts response.original_status
257
- puts response.pc_status
272
+ puts response.cb_status
258
273
  puts response.url
259
274
  puts response.status_code
260
275
  puts response.rid
@@ -271,7 +286,7 @@ or you can use the [RID](https://crawlbase.com/docs/storage-api/parameters/#rid)
271
286
  begin
272
287
  response = storage_api.get(RID)
273
288
  puts response.original_status
274
- puts response.pc_status
289
+ puts response.cb_status
275
290
  puts response.url
276
291
  puts response.status_code
277
292
  puts response.rid
@@ -304,7 +319,7 @@ To do a bulk request with a list of RIDs, please send the list of rids as an arr
304
319
  begin
305
320
  response = storage_api.bulk([RID1, RID2, RID3, ...])
306
321
  puts response.original_status
307
- puts response.pc_status
322
+ puts response.cb_status
308
323
  puts response.url
309
324
  puts response.status_code
310
325
  puts response.rid
@@ -367,4 +382,4 @@ Everyone interacting in the Crawlbase project's codebases, issue trackers, chat
367
382
 
368
383
  ---
369
384
 
370
- Copyright 2025 Crawlbase
385
+ Copyright 2026 Crawlbase
data/lib/crawlbase/api.rb CHANGED
@@ -6,7 +6,11 @@ require 'uri'
6
6
 
7
7
  module Crawlbase
8
8
  class API
9
- attr_reader :token, :body, :status_code, :original_status, :pc_status, :url, :storage_url, :timeout
9
+ # Crawlbase HTTP response code for the API call itself.
10
+ attr_reader :token, :body, :status_code, :original_status, :url, :storage_url, :timeout
11
+
12
+ # Crawlbase status from the response (preferred name for former +pc_status+).
13
+ attr_reader :cb_status
10
14
 
11
15
  INVALID_TOKEN = 'Token is required'
12
16
  INVALID_URL = 'URL is required'
@@ -19,6 +23,12 @@ module Crawlbase
19
23
  @timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
20
24
  end
21
25
 
26
+ # Deprecated: use {#cb_status}. Returns the same resolved Crawlbase status.
27
+ def pc_status
28
+ StatusResolution.warn_pc_status_deprecated
29
+ @pc_status
30
+ end
31
+
22
32
  def get(url, options = {})
23
33
  raise INVALID_URL if url.empty?
24
34
 
@@ -80,7 +90,8 @@ module Crawlbase
80
90
  res = format == 'json' || base_url.include?('/scraper') ? JSON.parse(response.body) : response
81
91
 
82
92
  @original_status = res['original_status'].to_i
83
- @pc_status = res['pc_status'].to_i
93
+ @cb_status = StatusResolution.resolve_cb_status(res)
94
+ @pc_status = @cb_status
84
95
  @url = res['url']
85
96
  @storage_url = res['storage_url']
86
97
  @status_code = response.code.to_i
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crawlbase
4
+ # Resolves Crawlbase status from response headers or JSON bodies.
5
+ # Prefers +cb_status+, falling back to deprecated +pc_status+.
6
+ module StatusResolution
7
+ PC_STATUS_DEPRECATION =
8
+ '[Crawlbase] `pc_status` is deprecated and will be removed in a future major release. Use `cb_status` instead.'
9
+
10
+ module_function
11
+
12
+ def resolve_cb_status(source)
13
+ raw = source['cb_status']
14
+ raw = source['pc_status'] if raw.nil? || raw.to_s.empty?
15
+ raw.to_i
16
+ end
17
+
18
+ def warn_pc_status_deprecated
19
+ return if Crawlbase.instance_variable_get(:@pc_status_deprecation_warned)
20
+
21
+ Crawlbase.instance_variable_set(:@pc_status_deprecation_warned, true)
22
+ warn PC_STATUS_DEPRECATION, uplevel: 1
23
+ end
24
+ end
25
+ end
@@ -6,7 +6,10 @@ require 'uri'
6
6
 
7
7
  module Crawlbase
8
8
  class StorageAPI
9
- attr_reader :token, :original_status, :pc_status, :url, :status_code, :rid, :body, :stored_at
9
+ attr_reader :token, :original_status, :url, :status_code, :rid, :body, :stored_at
10
+
11
+ # Crawlbase status from the response (preferred name for former +pc_status+).
12
+ attr_reader :cb_status
10
13
 
11
14
  INVALID_TOKEN = 'Token is required'
12
15
  INVALID_RID = 'RID is required'
@@ -20,6 +23,12 @@ module Crawlbase
20
23
  @token = options[:token]
21
24
  end
22
25
 
26
+ # Deprecated: use {#cb_status}. Returns the same resolved Crawlbase status.
27
+ def pc_status
28
+ StatusResolution.warn_pc_status_deprecated
29
+ @pc_status
30
+ end
31
+
23
32
  def get(url_or_rid, format = 'html')
24
33
  raise INVALID_URL_OR_RID if url_or_rid.nil? || url_or_rid.empty?
25
34
 
@@ -30,7 +39,8 @@ module Crawlbase
30
39
  res = format == 'json' ? JSON.parse(response.body) : response
31
40
 
32
41
  @original_status = res['original_status'].to_i
33
- @pc_status = res['pc_status'].to_i
42
+ @cb_status = StatusResolution.resolve_cb_status(res)
43
+ @pc_status = @cb_status
34
44
  @url = res['url']
35
45
  @rid = res['rid']
36
46
  @stored_at = res['stored_at']
@@ -50,7 +60,7 @@ module Crawlbase
50
60
  request = Net::HTTP::Delete.new(uri.request_uri)
51
61
  response = http.request(request)
52
62
 
53
- @url, @original_status, @pc_status, @stored_at = nil
63
+ @url, @original_status, @cb_status, @pc_status, @stored_at = nil
54
64
  @status_code = response.code.to_i
55
65
  @rid = rid
56
66
  @body = JSON.parse(response.body)
@@ -71,7 +81,8 @@ module Crawlbase
71
81
  @body = JSON.parse(response.body)
72
82
  @original_status = @body.map { |item| item['original_status'].to_i }
73
83
  @status_code = response.code.to_i
74
- @pc_status = @body.map { |item| item['pc_status'].to_i }
84
+ @cb_status = @body.map { |item| StatusResolution.resolve_cb_status(item) }
85
+ @pc_status = @cb_status
75
86
  @url = @body.map { |item| item['url'] }
76
87
  @rid = @body.map { |item| item['rid'] }
77
88
  @stored_at = @body.map { |item| item['stored_at'] }
@@ -86,7 +97,7 @@ module Crawlbase
86
97
  uri.query = URI.encode_www_form(query_hash)
87
98
 
88
99
  response = Net::HTTP.get_response(uri)
89
- @url, @original_status, @pc_status, @stored_at = nil
100
+ @url, @original_status, @cb_status, @pc_status, @stored_at = nil
90
101
  @status_code = response.code.to_i
91
102
  @body = JSON.parse(response.body)
92
103
  @rid = @body
@@ -99,7 +110,7 @@ module Crawlbase
99
110
  uri.query = URI.encode_www_form(token: token)
100
111
 
101
112
  response = Net::HTTP.get_response(uri)
102
- @url, @original_status, @pc_status, @stored_at = nil
113
+ @url, @original_status, @cb_status, @pc_status, @stored_at = nil
103
114
  @status_code = response.code.to_i
104
115
  @rid = rid
105
116
  @body = JSON.parse(response.body)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crawlbase
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
data/lib/crawlbase.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'crawlbase/version'
4
+ require 'crawlbase/status_resolution'
4
5
  require 'crawlbase/api'
5
6
  require 'crawlbase/scraper_api'
6
7
  require 'crawlbase/leads_api'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crawlbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crawlbase
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-25 00:00:00.000000000 Z
11
+ date: 2026-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - CHANGELOG.md
92
93
  - CODE_OF_CONDUCT.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
@@ -102,6 +103,7 @@ files:
102
103
  - lib/crawlbase/leads_api.rb
103
104
  - lib/crawlbase/scraper_api.rb
104
105
  - lib/crawlbase/screenshots_api.rb
106
+ - lib/crawlbase/status_resolution.rb
105
107
  - lib/crawlbase/storage_api.rb
106
108
  - lib/crawlbase/version.rb
107
109
  homepage: https://github.com/crawlbase-source/crawlbase-ruby
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  requirements: []
126
- rubygems_version: 3.6.0.dev
128
+ rubygems_version: 3.5.11
127
129
  signing_key:
128
130
  specification_version: 4
129
131
  summary: Crawlbase API client for web scraping and crawling