Class: Shin::Reviews::Russin
- Inherits:
-
Object
- Object
- Shin::Reviews::Russin
show all
- Defined in:
- lib/shin/reviews/russin.rb
Defined Under Namespace
Classes: HTTPError, MissingArgument
Instance Method Summary
collapse
Instance Method Details
#find(h = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/shin/reviews/russin.rb', line 12
def find(h = {})
if h[:year] != ""
response = Base.get('http://www.russin.nu/api.php?soktitel='+URI.encode(h[:title])+"&year="+h[:year].to_s)
elsif h[:title] != ""
response = Base.get('http://www.russin.nu/api.php?soktitel='+URI.encode(h[:title]))
else
raise MissingArgument, "You are missing the argument 'title' which is required to use this source."
end
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
doc = Nokogiri::XML(response.body)
doc.remove_namespaces!
data = []
doc.xpath("//data/russinrecension").each do |review|
movie_title, movie_year = review.xpath('./filmtitel').text.split(", ")
title = review.xpath('./rubrik').text
rating = review.xpath('./betyg').text
url = review.xpath('./url').text
data << {name: movie_title, year: movie_year.to_i, title: title, rating: rating.to_i, url: url, votes: nil}
end
data.to_hashugar
end
|
#new ⇒ Object
8
9
10
|
# File 'lib/shin/reviews/russin.rb', line 8
def new
self
end
|