<repo_name>soumyaparambil/movie-rating<file_sep>/Dockerfile
FROM python:latest

WORKDIR /app

COPY . /app

# Install prerequisites
#RUN apt-get update && apt-get install -y \
#curl

RUN apt-get update && apt-get install curl -y && apt-get install jq -y 


CMD /bin/bash
<file_sep>/README.md
# movie-rating

This project gets the movie rating from Rotten Tomatoes from an external API http://www.omdbapi.com/ by the movie title. The project is dockerized.

# How to run from docker hub
1. Pull the image from dockerhub `docker pull soumyaparambil/movie-ratings:1.0-shell`
2. Run the docker container `docker run -it soumyaparambil/movie-ratings:1.0-shell`
3. Once the docker container is up, run the script `./movie-ratings.sh <movie_name>`

# Building locally and running ( if need to fork and make changes )
1. Create a docker image with the below command `docker build --tag=<docker-image-name> .`
2. Run the docker container `docker run -it <docker-image-name>`
3. Once the docker container is up, run the script `./movie-ratings.sh <movie_name>`


# Test Cases covered
1. Checks for empty string on movie names
2. Checks movie names with more than one words
3. Checks for valid movie names
<file_sep>/movie-ratings.sh
#!/bin/sh

MOVIE_NAME=$1
API_KEY=30a0de 				#### apikey is hardcoded now. This can be generalized based on the requirement.
MOVIE_RATINGS_BY="Rotten Tomatoes"	#### This can generalized based on the requirement later.

if [ -z "$MOVIE_NAME" ]
then 
	echo "No argument supplied. Usage is ./list-movies.sh MOVIE_NAME"
	exit 0
fi

urlencode() {
  python -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], sys.argv[2]))' \
    "$1" "$urlencode_safe"
}


ENC_MOVIE_NAME=$(urlencode "$MOVIE_NAME")

JSON_RESULT=$(curl -s "http://www.omdbapi.com/?t=$ENC_MOVIE_NAME&apikey=$API_KEY")

RESPONSE=$(echo $JSON_RESULT | jq -r '.Response')

if [ $RESPONSE != "True" ]
then
	echo "No movie found by the name '$MOVIE_NAME'"
	exit 0
fi


#RATING=$(curl -s "http://www.omdbapi.com/?t=$ENC_MOVIE_NAME&apikey=30a0de" | jq -r '.Ratings' | jq -r '.map(select(.Source=="Rotten Tomatoes")) | .[] .Value')
RATING=$( echo $JSON_RESULT | jq -r '.Ratings' | jq -r 'map(select(.Source=="Rotten Tomatoes")) | .[] .Value')

if [ -z "$RATING" ] 
then
	echo "No Rotten Tomatoes rating exist for the movie '$MOVIE_NAME'"
else 
	echo "Rotten Tomatoes rating for the movie '$MOVIE_NAME' is $RATING"
fi
