Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9d609d2
replaced data testing loop by a dictionary and a single function
chuckume Jul 23, 2018
9e607a2
complete refactor of data testing, in a separate file
chuckume Jul 24, 2018
0262bab
big refactor of publisher data testing - split to test_data.py file
chuckume Jul 24, 2018
08c256a
added data testing unit test
chuckume Jul 25, 2018
4054615
test_data modif
chuckume Jul 25, 2018
be9ca49
category tree and verification trigger script
chuckume Jul 25, 2018
e734cc6
create and delete category function and all related tests
chuckume Jul 25, 2018
134efaa
nested categories recursivity algorithm
chuckume Jul 27, 2018
56db0b5
bug fixing in tests plus get all function for test tree
chuckume Jul 29, 2018
b77695b
testing of category tree function
chuckume Aug 3, 2018
5e39d69
category tree testing bug fix, model update
chuckume Aug 3, 2018
e7eb17a
small modification to category tree function
chuckume Aug 14, 2018
0e6c454
trigger to prevent same parent same name category
chuckume Aug 14, 2018
da7321c
Replace cateogry model by category_tree
chuckume Aug 14, 2018
4af7339
create category_tree error fix
chuckume Aug 14, 2018
04b47ba
hashing category names in tests
chuckume Aug 14, 2018
4b140e5
modified functions to handle category tree
chuckume Sep 10, 2018
30b4b7b
Complete refactor of test and category to match category tree structure
chuckume Sep 18, 2018
bcf3b09
fix too many users connection error
chuckume Sep 19, 2018
1a42b49
Fix create category too many user error
chuckume Sep 19, 2018
8e3687e
publisher testing format fixing
chuckume Sep 19, 2018
783655e
Get categories and parent endpoint and tests
chuckume Sep 26, 2018
ca4ba28
delete categories and related test
chuckume Sep 27, 2018
7e2b576
Fixed Error handling for Peewee error and test handling
chuckume Oct 15, 2018
09c3135
Updated API documentation
chuckume Oct 15, 2018
ff549aa
Update API description
chuckume Oct 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 143 additions & 75 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# API INFORMATION
s# API INFORMATION

## INTRODUCTION

The api allows data being published to scry.info website.

If the data published has a category and this category requires data testing, the application will check data.

Check "category" below for information about how the data is being tested.


Step 1 : Get JWT Token - https://dev.scry.info:443/scry2/login
Step 2 : Send data to the publisher - https://dev.scry.info:443/meta/publisher



## AUTHENTICATION

Expand Down Expand Up @@ -72,110 +86,164 @@ RESPONSE:



## PUBLISH DATA

## DELETE CATEGORY

To publish data

```
GET https://dev.scry.info:443/meta/getcategories
```
To delete a category

AUTHENTICATION
```
POST https://dev.scry.info:443/meta/delete_categories
```

Headers :
```
"Authorization : JWT JwtToken"
```
AUTHENTICATION

INPUT
Headers :
```
"Authorization : JWT JwtToken"
```
The json must contain the id of the category. Ex:

```
{"Id":32}
```

Multiple file post, enctype="multiparnt/form-data".
If some childs depend on parent, the API will return the following error.
```
{'description': 'DB Error',
'status_code': 401,
'error': '{"message": "Dependent Categories"}'}
)
```

1) The first file should have name "data" and should contain a csv without headers.
2) The second file should be named "listing_info "
## CREATE CATEGORY

Listing info :
- category_name : extracted from "/getcategories" above. Must match exact values.
- price : price of the listing
- filename : name of the file that will be listed on scry.info and downloaded
- keyword : keywords related to the file that can be searched on scry.

To create a category

```
POST https://dev.scry.info:443/meta/categories
```

AUTHENTICATION

Headers :
```
{
"category_name":["Aviation", "Commercial", "Airline"],
"price":1000,
"filename":"Airlines.csv",
"keywords":"Commercial Airlines"
}
"Authorization : JWT JwtToken"
```

INPUT

Posts a json containing the following info

Listing info :
- category_name (String): Name of the category. For a parent category, all child names must unique, but different parent categories can have the same child name
- parent_id (Int, Optional): Category_id of the parent category. Can be left NULL.
- IsStructured (Boolean): If True, means the data is structured and must have metedata.
- Metadata (Json): keywords related to the file that can be searched on scry. Json is a list of objects structured as follow : {"ColumnName" : [{"MasterData":"Value"}]}

