crawlora-imdb 0.1.1
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 +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/lib/crawlora/imdb/client.rb +294 -0
- data/lib/crawlora/imdb/version.rb +5 -0
- data/lib/crawlora/imdb.rb +2 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ec19c584d08a8b425a45984ee1896ef4b9f62a1e3b7433bd3c54536a25a43960
|
|
4
|
+
data.tar.gz: ddac49b1760982ab51cb63f0122c59a8d33ea970289dffe82cf66a7483458959
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3238090ef5b997f2c36af8d49a724685767c0f3ef4a83604ba2b51039e6b1157e36fd6c70824af784a4ad640b444031dd926e040998e723da16cf492dedc4aac
|
|
7
|
+
data.tar.gz: 7656d00eac5b9b0d27fcb0bd44041139829cc4c7e9928d5040fde3c573245789c87d2c09fbcfc3b897f8597743907773ae54e17258916382755311ace8103c4a
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crawlora
|
|
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,33 @@
|
|
|
1
|
+
# Crawlora IMDb Ruby client
|
|
2
|
+
|
|
3
|
+
This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape IMDb directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-imdb"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=imdb-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=imdb-ruby-console) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
require "json"
|
|
15
|
+
require "crawlora/imdb"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Imdb::Client.new
|
|
18
|
+
result = client.request("imdb-search", JSON.parse("{\"query\": \"sample\"}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 30 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Imdb::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
|
|
27
|
+
# client.<operation_method>(<endpoint parameters>)
|
|
28
|
+
client.close
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
|
|
32
|
+
|
|
33
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=imdb-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=imdb-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-imdb) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Imdb
|
|
7
|
+
module Errors
|
|
8
|
+
class Error < StandardError
|
|
9
|
+
attr_reader :status, :operation_id, :body
|
|
10
|
+
|
|
11
|
+
def initialize(message, status: nil, operation_id: nil, body: nil)
|
|
12
|
+
super(message)
|
|
13
|
+
@status, @operation_id, @body = status, operation_id, body
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
class ClientError < Error; end
|
|
17
|
+
class ServerError < Error; end
|
|
18
|
+
class NetworkError < Error; end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
OPERATIONS = JSON.parse(<<~'JSON').freeze
|
|
22
|
+
{"imdb-charts": {"id": "imdb-charts", "method": "GET", "params": [{"default": "top_rated_movies", "description": "IMDb chart", "enum": ["top_rated_movies", "top_rated_tv_shows", "most_popular_movies", "most_popular_tv_shows", "top_rated_english_movies", "lowest_rated_movies"], "in": "query", "name": "chart", "type": "string"}, {"default": 25, "description": "Rows to return, default 25, max 250", "in": "query", "name": "limit", "type": "integer"}], "path": "/imdb/charts", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["top_rated_movies", "top_rated_tv_shows", "most_popular_movies", "most_popular_tv_shows", "top_rated_english_movies", "lowest_rated_movies"], "in": "query", "name": "chart", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-image-types": {"id": "imdb-image-types", "method": "GET", "params": [], "path": "/imdb/image-types", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "imdb-name": {"id": "imdb-name", "method": "GET", "params": [{"description": "IMDb name id", "in": "query", "name": "id", "type": "string", "x-example": "nm0634240"}, {"description": "Absolute https://www.imdb.com/name/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/name/nm0634240/"}], "path": "/imdb/name", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-name-awards": {"id": "imdb-name-awards", "method": "GET", "params": [{"description": "IMDb name id", "in": "query", "name": "id", "type": "string", "x-example": "nm0634240"}, {"description": "Absolute https://www.imdb.com/name/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/name/nm0634240/"}], "path": "/imdb/name/awards", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-name-credits": {"id": "imdb-name-credits", "method": "GET", "params": [{"description": "IMDb name id", "in": "query", "name": "id", "type": "string", "x-example": "nm0634240"}, {"description": "Absolute https://www.imdb.com/name/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/name/nm0634240/"}], "path": "/imdb/name/credits", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-name-images": {"id": "imdb-name-images", "method": "GET", "params": [{"description": "IMDb name id", "in": "query", "name": "id", "type": "string", "x-example": "nm0000151"}, {"description": "Absolute https://www.imdb.com/name/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/name/nm0000151/"}, {"description": "Image type filter, single value or comma-separated list", "enum": ["behind_the_scenes", "event", "poster", "product", "production_art", "publicity", "still_frame", "unknown"], "in": "query", "name": "type", "type": "string", "x-example": "still_frame"}, {"description": "Rows to return, default 50, max 1000", "in": "query", "name": "limit", "type": "integer", "x-example": 50}], "path": "/imdb/name/images", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"enum": ["behind_the_scenes", "event", "poster", "product", "production_art", "publicity", "still_frame", "unknown"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-name-videos": {"id": "imdb-name-videos", "method": "GET", "params": [{"description": "IMDb name id", "in": "query", "name": "id", "type": "string", "x-example": "nm0000151"}, {"description": "Absolute https://www.imdb.com/name/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/name/nm0000151/"}, {"description": "Rows to return, default 50, max 100", "in": "query", "name": "limit", "type": "integer", "x-example": 50}], "path": "/imdb/name/videos", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-search": {"id": "imdb-search", "method": "GET", "params": [{"description": "Search query", "in": "query", "name": "query", "required": true, "type": "string", "x-example": "inception"}, {"description": "Rows to return, default 10, max 20", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/imdb/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "required": true, "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-search-title": {"id": "imdb-search-title", "method": "GET", "params": [{"description": "Title-name substring match", "in": "query", "name": "title", "type": "string", "x-example": "matrix"}, {"description": "Comma-separated title types: `feature`, `tvSeries`, `short`, `tvEpisode`, `tvMiniSeries`, `tvMovie`, `tvSpecial`, `tvShort`, `videoGame`, `video`, `musicVideo`, `podcastSeries`, `podcastEpisode`", "in": "query", "name": "title_type", "type": "string", "x-example": "feature"}, {"description": "Comma-separated genres (include-only): `Action`, `Adventure`, `Animation`, `Biography`, `Comedy`, `Crime`, `Documentary`, `Drama`, `Family`, `Fantasy`, `Film-Noir`, `Game-Show`, `History`, `Horror`, `Music`, `Musical`, `Mystery`, `News`, `Reality-TV`, `Romance`, `Sci-Fi`, `Short`, `Sport`, `Talk-Show`, `Thriller`, `War`, `Western`", "in": "query", "name": "genres", "type": "string", "x-example": "Action,Adventure"}, {"description": "Release date lower bound: YYYY, YYYY-MM, or YYYY-MM-DD", "in": "query", "name": "release_date_from", "type": "string", "x-example": "2020-01-01"}, {"description": "Release date upper bound: YYYY, YYYY-MM, or YYYY-MM-DD", "in": "query", "name": "release_date_to", "type": "string", "x-example": "2021-12-31"}, {"description": "Minimum IMDb user rating, 0-10", "in": "query", "name": "min_user_rating", "type": "number", "x-example": 7}, {"description": "Maximum IMDb user rating, 0-10", "in": "query", "name": "max_user_rating", "type": "number", "x-example": 9.5}, {"description": "Minimum number of user rating votes", "in": "query", "name": "min_votes", "type": "integer", "x-example": 25000}, {"description": "Maximum number of user rating votes", "in": "query", "name": "max_votes", "type": "integer"}, {"description": "Minimum IMDb popularity rank (1 is most popular)", "in": "query", "name": "min_popularity", "type": "integer"}, {"description": "Maximum IMDb popularity rank", "in": "query", "name": "max_popularity", "type": "integer"}, {"description": "Minimum runtime in minutes", "in": "query", "name": "min_runtime", "type": "integer"}, {"description": "Maximum runtime in minutes", "in": "query", "name": "max_runtime", "type": "integer"}, {"description": "Comma-separated awards/curated-list groups: `oscar_winner`, `oscar_nominee`, `emmy_winner`, `emmy_nominee`, `golden_globe_winner`, `golden_globe_nominee`, `best_picture_winner`, `best_director_winner`, `razzie_winner`, `razzie_nominee`, `top_100`, `top_250`, `top_1000`, `bottom_100`, `bottom_250`, `bottom_1000`", "in": "query", "name": "groups", "type": "string"}, {"description": "Comma-separated plot keywords", "in": "query", "name": "keywords", "type": "string", "x-example": "superhero"}, {"description": "Comma-separated IMDb company ids, format `co########`", "in": "query", "name": "companies", "type": "string", "x-example": "co0000756"}, {"description": "Comma-separated `COUNTRY:RATING` certificate pairs, e.g. `US:PG-13`", "in": "query", "name": "certificates", "type": "string", "x-example": "US:PG-13"}, {"description": "Comma-separated color info: `color`, `black_and_white`, `colorized`, `aces`", "in": "query", "name": "colors", "type": "string"}, {"description": "Comma-separated ISO country codes", "in": "query", "name": "countries", "type": "string", "x-example": "US"}, {"description": "Comma-separated ISO language codes", "in": "query", "name": "languages", "type": "string", "x-example": "en"}, {"description": "Comma-separated sound mix names: `12-Track Digital Sound`, `3 Channel Stereo`, `4-Track Stereo`, `6-Track Stereo`, `70 mm 6-Track`, `AGA Sound System`, `Auro 11.1`, `CDS`, `Chronophone`, `Cinematophone`, `Cinephone`, `Cinerama 7-Track`, `Cinesound`, `D-Cinema 48kHz 5.1`, `Datasat`, `De Forest Phonofilm`, `Digitrac Digital Audio System`, `Dolby`, `Dolby Atmos`, `Dolby Digital`, `Dolby Digital EX`, `Dolby SR`, `Dolby Stereo`, `Dolby Surround 7.1`, `DTS`, `DTS 70 mm`, `DTS Stereo`, `DTS-ES`, `IMAX 6-Track`, `Kinoplasticon`, `LC-Concept Digital Sound`, `Matrix Surround`, `Mono`, `Perspecta Stereo`, `Phono-Kinema`, `SDDS`, `Sensurround`, `Silent`, `Sonics-DDP`, `Sonix`, `Stereo`, `Ultra Stereo`, `Vitaphone`", "in": "query", "name": "sound_mixes", "type": "string"}, {"description": "Comma-separated cast/crew IMDb name ids, format `nm########`", "in": "query", "name": "role", "type": "string", "x-example": "nm0634240"}, {"description": "Comma-separated character names", "in": "query", "name": "characters", "type": "string", "x-example": "Neo"}, {"description": "Plot text search term", "in": "query", "name": "plot", "type": "string", "x-example": "hacker"}, {"default": false, "description": "Include adult titles. Defaults to excluded", "in": "query", "name": "include_adult", "type": "boolean"}, {"description": "One of `moviemeter`, `alpha`, `user_rating`, `num_votes`, `boxoffice_gross_us`, `runtime`, `year`, `release_date`", "in": "query", "name": "sort", "type": "string", "x-example": "user_rating"}, {"description": "`asc` or `desc`. Defaults to `asc` when sort is set", "in": "query", "name": "sort_order", "type": "string", "x-example": "desc"}, {"description": "Rows to return, default 25, max 50", "in": "query", "name": "limit", "type": "integer", "x-example": 25}], "path": "/imdb/search/title", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "title", "type": "string"}, {"in": "query", "name": "title_type", "type": "string"}, {"in": "query", "name": "genres", "type": "string"}, {"in": "query", "name": "release_date_from", "type": "string"}, {"in": "query", "name": "release_date_to", "type": "string"}, {"in": "query", "name": "min_user_rating", "type": "number"}, {"in": "query", "name": "max_user_rating", "type": "number"}, {"in": "query", "name": "min_votes", "type": "integer"}, {"in": "query", "name": "max_votes", "type": "integer"}, {"in": "query", "name": "min_popularity", "type": "integer"}, {"in": "query", "name": "max_popularity", "type": "integer"}, {"in": "query", "name": "min_runtime", "type": "integer"}, {"in": "query", "name": "max_runtime", "type": "integer"}, {"in": "query", "name": "groups", "type": "string"}, {"in": "query", "name": "keywords", "type": "string"}, {"in": "query", "name": "companies", "type": "string"}, {"in": "query", "name": "certificates", "type": "string"}, {"in": "query", "name": "colors", "type": "string"}, {"in": "query", "name": "countries", "type": "string"}, {"in": "query", "name": "languages", "type": "string"}, {"in": "query", "name": "sound_mixes", "type": "string"}, {"in": "query", "name": "role", "type": "string"}, {"in": "query", "name": "characters", "type": "string"}, {"in": "query", "name": "plot", "type": "string"}, {"in": "query", "name": "include_adult", "type": "boolean"}, {"in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "sort_order", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-title": {"id": "imdb-title", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-awards": {"id": "imdb-title-awards", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/awards", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-box-office": {"id": "imdb-title-box-office", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0111161"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0111161/"}], "path": "/imdb/title/box-office", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-company-credits": {"id": "imdb-title-company-credits", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/company-credits", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-connections": {"id": "imdb-title-connections", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0111161"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0111161/"}, {"description": "Rows to return, default 50, max 250", "in": "query", "name": "limit", "type": "integer", "x-example": 50}], "path": "/imdb/title/connections", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-title-credits": {"id": "imdb-title-credits", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/credits", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-episodes": {"id": "imdb-title-episodes", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0944947"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0944947/"}, {"description": "Season number to request", "in": "query", "name": "season", "type": "integer", "x-example": 1}, {"description": "Rows to return, default 10, max 20", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/imdb/title/episodes", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"in": "query", "name": "season", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-title-filming-locations": {"id": "imdb-title-filming-locations", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/filming-locations", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-goofs": {"id": "imdb-title-goofs", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/goofs", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-images": {"id": "imdb-title-images", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0089753"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0089753/"}, {"description": "Image type filter, single value or comma-separated list", "enum": ["behind_the_scenes", "event", "poster", "product", "production_art", "publicity", "still_frame", "unknown"], "in": "query", "name": "type", "type": "string", "x-example": "still_frame"}, {"description": "Rows to return, default 50, max 1000", "in": "query", "name": "limit", "type": "integer", "x-example": 50}], "path": "/imdb/title/images", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"enum": ["behind_the_scenes", "event", "poster", "product", "production_art", "publicity", "still_frame", "unknown"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-title-keywords": {"id": "imdb-title-keywords", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/keywords", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-parental-guide": {"id": "imdb-title-parental-guide", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/parental-guide", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-public-facts-analysis": {"id": "imdb-title-public-facts-analysis", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/public-facts-analysis", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-quotes": {"id": "imdb-title-quotes", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/quotes", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-ratings": {"id": "imdb-title-ratings", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0111161"}, {"description": "Absolute IMDb title URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0111161/"}], "path": "/imdb/title/ratings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-release-info": {"id": "imdb-title-release-info", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/release-info", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-reviews": {"id": "imdb-title-reviews", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}, {"description": "Rows to return, default 10, max 20", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/imdb/title/reviews", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "imdb-title-similar": {"id": "imdb-title-similar", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt0111161"}, {"description": "Absolute IMDb title URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt0111161/"}], "path": "/imdb/title/similar", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-technical-specs": {"id": "imdb-title-technical-specs", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/technical-specs", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-trivia": {"id": "imdb-title-trivia", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}], "path": "/imdb/title/trivia", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}], "security": ["ApiKeyAuth"]}, "imdb-title-videos": {"id": "imdb-title-videos", "method": "GET", "params": [{"description": "IMDb title id", "in": "query", "name": "id", "type": "string", "x-example": "tt1375666"}, {"description": "Absolute https://www.imdb.com/title/<id>/ URL", "in": "query", "name": "url", "type": "string", "x-example": "https://www.imdb.com/title/tt1375666/"}, {"description": "Rows to return, default 50, max 100", "in": "query", "name": "limit", "type": "integer", "x-example": 50}], "path": "/imdb/title/videos", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "type": "string"}, {"in": "query", "name": "url", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["imdb-charts", "imdb-image-types", "imdb-name", "imdb-name-awards", "imdb-name-credits", "imdb-name-images", "imdb-name-videos", "imdb-search", "imdb-search-title", "imdb-title", "imdb-title-awards", "imdb-title-box-office", "imdb-title-company-credits", "imdb-title-connections", "imdb-title-credits", "imdb-title-episodes", "imdb-title-filming-locations", "imdb-title-goofs", "imdb-title-images", "imdb-title-keywords", "imdb-title-parental-guide", "imdb-title-public-facts-analysis", "imdb-title-quotes", "imdb-title-ratings", "imdb-title-release-info", "imdb-title-reviews", "imdb-title-similar", "imdb-title-technical-specs", "imdb-title-trivia", "imdb-title-videos"]
|
|
26
|
+
JSON
|
|
27
|
+
OPERATION_COUNT = OPERATION_IDS.length
|
|
28
|
+
|
|
29
|
+
class Client
|
|
30
|
+
attr_reader :base_url
|
|
31
|
+
|
|
32
|
+
def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-imdb-ruby/0.1.1", transport: nil)
|
|
33
|
+
@api_key = api_key
|
|
34
|
+
@base_url = base_url.to_s.sub(%r{/+$}, "")
|
|
35
|
+
@timeout = Float(timeout)
|
|
36
|
+
@user_agent = user_agent
|
|
37
|
+
@transport = transport
|
|
38
|
+
@closed = false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(operation_id, params = {}, response_type: :auto)
|
|
42
|
+
raise Errors::ClientError, "client is closed" if @closed
|
|
43
|
+
operation_id = operation_id.to_s
|
|
44
|
+
operation = OPERATIONS[operation_id]
|
|
45
|
+
raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
|
|
46
|
+
raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
|
|
47
|
+
normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
|
|
48
|
+
url = build_url(operation, normalized)
|
|
49
|
+
uri = URI.parse(url)
|
|
50
|
+
request = Net::HTTP::Get.new(uri)
|
|
51
|
+
request["x-api-key"] = @api_key
|
|
52
|
+
request["User-Agent"] = @user_agent
|
|
53
|
+
request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
|
|
54
|
+
begin
|
|
55
|
+
if @transport
|
|
56
|
+
response = @transport.call(url, request.to_hash, @timeout)
|
|
57
|
+
status = Integer(response.fetch(:status) { response.fetch("status") })
|
|
58
|
+
body = response.fetch(:body) { response.fetch("body", "") }
|
|
59
|
+
headers = response.fetch(:headers) { response.fetch("headers", {}) }
|
|
60
|
+
content_type = headers["content-type"] || headers["Content-Type"]
|
|
61
|
+
else
|
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
63
|
+
http.use_ssl = uri.scheme == "https"
|
|
64
|
+
http.open_timeout = @timeout
|
|
65
|
+
http.read_timeout = @timeout
|
|
66
|
+
response = http.start { |connection| connection.request(request) }
|
|
67
|
+
status = response.code.to_i
|
|
68
|
+
body = response.body
|
|
69
|
+
content_type = response["content-type"]
|
|
70
|
+
end
|
|
71
|
+
rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
|
|
72
|
+
raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
|
|
73
|
+
end
|
|
74
|
+
unless status >= 200 && status < 300
|
|
75
|
+
klass = status >= 500 ? Errors::ServerError : Errors::ClientError
|
|
76
|
+
raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
|
|
77
|
+
end
|
|
78
|
+
parse_response(body, content_type, operation, normalized, response_type)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def close
|
|
82
|
+
@closed = true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def closed?
|
|
86
|
+
@closed
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def with
|
|
90
|
+
return self unless block_given?
|
|
91
|
+
yield self
|
|
92
|
+
ensure
|
|
93
|
+
close if block_given?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.operation_count
|
|
97
|
+
OPERATION_COUNT
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.operation_ids
|
|
101
|
+
OPERATION_IDS
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.operations
|
|
105
|
+
OPERATIONS
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
define_method('charts') do |**params|
|
|
109
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
110
|
+
request('imdb-charts', params, response_type: response_type)
|
|
111
|
+
end
|
|
112
|
+
define_method('image_types') do |**params|
|
|
113
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
114
|
+
request('imdb-image-types', params, response_type: response_type)
|
|
115
|
+
end
|
|
116
|
+
define_method('name') do |**params|
|
|
117
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
118
|
+
request('imdb-name', params, response_type: response_type)
|
|
119
|
+
end
|
|
120
|
+
define_method('name_awards') do |**params|
|
|
121
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
122
|
+
request('imdb-name-awards', params, response_type: response_type)
|
|
123
|
+
end
|
|
124
|
+
define_method('name_credits') do |**params|
|
|
125
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
126
|
+
request('imdb-name-credits', params, response_type: response_type)
|
|
127
|
+
end
|
|
128
|
+
define_method('name_images') do |**params|
|
|
129
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
130
|
+
request('imdb-name-images', params, response_type: response_type)
|
|
131
|
+
end
|
|
132
|
+
define_method('name_videos') do |**params|
|
|
133
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
134
|
+
request('imdb-name-videos', params, response_type: response_type)
|
|
135
|
+
end
|
|
136
|
+
define_method('search') do |**params|
|
|
137
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
138
|
+
request('imdb-search', params, response_type: response_type)
|
|
139
|
+
end
|
|
140
|
+
define_method('search_title') do |**params|
|
|
141
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
142
|
+
request('imdb-search-title', params, response_type: response_type)
|
|
143
|
+
end
|
|
144
|
+
define_method('title') do |**params|
|
|
145
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
146
|
+
request('imdb-title', params, response_type: response_type)
|
|
147
|
+
end
|
|
148
|
+
define_method('title_awards') do |**params|
|
|
149
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
150
|
+
request('imdb-title-awards', params, response_type: response_type)
|
|
151
|
+
end
|
|
152
|
+
define_method('title_box_office') do |**params|
|
|
153
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
154
|
+
request('imdb-title-box-office', params, response_type: response_type)
|
|
155
|
+
end
|
|
156
|
+
define_method('title_company_credits') do |**params|
|
|
157
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
158
|
+
request('imdb-title-company-credits', params, response_type: response_type)
|
|
159
|
+
end
|
|
160
|
+
define_method('title_connections') do |**params|
|
|
161
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
162
|
+
request('imdb-title-connections', params, response_type: response_type)
|
|
163
|
+
end
|
|
164
|
+
define_method('title_credits') do |**params|
|
|
165
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
166
|
+
request('imdb-title-credits', params, response_type: response_type)
|
|
167
|
+
end
|
|
168
|
+
define_method('title_episodes') do |**params|
|
|
169
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
170
|
+
request('imdb-title-episodes', params, response_type: response_type)
|
|
171
|
+
end
|
|
172
|
+
define_method('title_filming_locations') do |**params|
|
|
173
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
174
|
+
request('imdb-title-filming-locations', params, response_type: response_type)
|
|
175
|
+
end
|
|
176
|
+
define_method('title_goofs') do |**params|
|
|
177
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
178
|
+
request('imdb-title-goofs', params, response_type: response_type)
|
|
179
|
+
end
|
|
180
|
+
define_method('title_images') do |**params|
|
|
181
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
182
|
+
request('imdb-title-images', params, response_type: response_type)
|
|
183
|
+
end
|
|
184
|
+
define_method('title_keywords') do |**params|
|
|
185
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
186
|
+
request('imdb-title-keywords', params, response_type: response_type)
|
|
187
|
+
end
|
|
188
|
+
define_method('title_parental_guide') do |**params|
|
|
189
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
190
|
+
request('imdb-title-parental-guide', params, response_type: response_type)
|
|
191
|
+
end
|
|
192
|
+
define_method('title_public_facts_analysis') do |**params|
|
|
193
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
194
|
+
request('imdb-title-public-facts-analysis', params, response_type: response_type)
|
|
195
|
+
end
|
|
196
|
+
define_method('title_quotes') do |**params|
|
|
197
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
198
|
+
request('imdb-title-quotes', params, response_type: response_type)
|
|
199
|
+
end
|
|
200
|
+
define_method('title_ratings') do |**params|
|
|
201
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
202
|
+
request('imdb-title-ratings', params, response_type: response_type)
|
|
203
|
+
end
|
|
204
|
+
define_method('title_release_info') do |**params|
|
|
205
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
206
|
+
request('imdb-title-release-info', params, response_type: response_type)
|
|
207
|
+
end
|
|
208
|
+
define_method('title_reviews') do |**params|
|
|
209
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
210
|
+
request('imdb-title-reviews', params, response_type: response_type)
|
|
211
|
+
end
|
|
212
|
+
define_method('title_similar') do |**params|
|
|
213
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
214
|
+
request('imdb-title-similar', params, response_type: response_type)
|
|
215
|
+
end
|
|
216
|
+
define_method('title_technical_specs') do |**params|
|
|
217
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
218
|
+
request('imdb-title-technical-specs', params, response_type: response_type)
|
|
219
|
+
end
|
|
220
|
+
define_method('title_trivia') do |**params|
|
|
221
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
222
|
+
request('imdb-title-trivia', params, response_type: response_type)
|
|
223
|
+
end
|
|
224
|
+
define_method('title_videos') do |**params|
|
|
225
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
226
|
+
request('imdb-title-videos', params, response_type: response_type)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
private
|
|
230
|
+
|
|
231
|
+
def build_url(operation, params)
|
|
232
|
+
known = operation["params"].map { |param| param["name"] }
|
|
233
|
+
unknown = params.keys - known
|
|
234
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
235
|
+
path = operation["path"].dup
|
|
236
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
237
|
+
value = params[param["name"]]
|
|
238
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
239
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
240
|
+
end
|
|
241
|
+
pairs = []
|
|
242
|
+
operation["queryParams"].each do |param|
|
|
243
|
+
name = param["name"]
|
|
244
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
245
|
+
if value.nil?
|
|
246
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
247
|
+
next
|
|
248
|
+
end
|
|
249
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
250
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
251
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
252
|
+
end
|
|
253
|
+
if value.is_a?(Array)
|
|
254
|
+
format = param["collectionFormat"] || "csv"
|
|
255
|
+
if format == "multi"
|
|
256
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
257
|
+
else
|
|
258
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
259
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
260
|
+
end
|
|
261
|
+
else
|
|
262
|
+
pairs << [name, scalar(value)]
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
266
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def scalar(value)
|
|
270
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def percent_encode(value)
|
|
274
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
278
|
+
type = response_type.to_s
|
|
279
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
280
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
281
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
282
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
283
|
+
json_format = format && format["enum"] && format["enum"].any? { |value| %w[json application/json].include?(value.to_s.downcase) } && %w[json application/json].include?(params["format"].to_s.downcase)
|
|
284
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
285
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
286
|
+
JSON.parse(body)
|
|
287
|
+
rescue JSON::ParserError => error
|
|
288
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
public
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-imdb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Crawlora
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Credential-free IMDb API access through Crawlora's hosted service.
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/crawlora/imdb.rb
|
|
23
|
+
- lib/crawlora/imdb/client.rb
|
|
24
|
+
- lib/crawlora/imdb/version.rb
|
|
25
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=imdb-ruby-homepage
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-imdb
|
|
30
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-imdb/blob/main/ruby/README.md
|
|
31
|
+
rubygems_mfa_required: 'true'
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.6'
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubygems_version: 3.4.19
|
|
48
|
+
signing_key:
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: IMDb client for the Crawlora hosted API
|
|
51
|
+
test_files: []
|