Class: Shin::Reviews::Kritiker
- Inherits:
-
Object
- Object
- Shin::Reviews::Kritiker
show all
- Defined in:
- lib/shin/reviews/kritiker.rb
Defined Under Namespace
Classes: HTTPError, MissingArgument, NotJSON
Instance Method Summary
collapse
Instance Method Details
#find(h = {}) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/shin/reviews/kritiker.rb', line 15
def find(h = {})
raise MissingArgument, "You are missing the argument 'imdb' or 'kritiker_token' which is required to use this source." unless h[:imdb] != "" and Shin.get[:kritiker_token] != ""
response = Base.get('http://api.kritiker.se/film/?imdb='+h[:imdb]+'&token='+Shin.get[:kritiker_token])
data = Oj.load(response.body) rescue nil
raise NotJSON, "Returned data isn't JSON. Couldn't parse it." if data == nil
year = data['datum'][/^(\d\d\d\d)/, 1].to_i unless data['datum'][/^(\d\d\d\d)/, 1].to_i == 0
{name: data['titel'], year: year, title: nil, rating: data['medelbetyg'].gsub(",", ".").to_f, url: data['kritiker'], votes: data['antalrecensioner'].to_i}.to_hashugar
end
|
#new ⇒ Object
11
12
13
|
# File 'lib/shin/reviews/kritiker.rb', line 11
def new
self
end
|