Skip to content

Commit e5cb1c8

Browse files
committed
首次提交
1 parent 88dd1ee commit e5cb1c8

File tree

18 files changed

+299
-1
lines changed

18 files changed

+299
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
.idea
56

67
# C extensions
78
*.so

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# python-sdk
1+
[![API Reference](https://img.shields.io/badge/api-reference-blue.svg)]()
2+
[![Build Status](https://img.shields.io/static/v1?label=build&message=passing&color=32CD32)]()
3+
[![Apache V2 License](https://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/linkv-io/python-sdk/blob/master/LICENSE)
4+
5+
# python-sdk
6+
7+
LINKV SDK for the Python programming language.
8+
9+
## Download
10+
```sh
11+
git clone https://github.com/linkv-io/python-sdk
12+
```
13+
14+
## Install
15+
```sh
16+
cd python-sdk
17+
python setup.py build
18+
python setup.py install --record log
19+
```
20+
21+
## Uninstall
22+
```sh
23+
cat log |sudo xargs rm -rf
24+
rm -rf build dist linkv_sdk.egg-info log
25+
```
26+
27+
## Usage
28+
29+
```python
30+
from json import dumps
31+
32+
from linkv_sdk import linkv_sdk
33+
34+
35+
def main():
36+
app_id = 'qOPBZYGqnqgCSJCobhLFRtvvJzeLLzDR'
37+
app_secret = '1EE940FB2E0AB99368DDEF4A7446A17E3418CE9B1721464624A504BBD977A4FC1477F6A1A02B22AF64070A49C32E05B1AC23E47D86BF6C490D637A42735E6DF7589D5644B3DF1BCD489186940ADE4C3D61C6028FCAF90D57FDCA7BA1888DD4B060B2996BCF41087A8CDEE52D775548166FC92B83D88125434597B9394AC3F7C81C9B8A41C0191B0A09AD59F20881A087574C51B0288A1867D8B7EE9CABC97C322F6469E4E19261C7A26527CD65299A564B319F42DB70E016537A5AFAAE896BEE'
38+
39+
if not linkv_sdk.init(app_id, app_secret):
40+
return
41+
42+
print(dumps(obj=linkv_sdk.im().cfg.__dict__, ensure_ascii=False))
43+
print(dumps(obj=linkv_sdk.rtc().cfg.__dict__, ensure_ascii=False))
44+
45+
46+
if __name__ == "__main__":
47+
main()
48+
```
49+
50+
## License
51+
52+
This SDK is distributed under the
53+
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
54+
see LICENSE.txt and NOTICE.txt for more information.

linkv_sdk/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
LINKV SDK for the Python programming language.
3+
"""
4+
5+
__version__ = '0.0.4'
6+
__licence__ = 'Apache-2.0 License'
7+
__doc__ = 'LINKV SDK for the Python programming language.'
8+
__all__ = ['linkv_sdk']

linkv_sdk/__main__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from json import dumps
2+
3+
import linkv_sdk
4+
5+
6+
def main():
7+
app_id = 'qOPBZYGqnqgCSJCobhLFRtvvJzeLLzDR'
8+
app_secret = '1EE940FB2E0AB99368DDEF4A7446A17E3418CE9B1721464624A504BBD977A4FC1477F6A1A02B22AF64070A49C32E05B1AC23E47D86BF6C490D637A42735E6DF7589D5644B3DF1BCD489186940ADE4C3D61C6028FCAF90D57FDCA7BA1888DD4B060B2996BCF41087A8CDEE52D775548166FC92B83D88125434597B9394AC3F7C81C9B8A41C0191B0A09AD59F20881A087574C51B0288A1867D8B7EE9CABC97C322F6469E4E19261C7A26527CD65299A564B319F42DB70E016537A5AFAAE896BEE'
9+
10+
if not linkv_sdk.init(app_id, app_secret):
11+
return
12+
13+
print(dumps(obj=linkv_sdk.im().cfg.__dict__, ensure_ascii=False))
14+
print(dumps(obj=linkv_sdk.rtc().cfg.__dict__, ensure_ascii=False))
15+
16+
17+
if __name__ == "__main__":
18+
main()

linkv_sdk/config/__init__.py

Whitespace-only changes.

linkv_sdk/config/bindings/__init__.py

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from ffi import dlopen_platform_specific, download
2+
from ctypes import c_char_p, c_void_p, cast
3+
4+
VERSION = '0.0.4'
5+
FILE = 'decrypt'
6+
7+
8+
class _Binding:
9+
core = None
10+
11+
def __init__(self):
12+
self.core = dlopen_platform_specific(FILE, '')
13+
14+
def decrypt(self, app_id, app_secret):
15+
self.core.decrypt.argtypes = [c_char_p, c_char_p]
16+
self.core.decrypt.restype = c_void_p
17+
ptr = self.core.decrypt(app_id.encode('utf-8'), app_secret.encode('utf-8'))
18+
app_config = cast(ptr, c_char_p).value
19+
self.core.release.argtypes = c_void_p,
20+
self.core.release.restype = None
21+
self.core.release(ptr)
22+
return app_config
23+
24+
25+
def download_library():
26+
return download(FILE, "", VERSION)
27+
28+
29+
_binding = None
30+
31+
32+
def binding():
33+
global _binding
34+
if _binding:
35+
return _binding
36+
_binding = _Binding()
37+
return _binding

linkv_sdk/config/bindings/ffi.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import platform
2+
import os
3+
from requests import get
4+
from tempfile import gettempdir
5+
from ctypes import CDLL
6+
7+
8+
def _platform_file(name):
9+
ext = ''
10+
11+
if platform.uname()[0] == "Linux":
12+
ext = 'so'
13+
elif platform.uname()[0] == "Darwin":
14+
ext = 'dylib'
15+
elif platform.uname()[0] == "Windows":
16+
ext = 'dll'
17+
18+
return "lib{}.{}".format(name, ext)
19+
20+
21+
def dlopen_platform_specific(name, path):
22+
return CDLL('{}/{}'.format(gettempdir() if path == "" else path, _platform_file(name)))
23+
24+
25+
DownloadURL = 'http://dl.linkv.fun/static/server'
26+
27+
28+
def download(name, path, version):
29+
filepath = '{}/{}'.format(gettempdir() if path == "" else path, _platform_file(name))
30+
if os.path.exists(filepath):
31+
return True
32+
33+
r = get('{}/{}/{}'.format(DownloadURL, version, _platform_file(name)))
34+
35+
if r.status_code != 200:
36+
return False
37+
38+
with open(filepath, 'wb') as f:
39+
f.write(r.content)
40+
41+
r.close()
42+
return True

linkv_sdk/config/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from linkv_sdk.im.config import dict_config as dict_im_config
2+
from linkv_sdk.rtc.config import dict_config as dict_rtc_config
3+
from bindings.binding import download_library, binding
4+
from json import loads
5+
6+
7+
def init(app_id, app_secret):
8+
if not download_library():
9+
return False
10+
json_data = binding().decrypt(app_id, app_secret)
11+
d = loads(json_data)
12+
dict_im_config(d['im'] if 'im' in d.keys() else {})
13+
dict_rtc_config(d['rtc'] if 'rtc' in d.keys() else {})
14+
15+
return True

linkv_sdk/im/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)