berrycrawl 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.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.fern/metadata.json +12 -0
  3. data/.rubocop.yml +103 -0
  4. data/CONTRIBUTING.md +120 -0
  5. data/LICENSE +17 -0
  6. data/README.md +183 -0
  7. data/Rakefile +20 -0
  8. data/custom.gemspec.rb +16 -0
  9. data/lib/Berrycrawl/account/client.rb +44 -0
  10. data/lib/Berrycrawl/brand/client.rb +48 -0
  11. data/lib/Berrycrawl/brand/types/brand_dto.rb +15 -0
  12. data/lib/Berrycrawl/client.rb +268 -0
  13. data/lib/Berrycrawl/environment.rb +7 -0
  14. data/lib/Berrycrawl/errors/api_error.rb +8 -0
  15. data/lib/Berrycrawl/errors/client_error.rb +17 -0
  16. data/lib/Berrycrawl/errors/redirect_error.rb +8 -0
  17. data/lib/Berrycrawl/errors/response_error.rb +42 -0
  18. data/lib/Berrycrawl/errors/server_error.rb +11 -0
  19. data/lib/Berrycrawl/errors/timeout_error.rb +8 -0
  20. data/lib/Berrycrawl/internal/errors/constraint_error.rb +10 -0
  21. data/lib/Berrycrawl/internal/errors/type_error.rb +10 -0
  22. data/lib/Berrycrawl/internal/http/base_request.rb +51 -0
  23. data/lib/Berrycrawl/internal/http/raw_client.rb +252 -0
  24. data/lib/Berrycrawl/internal/iterators/cursor_item_iterator.rb +28 -0
  25. data/lib/Berrycrawl/internal/iterators/cursor_page_iterator.rb +63 -0
  26. data/lib/Berrycrawl/internal/iterators/item_iterator.rb +65 -0
  27. data/lib/Berrycrawl/internal/iterators/offset_item_iterator.rb +30 -0
  28. data/lib/Berrycrawl/internal/iterators/offset_page_iterator.rb +103 -0
  29. data/lib/Berrycrawl/internal/json/request.rb +41 -0
  30. data/lib/Berrycrawl/internal/json/serializable.rb +25 -0
  31. data/lib/Berrycrawl/internal/multipart/multipart_encoder.rb +141 -0
  32. data/lib/Berrycrawl/internal/multipart/multipart_form_data.rb +78 -0
  33. data/lib/Berrycrawl/internal/multipart/multipart_form_data_part.rb +51 -0
  34. data/lib/Berrycrawl/internal/multipart/multipart_request.rb +40 -0
  35. data/lib/Berrycrawl/internal/types/array.rb +47 -0
  36. data/lib/Berrycrawl/internal/types/boolean.rb +34 -0
  37. data/lib/Berrycrawl/internal/types/enum.rb +56 -0
  38. data/lib/Berrycrawl/internal/types/hash.rb +36 -0
  39. data/lib/Berrycrawl/internal/types/model/field.rb +38 -0
  40. data/lib/Berrycrawl/internal/types/model.rb +208 -0
  41. data/lib/Berrycrawl/internal/types/type.rb +35 -0
  42. data/lib/Berrycrawl/internal/types/union.rb +161 -0
  43. data/lib/Berrycrawl/internal/types/unknown.rb +15 -0
  44. data/lib/Berrycrawl/internal/types/utils.rb +116 -0
  45. data/lib/Berrycrawl/jobs/client.rb +127 -0
  46. data/lib/Berrycrawl/jobs/types/cancel_jobs_request.rb +11 -0
  47. data/lib/Berrycrawl/jobs/types/get_jobs_request.rb +15 -0
  48. data/lib/Berrycrawl/jobs/types/list_jobs_request.rb +17 -0
  49. data/lib/Berrycrawl/jobs/types/list_jobs_request_status.rb +17 -0
  50. data/lib/Berrycrawl/jobs/types/list_jobs_request_type.rb +14 -0
  51. data/lib/Berrycrawl/types/account_response.rb +11 -0
  52. data/lib/Berrycrawl/types/account_response_data.rb +21 -0
  53. data/lib/Berrycrawl/types/account_response_data_plan.rb +17 -0
  54. data/lib/Berrycrawl/types/account_response_data_queue.rb +11 -0
  55. data/lib/Berrycrawl/types/action_dto.rb +21 -0
  56. data/lib/Berrycrawl/types/action_dto_direction.rb +12 -0
  57. data/lib/Berrycrawl/types/action_dto_type.rb +18 -0
  58. data/lib/Berrycrawl/types/agent_config_dto.rb +11 -0
  59. data/lib/Berrycrawl/types/agent_config_dto_mode.rb +12 -0
  60. data/lib/Berrycrawl/types/brand_asset.rb +17 -0
  61. data/lib/Berrycrawl/types/brand_profile.rb +27 -0
  62. data/lib/Berrycrawl/types/brand_profile_colors_item.rb +11 -0
  63. data/lib/Berrycrawl/types/brand_profile_fonts_item.rb +11 -0
  64. data/lib/Berrycrawl/types/brand_profile_socials_item.rb +11 -0
  65. data/lib/Berrycrawl/types/brand_response.rb +11 -0
  66. data/lib/Berrycrawl/types/brand_response_data.rb +11 -0
  67. data/lib/Berrycrawl/types/brand_response_data_meta.rb +15 -0
  68. data/lib/Berrycrawl/types/cancel_job_response.rb +11 -0
  69. data/lib/Berrycrawl/types/cancel_job_response_data.rb +11 -0
  70. data/lib/Berrycrawl/types/change_tracking_format_dto.rb +15 -0
  71. data/lib/Berrycrawl/types/change_tracking_format_dto_type.rb +11 -0
  72. data/lib/Berrycrawl/types/crawl_dto.rb +41 -0
  73. data/lib/Berrycrawl/types/crawl_dto_sitemap.rb +13 -0
  74. data/lib/Berrycrawl/types/extract_dto.rb +29 -0
  75. data/lib/Berrycrawl/types/extract_webhook_config_dto.rb +15 -0
  76. data/lib/Berrycrawl/types/job_created_response.rb +15 -0
  77. data/lib/Berrycrawl/types/job_response.rb +11 -0
  78. data/lib/Berrycrawl/types/job_response_data.rb +37 -0
  79. data/lib/Berrycrawl/types/job_response_data_errors_item.rb +11 -0
  80. data/lib/Berrycrawl/types/job_summary.rb +29 -0
  81. data/lib/Berrycrawl/types/job_summary_type.rb +12 -0
  82. data/lib/Berrycrawl/types/json_format_dto.rb +13 -0
  83. data/lib/Berrycrawl/types/json_format_dto_type.rb +11 -0
  84. data/lib/Berrycrawl/types/list_jobs_response.rb +11 -0
  85. data/lib/Berrycrawl/types/list_jobs_response_data.rb +11 -0
  86. data/lib/Berrycrawl/types/list_webhooks_response.rb +11 -0
  87. data/lib/Berrycrawl/types/location_dto.rb +11 -0
  88. data/lib/Berrycrawl/types/map_dto.rb +23 -0
  89. data/lib/Berrycrawl/types/map_dto_sitemap.rb +13 -0
  90. data/lib/Berrycrawl/types/map_link.rb +13 -0
  91. data/lib/Berrycrawl/types/map_response.rb +15 -0
  92. data/lib/Berrycrawl/types/message_response.rb +11 -0
  93. data/lib/Berrycrawl/types/pagination.rb +15 -0
  94. data/lib/Berrycrawl/types/parse_dto.rb +11 -0
  95. data/lib/Berrycrawl/types/scrape_dto.rb +49 -0
  96. data/lib/Berrycrawl/types/scrape_dto_formats_item.rb +17 -0
  97. data/lib/Berrycrawl/types/scrape_dto_formats_item_zero.rb +18 -0
  98. data/lib/Berrycrawl/types/scrape_dto_proxy.rb +16 -0
  99. data/lib/Berrycrawl/types/scrape_metadata.rb +17 -0
  100. data/lib/Berrycrawl/types/scrape_response.rb +17 -0
  101. data/lib/Berrycrawl/types/scrape_response_credits.rb +9 -0
  102. data/lib/Berrycrawl/types/screenshot_clip_dto.rb +15 -0
  103. data/lib/Berrycrawl/types/screenshot_cookie_dto.rb +21 -0
  104. data/lib/Berrycrawl/types/screenshot_cookie_dto_same_site.rb +13 -0
  105. data/lib/Berrycrawl/types/screenshot_dto.rb +79 -0
  106. data/lib/Berrycrawl/types/screenshot_dto_color_scheme.rb +12 -0
  107. data/lib/Berrycrawl/types/screenshot_dto_device.rb +15 -0
  108. data/lib/Berrycrawl/types/screenshot_dto_format.rb +13 -0
  109. data/lib/Berrycrawl/types/screenshot_dto_full_page_algorithm.rb +13 -0
  110. data/lib/Berrycrawl/types/screenshot_dto_proxy.rb +16 -0
  111. data/lib/Berrycrawl/types/screenshot_dto_response_format.rb +12 -0
  112. data/lib/Berrycrawl/types/screenshot_dto_scale.rb +12 -0
  113. data/lib/Berrycrawl/types/screenshot_dto_wait_until.rb +13 -0
  114. data/lib/Berrycrawl/types/screenshot_location_dto.rb +11 -0
  115. data/lib/Berrycrawl/types/screenshot_viewport_dto.rb +11 -0
  116. data/lib/Berrycrawl/types/search_dto.rb +23 -0
  117. data/lib/Berrycrawl/types/search_response.rb +19 -0
  118. data/lib/Berrycrawl/types/search_response_provider.rb +11 -0
  119. data/lib/Berrycrawl/types/search_result.rb +19 -0
  120. data/lib/Berrycrawl/types/search_result_provider.rb +11 -0
  121. data/lib/Berrycrawl/types/summary_format_dto.rb +11 -0
  122. data/lib/Berrycrawl/types/summary_format_dto_type.rb +11 -0
  123. data/lib/Berrycrawl/types/test_webhook_response.rb +15 -0
  124. data/lib/Berrycrawl/types/webhook.rb +23 -0
  125. data/lib/Berrycrawl/types/webhook_config_dto.rb +15 -0
  126. data/lib/Berrycrawl/types/webhook_response.rb +11 -0
  127. data/lib/Berrycrawl/version.rb +5 -0
  128. data/lib/Berrycrawl/webhooks/client.rb +214 -0
  129. data/lib/Berrycrawl/webhooks/types/create_webhook_dto.rb +13 -0
  130. data/lib/Berrycrawl/webhooks/types/delete_webhooks_request.rb +11 -0
  131. data/lib/Berrycrawl/webhooks/types/get_webhooks_request.rb +11 -0
  132. data/lib/Berrycrawl/webhooks/types/test_webhook_dto.rb +15 -0
  133. data/lib/Berrycrawl/webhooks/types/update_webhook_dto.rb +17 -0
  134. data/lib/Berrycrawl.rb +130 -0
  135. data/reference.md +1759 -0
  136. metadata +179 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e72ddcb7e1f231189749c045fa62223de12c715a8f767c163e84d0856df40be
