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
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ class Client
5
+ attr_reader :secret_key, :url
6
+
7
+ def initialize(secret_key, url: "https://kinopoiskapiunofficial.tech")
8
+ @secret_key = secret_key
9
+ @url = url
10
+ end
11
+
12
+ def connection
13
+ @connection ||= Faraday.new(url: url, headers: { "X-API-KEY" => secret_key }) do |faraday|
14
+ faraday.adapter KinopoiskUnofficialApi.configuration.adapter
15
+ faraday.options.timeout = KinopoiskUnofficialApi.configuration.connection_timeout
16
+ faraday.options.open_timeout = KinopoiskUnofficialApi.configuration.connection_open_timeout
17
+ end
18
+ end
19
+
20
+ def method_missing(method_name, *args, &block)
21
+ return super unless ENDPOINTS.key?(method_name)
22
+
23
+ result = call(method_name, *args)
24
+
25
+ ENDPOINTS[method_name][:response_type].call(result)
26
+ end
27
+
28
+ def respond_to_missing?(*args)
29
+ method_name = args[0]
30
+
31
+ ENDPOINTS.key?(method_name) || super
32
+ end
33
+
34
+ def call(method_name, raw_params = {})
35
+ params = build_params(method_name, raw_params)
36
+ path = build_path(method_name, params)
37
+ response = connection.get(path, params)
38
+ raise Exceptions::ResponseError.new(response: response) unless response.status == 200
39
+
40
+ JSON.parse(response.body)
41
+ end
42
+
43
+ private
44
+
45
+ def build_params(method_name, raw_params)
46
+ return {} if ENDPOINTS[method_name][:no_params]
47
+
48
+ schema_name = method_name.to_s.split("_").map(&:capitalize).join
49
+
50
+ schema = KinopoiskUnofficialApi::RequestSchemas.const_get(schema_name)
51
+
52
+ schema.call(raw_params).to_params_hash
53
+ end
54
+
55
+ def build_path(method_name, params)
56
+ endpoint = ENDPOINTS[method_name]
57
+ version = endpoint[:version]
58
+ path = endpoint[:path]
59
+
60
+ endpoint[:path_params]&.each do |param|
61
+ path = path.gsub("{#{param}}", params.delete(param))
62
+ end
63
+
64
+ (+"/api/").concat(version, path)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ class Configuration
5
+ attr_accessor :adapter, :connection_open_timeout, :connection_timeout, :genres, :countries
6
+
7
+ def initialize
8
+ @adapter = Faraday.default_adapter
9
+ @connection_open_timeout = 20
10
+ @connection_timeout = 20
11
+ @genres = JSON.parse(File.read("#{__dir__}/../../data/genres.json"), symbolize_names: true)
12
+ @countries = JSON.parse(File.read("#{__dir__}/../../data/countries.json"), symbolize_names: true)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/ModuleLength
4
+ module KinopoiskUnofficialApi
5
+ ENDPOINTS = {
6
+ film: {
7
+ path: "/films/{id}",
8
+ path_params: %w[id],
9
+ response_type: Types::Film,
10
+ version: "v2.2"
11
+ }.freeze,
12
+ film_seasons: {
13
+ path: "/films/{id}/seasons",
14
+ path_params: %w[id],
15
+ response_type: Types::SeasonResponse,
16
+ version: "v2.2"
17
+ }.freeze,
18
+ film_facts: {
19
+ path: "/films/{id}/facts",
20
+ path_params: %w[id],
21
+ response_type: Types::FactResponse,
22
+ version: "v2.2"
23
+ }.freeze,
24
+ film_distributions: {
25
+ path: "/films/{id}/distributions",
26
+ path_params: %w[id],
27
+ response_type: Types::DistributionResponse,
28
+ version: "v2.2"
29
+ }.freeze,
30
+ film_box_office: {
31
+ path: "/films/{id}/box_office",
32
+ path_params: %w[id],
33
+ response_type: Types::BoxOfficeResponse,
34
+ version: "v2.2"
35
+ }.freeze,
36
+ film_awards: {
37
+ path: "/films/{id}/awards",
38
+ path_params: %w[id],
39
+ response_type: Types::AwardResponse,
40
+ version: "v2.2"
41
+ }.freeze,
42
+ film_videos: {
43
+ path: "/films/{id}/videos",
44
+ path_params: %w[id],
45
+ response_type: Types::VideoResponse,
46
+ version: "v2.2"
47
+ }.freeze,
48
+ film_similars: {
49
+ path: "/films/{id}/similars",
50
+ path_params: %w[id],
51
+ response_type: Types::RelatedFilmResponse,
52
+ version: "v2.2"
53
+ }.freeze,
54
+ film_images: {
55
+ path: "/films/{id}/images",
56
+ path_params: %w[id],
57
+ response_type: Types::ImageResponse,
58
+ version: "v2.2"
59
+ }.freeze,
60
+ film_reviews: {
61
+ path: "/films/{id}/reviews",
62
+ path_params: %w[id],
63
+ response_type: Types::ReviewResponse,
64
+ version: "v2.2"
65
+ }.freeze,
66
+ film_external_sources: {
67
+ path: "/films/{id}/external_sources",
68
+ path_params: %w[id],
69
+ response_type: Types::ExternalSourceResponse,
70
+ version: "v2.2"
71
+ }.freeze,
72
+ film_collections: {
73
+ path: "/films/collections",
74
+ response_type: Types::FilmCollectionResponse,
75
+ version: "v2.2"
76
+ }.freeze,
77
+ film_premieres: {
78
+ path: "/films/premieres",
79
+ response_type: Types::PremiereResponse,
80
+ version: "v2.2"
81
+ }.freeze,
82
+ film_filters: {
83
+ path: "/films/filters",
84
+ response_type: Types::FiltersResponse,
85
+ no_params: true,
86
+ version: "v2.2"
87
+ }.freeze,
88
+ films: {
89
+ path: "/films",
90
+ response_type: Types::FilmSearchByFiltersResponse,
91
+ version: "v2.2"
92
+ }.freeze,
93
+ film_sequels_and_prequels: {
94
+ path: "/films/{id}/sequels_and_prequels",
95
+ path_params: %w[id],
96
+ response_type: Types::Array.of(Types::FilmSequelsAndPrequelsResponse),
97
+ version: "v2.1"
98
+ }.freeze,
99
+ search_film_by_keyword: {
100
+ path: "/films/search-by-keyword",
101
+ response_type: Types::FilmSearchResponse,
102
+ version: "v2.1"
103
+ }.freeze,
104
+ film_staff: {
105
+ path: "/staff",
106
+ response_type: Types::Array.of(Types::StaffResponse),
107
+ version: "v1"
108
+ }.freeze,
109
+ staff: {
110
+ path: "/staff/{id}",
111
+ path_params: %w[id],
112
+ response_type: Types::PersonResponse,
113
+ version: "v1"
114
+ }.freeze,
115
+ persons: {
116
+ path: "/persons",
117
+ response_type: Types::PersonByNameResponse,
118
+ version: "v1"
119
+ }.freeze,
120
+ kp_user_votes: {
121
+ path: "/kp_users/{id}/votes",
122
+ path_params: %w[id],
123
+ response_type: Types::KinopoiskUserVoteResponse,
124
+ version: "v1"
125
+ }.freeze,
126
+ api_key: {
127
+ path: "/api_keys/{apiKey}",
128
+ path_params: %w[apiKey],
129
+ response_type: Types::ApiKeyResponse,
130
+ version: "v1"
131
+ }.freeze,
132
+ media_posts: {
133
+ path: "/media_posts",
134
+ response_type: Types::MediaPostsResponse,
135
+ version: "v1"
136
+ }.freeze
137
+ }.freeze
138
+ end
139
+ # rubocop:enable Metrics/ModuleLength
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module Exceptions
5
+ class Base < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module Exceptions
5
+ class ResponseError < Base
6
+ attr_reader :response
7
+
8
+ def initialize(response:)
9
+ @response = response
10
+
11
+ super("Kinopoisk Unofficial API has returned the error. (#{error_data_dump})")
12
+ end
13
+
14
+ def error_code
15
+ response.status
16
+ end
17
+
18
+ def error_message
19
+ data[:message] || data["message"]
20
+ end
21
+
22
+ def data
23
+ @data ||= begin
24
+ JSON.parse(response.body)
25
+ rescue JSON::ParserError
26
+ { error_code: response.status, uri: response.env.url.to_s }
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def error_data_dump
33
+ data.map { |k, v| %(#{k}: #{v.inspect}) }.join(", ")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class ApiKey < Base
6
+ attribute :apiKey, Types::String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class Base < Dry::Struct
6
+ transform_keys do |key|
7
+ words = key.to_s.split("_")
8
+ words.drop(1).map(&:capitalize!)
9
+ words.join.to_sym
10
+ end
11
+
12
+ def to_params_hash
13
+ to_h.transform_keys(&:to_s).transform_values(&:to_s)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class Film < Base
6
+ transform_keys { |k| %i[film_id filmId id].include?(k.to_sym) ? :id : k }
7
+
8
+ attribute :id, Types::Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmAwards < Film; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmBoxOffice < Film; end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmCollections < Base
6
+ TYPES = %w[
7
+ TOP_POPULAR_ALL
8
+ TOP_POPULAR_MOVIES
9
+ TOP_250_TV_SHOWS
10
+ TOP_250_MOVIES
11
+ VAMPIRE_THEME
12
+ COMICS_THEME
13
+ CLOSES_RELEASES
14
+ FAMILY
15
+ OSKAR_WINNERS_2021
16
+ LOVE_THEME
17
+ ZOMBIE_THEME
18
+ CATASTROPHE_THEME
19
+ KIDS_ANIMATION_THEME
20
+ POPULAR_SERIES
21
+ ].freeze
22
+
23
+ attribute?(:type, Types::String.default(TYPES.first)
24
+ .constrained(included_in: TYPES)
25
+ .constructor { |v| v == Undefined ? v : v.to_s.upcase })
26
+ attribute? :page, Types::Integer.default(1)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmDistributions < Film; end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmExternalSources < Film
6
+ attribute? :page, Types::Integer.default(1)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmFacts < Film; end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmImages < Film
6
+ TYPES = %w[
7
+ STILL
8
+ SHOOTING
9
+ POSTER
10
+ FAN_ART
11
+ PROMO
12
+ CONCEPT
13
+ WALLPAPER
14
+ COVER
15
+ SCREENSHOT
16
+ ].freeze
17
+
18
+ attribute?(:type, Types::String.default(TYPES.first)
19
+ .constrained(included_in: TYPES)
20
+ .constructor { |v| v == Undefined ? v : v.to_s.upcase })
21
+ attribute? :page, Types::Integer.default(1)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmPremieres < Base
6
+ attribute :year, Types::Integer
7
+ attribute(:month, Types::String.constrained(included_in: Date::MONTHNAMES.compact.map(&:upcase))
8
+ .constructor do |value|
9
+ case value
10
+ when ::Integer
11
+ value.between?(1, 12) ? Date::MONTHNAMES[value].upcase : value
12
+ when ::Symbol, ::String
13
+ if Date::MONTHNAMES.include?(value.to_s.capitalize)
14
+ value.to_s.upcase
15
+ elsif Date::ABBR_MONTHNAMES.include?(value.to_s.capitalize)
16
+ month_index = Date::ABBR_MONTHNAMES.index(value.to_s.capitalize)
17
+ Date::MONTHNAMES[month_index].upcase
18
+ end
19
+ else
20
+ value
21
+ end
22
+ end)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmReviews < Film
6
+ ORDER_TYPES = %w[
7
+ DATE_ASC
8
+ DATE_DESC
9
+ USER_POSITIVE_RATING_ASC
10
+ USER_POSITIVE_RATING_DESC
11
+ USER_NEGATIVE_RATING_ASC
12
+ USER_NEGATIVE_RATING_DESC
13
+ ].freeze
14
+
15
+ attribute? :page, Types::Integer.default(1)
16
+ attribute?(:order, Types::String.default(ORDER_TYPES.first)
17
+ .constrained(included_in: ORDER_TYPES)
18
+ .constructor { |v| v == Undefined ? v : v.to_s.upcase })
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmSeasons < Film; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmSequelsAndPrequels < Film; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmSimilars < Film; end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmStaff < Base
6
+ transform_keys { |k| %i[film_id filmId].include?(k.to_sym) ? :filmId : k }
7
+
8
+ attribute :filmId, Types::Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class FilmVideos < Film; end
6
+ end
7
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class Films < Base
6
+ GENRES =
7
+ KinopoiskUnofficialApi.configuration.genres
8
+ .reduce({}) { |res, value| res.merge(value[:genre].downcase => value[:id]) }
9
+ .delete_if { |k, _| k == "" }
10
+ .freeze
11
+ COUNTRIES =
12
+ KinopoiskUnofficialApi.configuration.countries
13
+ .reduce({}) { |res, value| res.merge(value[:country].downcase => value[:id]) }
14
+ .delete_if { |k, _| k == "" }
15
+ .freeze
16
+ ORDER_TYPES = %w[
17
+ RATING
18
+ NUM_VOTE
19
+ YEAR
20
+ ].freeze
21
+ TYPES = %w[
22
+ ALL
23
+ FILM
24
+ TV_SHOW
25
+ TV_SERIES
26
+ MINI_SERIES
27
+ ].freeze
28
+
29
+ attribute?(:genres, Types::String.constrained(format: /^\d+(,\d+)*$/)
30
+ .constructor do |value|
31
+ case value
32
+ when ::Integer
33
+ value.to_s
34
+ when ::Array
35
+ value.map do |v|
36
+ case v
37
+ when ::String, ::Symbol
38
+ GENRES[v.to_s.downcase] || v
39
+ else
40
+ v
41
+ end
42
+ end.join(",")
43
+ when ::String, ::Symbol
44
+ (GENRES[value.to_s.downcase] || value).to_s
45
+ else
46
+ value
47
+ end
48
+ end)
49
+ attribute?(:countries, Types::String.constrained(format: /^\d+(,\d+)*$/)
50
+ .constructor do |value|
51
+ case value
52
+ when ::Integer
53
+ value.to_s
54
+ when ::Array
55
+ value.map do |v|
56
+ case v
57
+ when ::String, ::Symbol
58
+ COUNTRIES[v.to_s.downcase] || v
59
+ else
60
+ v
61
+ end
62
+ end.join(",")
63
+ when ::String, ::Symbol
64
+ (COUNTRIES[value.to_s.downcase] || value).to_s
65
+ else
66
+ value
67
+ end
68
+ end)
69
+ attribute?(:order, Types::String.default(ORDER_TYPES.first)
70
+ .constrained(included_in: ORDER_TYPES)
71
+ .constructor { |v| v == Undefined ? v : v.to_s.upcase })
72
+ attribute?(:type, Types::String.default(TYPES.first)
73
+ .constrained(included_in: TYPES)
74
+ .constructor { |v| v == Undefined ? v : v.to_s.upcase })
75
+ attribute? :ratingFrom, (Types::Float | Types::Integer).default(0)
76
+ attribute? :ratingTo, (Types::Float | Types::Integer).default(10)
77
+ attribute? :yearFrom, Types::Integer.default(1000)
78
+ attribute? :yearTo, Types::Integer.default(3000)
79
+ attribute? :imdbId, Types::String
80
+ attribute? :keyword, Types::String
81
+ attribute? :page, Types::Integer.default(1)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class KpUserVotes < Base
6
+ transform_keys { |k| %i[kp_user_id kpUserId user_id userId id].include?(k.to_sym) ? :id : k }
7
+
8
+ attribute :id, Types::Integer
9
+ attribute? :page, Types::Integer.default(1)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class MediaPosts < Base
6
+ attribute? :page, Types::Integer.default(1)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class Persons < Base
6
+ attribute :name, Types::String
7
+ attribute? :page, Types::Integer.default(1)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class SearchFilmByKeyword < Base
6
+ attribute(:keyword, Types::String.constructor { |v| v.is_a?(Array) ? v.join(", ") : v })
7
+ attribute? :page, Types::Integer.default(1)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ class Staff < Base
6
+ transform_keys { |k| %i[staff_id staffId person_id personId id].include?(k.to_sym) ? :id : k }
7
+
8
+ attribute :id, Types::Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module RequestSchemas
5
+ include Dry.Types()
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KinopoiskUnofficialApi
4
+ module Types
5
+ class ApiKeyResponse < Base
6
+ class DailyQuota < Base
7
+ attribute :value, Types::Integer
8
+ attribute :used, Types::Integer
9
+ end
10
+ end
11
+ end
12
+ end