kp_api 0.10.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,56 @@
1
+ module KpApi
2
+ class Today < Agent
3
+ attr_accessor :url
4
+
5
+ def initialize(city_id=1, country_id=2)
6
+ @url = "#{DOMAINS[:api]}#{METHODS[:get_today_films][:method]}?cityID=#{city_id}&countryID=#{country_id}"
7
+ @json = json
8
+
9
+ unless status
10
+ raise ApiError.new(@json[:message], @json[:data])
11
+ end
12
+ end
13
+
14
+ def view
15
+
16
+ films.map do |film|
17
+ {
18
+ id: int_data(String, film['id' ]),
19
+ kp_type: str_data(String, film['type' ]),
20
+ name_ru: str_data(String, film['nameRU' ]),
21
+ name_en: str_data(String, film['nameEN' ]),
22
+ slogan: str_data(String, film['slogan' ]),
23
+ description: str_data(String, film['description' ]),
24
+ poster_url: url_data(String, film['posterURL' ], film["id"], :film),
25
+ year: int_data(String, film['year' ]),
26
+ reviews_count: int_data(String, film['reviewsCount']),
27
+ duration: min_data(String, film['filmLength' ]),
28
+ countries: arr_data(String, film['country' ]),
29
+ genres: arr_data(String, film['genre' ]),
30
+ video: film['videoURL'],
31
+ is_sequel_or_prequel: bool_data(String, film['hasSequelsAndPrequelsFilms']),
32
+ is_similar_films: bool_data(String, film['hasRelatedFilms' ]),
33
+ is_imax: bool_data(String, film['isIMAX' ]),
34
+ is_3d: bool_data(String, film['is3D' ]),
35
+ rating_mpaa: str_data(String, film['ratingMPAA' ]),
36
+ minimal_age: int_data(String, film['ratingAgeLimits' ])
37
+ }
38
+ end
39
+ end
40
+
41
+ def film_ids
42
+ films.map{|film| int_data(String, film['id'], nil) }.compact
43
+ end
44
+
45
+ private
46
+
47
+ def films
48
+ if @json['filmsData'].nil?
49
+ []
50
+ else
51
+ @json['filmsData']
52
+ end
53
+ end
54
+
55
+ end
56
+ end
data/lib/kp_api/top.rb ADDED
@@ -0,0 +1,57 @@
1
+ module KpApi
2
+ class Top < Agent
3
+ attr_accessor :url
4
+
5
+ def initialize(top_list=nil)
6
+ if !top_list.nil? && !METHODS[:get_top][:types][top_list].nil?
7
+ @type = METHODS[:get_top][:types][top_list]
8
+ @page = 1
9
+ gen_url
10
+ @json = json
11
+ @page_count = @json['pagesCount']
12
+ else
13
+ #todo
14
+ raise ArgumentError
15
+ end
16
+ end
17
+
18
+
19
+ def view
20
+ @json['items'].map do |film|
21
+ film_hash(film,'id')
22
+ end
23
+ end
24
+
25
+ def view_all(limit=15)
26
+ all = view
27
+ while @page <= limit && next_page
28
+ all += @json['items'].map do |film|
29
+ film_hash(film,'id')
30
+ end
31
+ end
32
+ all
33
+ end
34
+
35
+ def ids_all(limit=15)
36
+ all = @json['items'].map{|film| film['id']}
37
+ while @page <= limit && next_page
38
+ all += @json['items'].map do |film|
39
+ film['id']
40
+ end
41
+ end
42
+ all
43
+ end
44
+
45
+ private
46
+
47
+ def gen_url
48
+ @url = [
49
+ "#{DOMAINS[:api]}#{METHODS[:get_top][:method]}",
50
+ "?#{METHODS[:get_top][:type]}=#{@type}",
51
+ "&#{METHODS[:get_top][:page]}=#{@page}"
52
+ ].join('')
53
+ end
54
+
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module KpApi
2
+ VERSION = "0.10.0"
3
+ end
data/lib/kp_api.rb ADDED
@@ -0,0 +1,179 @@
1
+ require 'net/http'
2
+ require 'digest'
3
+ require 'json'
4
+ require 'date'
5
+ require 'time'
6
+
7
+ require 'kp_api/api_error'
8
+ require 'kp_api/agent'
9
+ require 'kp_api/film'
10
+ require 'kp_api/people'
11
+ require 'kp_api/category'
12
+ require 'kp_api/today'
13
+ require 'kp_api/top'
14
+ require 'kp_api/global_search'
15
+ require 'kp_api/film_search'
16
+ require 'kp_api/people_search'
17
+
18
+ #require 'kp_api/reviews'
19
+ #require 'kp_api/gallery'
20
+ #require 'kp_api/similar'
21
+
22
+ require 'kp_api/version'
23
+
24
+ module KpApi
25
+ DOMAINS = {
26
+ api: 'https://ext.kinopoisk.ru/ios/5.0.0/',
27
+ salt: 'IDATevHDS7',
28
+
29
+ kinopoisk: {
30
+ main: 'https://www.kinopoisk.ru',
31
+ poster: {
32
+ film: 'https://st.kp.yandex.net/images/film_iphone/iphone360',
33
+ name: 'https://st.kp.yandex.net/images/actor_iphone/iphone360',
34
+ gallery: 'https://st.kp.yandex.net/images'
35
+ }
36
+ }
37
+ }
38
+
39
+ METHODS = {
40
+ get_film: {
41
+ method: 'getKPFilmDetailView',
42
+ id: 'filmID'
43
+ },
44
+ get_staff: {
45
+ method: 'getStaffList',
46
+ id: 'filmID'
47
+ },
48
+ get_gallery: {
49
+ method: 'getGallery',
50
+ id: 'filmID'
51
+ },
52
+ get_similar: {
53
+ method: 'getKPFilmsList',
54
+ type: 'kp_similar_films',
55
+ id: 'filmID'
56
+ },
57
+
58
+ navigator_filters:{
59
+ method: 'navigatorFilters'
60
+ },
61
+
62
+ get_reviews: {
63
+ method: 'getKPReviews',
64
+ id: 'filmID'
65
+ },
66
+ get_review_detail: {
67
+ method: 'getReviewDetail',
68
+ id: 'reviewID'
69
+ },
70
+
71
+ get_people: {
72
+ method: 'getKPPeopleDetailView',
73
+ id: 'peopleID'
74
+ },
75
+ get_today_films: {
76
+ method: 'getKPTodayFilms'
77
+ },
78
+ get_cinemas: {
79
+ method: 'getCinemas'
80
+ },
81
+ get_cinema_detail: {
82
+ method: 'getCinemaDetail',
83
+ id: 'cinemaID'
84
+ },
85
+ get_seance: {
86
+ method: 'getSeance',
87
+ id: 'filmID'
88
+ },
89
+ get_dates_for_detail_cinema: {
90
+ method: 'getDatesForDetailCinema',
91
+ id: 'filmID'
92
+ },
93
+ get_soon_films: {
94
+ method: 'getSoonFilms'
95
+ },
96
+ get_soon_dvd: {
97
+ method: 'getSoonDVD'
98
+ },
99
+ get_dates_for_soon_films: {
100
+ method: 'getDatesForSoonFilms'
101
+ },
102
+ get_dates_for_soon_dvd: {
103
+ method: 'getDatesForSoonDVD'
104
+ },
105
+
106
+ get_top: {
107
+ method: 'getKPTop',
108
+ page: 'page',
109
+ type: 'type',
110
+ types: {
111
+ popular_films: 'kp_item_top_popular_films',
112
+ best_films: 'kp_item_top_best_films',
113
+ await_films: 'kp_item_top_await',
114
+ popular_people: 'kp_item_top_popular_people',
115
+
116
+ }
117
+ },
118
+
119
+ get_best_films_list: {
120
+ method: 'getBestFilmsList'
121
+ },
122
+
123
+ get_all_cities_view:{
124
+ method: 'getKPAllCitiesView'
125
+ },
126
+
127
+
128
+ search_global: {
129
+ method: 'getKPGlobalSearch',
130
+ keyword: 'keyword'
131
+ },
132
+ search_film: {
133
+ method: 'getKPSearchInFilms',
134
+ keyword: 'keyword',
135
+ page: 'page'
136
+ },
137
+ search_people: {
138
+ method: 'getKPSearchInPeople',
139
+ keyword: 'keyword',
140
+ page: 'page'
141
+ },
142
+
143
+ search_cinemas: {
144
+ method: 'searchCinemas',
145
+ keyword: 'keyword'
146
+ },
147
+ news: {
148
+ method: 'getNews'
149
+ },
150
+ get_news_detail: {
151
+ method: 'getNewsDetail'
152
+ }
153
+ }
154
+
155
+ def self.api_access(url)
156
+ #uri = URI.parse(url)
157
+ #http = Net::HTTP.new(uri.host, uri.port)
158
+ #response = http.request_head(uri.path)
159
+ #
160
+ #if response.code == '200'
161
+ # true
162
+ #else
163
+ # false
164
+ #end
165
+ raise ToDo
166
+ end
167
+
168
+ def self.valid_json?(j)
169
+ begin
170
+ JSON.parse(j)
171
+
172
+
173
+ return true
174
+ rescue JSON::ParserError => e
175
+ return false
176
+ end
177
+ end
178
+
179
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::Category do
4
+ r = KpApi::Category.new(2)
5
+
6
+
7
+ it "Check return Category not formatted data" do
8
+ expect( r.data.class ).to eql(Hash)
9
+ expect( r.status ).to eql(true)
10
+ expect( r.data['genre' ].class ).to eql(Array)
11
+ expect( r.data['country'].class ).to eql(Array)
12
+ expect( r.data['genre' ].count > 0 ).to eql(true)
13
+ expect( r.data['country'].count > 0 ).to eql(true)
14
+
15
+ expect( r.data['country'].first['id' ].class ).to eql(String)
16
+ expect( r.data['country'].first['name' ].class ).to eql(String)
17
+
18
+ expect( r.data['genre'].first['id' ].class ).to eql(String)
19
+ expect( r.data['genre'].first['name' ].class ).to eql(String)
20
+
21
+ end
22
+
23
+ it "Check return Category genres formatted data" do
24
+ expect( r.genres.class ).to eql(Array)
25
+ expect( r.genres.count > 0 ).to eql(true)
26
+
27
+ expect( r.genres.first[:id ].class ).to eql(Integer)
28
+ expect( r.genres.first[:name ].class ).to eql(String)
29
+ end
30
+
31
+ it "Check return Category countries formatted data" do
32
+ expect( r.countries.class ).to eql(Array)
33
+ expect( r.countries.count > 0 ).to eql(true)
34
+
35
+ expect( r.countries.first[:id ].class ).to eql(Integer)
36
+ expect( r.countries.first[:name ].class ).to eql(String)
37
+ end
38
+
39
+ it "Check return Category before cities data" do
40
+ expect( r.data2 ).to eql(nil)
41
+ end
42
+
43
+ it "Check return Category cities data" do
44
+ expect( r.cities.class ).to eql(Array)
45
+ expect( r.cities.count > 0 ).to eql(true)
46
+
47
+ expect( r.cities.first[:id ].class ).to eql(Integer)
48
+ expect( r.cities.first[:name ].class ).to eql(String)
49
+ end
50
+
51
+ it "Check return not found country_id" do
52
+ expect { KpApi::Category.new(9999999999).cities }
53
+ .to raise_error(KpApi::ApiError)
54
+ end
55
+
56
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::FilmSearch do
4
+ gs1 = KpApi::FilmSearch.new('Бразилия')
5
+ gs2 = KpApi::FilmSearch.new('олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув')
6
+
7
+ it "Check return FilmSearch not formatted data" do
8
+ expect( gs1.data.class ).to eql(Hash)
9
+ expect( gs1.data['class'] ).to eql("KPSearchInFilms")
10
+ expect( gs1.data['keyword'] ).to eql("Бразилия")
11
+ expect( gs1.data['searchFilms'].count ).to eql(20)
12
+ expect( gs1.data['searchFilmsCountResult'] > 40).to eql(true)
13
+ expect( gs1.data['pagesCount'] > 2).to eql(true)
14
+
15
+ expect( gs2.data.class ).to eql(Hash)
16
+ expect( gs2.data['class'] ).to eql("KPSearchInFilms")
17
+ expect( gs2.data['keyword'] ).to eql("олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув")
18
+ expect( gs2.data['pagesCount'] ).to eql(0)
19
+ end
20
+
21
+ it "Check return FilmSearch formatted data \"Бразилия\" and paginate" do
22
+ expect( gs1.found? ).to eql(true)
23
+ expect( gs1.view.count == 20 ).to eql(true)
24
+ expect( gs1.films_count > 40 ).to eql(true)
25
+ expect( gs1.current_page ).to eql(1)
26
+ expect( gs1.page_count > 2 ).to eql(true)
27
+ f_id = gs1.view.first[:id]
28
+
29
+ 2.upto( gs1.page_count ).map do |page|
30
+ expect( gs1.next_page ).to eql(true)
31
+ expect( gs1.current_page ).to eql(page)
32
+ end
33
+
34
+ expect( gs1.next_page ).to eql(false)
35
+ expect( gs1.view.count > 0 ).to eql(true)
36
+ expect( f_id != gs1.view.first[:id] ).to eql(true)
37
+
38
+ end
39
+
40
+ it "Check return FilmSearch formatted not found data" do
41
+ expect( gs2.found? ).to eql(false)
42
+ end
43
+
44
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::Film do
4
+ id = 444
5
+ resource = KpApi::Film.new(id)
6
+
7
+
8
+ it "Check return Film not formatted data" do
9
+ expect( resource.data.class ).to eql(Hash)
10
+ expect( resource.status ).to eql(true)
11
+
12
+ expect( resource.data['class'] ).to eql("KPFilmDetailView")
13
+ expect( resource.data['type'] ).to eql("KPFilm")
14
+ expect( resource.data['filmID'] ).to eql(444)
15
+ expect( resource.data['webURL'] ).to eql("http://www.kinopoisk.ru/film/444/")
16
+ expect( resource.data['nameRU'] ).to eql("Терминатор 2: Судный день")
17
+ expect( resource.data['nameEN'] ).to eql("Terminator 2: Judgment Day")
18
+ expect( resource.data['filmLength'] ).to eql("2:17")
19
+ expect( resource.data['year'] ).to eql("1991")
20
+ end
21
+
22
+ it "Check return Film formatted data" do
23
+ expect( resource.view[:kp_type] ).to eql("KPFilm")
24
+ expect( resource.view[:id] ).to eql(444)
25
+ expect( resource.view[:name_ru] ).to eql("Терминатор 2: Судный день")
26
+ expect( resource.view[:name_en] ).to eql("Terminator 2: Judgment Day")
27
+ expect( resource.view[:slogan] ).to eql("Same Make. Same Model. New Mission")
28
+ expect( resource.view[:duration] ).to eql(137)
29
+ expect( resource.view[:year] ).to eql(1991)
30
+ expect( resource.view[:countries] ).to eql(["США", "Франция"])
31
+ expect( resource.view[:genres] ).to eql(["фантастика", "боевик", "триллер"])
32
+ end
33
+
34
+
35
+
36
+ it "Check return Film peoples data" do
37
+ expect( resource.peoples.count ).to eql(7)
38
+ expect( resource.peoples.first.class ).to eql(Hash)
39
+ expect( resource.peoples.first[:id].class ).to eql(Integer)
40
+ expect( resource.peoples.first[:name_ru].class ).to eql(String)
41
+ expect( resource.peoples.first[:name_en].class ).to eql(String)
42
+ end
43
+
44
+ it "Check return Film peoples_full data" do
45
+ expect( resource.data2 ).to eql(nil)
46
+ end
47
+
48
+ it "Check return Film peoples_full data" do
49
+ expect( resource.peoples_full.count ).to eql(84)
50
+ expect( resource.data2.class ).to eql(Hash)
51
+ expect( resource.status2 ).to eql(true)
52
+ end
53
+
54
+ it "Check return not found Film" do
55
+ expect { KpApi::Film.new(1) }
56
+ .to raise_error(KpApi::ApiError)
57
+ end
58
+
59
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::GlobalSearch do
4
+ gs1 = KpApi::GlobalSearch.new('Бразилия')
5
+ gs2 = KpApi::GlobalSearch.new('Привет')
6
+ gs3 = KpApi::GlobalSearch.new('олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув')
7
+
8
+
9
+ it "Check return GlobalSearch not formatted data" do
10
+ expect( gs1.data.class ).to eql(Hash)
11
+ expect( gs1.data['class'] ).to eql("KPGlobalSearch")
12
+ expect( gs1.data['keyword'] ).to eql("Бразилия")
13
+ expect( gs1.data['searchFilms'].count ).to eql(3)
14
+ expect( gs1.data['searchPeople'].count > 0).to eql(true)
15
+ expect( gs1.data['searchFilmsCountResult'] > 0).to eql(true)
16
+ expect( gs1.data['searchPeoplesCountResult'] > 0).to eql(true)
17
+
18
+ expect( gs2.data.class ).to eql(Hash)
19
+ expect( gs2.data['class'] ).to eql("KPGlobalSearch")
20
+ expect( gs2.data['keyword'] ).to eql("Привет")
21
+ expect( gs2.data['searchFilms'].count ).to eql(3)
22
+ expect( gs2.data['searchPeople'] ).to eql(nil)
23
+ expect( gs2.data['searchFilmsCountResult'] > 0).to eql(true)
24
+ expect( gs2.data['searchPeoplesCountResult']).to eql(nil)
25
+
26
+ expect( gs3.data.class ).to eql(Hash)
27
+ expect( gs3.data['class'] ).to eql("KPGlobalSearch")
28
+ expect( gs3.data['keyword'] ).to eql("олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув")
29
+ expect( gs3.data['searchFilms'] ).to eql([])
30
+ expect( gs3.data['searchFilmsCountResult']).to eql(nil)
31
+ expect( gs3.data['searchPeoplesCountResult']).to eql(nil)
32
+
33
+ end
34
+
35
+ it "Check return GlobalSearch formatted data \"Бразилия\"" do
36
+ expect( gs1.found? ).to eql(true)
37
+ expect( gs1.films_count > 40 ).to eql(true)
38
+ expect( gs1.peoples_count > 0 ).to eql(true)
39
+
40
+ expect( gs1.films.count == 3 ).to eql(true)
41
+ expect( gs1.peoples.count > 0 ).to eql(true)
42
+
43
+ expect( gs1.films.first.class ).to eql(Hash)
44
+ expect( gs1.films.first[:id] > 0).to eql(true)
45
+
46
+ expect( gs1.peoples.first.class ).to eql(Hash)
47
+ expect( gs1.peoples.first[:id] > 0).to eql(true)
48
+
49
+ expect( gs1.youmean.class ).to eql(Hash)
50
+ expect( gs1.youmean[:id] > 0).to eql(true)
51
+
52
+ end
53
+
54
+ it "Check return GlobalSearch formatted data \"Привет\"" do
55
+ expect( gs2.found? ).to eql(true)
56
+ expect( gs2.films_count > 100 ).to eql(true)
57
+ expect( gs2.peoples_count == 0 ).to eql(true)
58
+
59
+ expect( gs2.films.count == 3 ).to eql(true)
60
+ expect( gs2.peoples ).to eql(nil)
61
+
62
+ expect( gs2.films.first.class ).to eql(Hash)
63
+ expect( gs2.films.first[:id] > 0).to eql(true)
64
+
65
+ end
66
+
67
+ it "Check return GlobalSearch formatted not found data" do
68
+ expect( gs3.found? ).to eql(false)
69
+ end
70
+
71
+
72
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::PeopleSearch do
4
+ gs1 = KpApi::PeopleSearch.new('Дуров')
5
+ gs2 = KpApi::PeopleSearch.new('олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув')
6
+
7
+ it "Check return PeopleSearch not formatted data" do
8
+ expect( gs1.data.class ).to eql(Hash)
9
+ expect( gs1.data['class'] ).to eql("KPSearchInPeople")
10
+ expect( gs1.data['keyword'] ).to eql("Дуров")
11
+ expect( gs1.data['searchPeople'].count ).to eql(20)
12
+ expect( gs1.data['searchPeoplesCountResult'] > 80).to eql(true)
13
+ expect( gs1.data['pagesCount'] > 4).to eql(true)
14
+
15
+ expect( gs2.data.class ).to eql(Hash)
16
+ expect( gs2.data['class'] ).to eql("KPSearchInPeople")
17
+ expect( gs2.data['keyword'] ).to eql("олимркмрумщшрушосрволыдсродлрфдлоыврцлдоув")
18
+ expect( gs2.data['pagesCount'] ).to eql(0)
19
+ end
20
+
21
+ it "Check return PeopleSearch formatted data \"Бразилия\" and paginate" do
22
+ expect( gs1.found? ).to eql(true)
23
+ expect( gs1.view.count == 20 ).to eql(true)
24
+ expect( gs1.peoples_count > 80 ).to eql(true)
25
+ expect( gs1.current_page ).to eql(1)
26
+ expect( gs1.page_count > 4 ).to eql(true)
27
+ f_id = gs1.view.first[:id]
28
+
29
+ 2.upto( gs1.page_count ).map do |page|
30
+ expect( gs1.next_page ).to eql(true)
31
+ expect( gs1.current_page ).to eql(page)
32
+ end
33
+
34
+ expect( gs1.next_page ).to eql(false)
35
+ expect( gs1.view.count > 0 ).to eql(true)
36
+ expect( f_id != gs1.view.first[:id] ).to eql(true)
37
+
38
+ end
39
+
40
+ it "Check return PeopleSearch formatted not found data" do
41
+ expect( gs2.found? ).to eql(false)
42
+ end
43
+
44
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::People do
4
+ id = 1
5
+ r = KpApi::People.new(id)
6
+
7
+ it "Check return Film not formatted data" do
8
+ expect( r.data.class ).to eql(Hash)
9
+ expect( r.status ).to eql(true)
10
+
11
+ expect( r.data['class'] ).to eql("KPPeopleDetailView")
12
+ expect( r.data['peopleID'] ).to eql("1")
13
+ expect( r.data['webURL'] ).to eql("http://www.kinopoisk.ru/name/1/")
14
+ expect( r.data['nameRU'] ).to eql("Стивен Карпентер")
15
+ expect( r.data['nameEN'] ).to eql("Stephen Carpenter")
16
+ expect( r.data['sex'] ).to eql("male")
17
+ expect( r.data['birthplace'] ).to eql("Уэтерфорд, Техас, США")
18
+ end
19
+
20
+ it "Check return Film formatted data" do
21
+ expect( r.view[:kp_type] ).to eql("KPPeopleDetailView")
22
+ expect( r.view[:id] ).to eql(1)
23
+ expect( r.view[:name_ru] ).to eql("Стивен Карпентер")
24
+ expect( r.view[:name_en] ).to eql("Stephen Carpenter")
25
+ expect( r.view[:sex] ).to eql("male")
26
+ expect( r.view[:profession] ).to eql(["Сценарист", "Режиссер", "Оператор"])
27
+ expect( r.view[:birthplace] ).to eql("Уэтерфорд, Техас, США")
28
+ end
29
+
30
+ it "Check return People films data" do
31
+ expect( r.films.count > 21 ).to eql(true)
32
+ expect( r.films.first[:id].class ).to eql(Integer)
33
+ expect( r.film_ids.map{|i| i.class == Integer && i > 0 }.uniq). to eql([true])
34
+ end
35
+
36
+ it "Check return not found Film" do
37
+ expect { KpApi::People.new(999999999999999999999999) }
38
+ .to raise_error(KpApi::ApiError)
39
+ end
40
+
41
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe KpApi::Today do
4
+ r = KpApi::Today.new()
5
+
6
+ it "Check return Today not formatted data" do
7
+ expect( r.data.class ).to eql(Hash)
8
+ expect( r.status ).to eql(true)
9
+
10
+ expect( r.data['class' ] ).to eql('KPTodayFilms')
11
+ expect( r.data['filmsData'].class ).to eql(Array)
12
+ expect( r.data['filmsData'].count > 0 ).to eql(true)
13
+
14
+ expect( r.data['filmsData'].first['id' ].class ).to eql(String)
15
+ expect( r.data['filmsData'].first['nameRU' ].class ).to eql(String)
16
+ expect( r.data['filmsData'].first['nameEN' ].class ).to eql(String)
17
+ end
18
+
19
+ it "Check return Today formatted data" do
20
+ expect( r.view.class ).to eql(Array)
21
+ expect( r.view.count > 0 ).to eql(true)
22
+
23
+ expect( r.view.first[:id ].class ).to eql(Integer)
24
+ expect( r.view.first[:name_ru].class ).to eql(String)
25
+ expect( r.view.first[:name_en].class ).to eql(String)
26
+ end
27
+
28
+ it "Check return Today ids formatted data" do
29
+ expect( r.film_ids.count > 0 ).to eql(true)
30
+ expect( r.film_ids.first.class ).to eql(Integer)
31
+ expect( r.film_ids.map{|i| i.class == Integer && i > 0 }.uniq). to eql([true])
32
+ end
33
+
34
+ it "Check return Today not found country_id" do
35
+ expect( KpApi::Today.new(9999999999, 99999999999).view ).to eql([])
36
+ end
37
+
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'kp_api'
2
+ require 'pry'
3
+ require 'awesome_print'
4
+ require 'hashie'
5
+
6
+ RSpec.configure do |config|
7
+ config.raise_errors_for_deprecations!
8
+
9
+ config.before(:suite) do
10
+ Hashie.logger = Logger.new(nil)
11
+ end
12
+ end
13
+
14
+ RSpec::Matchers.define :log_requests do
15
+ match do |logger|
16
+ logger.log_requests?
17
+ end
18
+ end
19
+
20
+ RSpec::Matchers.define :log_errors do
21
+ match do |logger|
22
+ logger.log_errors?
23
+ end
24
+ end
25
+
26
+ RSpec::Matchers.define :log_responses do
27
+ match do |logger|
28
+ logger.log_responses?
29
+ end
30
+ end