Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 9c16a68

Browse files
nuhamozainiecleel
authored andcommitted
Install requirements update + __str__ returns obj as json (#7)
* renamed constructor.py to helpers.py to add new class for __str__ * Implemented __str__ for Resource and Source
1 parent 434fe1c commit 9c16a68

9 files changed

Lines changed: 33 additions & 16 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See the `Python API docs. <https://moyasar.com/docs/api/?python>`_
1717
Requirements
1818
-------------
1919

20-
* Python +2.7 or +3.x
20+
* Python +3.x
2121

2222
--------------
2323
Installation

moyasar/actions/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moyasar
22
import json
3-
from moyasar.constructor import Constructor
3+
from moyasar.helpers import Constructor
44

55

66
class Create(Constructor):

moyasar/actions/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moyasar
22
import json
3-
from moyasar.constructor import Constructor
3+
from moyasar.helpers import Constructor
44

55

66
class Fetch(Constructor):

moyasar/actions/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moyasar
22
import json
3-
from moyasar.constructor import Constructor
3+
from moyasar.helpers import Constructor
44

55

66
class List(Constructor):

moyasar/constructor.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

moyasar/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import json
2+
3+
4+
class Constructor:
5+
def __init__(self, data):
6+
for key in data:
7+
setattr(self, key, data[key])
8+
9+
10+
class Format:
11+
def __str__(self):
12+
dict = self.__dict__
13+
for key in dict:
14+
if isinstance(dict[key], Format):
15+
dict[key] = dict[key].__dict__
16+
return json.dumps(self.__dict__)

moyasar/invoice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from moyasar.actions.create import Create
22
from moyasar.resource import Resource
33
from moyasar.actions.cancel import Cancel
4+
from moyasar.helpers import Format
45

56

6-
class Invoice(Resource, Cancel, Create):
7+
class Invoice(Resource, Cancel, Create, Format):
78
pass

moyasar/payment.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import json
2+
13
from moyasar.resource import Resource
24
from moyasar.actions.refund import Refund
3-
from moyasar.constructor import Constructor
5+
from moyasar.helpers import Constructor
6+
from moyasar.helpers import Format
47

58

6-
class Source(Constructor):
7-
def __init__(self, data):
8-
super().__init__(data)
9+
class Source(Constructor, Format):
910

1011
@classmethod
1112
def build(cls, source):
@@ -27,14 +28,16 @@ def source_to_sadad(cls, data):
2728

2829

2930
class CreditCard(Source):
30-
pass
31+
def __str__(self):
32+
return json.dumps(self.__dict__)
3133

3234

3335
class Sadad(Source):
3436
pass
3537

3638

37-
class Payment(Resource, Refund):
39+
class Payment(Resource, Refund, Format):
40+
3841
def __init__(self, data):
3942
super().__init__(data)
4043
self.source = Source.build(self.source)

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
],
2020
install_requires=[
2121
'requests',
22+
],
23+
tests_require=[
2224
'httpretty',
2325
'pytest'
2426
],

0 commit comments

Comments
 (0)