KinopoiskAPI 0.8.2 → 0.9.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.
@@ -0,0 +1,61 @@
1
+ module KinopoiskAPI
2
+ class People < Agent
3
+ attr_accessor :id, :url
4
+
5
+ def initialize(id)
6
+ @id = id.to_i
7
+ @url = "#{DOMAINS[:api]}/#{METHODS[:get_people][:method]}?#{METHODS[:get_people][:id]}=#{id}"
8
+ @json = json
9
+
10
+ unless status
11
+ raise APIerror.new(@json[:mesage], @json[:data])
12
+ end
13
+ end
14
+
15
+ def view
16
+ {
17
+ :id => @id,
18
+ :kp_type => str_data(nil, 'class'),
19
+ :name_ru => str_data(nil, 'nameRU'),
20
+ :name_en => str_data(nil, 'nameEN'),
21
+ :poster_url => url_data(nil, 'posterURL', @id, :name),
22
+ :sex => str_data(nil, 'sex'),
23
+ :growth => int_data(nil, 'growth'),
24
+ :birthday => time_data(nil, 'birthday'),
25
+ :birthplace => str_data(nil, 'birthplace'),
26
+ :has_awards => bool_data(nil, 'has_awards'),
27
+ :profession => s2a(str_data(nil, 'profession'))
28
+ }
29
+ end
30
+
31
+ def films
32
+ filmography.map do |film|
33
+ {
34
+ :id => int_data(String, film['filmID' ]),
35
+ :rating => int_data(String, film['rating' ], nil, Float),
36
+ :rating_vote_count => int_data(String, film['ratingVoteCount']),
37
+ :description => str_data(String, film['description' ]),
38
+ :profession_text => str_data(String, film['professionText ']),
39
+ :profession_key => str_data(String, film['professionKey' ]),
40
+ :name_ru => str_data(String, film['nameRU' ]),
41
+ :name_en => str_data(String, film['nameEN' ]),
42
+ :year => time_data(String, film['year' ])
43
+ }
44
+ end
45
+ end
46
+
47
+ def film_ids
48
+ filmography.map {|film| int_data(String, film['filmID']) }
49
+ end
50
+
51
+ private
52
+
53
+ def filmography
54
+ @json['filmography'].flatten
55
+ end
56
+
57
+
58
+
59
+
60
+ end
61
+ end
@@ -0,0 +1,53 @@
1
+ module KinopoiskAPI
2
+ class PeopleSearch < Agent
3
+ attr_accessor :keyword, :url
4
+
5
+ def initialize(keyword)
6
+ @keyword = URI.encode(keyword)
7
+ @page = 1
8
+ gen_url
9
+ @json = json
10
+ @page_count = @json['pagesCount']
11
+ end
12
+
13
+ def peoples_count
14
+ @json['searchPeoplesCountResult']
15
+ end
16
+
17
+ def page_count
18
+ @page_count
19
+ end
20
+
21
+ def current_page
22
+ @current_page
23
+ end
24
+
25
+ def view
26
+ @json['searchPeople'].map do |film|
27
+ people_hash(film)
28
+ end
29
+ end
30
+
31
+ def next_page
32
+ if @page < @page_count
33
+ @page += 1
34
+ gen_url
35
+ @json = json
36
+ true
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def gen_url
45
+ @url = [
46
+ "#{DOMAINS[:api]}/#{METHODS[:search_people][:method]}",
47
+ "?#{METHODS[:search_people][:keyword]}=#{@keyword}",
48
+ "&#{METHODS[:search_people][:page]}=#{@page}"
49
+ ].join('')
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,47 @@
1
+ module KinopoiskAPI
2
+ class Today < Agent
3
+ attr_accessor :url
4
+
5
+ def initialize
6
+ @url = "#{DOMAINS[:api]}/#{METHODS[:get_today_films][:method]}"
7
+ @json = json
8
+ end
9
+
10
+ def view
11
+ films.map do |film|
12
+ {
13
+ id: int_data(String, film['id' ]),
14
+ kp_type: str_data(String, film['type' ]),
15
+ name_ru: str_data(String, film['nameRU' ]),
16
+ name_en: str_data(String, film['nameEN' ]),
17
+ slogan: str_data(String, film['slogan' ]),
18
+ description: str_data(String, film['description' ]),
19
+ poster_url: url_data(String, film['posterURL' ], film["id"], :film),
20
+ year: int_data(String, film['year' ]),
21
+ reviews_count: int_data(String, film['reviewsCount']),
22
+ duration: min_data(String, film['filmLength' ]),
23
+ countries: arr_data(String, film['country' ]),
24
+ genres: arr_data(String, film['genre' ]),
25
+ video: film['videoURL'],
26
+ is_sequel_or_prequel: bool_data(String, film['hasSequelsAndPrequelsFilms']),
27
+ is_similar_films: bool_data(String, film['hasRelatedFilms' ]),
28
+ is_imax: bool_data(String, film['isIMAX' ]),
29
+ is_3d: bool_data(String, film['is3D' ]),
30
+ rating_mpaa: str_data(String, film['ratingMPAA' ]),
31
+ minimal_age: int_data(String, film['ratingAgeLimits' ])
32
+ }
33
+ end
34
+ end
35
+
36
+ def film_ids
37
+ films.map{|film| int_data(String, film['id'], nil) }.compact
38
+ end
39
+
40
+ private
41
+
42
+ def films
43
+ @json['filmsData']
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ module KinopoiskAPI
2
+ class Top < Agent
3
+ attr_accessor :url
4
+
5
+ def initialize
6
+ @url = "#{DOMAINS[:api]}/#{METHODS[:get_today_films][:method]}"
7
+ @json = json
8
+ raise todo
9
+ end
10
+
11
+ def films_view
12
+ films.map do |film|
13
+ {
14
+ id: int_data(String, film['id' ]),
15
+ kp_type: str_data(String, film['type' ]),
16
+ name_ru: str_data(String, film['nameRU' ]),
17
+ name_en: str_data(String, film['nameEN' ]),
18
+ slogan: str_data(String, film['slogan' ]),
19
+ description: str_data(String, film['description' ]),
20
+ poster_url: url_data(String, film['posterURL' ], film["id"], :film),
21
+ year: int_data(String, film['year' ]),
22
+ reviews_count: int_data(String, film['reviewsCount']),
23
+ duration: min_data(String, film['filmLength' ]),
24
+ countries: arr_data(String, film['country' ]),
25
+ genres: arr_data(String, film['genre' ]),
26
+ video: film['videoURL'],
27
+ is_sequel_or_prequel: bool_data(String, film['hasSequelsAndPrequelsFilms']),
28
+ is_similar_films: bool_data(String, film['hasRelatedFilms' ]),
29
+ is_imax: bool_data(String, film['isIMAX' ]),
30
+ is_3d: bool_data(String, film['is3D' ]),
31
+ rating_mpaa: str_data(String, film['ratingMPAA' ]),
32
+ minimal_age: int_data(String, film['ratingAgeLimits' ])
33
+ }
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module KinopoiskAPI
2
- VERSION = '0.8.2'
2
+ VERSION = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: KinopoiskAPI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vildyaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-25 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,14 +74,18 @@ files:
74
74
  - bin/setup
