kinopoisk_unofficial_api 1.0.0.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.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +1 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +23 -0
  5. data/CHANGELOG.md +3 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +185 -0
  8. data/Rakefile +17 -0
  9. data/data/countries.json +1002 -0
  10. data/data/genres.json +134 -0
  11. data/data/type_attributes.json +1589 -0
  12. data/lib/kinopoisk_unofficial_api/client.rb +67 -0
  13. data/lib/kinopoisk_unofficial_api/configuration.rb +15 -0
  14. data/lib/kinopoisk_unofficial_api/endpoints.rb +139 -0
  15. data/lib/kinopoisk_unofficial_api/exceptions/base.rb +7 -0
  16. data/lib/kinopoisk_unofficial_api/exceptions/response_error.rb +37 -0
  17. data/lib/kinopoisk_unofficial_api/request_schemas/api_key.rb +9 -0
  18. data/lib/kinopoisk_unofficial_api/request_schemas/base.rb +17 -0
  19. data/lib/kinopoisk_unofficial_api/request_schemas/film.rb +11 -0
  20. data/lib/kinopoisk_unofficial_api/request_schemas/film_awards.rb +7 -0
  21. data/lib/kinopoisk_unofficial_api/request_schemas/film_box_office.rb +7 -0
  22. data/lib/kinopoisk_unofficial_api/request_schemas/film_collections.rb +29 -0
  23. data/lib/kinopoisk_unofficial_api/request_schemas/film_distributions.rb +7 -0
  24. data/lib/kinopoisk_unofficial_api/request_schemas/film_external_sources.rb +9 -0
  25. data/lib/kinopoisk_unofficial_api/request_schemas/film_facts.rb +7 -0
  26. data/lib/kinopoisk_unofficial_api/request_schemas/film_images.rb +24 -0
  27. data/lib/kinopoisk_unofficial_api/request_schemas/film_premieres.rb +25 -0
  28. data/lib/kinopoisk_unofficial_api/request_schemas/film_reviews.rb +21 -0
  29. data/lib/kinopoisk_unofficial_api/request_schemas/film_seasons.rb +7 -0
  30. data/lib/kinopoisk_unofficial_api/request_schemas/film_sequels_and_prequels.rb +7 -0
  31. data/lib/kinopoisk_unofficial_api/request_schemas/film_similars.rb +7 -0
  32. data/lib/kinopoisk_unofficial_api/request_schemas/film_staff.rb +11 -0
  33. data/lib/kinopoisk_unofficial_api/request_schemas/film_videos.rb +7 -0
  34. data/lib/kinopoisk_unofficial_api/request_schemas/films.rb +84 -0
  35. data/lib/kinopoisk_unofficial_api/request_schemas/kp_user_votes.rb +12 -0
  36. data/lib/kinopoisk_unofficial_api/request_schemas/media_posts.rb +9 -0
  37. data/lib/kinopoisk_unofficial_api/request_schemas/persons.rb +10 -0
  38. data/lib/kinopoisk_unofficial_api/request_schemas/search_film_by_keyword.rb +10 -0
  39. data/lib/kinopoisk_unofficial_api/request_schemas/staff.rb +11 -0
  40. data/lib/kinopoisk_unofficial_api/request_schemas.rb +7 -0
  41. data/lib/kinopoisk_unofficial_api/types/api_key_response/daily_quota.rb +12 -0
  42. data/lib/kinopoisk_unofficial_api/types/api_key_response/total_quota.rb +12 -0
  43. data/lib/kinopoisk_unofficial_api/types/api_key_response.rb +11 -0
  44. data/lib/kinopoisk_unofficial_api/types/award.rb +14 -0
  45. data/lib/kinopoisk_unofficial_api/types/award_person.rb +21 -0
  46. data/lib/kinopoisk_unofficial_api/types/award_response.rb +10 -0
  47. data/lib/kinopoisk_unofficial_api/types/base.rb +14 -0
  48. data/lib/kinopoisk_unofficial_api/types/box_office.rb +13 -0
  49. data/lib/kinopoisk_unofficial_api/types/box_office_response.rb +10 -0
  50. data/lib/kinopoisk_unofficial_api/types/compactable.rb +19 -0
  51. data/lib/kinopoisk_unofficial_api/types/company.rb +9 -0
  52. data/lib/kinopoisk_unofficial_api/types/country.rb +9 -0
  53. data/lib/kinopoisk_unofficial_api/types/digital_release_item.rb +22 -0
  54. data/lib/kinopoisk_unofficial_api/types/digital_release_response.rb +11 -0
  55. data/lib/kinopoisk_unofficial_api/types/distribution.rb +14 -0
  56. data/lib/kinopoisk_unofficial_api/types/distribution_response.rb +10 -0
  57. data/lib/kinopoisk_unofficial_api/types/episode.rb +14 -0
  58. data/lib/kinopoisk_unofficial_api/types/external_source_response/item.rb +18 -0
  59. data/lib/kinopoisk_unofficial_api/types/external_source_response.rb +10 -0
  60. data/lib/kinopoisk_unofficial_api/types/fact.rb +11 -0
  61. data/lib/kinopoisk_unofficial_api/types/fact_response.rb +10 -0
  62. data/lib/kinopoisk_unofficial_api/types/film.rb +53 -0
  63. data/lib/kinopoisk_unofficial_api/types/film_collection_response/item.rb +22 -0
  64. data/lib/kinopoisk_unofficial_api/types/film_collection_response.rb +11 -0
  65. data/lib/kinopoisk_unofficial_api/types/film_search_by_filters_response/item.rb +23 -0
  66. data/lib/kinopoisk_unofficial_api/types/film_search_by_filters_response.rb +11 -0
  67. data/lib/kinopoisk_unofficial_api/types/film_search_response/film.rb +23 -0
  68. data/lib/kinopoisk_unofficial_api/types/film_search_response.rb +12 -0
  69. data/lib/kinopoisk_unofficial_api/types/film_sequels_and_prequels_response.rb +15 -0
  70. data/lib/kinopoisk_unofficial_api/types/filters_response/country.rb +12 -0
  71. data/lib/kinopoisk_unofficial_api/types/filters_response/genre.rb +12 -0
  72. data/lib/kinopoisk_unofficial_api/types/filters_response.rb +10 -0
  73. data/lib/kinopoisk_unofficial_api/types/genre.rb +9 -0
  74. data/lib/kinopoisk_unofficial_api/types/image_response/item.rb +12 -0
  75. data/lib/kinopoisk_unofficial_api/types/image_response.rb +11 -0
  76. data/lib/kinopoisk_unofficial_api/types/kinopoisk_user_vote_response/item.rb +23 -0
  77. data/lib/kinopoisk_unofficial_api/types/kinopoisk_user_vote_response.rb +11 -0
  78. data/lib/kinopoisk_unofficial_api/types/media_posts_response/item.rb +16 -0
  79. data/lib/kinopoisk_unofficial_api/types/media_posts_response.rb +11 -0
  80. data/lib/kinopoisk_unofficial_api/types/pattern_matching.rb +11 -0
  81. data/lib/kinopoisk_unofficial_api/types/person_by_name_response/item.rb +16 -0
  82. data/lib/kinopoisk_unofficial_api/types/person_by_name_response.rb +10 -0
  83. data/lib/kinopoisk_unofficial_api/types/person_response/film.rb +17 -0
  84. data/lib/kinopoisk_unofficial_api/types/person_response/spouse.rb +18 -0
  85. data/lib/kinopoisk_unofficial_api/types/person_response.rb +25 -0
  86. data/lib/kinopoisk_unofficial_api/types/premiere_response.rb +10 -0
  87. data/lib/kinopoisk_unofficial_api/types/premiere_response_item.rb +18 -0
  88. data/lib/kinopoisk_unofficial_api/types/related_film_response/item.rb +17 -0
  89. data/lib/kinopoisk_unofficial_api/types/related_film_response.rb +10 -0
  90. data/lib/kinopoisk_unofficial_api/types/review_response/item.rb +18 -0
  91. data/lib/kinopoisk_unofficial_api/types/review_response.rb +14 -0
  92. data/lib/kinopoisk_unofficial_api/types/season.rb +10 -0
  93. data/lib/kinopoisk_unofficial_api/types/season_response.rb +10 -0
  94. data/lib/kinopoisk_unofficial_api/types/staff_response.rb +15 -0
  95. data/lib/kinopoisk_unofficial_api/types/video_response/item.rb +13 -0
  96. data/lib/kinopoisk_unofficial_api/types/video_response.rb +10 -0
  97. data/lib/kinopoisk_unofficial_api/types.rb +7 -0
  98. data/lib/kinopoisk_unofficial_api/version.rb +5 -0
  99. data/lib/kinopoisk_unofficial_api.rb +25 -0
  100. data/rakelib/parse_schema.rake +103 -0
  101. data/rakelib/rebuild_types.rake +105 -0
  102. data/rakelib/templates/empty_type.erb +12 -0
  103. data/rakelib/templates/nested_type.erb +13 -0
  104. data/rakelib/templates/type.erb +11 -0
  105. metadata +188 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5aa0ff48084fede2dc372c7508fda7860b8655c92a3226043230ee8157bb0fd6
