├── .gitignore ├── LICENSE ├── ghasedakpack ├── __init__.py └── ghasedakpack.py ├── readme.md └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ghasedak API 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ghasedakpack/__init__.py: -------------------------------------------------------------------------------- 1 | from .ghasedakpack import Ghasedak 2 | -------------------------------------------------------------------------------- /ghasedakpack/ghasedakpack.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | ghasedak.py 4 | ~~~~~~~~~ 5 | :copyright: (c) 2019 by Ghasedak ICT 6 | :license: MIT, see LICENSE for more details. 7 | """ 8 | import requests 9 | import json 10 | 11 | 12 | class Ghasedak: 13 | """docstring for Ghasedak.""" 14 | 15 | def __init__(self, apikey,baseurl='https://api.ghasedak.me'): 16 | self.baseurl = baseurl 17 | self.apikey = apikey 18 | 19 | # send request to api 20 | def request_api(self, opts): 21 | headers = { 22 | 'Accept': "application/json", 23 | "Content-Type": "application/x-www-form-urlencoded", 24 | 'charset': "utf-8", 25 | 'apikey': self.apikey, 26 | 27 | } 28 | 29 | url = (self.baseurl + '/v2/')+ opts['path'] 30 | data = opts['data'] 31 | 32 | r = requests.post(url, data=data, headers=headers) 33 | 34 | return r 35 | 36 | def status(self, opts): 37 | data = {} 38 | data['path'] = "sms/status?agent=python" 39 | data['data'] = { 40 | 'id': opts['id'], 41 | 'type': opts['type'] 42 | } 43 | 44 | r = self.request_api(data) 45 | 46 | 47 | jr = r.json() 48 | # print(jr["items"]) 49 | 50 | if r.status_code == 200: 51 | return jr["items"] 52 | 53 | return [] 54 | 55 | def send(self, opts): 56 | data = {} 57 | data['path'] = "sms/send/simple?agent=python" 58 | data['data'] = { 59 | 'message': opts['message'], 60 | 'receptor': opts['receptor'], 61 | 'linenumber': opts['linenumber'] if 'linenumber' in opts.keys() else "", 62 | 'senddate': opts['senddate'] if 'senddate' in opts.keys() else "", 63 | 'checkid': opts['checkid'] if 'checkid' in opts.keys() else "" 64 | } 65 | 66 | r = self.request_api(data) 67 | 68 | # # Get status data right after sending 69 | # jdata = json.loads(r.text) 70 | # self.status({str(jdata['items'][0]), '1'}) 71 | 72 | if r.status_code == 200: 73 | return True 74 | 75 | return False 76 | 77 | def bulk1(self, opts): 78 | data = {} 79 | data['path'] = "sms/send/bulk?agent=python" 80 | data['data'] = { 81 | 'message': opts['message'], 82 | 'receptor': opts['receptor'], 83 | 'linenumber': opts['linenumber'] if 'linenumber' in opts.keys() else "", 84 | 'senddate': opts['senddate'] if 'senddate' in opts.keys() else "", 85 | 'checkid': opts['checkid'] if 'checkid' in opts.keys() else "" 86 | } 87 | print(opts['receptor']) 88 | 89 | r = self.request_api(data) 90 | if r.status_code == 200: 91 | return True 92 | 93 | return False 94 | 95 | def bulk2(self, opts): 96 | data = {} 97 | data['path'] = "sms/send/pair?agent=python" 98 | data['data'] = { 99 | 'message': opts['message'], 100 | 'receptor': opts['receptor'], 101 | 'linenumber': opts['linenumber'] if 'linenumber' in opts.keys() else "", 102 | 'senddate': opts['senddate'] if 'senddate' in opts.keys() else "", 103 | 'checkid': opts['checkid'] if 'checkid' in opts.keys() else "" 104 | } 105 | 106 | r = self.request_api(data) 107 | if r.status_code == 200: 108 | return True 109 | 110 | return False 111 | 112 | def pair(self, opts): 113 | data = {} 114 | data['path'] = "sms/send/pair?agent=python" 115 | data['data'] = { 116 | 'message': opts['message'], 117 | 'receptor': opts['receptor'], 118 | 'linenumber': opts['linenumber'] if 'linenumber' in opts.keys() else "", 119 | 'senddate': opts['senddate'] if 'senddate' in opts.keys() else "", 120 | 'checkid': opts['checkid'] if 'checkid' in opts.keys() else "" 121 | } 122 | 123 | r = self.request_api(data) 124 | if r.status_code == 200: 125 | return True 126 | 127 | return False 128 | 129 | def voicecall(self, opts): 130 | data = {} 131 | data['path'] = "voice/send?agent=python" 132 | data['data'] = { 133 | 'message': opts['message'], 134 | 'receptor': opts['receptor'], 135 | 'senddate': opts['senddate'] if 'senddate' in opts.keys() else "" 136 | } 137 | 138 | r = self.request_api(data) 139 | if r.status_code == 200: 140 | return True 141 | 142 | return False 143 | 144 | def verification(self, opts): 145 | data = {} 146 | data['path'] = "verification/send/simple?agent=python" 147 | data['data'] = { 148 | 'receptor': opts['receptor'], 149 | 'type': opts['type'] if 'type' in opts.keys() else "", 150 | 'template': opts['template'], 151 | 'ip': opts['ip'] if 'ip' in opts.keys() else "", 152 | 'param1': opts['param1'], 153 | 'param2': opts['param2'] if 'param2' in opts.keys() else "", 154 | 'param3': opts['param3'] if 'param3' in opts.keys() else "", 155 | 'param4': opts['param4'] if 'param4' in opts.keys() else "", 156 | 'param5': opts['param5'] if 'param5' in opts.keys() else "", 157 | 'param6': opts['param6'] if 'param6' in opts.keys() else "", 158 | 'param7': opts['param7'] if 'param7' in opts.keys() else "", 159 | 'param8': opts['param8'] if 'param8' in opts.keys() else "", 160 | 'param9': opts['param9'] if 'param9' in opts.keys() else "", 161 | 'param10': opts['param10'] if 'param10' in opts.keys() else "" 162 | } 163 | 164 | r = self.request_api(data) 165 | if r.status_code == 200: 166 | return True 167 | 168 | return False 169 | 170 | def check_verification(self, opts): 171 | data = {} 172 | data['path'] = "sms/check/verification?agent=python" 173 | data['data'] = { 174 | 'receptor': opts['receptor'], 175 | 'token': opts['token'], 176 | 'ip': opts['ip'] if 'ip' in opts.keys() else "" 177 | } 178 | 179 | r = self.request_api(data) 180 | if r.status_code == 200: 181 | return True 182 | 183 | return False 184 | 185 | def receive(self, opts): 186 | data = {} 187 | data['path'] = "sms/receive/last?agent=python" 188 | data['data'] = { 189 | 'linenumber': opts['linenumber'], 190 | 'isread': opts['isread'] 191 | } 192 | 193 | r = self.request_api(data) 194 | jr = r.json() 195 | if r.status_code == 200: 196 | return jr["items"] 197 | 198 | return [] 199 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Ghasedak-python 2 | 3 | [Ghasedak sms webservice](https://ghasedak.me) python package. 4 | 5 | ## installation 6 | 7 | You can simply install ghasedak python package with `pip`: 8 | 9 | ```shell 10 | pip install ghasedakpack 11 | ``` 12 | 13 | ## usage 14 | 15 | 16 | ```python 17 | import ghasedakpack 18 | 19 | #create an instance: 20 | sms = ghasedakpack.Ghasedak("Your APIKEY") 21 | 22 | #send a single message to a single number: 23 | sms.send({'message':'hello, world!', 'receptor' : '09xxxxxxxxx', 'linenumber': 'xxxx', 'senddate': '', 'checkid': ''}) 24 | 25 | #send a single message to multiple numbers: 26 | sms.bulk1({'message':'hello, world!', 'receptor' : '09xxxxxxxxx,09xxxxxxxxx,09xxxxxxxxx', 'linenumber': 'xxxx', 'senddate': '', 'checkid': ''}) 27 | 28 | #send multiple massages to multiple numbers: 29 | sms.bulk2({'message':'hello, world!,another massage', 'receptor' : '09xxxxxxxxx,09xxxxxxxxx,09xxxxxxxxx', 'linenumber': 'xxxx', 'senddate': '', 'checkid': ''}) 30 | 31 | #get the status of massages: 32 | print(sms.status({'id': 'messageId', 'type': '1'})) 33 | 34 | #send verification massages: 35 | sms.verification({'receptor': '09xxxxxxxxx','type': '1','template': 'Your Template','param1': '','param2': '','param3': ''}) 36 | ``` 37 | 38 | ## license 39 | 40 | Released under the MIT License. 41 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | # with open("readme.md", "r") as fh: 4 | # long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="ghasedakpack", 8 | version="0.1.13", 9 | author="Ghasedak Group", 10 | author_email="", 11 | description="Ghasedak sms webservice api wrapper for python.", 12 | # long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="http://github.com/ghasedakapi/ghasedak-python", 15 | packages=setuptools.find_packages(), 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "License :: OSI Approved :: MIT License", 19 | "Operating System :: OS Independent", 20 | ], 21 | ) 22 | --------------------------------------------------------------------------------