anchor.diff: -﻿module Fake.HttpClientHelper
  +﻿/// Contains a http listener for FAKE.Deploy.
  +module Fake.HttpClientHelper
   
   open System
   open System.IO
   open System.Net
   
  +/// A http response type.
   type Response = {
       Messages : seq<ConsoleMessage>
       Exception : obj
  -    IsError : bool
  -}
  +    IsError : bool }
   
  +/// Deployment result type.
   type DeploymentResponse =
   | Success of Response
   | Failure of Response
   | QueryResult of seq<NuSpecPackage>
   
  -let get f url = 
  +/// Gets the http response from the given URL and runs it with the given function.
  +let get f url =
       let uri = new Uri(url, UriKind.Absolute)
       let client = new WebClient()
       client.Headers.Add(HttpRequestHeader.ContentType, "application/fake")
       client.DownloadString(uri) |> f
   
  +/// Posts the given body to the given URL.
   let post url body = 
       let uri = new Uri(url, UriKind.Absolute)
       let client = new WebClient()
  
positive.code:     use sr = new StreamReader(ms, Text.Encoding.UTF8)
      sr.ReadToEnd() |> Json.deserialize<DeploymentResponse>
  
  let getReleasesFor server appname status =
      if String.IsNullOrEmpty(appname)
      then server + "/deployments?status=" + status 
      else server + "/deployments/" + appname + "?status=" + status
      |> get (Json.deserialize<DeploymentResponse>)
  
  let rollbackTo server appname version =
      server + "/deployments/"+ appname + "?version=" + version 
          |> put [||]
  
  let getAllActiveReleases server = getReleasesFor server null "active"
  
  let getActiveReleasesFor server appname = getReleasesFor server appname "active"
  
  let getAllReleasesFor server appname = 
      if String.IsNullOrEmpty(appname)
      then server + "/deployments/"
      else server + "/deployments/" + appname + "/"
      |> get (Json.deserialize<DeploymentResponse>)
  
  let getAllReleases server = getAllReleasesFor server null
  
  let postDeploymentPackage url packageFileName = post url (ReadFileAsBytes packageFileName)
  
  let PostDeploymentPackage url packageFileName = 
      match postDeploymentPackage url packageFileName with
      | Success _ -> tracefn "Deployment of %s successful" packageFileName
      | Failure exn -> failwithf "Deployment of %A failed\r\n%A" packageFileName exn.Exception
      | response -> failwithf "Deployment of %A failed\r\n%A" packageFileName response
  
  let RollbackPackage url appName version = 
      match rollbackTo url appName version with
      | Success _ -> tracefn "Rollback of %s to %s successful" appName version
  
negative.code:     use sr = new StreamReader(ms, Text.Encoding.UTF8)
      sr.ReadToEnd() |> Json.deserialize<DeploymentResponse>
  
  /// Puts the given body to the given URL.
  let put body url = 
      let uri = new Uri(url, UriKind.Absolute)
      let client = new WebClient()
  