@@ -26,14 +26,14 @@ module Minduca.Freebase {
26
26
27
27
constructor ( private auth ?: IFreebaseRequestAuthenticationOptions ) { }
28
28
29
- public topic ( mId : string , invokeOptions : IFreebaseInvokeOptions , options ?: IFreebaseTopicRequestOptions ) : any {
29
+ public topic ( mId : string , invokeOptions : IFreebaseTopicInvokeOptions , options ?: IFreebaseTopicRequestOptions ) : any {
30
30
if ( ! mId || mId == '' )
31
31
return ;
32
32
33
33
var url : string = this . getTopicUrl ( mId , options ) ;
34
34
this . invoke ( url , invokeOptions ) ;
35
35
}
36
- public search ( options : IFreebaseSearchRequestOptions , invokeOptions : IFreebaseInvokeOptions ) : any {
36
+ public search ( options : IFreebaseSearchRequestOptions , invokeOptions : IFreebaseSearchInvokeOptions ) : any {
37
37
38
38
if ( ! options || ! options . query || options . query == '' )
39
39
return ;
@@ -60,20 +60,7 @@ module Minduca.Freebase {
60
60
} ;
61
61
62
62
$ . ajax ( request )
63
- . done ( function ( data : any , textStatus : string , jqXHR : JQueryXHR ) {
64
-
65
- if ( ! data )
66
- return options . fail ( jqXHR , "error" , "that was weird.. Nothing was returned." ) ;
67
-
68
- if ( data . status == '200 OK' ) {
69
- return options . done ( data , textStatus , jqXHR ) ;
70
- }
71
- else return data . error ?
72
- options . fail ( jqXHR , "error" , "An error occurred. Please see the returned data for more information" , data )
73
- :
74
- options . fail ( jqXHR , "error" , "Unknown behavior." , data ) ;
75
-
76
- } )
63
+ . done ( options . done )
77
64
. fail ( options . fail )
78
65
. always ( options . always ) ;
79
66
}
@@ -84,6 +71,7 @@ module Minduca.Freebase {
84
71
private getSearchUrl ( options : IFreebaseSearchRequestOptions ) : string { return this . buildServiceRequestUrl ( 'search' , options ) ; }
85
72
private getTopicUrl ( mId : string , options ?: IFreebaseTopicRequestOptions ) { return this . buildServiceRequestUrl ( 'topic' , options , mId ) ; }
86
73
private getImageUrl ( mid : string , options ?: IFreebaseImageRequestOptions ) : string { return this . buildServiceRequestUrl ( 'image' , options , mid ) ; }
74
+ private getBaseUrl ( ) : string { return 'https://www.googleapis.com/freebase/v1/' ; }
87
75
88
76
private buildServiceRequestUrl ( serviceRelativePath : string , jsonQS ?: IFreebaseRequestOptionsBase , ...pathsVariables : string [ ] ) : string {
89
77
@@ -104,11 +92,11 @@ module Minduca.Freebase {
104
92
105
93
if ( pathsVariables && pathsVariables . length > 0 ) {
106
94
paths = pathsVariables . join ( "/" ) ;
107
- if ( ( < any > paths . match ( "^/" ) ) = = "/" )
95
+ if ( ( < any > paths . match ( "^/" ) ) ! = "/" )
108
96
paths = "/" + paths ;
109
97
}
110
98
111
- return 'https://www.googleapis.com/freebase/v1/' . concat ( serviceRelativePath , paths , qs ) ;
99
+ return this . getBaseUrl ( ) . concat ( serviceRelativePath , paths , qs ) ;
112
100
}
113
101
}
114
102
@@ -168,10 +156,17 @@ module Minduca.Freebase {
168
156
raw ?: boolean ;
169
157
}
170
158
171
- export interface IFreebaseInvokeOptions {
159
+ export interface IFreebaseSearchInvokeOptions extends IFreebaseInvokeOptions {
172
160
done ( data : IFreebaseSearchResult , textStatus : string , jqXHR : JQueryXHR ) : any ;
161
+ }
162
+ export interface IFreebaseTopicInvokeOptions extends IFreebaseInvokeOptions {
163
+ done ( data : IFreebaseTopicResultProperty , textStatus : string , jqXHR : JQueryXHR ) : any ;
164
+ }
165
+
166
+ export interface IFreebaseInvokeOptions {
167
+ done ( data : any , textStatus : string , jqXHR : JQueryXHR ) : any ;
173
168
fail ? ( jqXHR : JQueryXHR , textStatus : string , errorThrow : string , data ?: any ) : any ;
174
- fail ? ( jqXHR : JQueryXHR , textStatus : string , errorThrow : string , data ?: IFreebaseSearchResultError ) : any ;
169
+ fail ? ( jqXHR : JQueryXHR , textStatus : string , errorThrow : string , data ?: IFreebaseResultError ) : any ;
175
170
always ? ( jqXHR : JQueryXHR , textStatus : string ) : any ;
176
171
async ?: boolean ;
177
172
}
@@ -183,6 +178,7 @@ module Minduca.Freebase {
183
178
cursor : number ;
184
179
cost : number ;
185
180
hits : number ;
181
+ output ?: { [ prop : string ] : any } ;
186
182
}
187
183
188
184
export interface IFreebaseSearchResultItem {
@@ -198,7 +194,7 @@ module Minduca.Freebase {
198
194
output ?: any ;
199
195
}
200
196
201
- export interface IFreebaseSearchResultError {
197
+ export interface IFreebaseResultError {
202
198
error :
203
199
{
204
200
errors : {
0 commit comments