Skip to content

Commit 9f17495

Browse files
Merge branch 'feature/Unique_response_type_for_JSON_responses' into develop
2 parents 827e209 + 7c3ffb1 commit 9f17495

File tree

10 files changed

+32
-27
lines changed

10 files changed

+32
-27
lines changed

NScrape.Test/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following

NScrape/Forms/HtmlForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private string DownloadFormHtml() {
315315
private void Initialize( int formOrdinal ) {
316316
var formDefinitions = HtmlFormDefinition.Parse( Html ).ToList();
317317

318-
if ( formOrdinal < 0 || formOrdinal >= formDefinitions.Count() ) {
318+
if ( formOrdinal < 0 || formOrdinal >= formDefinitions.Count ) {
319319
throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, NScrapeResources.InvalidFormOrdinal, formOrdinal ) );
320320
}
321321

NScrape/GetWebRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public GetWebRequest( Uri destination, bool autoRedirect )
4040
/// </returns>
4141
public override string ToString()
4242
{
43-
return string.Format("GET {0}", this.Destination);
43+
return string.Format("GET {0}", Destination);
4444
}
4545
}
4646
}

NScrape/JsonWebResponse.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
using System;
22
using System.Text;
33

4-
namespace NScrape
5-
{
6-
/// <summary>
7-
/// Represents a web response for a request that returned JSON.
8-
/// </summary>
9-
public class JsonWebResponse : TextWebResponse
10-
{
11-
internal JsonWebResponse(bool success, Uri url, string text, Encoding encoding)
12-
: base(url, WebResponseType.JavaScript, success, text, encoding)
13-
{
14-
}
4+
namespace NScrape {
5+
/// <summary>
6+
/// Represents a web response for a request that returned JSON.
7+
/// </summary>
8+
public class JsonWebResponse : TextWebResponse {
159

16-
/// <summary>
17-
/// Gets the JSON data.
18-
/// </summary>
19-
public string Json { get { return Text; } }
20-
}
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="JsonWebResponse"/> class.
12+
/// </summary>
13+
/// <param name="success"><b>true</b> if the response is considered successful, <b>false</b> otherwise.</param>
14+
/// <param name="responseUrl">The URL of the response.</param>
15+
/// <param name="text">The JSON text of the response.</param>
16+
/// <param name="encoding">The encoding of the JSON text.</param>
17+
public JsonWebResponse( bool success, Uri responseUrl, string text, Encoding encoding )
18+
: base( responseUrl, WebResponseType.Json, success, text, encoding ) {
19+
}
20+
21+
/// <summary>
22+
/// Gets the JSON data.
23+
/// </summary>
24+
public string Json { get { return Text; } }
25+
}
2126
}

NScrape/NScrapeUtility.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.Collections.Specialized;
32
using System.Globalization;
4-
using System.Web;
5-
using Microsoft.JScript;
63

74
namespace NScrape {
85
/// <summary>

NScrape/PostWebRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public PostWebRequest( Uri destination, string requestData, string contentType,
120120
/// </returns>
121121
public override string ToString()
122122
{
123-
return string.Format("POST {0}", this.Destination);
123+
return string.Format("POST {0}", Destination);
124124
}
125125
}
126126
}

NScrape/RedirectedWebResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32

43
namespace NScrape {
54
/// <summary>

NScrape/TextWebResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class TextWebResponse : WebResponse {
1717
/// <param name="success"><b>true</b> if the response is considered successful, <b>false</b> otherwise.</param>
1818
/// <param name="text">The text of the response.</param>
1919
/// <param name="encoding">The encoding of the text.</param>
20-
public TextWebResponse( Uri responseUrl, WebResponseType responseType, bool success, string text, Encoding encoding )
20+
protected TextWebResponse( Uri responseUrl, WebResponseType responseType, bool success, string text, Encoding encoding )
2121
: base( responseUrl, responseType, success ) {
2222
this.text = text;
2323
this.encoding = encoding;

NScrape/UnexpectedWebResponseGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static Exception CreateException( string message, WebResponse response )
1212
switch ( response.ResponseType ) {
1313

1414
case WebResponseType.Exception:
15-
var exceptionResponse = response as ExceptionWebResponse;
15+
var exceptionResponse = (ExceptionWebResponse)response;
1616

1717
exception = exceptionResponse.Exception;
1818
break;
@@ -26,7 +26,7 @@ public static Exception CreateException( string message, WebResponse response )
2626
break;
2727

2828
case WebResponseType.Unsupported:
29-
var unsupportedResponse = response as UnsupportedWebResponse;
29+
var unsupportedResponse = (UnsupportedWebResponse)response;
3030

3131
exception = new WebException( string.Format( CultureInfo.CurrentCulture, NScrapeResources.UnsupportedResponseContentType, unsupportedResponse.ContentType ) );
3232
break;

NScrape/WebResponseType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public enum WebResponseType {
2323
/// </summary>
2424
JavaScript,
2525

26+
/// <summary>
27+
/// A JSON reponse.
28+
/// </summary>
29+
Json,
30+
2631
/// <summary>
2732
/// A redirect reponse.
2833
/// </summary>

0 commit comments

Comments
 (0)