steltix-search-service-dev

1.1.8 • Public • Published

Installation

install the package

npm install steltix-search-service --save

Add the references

import { SteltixSearchService  } from 'steltix-search-service/Services/steltix-search-service';
import { SelectApi } from 'steltix-search-service/Services/dictionary-api.service';
class test {
    test2() {
        var x = new SteltixSearchService();
        x.DictionaryApiService.selectApi(SelectApi.CollegiateDictionary);

    }
}

SteltixSearchService

This service is made for Steltix to access multiple API's and calls from one central location

this I created as an entry point here you can get access all the services (steltix-search.service.ts)

//imports
import { OwlBotService } from './Services/owl-bot.service';
import { DictionaryApiService, SelectApi } from './Services/dictionary-api.service';
import { SweetSearchSevice } from './Services/sweet-search.service';
import { WolframAlphaService } from './Services/wolfram-alpha.service';
import { WordsApiService } from './Services/words-api.service';


export class SteltixSearchService {
    OwlBotService = new OwlBotService();
    SelectApi = new SelectApi();
    WordsApiService = new WordsApiService();
    DictionaryApiService = new DictionaryApiService();
    SweetSearchSevice = new SweetSearchSevice();
    WolframAlphaService = new WolframAlphaService();
}

usage:

class test{
   testApp() {
        let sss = new SteltixSearchService();
        //DictionaryApiService
        sss.DictionaryApiService.selectApi(SelectApi.CollegiateDictionary);
        sss.DictionaryApiService.getQueryResults("searchTerm")
        //OwlBotService
        sss.OwlBotService.getQueryResults("searchTerm");
        //WordsApiService
        sss.WordsApiService.getQueryResults("searchTerm");
        //SweetSearchSevice
        sss.SweetSearchSevice.getQueryResults("searchTerm");
        //WolframAlphaService
        sss.WolframAlphaService.getQueryResults("searchTerm");
    }
}

Services

Please note all search terms must be URL encoded

DictionaryApiService

This service has multiple api services and auth keys therefore I have made a class to set it

here is where you would set it "dictionary-api.service.ts"

export class SelectApi {
    static CollegiateDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/collegiate/json" };
    static CollegiateThesaurus: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/thesaurus/json" };
    static IntermediateThesaurus: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/ithesaurus/json" };
    static SpanishEnglishDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/spanish/json" };
    static MedicalDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/medical/json" };
    static ElementaryDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/sd2/json" };
    static IntermediateDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/sd3/json" };
    static SchoolDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/sd4/json" };
    static LearnersDictionary: SelectApiModel = { "token": "Your API KEY", "urlExt": "references/learners/json" };
}

once this is set you can use the service please remember to call "DictionaryApiService.selectApi()"

Usage of service:

class test {
    Das = new DictionaryApiService();
    testDictionaryService() {
        this.Das.selectApi(SelectApi.CollegiateDictionary)
        let result = this.Das.getQueryResults("searchTerm");
        result.then((data) => {
            console.log(data);
        });
    }
}

it will return a promise with the data

OwlBotService

this classes api key has to be set in the service

export class OwlBotService extends BaseSearchService {
    constructor() {
        super();
        //TODO: this must be replaced with your token
        this.apiToken = "Your API KEY";
    }
    getQueryResults(searchQuery: string) {
        return Owlbot(this.apiToken).define('owl');
    }
}

usage:

class test {
    Obs = new OwlBotService();
    testOwlBotService() {
        let result = this.Obs.getQueryResults("searchTerm");
        result.then((data) => {
            console.log(data);
        });
    }
}

WordsApiService

this classes api key has to be set in the service

export class WordsApiService extends BaseSearchService {
    constructor() {
        super();
        this.baseUrl = "https://wordsapiv1.p.mashape.com"
        this.queryString = "words";
        this.apiToken = "your api key";
    }

    getQueryResults(searchQuery: string) {
        return this.unirest.get(`${this.baseUrl}/${this.queryString}/${searchQuery}`)
            .header("X-Mashape-Key", this.apiToken)
            .header("Accept", "application/json");
    }
}

usage:

class test {
    Was = new WordsApiService();
    testDictionaryService() {
        let result = this.Was.getQueryResults("searchTerm");
        result.then((data) => {
            console.log(data);
        });
    }
}

WolframAlphaService

this classes api key has to be set in the service

export class WolframAlphaService extends BaseSearchService {
    constructor() {
        super();
        this.baseUrl = "http://api.wolframalpha.com/v2"
        //TODO: change this token
        this.apiToken = "Your api key";
    }
    getQueryResults(searchQuery: string) {
        return this.unirest.get(`${this.baseUrl}/query?appid=${this.apiToken}&input=${searchQuery}?key=${this.apiToken}&includepodid=Result&output=json&format=plaintext`);;
    }
}

usage:

class test {
    Wras = new WolframAlphaService();
    testDictionaryService() {
        let result = this.Wras.getQueryResults("searchTerm");
        result.then((data) => {
            console.log(data);
        });
    }
}

Please Note: The JSON returned in the body is in string format and as such has to be parsed into an object this unfortunately is unavoidable as this is the result from the api

SweetSearchService

This service requires no api key but the result in the promise is html

class test {
    Sss = new SweetSearchSevice();
    testDictionaryService() {
        let result = this.Sss.getQueryResults("searchTerm");
        result.then((data) => {
            console.log(data);
        });
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i steltix-search-service-dev

Weekly Downloads

2

Version

1.1.8

License

none

Unpacked Size

56.5 kB

Total Files

41

Last publish

Collaborators

  • bloodchild