75
75
  - lib/KinopoiskAPI.rb
76
76
  - lib/KinopoiskAPI/agent.rb
77
+ - lib/KinopoiskAPI/api_error.rb
78
+ - lib/KinopoiskAPI/category.rb
77
79
  - lib/KinopoiskAPI/film.rb
78
- - lib/KinopoiskAPI/gallery.rb
79
- - lib/KinopoiskAPI/genres.rb
80
+ - lib/KinopoiskAPI/film_search.rb
81
+ - lib/KinopoiskAPI/gallery.rb.old
80
82
  - lib/KinopoiskAPI/global_search.rb
81
- - lib/KinopoiskAPI/reviews.rb
82
- - lib/KinopoiskAPI/similar.rb
83
- - lib/KinopoiskAPI/staff.rb
84
- - lib/KinopoiskAPI/today_films.rb
83
+ - lib/KinopoiskAPI/people.rb
84
+ - lib/KinopoiskAPI/people_search.rb
85
+ - lib/KinopoiskAPI/reviews.rb.old
86
+ - lib/KinopoiskAPI/similar.rb.old
87
+ - lib/KinopoiskAPI/today.rb
88
+ - lib/KinopoiskAPI/top.rb
85
89
  - lib/KinopoiskAPI/version.rb
86
90
  homepage: https://github.com/alpha-ver/Kinopoisk-API-Gem
87
91
  licenses:
