Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
##Usage :
> ruby program.rb [name of the movie] [number of results]

- [name of the movie] : required
- [number of results] : optional (all by default)

# Made for :

# Seevibes Pre-Interview Test

![Seevibes Logo](http://www.seevibes.com/assets/corpo/logo-small.png)
Expand Down
39 changes: 39 additions & 0 deletions program.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'net/http'
require 'rexml/document'

if ARGV.length != 1 && ARGV.length != 2
abort("Error! Expected 1 parameter, received " + ARGV.length.to_s + ".")
else
input = ARGV[0]
end
count = -1
if ARGV.length == 2
begin
count = Integer(ARGV[1]) - 1
rescue
count = -1
end
end
url = 'http://www.omdbapi.com/?s='+ input +'&r=xml';
xml_data = Net::HTTP.get_response(URI.parse(URI.encode(url)))
if xml_data.is_a?(Net::HTTPSuccess);
doc = REXML::Document.new(xml_data.body)
if(doc.root.attributes['response'] == 'False')
puts 'No data found!'
else
title = []
year = []
doc.elements.each('*/result') do |ele|
title << ele.attributes["title"]
year << ele.attributes["year"]
end
if(count == -1 || count > title.size()-1)
count = title.size()-1
end
for i in 0..count
puts title[i] + ', ' + year[i]
end
end
else
abort("Error! Unable to etablish the connection")
end