4
+ data.tar.gz: c5d667b602860e6fa52c360d019b177f037e0befb123bb4286390864ea5d7ebb
5
+ SHA512:
6
+ metadata.gz: 0bbb2bf3a70a0a9fb447c080ee59dbbf36f5fffd17ca66ddf3ed69ddb9310c8455034692885901dc1df5daa0c42dd19491b7990dec1842f9f0d03f244377232f
7
+ data.tar.gz: d7ae3f5ea207dfba87d1cb532ef32a12edcfb8162db22688e738baf5db67b22e523baa1ccf2fce906c77488b8cf3028902c044964a8bd06f99be0e399c11c0fd
@@ -0,0 +1,12 @@
1
+ {
2
+ "cliVersion": "5.72.1",
3
+ "generatorName": "fernapi/fern-ruby-sdk",
4
+ "generatorVersion": "1.17.1",
5
+ "generatorConfig": {
6
+ "moduleName": "Berrycrawl"
7
+ },
8
+ "originGitCommit": "a392c48ac4c6239a0801aa8866d9ad06f5f10496",
9
+ "originGitCommitIsDirty": true,
10
+ "invokedBy": "manual",
11
+ "requestedVersion": "0.1.0"
12
+ }
data/.rubocop.yml ADDED
@@ -0,0 +1,103 @@
1
+ plugins:
2
+ - rubocop-minitest
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.3
6
+ NewCops: enable
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/AccessModifierDeclarations:
15
+ Enabled: false
16
+
17
+ Lint/ConstantDefinitionInBlock:
18
+ Enabled: false
19
+
20
+ Metrics/AbcSize:
21
+ Enabled: false
22
+
23
+ Metrics/BlockLength:
24
+ Enabled: false
25
+
26
+ Metrics/ClassLength:
27
+ Enabled: false
28
+
29
+ Metrics/MethodLength:
30
+ Enabled: false
31
+
32
+ Metrics/ParameterLists:
33
+ Enabled: false
34
+
35
+ Metrics/PerceivedComplexity:
36
+ Enabled: false
37
+
38
+ Metrics/CyclomaticComplexity:
39
+ Enabled: false
40
+
41
+ Metrics/ModuleLength:
42
+ Enabled: false
43
+
44
+ Layout/LineLength:
45
+ Enabled: false
46
+
47
+ Naming/VariableNumber:
48
+ EnforcedStyle: normalcase
49
+ Severity: warning
50
+
51
+ Style/Documentation:
52
+ Enabled: false
53
+
54
+ Style/Lambda:
55
+ EnforcedStyle: literal
56
+
57
+ Minitest/MultipleAssertions:
58
+ Enabled: false
59
+
60
+ Minitest/UselessAssertion:
61
+ Enabled: false
62
+
63
+ # Dynamic snippets are code samples for documentation, not standalone Ruby files.
64
+ Style/FrozenStringLiteralComment:
65
+ Exclude:
66
+ - "dynamic-snippets/**/*"
67
+
68
+ # Indent hash elements 2 spaces from the start of the enclosing line rather than
69
+ # aligning with the preceding paren or bracket. Generated code nests hashes inside
70
+ # arrays and method calls; the "consistent" style is more readable there.
71
+ Layout/FirstHashElementIndentation:
72
+ EnforcedStyle: consistent
73
+ Exclude:
74
+ - "dynamic-snippets/**/*"
75
+
76
+ # Match Layout/FirstHashElementIndentation: indent the first argument 2 spaces
77
+ # from the start of the method call's line, regardless of parenthesis position.
78
+ # Dynamic snippets are code samples, not standalone Ruby files; exclude them to
79
+ # keep this config symmetric with Layout/FirstHashElementIndentation above.
80
+ Layout/FirstArgumentIndentation:
81
+ EnforcedStyle: consistent
82
+ Exclude:
83
+ - "dynamic-snippets/**/*"
84
+
85
+ # The generator emits non-idiomatic class names (e.g. Get_With_Query, JSON_)
86
+ # derived from IR type names whose wire form contains underscores or digits.
87
+ # Rubocop never auto-corrected these (naming cops have no autocorrecter), so
88
+ # disabling the cop keeps CI green without changing customer output. Fixing at
89
+ # source would rename public types across every existing SDK and therefore
90
+ # requires a ruby-v2 major-version bump with a generator migration.
91
+ Naming/ClassAndModuleCamelCase:
92
+ Enabled: false
93
+
94
+ # Integer literals are emitted unformatted (e.g. 1000000, not 1_000_000).
95
+ # Rubocop has an autocorrecter for this cop, but the only caller of integer
96
+ # emission is the dynamic-snippets path, which feeds customer-facing surfaces:
97
+ # (1) snippet markdown in reference docs, (2) dynamic-snippets/*.rb sample
98
+ # files. Neither is rubocop-gated (markdown isn't Ruby, dynamic-snippets/**/*
99
+ # is excluded above), so formatting integers there would change docs/dashboard
100
+ # output without any rubocop benefit. Disabling the cop keeps integers raw
101
+ # everywhere and avoids customer-visible diffs.
102
+ Style/NumericLiterals:
103
+ Enabled: false
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,120 @@
1
+ # Contributing
2
+
3
+ Thanks for your interest in contributing to this SDK! This document provides guidelines for contributing to the project.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Ruby 3.0+
10
+ - Bundler
11
+
12
+ ### Installation
13
+
14
+ Install the project dependencies:
15
+
16
+ ```bash
17
+ bundle install
18
+ ```
19
+
20
+ ### Building
21
+
22
+ Build the gem:
23
+
24
+ ```bash
25
+ gem build *.gemspec
26
+ ```
27
+
28
+ ### Testing
29
+
30
+ Run the test suite:
31
+
32
+ ```bash
33
+ bundle exec rspec
34
+ ```
35
+
36
+ ### Linting and Formatting
37
+
38
+ Check code style:
39
+
40
+ ```bash
41
+ bundle exec rubocop
42
+ ```
43
+
44
+ Fix code style issues:
45
+
46
+ ```bash
47
+ bundle exec rubocop -a
48
+ ```
49
+
50
+ ## About Generated Code
51
+
52
+ **Important**: Most files in this SDK are automatically generated by [Fern](https://buildwithfern.com) from the API definition. Direct modifications to generated files will be overwritten the next time the SDK is generated.
53
+
54
+ ### Generated Files
55
+
56
+ The following directories contain generated code:
57
+ - `lib/` - API client classes and types
58
+ - Most Ruby files in the project
59
+
60
+ ### How to Customize
61
+
62
+ If you need to customize the SDK, you have two options:
63
+
64
+ #### Option 1: Use `.fernignore`
65
+
66
+ For custom code that should persist across SDK regenerations:
67
+
68
+ 1. Create a `.fernignore` file in the project root
69
+ 2. Add file patterns for files you want to preserve (similar to `.gitignore` syntax)
70
+ 3. Add your custom code to those files
71
+
72
+ Files listed in `.fernignore` will not be overwritten when the SDK is regenerated.
73
+
74
+ For more information, see the [Fern documentation on custom code](https://buildwithfern.com/learn/sdks/overview/custom-code).
75
+
76
+ #### Option 2: Contribute to the Generator
77
+
78
+ If you want to change how code is generated for all users of this SDK:
79
+
80
+ 1. The Ruby SDK generator lives in the [Fern repository](https://github.com/fern-api/fern)
81
+ 2. Generator code is located at `generators/ruby-v2/`
82
+ 3. Follow the [Fern contributing guidelines](https://github.com/fern-api/fern/blob/main/CONTRIBUTING.md)
83
+ 4. Submit a pull request with your changes to the generator
84
+
85
+ This approach is best for:
86
+ - Bug fixes in generated code
87
+ - New features that would benefit all users
88
+ - Improvements to code generation patterns
89
+
90
+ ## Making Changes
91
+
92
+ ### Workflow
93
+
94
+ 1. Create a new branch for your changes
95
+ 2. Make your modifications
96
+ 3. Run tests to ensure nothing breaks: `bundle exec rspec`
97
+ 4. Run linting: `bundle exec rubocop`
98
+ 5. Build the gem: `gem build *.gemspec`
99
+ 6. Commit your changes with a clear commit message
100
+ 7. Push your branch and create a pull request
101
+
102
+ ### Commit Messages
103
+
104
+ Write clear, descriptive commit messages that explain what changed and why.
105
+
106
+ ### Code Style
107
+
108
+ This project uses RuboCop for code formatting. Run `bundle exec rubocop` before committing to ensure your code meets the project's style guidelines.
109
+
110
+ ## Questions or Issues?
111
+
112
+ If you have questions or run into issues:
113
+
114
+ 1. Check the [Fern documentation](https://buildwithfern.com)
115
+ 2. Search existing [GitHub issues](https://github.com/fern-api/fern/issues)
116
+ 3. Open a new issue if your question hasn't been addressed
117
+
118
+ ## License
119
+
120
+ By contributing to this project, you agree that your contributions will be licensed under the same license as the project.
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Strawberry Labs LLC
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ https://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Berrycrawl Ruby SDK
2
+
3
+
4
+ The official Ruby SDK for scraping, crawling, searching, mapping, structured extraction, screenshots, and brand profiles.
5
+
6
+ [Documentation](https://docs.berrycrawl.com) · [Dashboard](https://app.berrycrawl.com) · [GitHub](https://github.com/strawberry-labs/berrycrawl-ruby)
7
+
8
+ ## Table of Contents
9
+
10
+ - [Reference](#reference)
11
+ - [Usage](#usage)
12
+ - [Environments](#environments)
13
+ - [Errors](#errors)
14
+ - [Advanced](#advanced)
15
+ - [Retries](#retries)
16
+ - [Timeouts](#timeouts)
17
+ - [Additional Headers](#additional-headers)
18
+ - [Additional Query Parameters](#additional-query-parameters)
19
+ - [Contributing](#contributing)
20
+
21
+ ## Reference
22
+
23
+ A full reference for this library is available [here](./reference.md).
24
+
25
+ ## Usage
26
+
27
+ Set `BERRYCRAWL_API_KEY` to an API key from the [Berrycrawl dashboard](https://app.berrycrawl.com).
28
+
29
+ ```ruby
30
+ require "berrycrawl"
31
+
32
+ client = Berrycrawl::Client.new(api_key: ENV.fetch("BERRYCRAWL_API_KEY"))
33
+ page = client.scrape(url: "https://example.com/pricing")
34
+ puts page.data["markdown"]
35
+ ```
36
+
37
+ ### Crawl, search, and map
38
+
39
+ ```ruby
40
+ job = client.crawl(url: "https://example.com/docs", limit: 50)
41
+ results = client.search(query: "best headless browser libraries", limit: 10)
42
+ site_map = client.map(url: "https://example.com", search: "documentation")
43
+ ```
44
+
45
+ ### Retrieve a brand profile
46
+
47
+ ```ruby
48
+ brand = client.brand.retrieve(url: "https://stripe.com")
49
+ puts brand.data
50
+ ```
51
+
52
+ ## Environments
53
+
54
+ This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
55
+ ### Environments
56
+ ```ruby
57
+ require "Berrycrawl"
58
+
59
+ Berrycrawl = Berrycrawl::Client.new(
60
+ base_url: Berrycrawl::Environment::PRODUCTION
61
+ )
62
+ ```
63
+
64
+ ### Custom URL
65
+ ```ruby
66
+ require "Berrycrawl"
67
+
68
+ client = Berrycrawl::Client.new(
69
+ base_url: "https://example.com"
70
+ )
71
+ ```
72
+
73
+ ## Errors
74
+
75
+ Failed API calls will raise errors that can be rescued from granularly.
76
+
77
+ ```ruby
78
+ require "Berrycrawl"
79
+
80
+ client = Berrycrawl::Client.new(
81
+ base_url: "https://example.com"
82
+ )
83
+
84
+ begin
85
+ result = client.brand.retrieve
86
+ rescue Berrycrawl::Errors::TimeoutError
87
+ puts "API didn't respond before our timeout elapsed"
88
+ rescue Berrycrawl::Errors::ServiceUnavailableError
89
+ puts "API returned status 503, is probably overloaded, try again later"
90
+ rescue Berrycrawl::Errors::ServerError
91
+ puts "API returned some other 5xx status, this is probably a bug"
92
+ rescue Berrycrawl::Errors::ResponseError => e
93
+ puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
94
+ rescue Berrycrawl::Errors::ApiError => e
95
+ puts "Some other error occurred when calling the API: #{e.message}"
96
+ end
97
+ ```
98
+
99
+ ## Advanced
100
+
101
+ ### Retries
102
+
103
+ The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed
104
+ retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
105
+
106
+ A request is deemed retryable when any of the following HTTP status codes is returned:
107
+
108
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
109
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
110
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)
111
+
112
+ The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:
113
+
114
+ - `legacy` (default): Retries `408`, `429`, `500`, `502`, `503`, `504`, `521`, `522`, `524`
115
+ - `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)
116
+
117
+ Use the `max_retries` option to configure this behavior.
118
+
119
+ ```ruby
120
+ require "Berrycrawl"
121
+
122
+ client = Berrycrawl::Client.new(
123
+ base_url: "https://example.com",
124
+ max_retries: 3 # Configure max retries (default is 2)
125
+ )
126
+ ```
127
+
128
+ ### Timeouts
129
+
130
+ The SDK defaults to a 60 second timeout. Use the `timeout` option to configure this behavior.
131
+
132
+ ```ruby
133
+ require "Berrycrawl"
134
+
135
+ response = client.brand.retrieve(
136
+ ...,
137
+ timeout: 30 # 30 second timeout
138
+ )
139
+ ```
140
+
141
+ ### Additional Headers
142
+
143
+ If you would like to send additional headers as part of the request, use the `additional_headers` request option.
144
+
145
+ ```ruby
146
+ require "Berrycrawl"
147
+
148
+ response = client.brand.retrieve(
149
+ ...,
150
+ request_options: {
151
+ additional_headers: {
152
+ "X-Custom-Header" => "custom-value"
153
+ }
154
+ }
155
+ )
156
+ ```
157
+
158
+ ### Additional Query Parameters
159
+
160
+ If you would like to send additional query parameters as part of the request, use the `additional_query_parameters` request option.
161
+
162
+ ```ruby
163
+ require "Berrycrawl"
164
+
165
+ response = client.brand.retrieve(
166
+ ...,
167
+ request_options: {
168
+ additional_query_parameters: {
169
+ "custom_param" => "custom-value"
170
+ }
171
+ }
172
+ )
173
+ ```
174
+
175
+ ## Contributing
176
+
177
+ While we value open-source contributions to this SDK, this library is generated programmatically.
178
+ Additions made directly to this library would have to be moved over to our generation code,
179
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
180
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
181
+ an issue first to discuss with us!
182
+
183
+ On the other hand, contributions to the README are always very welcome!
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test]
13
+
14
+ task lint: %i[rubocop]
15
+
16
+ # Run only the custom test file
17
+ Minitest::TestTask.create(:customtest) do |t|
18
+ t.libs << "test"
19
+ t.test_globs = ["test/custom.test.rb"]
20
+ end
data/custom.gemspec.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Custom gemspec configuration file
4
+ # This file is automatically loaded by the main gemspec file. The 'spec' variable is available
5
+ # in this context from the main gemspec file. You can modify this file to add custom metadata,
6
+ # dependencies, or other gemspec configurations. If you do make changes to this file, you will
7
+ # need to add it to the .fernignore file to prevent your changes from being overwritten.
8
+
9
+ def add_custom_gemspec_data(spec)
10
+ # Example custom configurations (uncomment and modify as needed)
11
+
12
+ # spec.authors = ["Your name"]
13
+ # spec.email = ["your.email@example.com"]
14
+ # spec.homepage = "https://github.com/your-org/berrycrawl-ruby"
15
+ # spec.license = "Your license"
16
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Berrycrawl
4
+ module Account
5
+ class Client
6
+ # @param client [Berrycrawl::Internal::Http::RawClient]
7
+ #
8
+ # @return [void]
9
+ def initialize(client:)
10
+ @client = client
11
+ end
12
+
13
+ # @param request_options [Hash]
14
+ # @param _params [Hash]
15
+ # @option request_options [String] :base_url
16
+ # @option request_options [Hash{String => Object}] :additional_headers
17
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
18
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
19
+ # @option request_options [Integer] :timeout_in_seconds
20
+ #
21
+ # @return [Berrycrawl::Types::AccountResponse]
22
+ def get(request_options: {}, **_params)
23
+ request = Berrycrawl::Internal::JSON::Request.new(
24
+ base_url: request_options[:base_url],
25
+ method: "GET",
26
+ path: "account",
27
+ request_options: request_options
28
+ )
29
+ begin
30
+ response = @client.send(request)
31
+ rescue Net::HTTPRequestTimeout
32
+ raise Berrycrawl::Errors::TimeoutError
33
+ end
34
+ code = response.code.to_i
35
+ if code.between?(200, 299)
36
+ Berrycrawl::Types::AccountResponse.load(response.body)
37
+ else
38
+ error_class = Berrycrawl::Errors::ResponseError.subclass_for_code(code)
39
+ raise error_class.new(response.body, code: code)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Berrycrawl
4
+ module Brand
5
+ class Client
6
+ # @param client [Berrycrawl::Internal::Http::RawClient]
7
+ #
8
+ # @return [void]
9
+ def initialize(client:)
10
+ @client = client
11
+ end
12
+
13
+ # Send one website URL. BerryCrawl returns the brand identity found on that site.
14
+ #
15
+ # @param request_options [Hash]
16
+ # @param params [Berrycrawl::Brand::Types::BrandDto]
17
+ # @option request_options [String] :base_url
18
+ # @option request_options [Hash{String => Object}] :additional_headers
19
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
20
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
21
+ # @option request_options [Integer] :timeout_in_seconds
22
+ #
23
+ # @return [Berrycrawl::Types::BrandResponse]
24
+ def retrieve(request_options: {}, **params)
25
+ params = Berrycrawl::Internal::Types::Utils.normalize_keys(params)
26
+ request = Berrycrawl::Internal::JSON::Request.new(
27
+ base_url: request_options[:base_url],
28
+ method: "POST",
29
+ path: "brand",
30
+ body: Berrycrawl::Brand::Types::BrandDto.new(params).to_h,
31
+ request_options: request_options
32
+ )
33
+ begin
34
+ response = @client.send(request)
35
+ rescue Net::HTTPRequestTimeout
36
+ raise Berrycrawl::Errors::TimeoutError
37
+ end
38
+ code = response.code.to_i
39
+ if code.between?(200, 299)
40
+ Berrycrawl::Types::BrandResponse.load(response.body)
41
+ else
42
+ error_class = Berrycrawl::Errors::ResponseError.subclass_for_code(code)
43
+ raise error_class.new(response.body, code: code)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Berrycrawl
4
+ module Brand
5
+ module Types
6
+ class BrandDto < Internal::Types::Model
7
+ field :refresh, -> { Internal::Types::Boolean }, optional: true, nullable: false
8
+
9
+ field :timeout, -> { Integer }, optional: true, nullable: false
10
+
11
+ field :url, -> { String }, optional: false, nullable: false
12
+ end
13
+ end
14
+ end
15
+ end