Created
March 7, 2017 04:01
-
-
Save jesulink2514/13f7f57ccba0b66eee5fae9e6807f4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
using Refit; | |
namespace DemoRefit.Client | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string input; | |
do | |
{ | |
Console.WriteLine("Enter the title:"); | |
input = Console.ReadLine(); | |
SearchMovie(input); | |
Console.WriteLine("Enter 'X' to exit"); | |
} while (!string.Equals(input, "x", StringComparison.InvariantCultureIgnoreCase)); | |
} | |
private static void SearchMovie(string title) | |
{ | |
if (string.Equals(title,"x", StringComparison.InvariantCultureIgnoreCase)) return; | |
var moviesClient = CreateMoviesClient(); | |
var r = moviesClient.FindMovies(null,title, null, null,PlotType.Full).Result; | |
PrintMovie(r); | |
} | |
private static IMoviesApi CreateMoviesClient() | |
{ | |
var moviesClient = RestService.For<IMoviesApi>("http://www.omdbapi.com", | |
new RefitSettings | |
{ | |
JsonSerializerSettings = new JsonSerializerSettings {Converters = {new StringEnumConverter()}} | |
}); | |
return moviesClient; | |
} | |
private static void PrintMovie(Movie r) | |
{ | |
Console.WriteLine($"year: {r.Year}"); | |
Console.WriteLine(r.Plot); | |
Console.WriteLine(); | |
Console.WriteLine($"Poster: {r.Poster}"); | |
Console.WriteLine("=============================================="); | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment