-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
319 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Sherlock API | ||
* | ||
* @Author : Mayank Sindwani | ||
* @Date : 2017-10-21 | ||
* | ||
* Description : Defines a set of api functions. | ||
**/ | ||
|
||
import SherlockUtils from './util'; | ||
import axios from 'axios'; | ||
|
||
class SherlockAPI { | ||
|
||
/** | ||
* Fetch Files | ||
* | ||
* Description: Fetches files from the director in the path provided. | ||
* @param {path} // An arary of strings representing the path to a directory. | ||
* @param {success} // The success callback. | ||
* @param {failure} // The failure callback. | ||
*/ | ||
static fetchFiles(path, success, failure) { | ||
let uri; | ||
if (path.length > 0) { | ||
uri = `/api/search/files?path=${JSON.stringify(path)}`; | ||
} else { | ||
uri = '/api/search/files'; | ||
} | ||
axios.get(encodeURI(uri)) | ||
.then(success) | ||
.catch(failure); | ||
} | ||
|
||
/** | ||
* Fetch File | ||
* | ||
* Description: Fetches the contents of a file and returns it as a string. | ||
* @param {path} // An arary of strings representing the path to a file. | ||
* @param {success} // The success callback. | ||
* @param {failure} // The failure callback. | ||
*/ | ||
static fetchFile(path, success, failure) { | ||
const uri = `/api/search/file?path=${JSON.stringify(path)}`; | ||
axios.get(encodeURI(uri), { headers: { 'Accept': 'text/plain' } }) | ||
.then(success) | ||
.catch(failure); | ||
} | ||
|
||
/** | ||
* Search Files | ||
* | ||
* Description: Searches files for the given search string. | ||
* @param {searchText} // The text to search for. | ||
* @param {success} // The success callback. | ||
* @param {failure} // The failure callback. | ||
*/ | ||
static searchFiles(searchText, success, failure) { | ||
const uri = `/api/search/?query=${searchText}`; | ||
axios.get(encodeURI(uri)) | ||
.then(success) | ||
.catch(failure); | ||
} | ||
|
||
} | ||
|
||
export default SherlockAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.