@@ -1,38 +0,0 @@
1
- module KinopoiskAPI
2
- class Gallery < Agent
3
- attr_accessor :id, :url
4
-
5
- def initialize(id)
6
- @id = id
7
- @url = "#{DOMAINS[:api]}/#{METHODS[:get_gallery][:method]}?#{METHODS[:get_gallery][:id]}=#{id}"
8
- @json = json
9
- end
10
-
11
- def all
12
- correctly = {}
13
- gallery.each do |items|
14
- new_items = []
15
- items.last.each do |item|
16
- new_item = {
17
- image: "#{DOMAINS[:kinopoisk][:poster][:gallery]}/#{item['image']}",
18
- preview: "#{DOMAINS[:kinopoisk][:poster][:gallery]}/#{item['preview']}"
19
- }
20
- new_items.push(new_item)
21
- end
22
- correctly[items.first] = new_items
23
- end
24
- correctly
25
- end
26
-
27
- def section(name)
28
- all[name]
29
- end
30
-
31
- private
32
-
33
- def gallery
34
- @json['gallery']
35
- end
36
-
37
- end
38
- end
@@ -1,29 +0,0 @@
1
- module KinopoiskAPI
2
- class Genres < Agent
3
- attr_accessor :url
4
-
5
- def initialize
6
- @url = "#{DOMAINS[:api]}/#{METHODS[:get_genres][:method]}"
7
- @json = json
8
- end
9
-
10
- def all
11
- correctly = []
12
- genres.each do |item|
13
- new_item = {
14
- id: item['genreID'],
15
- name: item['genreName']
16
- }
17
- correctly.push(new_item)
18
- end
19
- correctly
20
- end
21
-
22
- private
23
-
24
- def genres
25
- @json['genreData']
26
- end
27
-
28
- end
29
- end
@@ -1,66 +0,0 @@
1
- module KinopoiskAPI
2
- class Reviews < Agent
3
- attr_accessor :id, :url
4
-
5
- def initialize(id)
6
- @id = id
7
- @url = "#{DOMAINS[:api]}/#{METHODS[:get_reviews][:method]}?#{METHODS[:get_reviews][:id]}=#{id}"
8
- @json = json
9
- end
10
-
11
- def all
12
- {
13
- pages: pages,
14
- page: page,
15
- quantity: quantity,
16
- reviews: reviews
17
- }
18
- end
19
-
20
- def pages
21
- @json['pagesCount']
22
- end
23
-
24
- def page
25
- @json['page']
26
- end
27
-
28
- def quantity
29
- {
30
- reviews: @json['reviewAllCount'],
31
- good_reviews: @json['reviewPositiveCount'],
32
- good_reviews_in_percent: @json['reviewAllPositiveRatio'],
33
- bad_reviews: @json['reviewNegativeCount'],
34
- neutral_reviews: @json['reviewNeutralCount']
35
- }
36
- end
37
-
38
- def reviews
39
- correctly = []
40
- json_reviews.each do |item|
41
- type_array = item['reviewType'].split('_')
42
- type = type_array.last
43
- new_item = {
44
- id: item['reviewID'],
45
- type: type,
46
- data: item['reviewData'],
47
- author: {
48
- name: item['reviewAutor'],
49
- avatar: "#{DOMAINS[:kinopoisk][:poster][:gallery]}/#{item['reviewAutorImageURL']}"
50
- },
51
- title: item['reviewTitle'],
52
- description: item['reviewDescription']
53
- }
54
- correctly.push(new_item)
55
- end
56
- correctly
57
- end
58
-
59
- private
60
-
61
- def json_reviews
62
- @json['reviews']
63
- end
64
-
65
- end
66
- end
@@ -1,42 +0,0 @@
1
- module KinopoiskAPI
2
- class Similar < Agent
3
- attr_accessor :id, :url
4
-
5
- def initialize(id)
6
- @id = id
7
- @url = "#{DOMAINS[:api]}/#{METHODS[:get_similar][:method]}?#{METHODS[:get_similar][:id]}=#{id}&type=#{METHODS[:get_similar][:type]}"
8
- @json = json
9
- end
10
-
11
- def all
12
- correctly = []
13
- json['items'].each do |items|
14
- items.each do |item|
15
- rating_array = item['rating'].delete(' ').split('(')
16
- new_item = {
17
- title: {
18
- ru: item['nameRU'],
19
- en: item['nameEN']
20
- },
21
- year: item['year'],
22
- rating: rating_array.first,
23
- number_of_rated: rating_array.last.delete(')'),
24
- poster: "#{DOMAINS[:kinopoisk][:poster][:film]}_#{item['id']}.jpg",
25
- duration: item['filmLength'],
26
- countries: item['country'].split(',').map { |country| country.strip },
27
- genres: item['genre'].split(',').map { |genre| genre.strip }
28
- }
29
- correctly.push(new_item)
30
- end
31
- end
32
- correctly
33
- end
34
-
35
- private
36
-
37
- def items
38
- @json['items']
39
- end
40
-
41
- end
42
- end
@@ -1,53 +0,0 @@
1
- module KinopoiskAPI
2
- class Staff < Agent
3
- attr_accessor :id, :url
4
-
5
- def initialize(id)
6
- @id = id
7
- @url = "#{DOMAINS[:api]}/#{METHODS[:get_name][:method]}?#{METHODS[:get_name][:id]}=#{id}"
8
- @json = json
9
- end
10
-
11
- def all
12
- correctly = {}
13
- unless creators.nil?
14
- creators.each do |items|
15
- new_items = []
16
- items.each do |item|
17
- poster = item['posterURL'].present? ? "#{DOMAINS[:kinopoisk][:poster][:name]}_#{item['id']}.jpg" : nil
18
- new_item = {
19
- id: item['id'],
20
- url: "#{DOMAINS[:kinopoisk][:main]}/name/#{item['id']}",
21
- full_name: {
22
- ru: item['nameRU'],
23
- en: item['nameEN']
24
- },
25
- poster: poster,
26
- profession: item['professionText']
27
- }
28
- new_items.push(new_item)
29
- end
30
- items.each do |item|
31
- correctly[item['professionKey']] = new_items
32
- end
33
- end
34
- end
35
- correctly
36
- end
37
-
38
- def profession(name)
39
- all[name]
40
- end
41
-
42
- private
43
-
44
- def creators
45
- if @json.present?
46
- @json['creators'].present? ? @json['creators'] : nil
47
- else
48
- nil
49
- end
50
- end
51
-
52
- end
53
- end