Skip to content

Commit

Permalink
fixing import errors, setup testing, better response documented
Browse files Browse the repository at this point in the history
  • Loading branch information
TralahM committed May 20, 2020
1 parent 0acd5f6 commit 9736c10
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 34 deletions.
16 changes: 15 additions & 1 deletion greydot/airtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
Example reply :
{
"query": {
"query_result": {
"status": "Success",
"function": "Airtime balance",
"amount": "20.00"
},
"query_status": "DONE",
"query_code": "D0005"
}
}
"""

SAMPLE = """
<?xml version="1.0" encoding="utf-8" ?>
<query>
Expand All @@ -33,5 +48,4 @@
<query_code>D0005</query_code>
</query>
"""
26 changes: 21 additions & 5 deletions greydot/b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
https://greydotapi.me/?par2=1&par1=25911000000&k=abcdefghijklmnopqrst&do=2
Example reply :
{
"query": {
"query_result": {
"status": "Success",
"function": "Wallet transfer",
"amount": "1",
"to": "25911000000"
},
"query_status": "DONE",
"query_code": "D0002"
}
}
"""
from sms import GREYDOT_APP_KEY, API_URL, parse_xml_response
import requests
import urllib.parse

FID = 2
SAMPLE = """
<?xml version="1.0" encoding="utf-8" ?>
<query>
<query_result>
Expand All @@ -26,11 +47,6 @@
<query_code>D0002</query_code>
</query>
"""
from greydot.sms import GREYDOT_APP_KEY, URL, parse_xml_response
import requests
import urllib.parse

FID = 2


def send_money(Amount=0.0, To=""):
Expand Down
11 changes: 11 additions & 0 deletions greydot/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class NoMessageRecipients(Exception):
"""
Raised when Message Recipients are not specified.
"""
pass

class InvalidAmount(Exception):
"""
Raised when an invalid currency amount is specified
"""
pass
53 changes: 53 additions & 0 deletions greydot/responses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"query": {
"query_result": {
"status": "Success",
"function": "Airtime balance",
"amount": "20.00"
},
"query_status": "DONE",
"query_code": "D0005"
}
},
{
"query": {
"query_result": {
"status": "Success",
"function": "Wallet transfer",
"amount": "1",
"to": "25911000000"
},
"query_status": "DONE",
"query_code": "D0002"
}
},
{
"query": {
"query_result": {
"status": "Success",
"function": "SignUp",
"signup_status": "Registered",
"identity": "0123456789",
"password": "9876543210",
"appkey": "abcdefghijklmnopqrst"
},
"query_status": "DONE",
"query_code": "D0017"
}
},
{
"query": {
"query_result": {
"status": [
"Success",
"Send_SMS"
],
"to": "27110000000",
"sms_id": "000"
},
"query_status": "DONE",
"query_code": "D0011"
}
}
]
19 changes: 19 additions & 0 deletions greydot/runtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tests


def run():
print("Testing airtime...")
tests.test_airtime()
print("Testing b2c...")
tests.test_b2c()
print("Testing wallet...")
tests.test_wallet()
print("Testing signup...")
tests.test_signup()
print("Testing sms...")
tests.test_sms()
print("DONE")


if __name__ == "__main__":
run()
31 changes: 25 additions & 6 deletions greydot/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@
https://greydotapi.me/?k=abcdefghijklmnopqrst&do=19&par1=Joe&par2=Black&par3=joe@email.me&par4=0898887744&par5=1234
Example reply :
{
"query": {
"query_result": {
"status": "Success",
"function": "SignUp",
"signup_status": "Registered",
"identity": "0123456789",
"password": "9876543210",
"appkey": "abcdefghijklmnopqrst"
},
"query_status": "DONE",
"query_code": "D0017"
}
}
"""
from sms import GREYDOT_APP_KEY, API_URL, parse_xml_response
import requests
import urllib.parse
from collections import defaultdict

FID = 19
SAMPLE = """
<?xml version="1.0" encoding="utf-8" ?>
<query>
<query_result>
Expand All @@ -35,12 +60,6 @@
<query_code>D0017</query_code>
</query>
"""
from greydot.sms import GREYDOT_APP_KEY, URL, parse_xml_response
import requests
import urllib.parse
from collections import defaultdict

FID = 19


def register(
Expand Down
35 changes: 14 additions & 21 deletions greydot/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,20 @@
Example reply :
<?xml version="1.0" encoding="utf-8" ?>
<query>
<query_result>
<status>Success</status>
<status>Send_SMS</status>
<to>27110000000</to>
<sms_id>000</sms_id>
</query_result>
<query_status>DONE</query_status>
<query_code>D0011</query_code>
</query>
{
"query": {
"query_result": {
"status": [
"Success",
"Send_SMS"
],
"to": "27110000000",
"sms_id": "000"
},
"query_status": "DONE",
"query_code": "D0011"
}
}
"""
import requests
Expand Down
5 changes: 5 additions & 0 deletions greydot/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .test_airtime import test_airtime
from .test_b2c import test_b2c
from .test_wallet import test_wallet
from .test_signup import test_signup
from .test_sms import test_sms
6 changes: 6 additions & 0 deletions greydot/tests/test_airtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sms import parse_xml_response
from airtime import SAMPLE


def test_airtime():
print(parse_xml_response(SAMPLE))
6 changes: 6 additions & 0 deletions greydot/tests/test_b2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sms import parse_xml_response
from b2c import SAMPLE


def test_b2c():
print(parse_xml_response(SAMPLE))
6 changes: 6 additions & 0 deletions greydot/tests/test_signup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sms import parse_xml_response
from signup import SAMPLE


def test_signup():
print(parse_xml_response(SAMPLE))
6 changes: 6 additions & 0 deletions greydot/tests/test_sms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sms import parse_xml_response
from sms import SAMPLE


def test_sms():
print(parse_xml_response(SAMPLE))
6 changes: 6 additions & 0 deletions greydot/tests/test_wallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sms import parse_xml_response
from wallet import SAMPLE


def test_wallet():
print(parse_xml_response(SAMPLE))
21 changes: 21 additions & 0 deletions greydot/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,24 @@
<query_code>D0003</query_code>
"""
SAMPLE = """
<?xml version="1.0" encoding="utf-8" ?>
<query>
<query_result>
<status>Success</status>
<function>Digit balance</function>
<amount>10.00</amount>
</query_result>
<query_status>DONE</query_status>
<query_code>D0003</query_code>
"""
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = greydot-api
version = 0.7
version = 0.8
description = Unofficial Python SDK for GreyDot.me API
long_description = file: README.md
long_description_content_type=text/markdown
Expand Down

0 comments on commit 9736c10

Please sign in to comment.