4
+ data.tar.gz: 258c30f78eec6712857d9d5dd4db559c2e7b3436ef853e0f22290ce1b370455d
5
+ SHA512:
6
+ metadata.gz: dfa51875a54a9b605f3faadabb14ae9e709080acdd881771eea8a6bacc93267aa62513e583bc9985be6449c7f2e94fc518ecbe7c76c0e97a922c992bebdfee10
7
+ data.tar.gz: 00d23a90ed1acd589717f149e7aae6dc5c5efc1108c7412d3a65f50fb85fb3172da4066fffcebf3ff01e83bae94c4430699f0512940e87b70c5f2357e9a47d87
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ X_API_KEY=
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ ---
2
+ require:
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ plugins:
7
+ - rubocop-performance
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ TargetRubyVersion: 2.7
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Layout/LineLength:
17
+ Max: 120
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
21
+
22
+ Style/StringLiteralsInInterpolation:
23
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [1.0.0] - 2025-04-09
2
+
3
+ - Initial release version
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Aleksandr Klimenkov
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # kinopoisk_unofficial_api
2
+
3
+ Ruby wrapper for [Kinopoisk Unofficial API](https://kinopoiskapiunofficial.tech/documentation/api/).
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/kinopoisk_unofficial_api.svg)](http://badge.fury.io/rb/kinopoisk_unofficial_api)
6
+ [![Build Status](https://github.com/prisioner/kinopoisk_unofficial_api_client/actions/workflows/main.yml/badge.svg)](https://github.com/prisioner/kinopoisk_unofficial_api_client/actions)
7
+
8
+ ## Installation
9
+
10
+ Add following line to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'kinopoisk_unofficial_api', '~> 1.0.0'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```shell
19
+ bundle
20
+ ```
21
+
22
+ Or install it system-wide:
23
+
24
+ ```shell
25
+ gem install kinopoisk_unofficial_api
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ First things first, you need to [obtain an Api Key](https://kinopoiskapiunofficial.tech/) for your client.
31
+ Then create your API Client like this:
32
+
33
+ ```ruby
34
+ require 'kinopoisk_unofficial_api'
35
+
36
+ api_key = 'YOUR_KINOPOISK_UNOFFICIAL_API_API_KEY'
37
+
38
+ client = KinopoiskUnofficialApi::Client.new(api_key)
39
+
40
+ shawshank_redemption = client.film(id: 326)
41
+
42
+ # attributes accessible with snake_case methods
43
+ shawshank_redemption.kinopoisk_id # => 326
44
+ shawshank_redemption.imdb_id # => "tt0111161"
45
+ shawshank_redemption.rating_kinopoisk # => 9.1
46
+ shawshank_redemption.rating_imdb # => 9.3
47
+ shawshank_redemption.name_ru # => "Побег из Шоушенка"
48
+ shawshank_redemption.name_original # => "The Shawshank Redemption"
49
+
50
+ # attributes accessible with hash keys
51
+ shawshank_redemption[:kinopoisk_id] # => 326
52
+ shawshank_redemption[:name_original] # => "The Shawshank Redemption"
53
+
54
+ # #to_h also converts to hash
55
+ shawshank_redemption.to_h # => {kinopoisk_id: 326, kinopoisk_hdid: ...}
56
+
57
+ # nested objects accessible
58
+ shawshank_redemption.countries.first.country # => "США"
59
+
60
+ # keys could be in snake or camel cases
61
+ # genres and countries could be passed with names or ids
62
+ # ids could be obtained via client.film_filters
63
+ query_params = {
64
+ genres: 'фантастика', # case insensitive, ids, strings and symbols allowed
65
+ type: :tv_series, # case insensitive, strings and symbols allowed
66
+ rating_from: 7.5, # float and integers allowed
67
+ rating_to: 10, # float and integers allowed
68
+ year_from: 2019,
69
+ year_to: 2024,
70
+ countries: 'Россия', # case insensitive, ids, strings and symbols allowed
71
+ keyword: 'деревня'
72
+ }
73
+
74
+ # will provoke request with following params:
75
+ # https://kinopoiskapiunofficial.tech/api/v2.2/films
76
+ # ?countries=34
77
+ # &genres=6
78
+ # &keyword=%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BD%D1%8F
79
+ # &order=RATING
80
+ # &page=1
81
+ # &ratingFrom=7.5
82
+ # &ratingTo=10
83
+ # &type=TV_SERIES
84
+ # &yearFrom=2019
85
+ # &yearTo=2024
86
+
87
+ movies = client.movie(query_params)
88
+ ```
89
+
90
+ Implemented all endpoints of API v2.2.
91
+
92
+ Mapping client method names to endpoints available in [lib/kinopoisk_unofficial_api/endpoints.rb](lib/kinopoisk_unofficial_api/endpoints.rb)
93
+
94
+ ## Overriding countries and genres name-to-id mapping
95
+
96
+ If you want override mapping
97
+
98
+ 1. Actual mapping could be learned from [data/countries.json](data/countries.json) and [data/genres.json](data/genres.json)
99
+
100
+ 2. Make your own `.json` files
101
+
102
+ ```json
103
+ // my_genres.json
104
+ [
105
+ {
106
+ "id": 10,
107
+ "genre": "Western"
108
+ },
109
+ {
110
+ "id": 13,
111
+ "genre": "Comedy"
112
+ },
113
+ {
114
+ "id": 6,
115
+ "genre": "Sci-Fi"
116
+ }
117
+ ]
118
+
119
+ // my_countries.json
120
+ [
121
+ {
122
+ "id": 1,
123
+ "country": "USA"
124
+ },
125
+ {
126
+ "id": 3,
127
+ "country": "France"
128
+ },
129
+ {
130
+ "id": 33,
131
+ "country": "USSR"
132
+ },
133
+ {
134
+ "id": 34,
135
+ "country": "Russia"
136
+ }
137
+ ]
138
+ ```
139
+
140
+ 4. Configure gem
141
+
142
+ ```ruby
143
+ KinopoiskUnofficialApi.configure do |config|
144
+ config.genres = JSON.parse(File.read("my_genres.json"), symbolize_names: true)
145
+ config.countries = JSON.parse(File.read("my_countries.json"), symbolize_names: true)
146
+ end
147
+ ```
148
+
149
+ 5. You can use your names in client.films
150
+
151
+ ```ruby
152
+ client.films(genres: :western, countries: 'USA')
153
+ ```
154
+
155
+ ## Proxy
156
+
157
+ You can set up your own proxy and use it to access Kinopoisk Unofficial API.
158
+ In this case you need to configure API URL:
159
+
160
+ ```ruby
161
+ KinopoiskUnofficialApi::Client.run(api_key, url: 'https://proxy.example.com') do |bot|
162
+ # ...
163
+ end
164
+ ```
165
+
166
+ ## Connection adapters
167
+
168
+ We rely on [faraday](https://github.com/lostisland/faraday) under the hood.
169
+ You can use any of supported adapters (for example, `net/http/persistent`):
170
+
171
+ ```ruby
172
+ require 'net/http/persistent'
173
+
174
+ KinopoiskUnofficialApi.configure do |config|
175
+ config.adapter = :net_http_persistent
176
+ end
177
+ ```
178
+
179
+ ## Contributing
180
+
181
+ 1. Fork it.
182
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
183
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
184
+ 4. Push to the branch (`git push origin my-new-feature`).
185
+ 5. Create a new Pull Request.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new(:rubocop) do |task|
11
+ task.fail_on_error = false
12
+ task.options = %w[--force-exclusion]
13
+ task.patterns = %w[{lib,spec}/**/*.rb Rakefile Gemfile rakelib/*.rake *.gemspec]
14
+ task.requires << "rubocop-rspec"
15
+ end
16
+
17
+ task default: %i[spec rubocop]