Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) SCIS SearchSee more SCiS Schools Catalogue ExamplesDemonstrates the SCIS (Schools Catalogue Information Service) search API call.
IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Implements the following CURL command: ; curl -i -X GET --url 'https://api.scisdata.com/catalogue/api/search?query=titleSearch%3Adogs%20AND%20publicationYear%3A2015&from=0&size=20&sort=author&order=asc' -H 'Authorization: Basic ****' ; Use the following online tool to generate HTTP code from a CURL command ; Convert a cURL Command to HTTP Source Code ; This causes the "Authorization: Basic ****" to be added to each request. CkHttp::setCkLogin(http, "myLogin") CkHttp::setCkPassword(http, "myPassword") CkHttp::setCkBasicAuth(http, 1) sbQuery.i = CkStringBuilder::ckCreate() If sbQuery.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbQuery,"titleSearch:dogs AND publicationYear:2015") sbUrl.i = CkStringBuilder::ckCreate() If sbUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbUrl,"https://api.scisdata.com/catalogue/api/search?query=") ; If non-usascii chars are included in the search, we don't know if utf-8 or windows-1252 is desired by the server. You'll need to find out.. CkStringBuilder::ckAppend(sbUrl,CkStringBuilder::ckGetEncoded(sbQuery,"url","utf-8")) CkStringBuilder::ckAppend(sbUrl,"&from=0&size=20&sort=author&order=asc") sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetSb(http,CkStringBuilder::ckGetAsString(sbUrl),sbResponseBody) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbQuery) CkStringBuilder::ckDispose(sbUrl) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttp::ckLastStatus(http) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttp::ckLastHeader(http) Debug "Failed." CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbQuery) CkStringBuilder::ckDispose(sbUrl) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "data": { ; "hits": { ; "hits": [ ; { ; "_index": "scisdata2", ; "_type": "bibdatatype", ; "_source": { ; "isbn": [ ; "9781517638160" ; ], ; "languageTermCode": [ ; "eng" ; ], ; "mainAuthor": { ; "namePersonalPrimary": [ ; "Abbott, Eleanor Hallowell." ; ] ; }, ; "title": { ; "titlePrimary": [ ; "Peace on Earth, good-will to dogs" ; ], ; "noteStmOfResponsibility": [ ; "by Eleanor Hallowell Abbott." ; ] ; }, ; "scisType": [ ; "Book" ; ], ; "dateIssuedMarc": 2015, ; "languageTermValue": [ ; "English" ; ], ; "contributor": {}, ; "isbn13": "9781517638160", ; "imageFileName": "9781517638160.jpg", ; "publicationDetails": "United States, Create Space Independent Publishing Platform, 2015", ; "isbn10": "151763816X", ; "id": "1867852" ; }, ; "_id": "1867852", ; "sort": [ ; "abbott, eleanor hallowell." ; ], ; "_score": null ; }, ; { ; "_index": "scisdata2", ; "_type": "bibdatatype", ; "_source": { ; "isbn": [ ; "9781780747910" ; ], ; "languageTermCode": [ ; "eng" ; ], ; "mainAuthor": { ; "namePersonalPrimary": [ ; "Adams, Richard." ; ] ; }, ; "title": { ; "titlePrimary": [ ; "The plague dogs" ; ], ; "noteStmOfResponsibility": [ ; "Richard Adams." ; ] ; }, ; "scisType": [ ; "Book" ; ], ; "dateIssuedMarc": 2015, ; "languageTermValue": [ ; "English" ; ], ; "contributor": {}, ; "isbn13": "9781780747910", ; "imageFileName": "9781780747910.jpg", ; "publicationDetails": "New York, Rock the Boat, 2015", ; "isbn10": "1780747918", ; "id": "1749228" ; }, ; "_id": "1749228", ; "sort": [ ; "adams, richard." ; ], ; "_score": null ; }, ; ... ; ], ; "total": 84, ; "max_score": null ; }, ; "took": 585, ; "timed_out": false ; }, ; "subscriptionStatus": {} ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON v_index.s v_type.s v_sourceDateIssuedMarc.i v_sourceIsbn13.s v_sourceImageFileName.s v_sourcePublicationDetails.s v_sourceIsbn10.s v_sourceId.s v_id.s v_score.s j.i count_j.i strVal.s dataHitsTotal.i = CkJsonObject::ckIntOf(jResp,"data.hits.total") dataHitsMax_score.s = CkJsonObject::ckStringOf(jResp,"data.hits.max_score") dataTook.i = CkJsonObject::ckIntOf(jResp,"data.took") dataTimed_out.i = CkJsonObject::ckBoolOf(jResp,"data.timed_out") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits") While i < count_i CkJsonObject::setCkI(jResp, i) v_index = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._index") v_type = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._type") v_sourceDateIssuedMarc = CkJsonObject::ckIntOf(jResp,"data.hits.hits[i]._source.dateIssuedMarc") v_sourceIsbn13 = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.isbn13") v_sourceImageFileName = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.imageFileName") v_sourcePublicationDetails = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.publicationDetails") v_sourceIsbn10 = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.isbn10") v_sourceId = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.id") v_id = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._id") v_score = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._score") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.isbn") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.isbn[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.languageTermCode") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.languageTermCode[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.mainAuthor.namePersonalPrimary") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.mainAuthor.namePersonalPrimary[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.title.titlePrimary") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.title.titlePrimary[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.title.noteStmOfResponsibility") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.title.noteStmOfResponsibility[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.scisType") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.scisType[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.languageTermValue") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.languageTermValue[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i].sort") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i].sort[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.contributor.namePersonalOther") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.contributor.namePersonalOther[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"data.hits.hits[i]._source.contributor.nameCorporateOther") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"data.hits.hits[i]._source.contributor.nameCorporateOther[j]") j = j + 1 Wend i = i + 1 Wend CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbQuery) CkStringBuilder::ckDispose(sbUrl) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.