@@ -533,29 +533,49 @@ private void OnGetEntitiesResponse(RESTConnector.Request req, RESTConnector.Resp
533
533
534
534
#region FeedDetection
535
535
private const string SERVICE_DETECT_FEEDS_URL = "/calls/url/URLGetFeedLinks" ;
536
+ private const string SERVICE_DETECT_FEEDS_HTML = "/calls/html/HTMLGetFeedLinks" ;
536
537
public delegate void OnDetectFeeds ( FeedData feedData , string data ) ;
537
538
538
- public bool DetectFeeds ( OnDetectFeeds callback , string url , string customData = default ( string ) )
539
+ public bool DetectFeeds ( OnDetectFeeds callback , string source , string customData = default ( string ) )
539
540
{
540
541
if ( callback == null )
541
542
throw new ArgumentNullException ( "callback" ) ;
542
- if ( string . IsNullOrEmpty ( url ) )
543
- throw new WatsonException ( "Please provide a url for GetEmotions." ) ;
543
+ if ( string . IsNullOrEmpty ( source ) )
544
+ throw new WatsonException ( "Please provide a source for GetEmotions." ) ;
544
545
if ( string . IsNullOrEmpty ( mp_ApiKey ) )
545
546
SetCredentials ( ) ;
546
547
547
548
DetectFeedsRequest req = new DetectFeedsRequest ( ) ;
548
549
req . Callback = callback ;
549
- req . Data = string . IsNullOrEmpty ( customData ) ? url : customData ;
550
+ req . Data = string . IsNullOrEmpty ( customData ) ? source : customData ;
550
551
551
552
req . Parameters [ "apikey" ] = mp_ApiKey ;
552
553
req . Parameters [ "outputMode" ] = "json" ;
553
554
554
555
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
555
556
req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
556
- req . Forms [ "url" ] = new RESTConnector . Form ( url ) ;
557
557
558
- RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , SERVICE_DETECT_FEEDS_URL ) ;
558
+ string service ;
559
+ string normalizedSource = source . Trim ( ) . ToLower ( ) ;
560
+ if ( normalizedSource . StartsWith ( "http://" ) || normalizedSource . StartsWith ( "https://" ) )
561
+ {
562
+ service = SERVICE_DETECT_FEEDS_URL ;
563
+ req . Forms [ "url" ] = new RESTConnector . Form ( source ) ;
564
+ }
565
+ else if ( Path . GetExtension ( normalizedSource ) . EndsWith ( ".html" ) && ! normalizedSource . StartsWith ( "http://" ) && ! normalizedSource . StartsWith ( "https://" ) )
566
+ {
567
+ service = SERVICE_DETECT_FEEDS_HTML ;
568
+ string htmlData = default ( string ) ;
569
+ htmlData = File . ReadAllText ( source ) ;
570
+ req . Forms [ "html" ] = new RESTConnector . Form ( htmlData ) ;
571
+ }
572
+ else
573
+ {
574
+ Log . Error ( "Alchemy Language" , "Either a URL or a html page source is required for DetectFeeds!" ) ;
575
+ return false ;
576
+ }
577
+
578
+ RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ;
559
579
if ( connector == null )
560
580
return false ;
561
581
@@ -874,7 +894,7 @@ private void OnGetMicroformatsResponse(RESTConnector.Request req, RESTConnector.
874
894
875
895
#region GetPubDate
876
896
private const string SERVICE_GET_PUBLICATION_DATE_URL = "/calls/url/URLGetPubDate" ;
877
- // private const string SERVICE_GET_PUBLICATION_DATE_HTML = "/calls/html/HTMLGetPubDate";
897
+ private const string SERVICE_GET_PUBLICATION_DATE_HTML = "/calls/html/HTMLGetPubDate" ;
878
898
public delegate void OnGetPublicationDate ( PubDateData pubDateData , string data ) ;
879
899
880
900
public bool GetPublicationDate ( OnGetPublicationDate callback , string source , string customData = default ( string ) )
@@ -905,12 +925,10 @@ private void OnGetMicroformatsResponse(RESTConnector.Request req, RESTConnector.
905
925
}
906
926
else if ( Path . GetExtension ( normalizedSource ) . EndsWith ( ".html" ) && ! normalizedSource . StartsWith ( "http://" ) && ! normalizedSource . StartsWith ( "https://" ) )
907
927
{
908
- Log . Error ( "AlchemyLanguage" , "PublicationDate by HTML is not supported!" ) ;
909
- return false ;
910
- // service = SERVICE_GET_PUBLICATION_DATE_HTML;
911
- // string htmlData = default(string);
912
- // htmlData = File.ReadAllText(source);
913
- // req.Forms["html"] = new RESTConnector.Form(htmlData);
928
+ service = SERVICE_GET_PUBLICATION_DATE_HTML ;
929
+ string htmlData = default ( string ) ;
930
+ htmlData = File . ReadAllText ( source ) ;
931
+ req . Forms [ "html" ] = new RESTConnector . Form ( htmlData ) ;
914
932
}
915
933
else
916
934
{
0 commit comments