Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Implemented the CurrentTheaterScheduleWebRequestManager
Browse files Browse the repository at this point in the history
  • Loading branch information
bofirial committed Jun 10, 2017
1 parent f5121ef commit 531236a
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Melody49Notifier.Models;
using System.Net;
using System.IO;
using Microsoft.Azure.WebJobs.Host;

namespace Melody49Notifier.DataAbstraction
{
public class CurrentTheaterScheduleWebRequestManager : ICurrentTheaterScheduleWebRequestManager
{
private readonly TraceWriter log;
private readonly ITheaterScheduleHTMLParser theaterScheduleHTMLParser;

public CurrentTheaterScheduleWebRequestManager(TraceWriter log, ITheaterScheduleHTMLParser theaterScheduleHTMLParser)
{
this.log = log;
this.theaterScheduleHTMLParser = theaterScheduleHTMLParser;
}

public string TheaterUrl => "http://www.chakerestheatres.com/melody49di.php";

public TheaterSchedule GetCurrentTheaterSchedule()
{
string currentTheaterHTML = GetCurrentTheaterScheduleHTML();

log.Verbose($"Received Current Theater Schedule HTML. ({currentTheaterHTML.Length} Characters)");

return theaterScheduleHTMLParser.ParseTheaterScheduleHTML(currentTheaterHTML);
}

private string GetCurrentTheaterScheduleHTML()
{
string currentTheaterHTML;
WebRequest webRequest = WebRequest.Create(TheaterUrl);
WebResponse webResponse = webRequest.GetResponse();

using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
{
currentTheaterHTML = streamReader.ReadToEnd();
}

return currentTheaterHTML;
}
}
}

0 comments on commit 531236a

Please sign in to comment.