Ex.: [
{"Id" : [
{ "DataType": "Int",
"IsUnique" : "True"
"IsPrimaryKey":"True"}
]},
{"UserName" : [
{ "DataType": "String",
"IsUnique" : "True"
"IsPrimaryKey":"True"}
]},
,
{"PhoneNumber" : [
{ "DataType": "Int",
"IsUnique" : "True"
]}
]


- DataType (String) : Define the type of the structure for a column
- IsNull (String) : True if the data can be null. If not value is specified, the default is value is False
- IsUnique (String) : Unique constraint on the column. It Default value is False.
the structure will be checked if it matches the the structure below. "DataType" is compulsory, "IsNull", "IsUnique" are optional

masterMetaData={
"DataType":["String","Int","Float","Date","Datetime","StandardTime"],
"IsNull" : ["True","False"],
"IsUnique":["True","False"],
"IsPrimaryKey":["True","False"]
}

Ex 1 :
```
{
"category_name": "Airline",
"parent_id": null,
"IsStructured": False,
"Metadata": null
}
```

## LISTING QUERY BY KEYWORDS
Ex 2 :
```
{
"category_name": "Airport",
"parent_id": 101,
"IsStructured": True,
"Metadata": [
{"Id" : [
{ "DataType": "Int",
"IsUnique" : "True"
"IsPrimaryKey":"True"}
]},
{"UserName" : [
{ "DataType": "String",
"IsUnique" : "True"
"IsPrimaryKey":"True"}
]},
,
{"PhoneNumber" : [
{ "DataType": "Int",
"IsUnique" : "True"
]}
]
}
```

## PUBLISH DATA

Keywords based listin gsearch function.
The funnction can search by categoryname, keywords provided by publisher or both.
If more than one keyword is provided, a "OR" is applied.
The function tokenizes using postgresql to vector so plural and verb tenses are handled.

Ex. aviation and aviations will be considered as the same.
To publish data

```
GET https://dev.scry.info:443/meta/search_keywords
```
AUTHENTICATION
```
POST https://dev.scry.info:443/meta/publisher
```

AUTHENTICATION

Headers :
```
"Authorization : JWT JwtToken"
```
Headers :
```
"Authorization : JWT JwtToken"
```

INPUT

- keywords : a string of keywords separated by a space
Ex : 'aviation commercial'
- searchtype: a string containining list of string. As of now there are two options
- 'keywords' : the keyword specified on publication
Ex :
```
keywords='schedule airline'
```
- 'searchtype' : area covered in the search. Can be either keywords provided by data publisher, categories name or both.
Ex :
```
searchtype='["keywords","category"]'
searchtype='["keywords"]'
searchtype='["category"]'
```

Multiple file post, enctype="multiparnt/form-data".

-> note : must be lowercase
1) The first file should have name "data" and should contain a csv without headers.
2) The second file should be named "listing_info "

Listing info :
- category_name (String): extracted from "/getcategories" above. Must match exact values.
- price (Int): price of the listing
- filename (String) : name of the file that will be listed on scry.info and downloaded
- keyword (String): keywords related to the file that can be searched on scry. Must be separated by a space.

```
[
{
"categoryId": 51,
"cid": "QmVdfC5kG7nTf69yaHryPVEcLKhxZNHff49UHSL8YBbYYm",
"created_at": "Thu, 14 Jun 2018 16:27:00 GMT",
"id": 16,
"isstructured": true,
"keywords": "Aviation,Commercial Flight, Schedule",
"name": "Schedule.csv",
"owner": {
"account": "0xef97584f1a5f98a51d8f8b68dfb3c165045e508e",
"created_at": "Mon, 28 May 2018 16:55:49 GMT",
"id": 8,
"name": "22",
"password_hash": "pbkdf2:sha256:50000$bf801740b8f08e65$294a006c03083fc08b43bf0d08226d6a2ce91b8cbc5f784dcb7ecf9c756def3e"
},
"price": 5000,
"size": "179831"
"category_name":["Aviation", "Commercial", "Airline"],
"price":1000,
"filename":"Airlines.csv",
"keywords":"Commercial Airlines"
}
]

```
42 changes: 39 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import requests
import json, io, requests
from categories import get_last_category_id


#scry_path='https://dev.scry.info:443/scry2/'
Expand All @@ -24,12 +24,16 @@ class ScryApi(object):
publisher=publisher_url,
categories=publisher_url,
listing_by_categories=publisher_url,
listing=publisher_url
listing=publisher_url,
get_categories=publisher_url,
get_categories_parents=publisher_url,
delete_categories=publisher_url,
)

def _get_url(self, path):
return self.paths[path] + path


def _make_headers(self):
if getattr(self, 'jwt_token', None) is not None:
return {"Authorization": "JWT " + self.jwt_token}
Expand All @@ -46,6 +50,7 @@ def _post(self, path, **payload):
raise ScryApiException(r.status_code, response)
return json.loads(r.text)


def _get(self, path, **payload):
r = requests.get(self._get_url(path), payload, headers=self._make_headers())
if r.status_code >= 400:
Expand Down Expand Up @@ -78,11 +83,42 @@ def publisher(self, data=None, listing_info=None):
f.close()
return res

def publisher2(self, data=None, listing_info=None):
files = {}
if data:
files['data'] = open(self.data_path + data, 'rb')
if listing_info:
f1 = open(self.listing_path + listing_info)
listing_info = json.loads(f1.read())
f1.close()
listing_info['category_id'] = get_last_category_id(listing_info['category_name'])
listing_info = json.dumps(listing_info)

files['listing_info'] = listing_info
try:
res = self._post('publisher', files=files)
finally:
for f in files.values():
try:
f.close()
except:
continue
return res

def search(self, payload):
return self._get('search_keywords', params=payload)

def categories(self, metadata):
return self._post('categories', json=metadata)

def get_categories(self, payload):
return self._post('get_categories', json=payload)

def get_categories_parents(self, payload):
return self._post('get_categories_parents', json=payload)

def delete_categories(self, payload):
return self._post('delete_categories', json=payload)

def listing_by_categories(self, payload):
return self._get('listing_by_categories', params=payload)
Loading