Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vrachieru committed May 1, 2017
0 parents commit ba1c3cf
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
Empty file added docs/.gitkeep
Empty file.
22 changes: 22 additions & 0 deletions example/account-info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
sys.path.append('../')

from rds import RDS

rds = RDS('username', 'password')
client = rds.get_client_info()
client = client['data']['items']

print 'Client id: %s' % client['clientId']
print 'Type: %s\n' % client['type']

print 'Name: %s' % client['name']
print 'BI: %s' % client['bi']
print 'CNP: %s' % client['cnp']
print 'Address: %s, %s, %s' % (client['address'], client['city'], client['state'])
print 'Email: %s\n' % client['email']

print 'Blacklisted: %s' % client['isBlacklisted']
print 'Suspended: %s' % client['isSuspended']
print 'Direct debit: %s' % (client['hasDirectDebit'] != '0')
print 'Email invoice: %s' % (client['hasEmailInvoice'] != 0)
25 changes: 25 additions & 0 deletions example/invoices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
sys.path.append('../')

from rds import RDS
from datetime import datetime

rds = RDS('username', 'password')
invoices = rds.get_invoices()
invoices = invoices['data']['items']

for invoice in invoices:
try:
if invoices[invoice]['type'] != 'Invoice':
continue
except:
continue

invoice = invoices[invoice]['items']

print 'Id: %s' % invoice['id']
print 'Number: %s' % invoice['number']
print 'Value: %s RON' % invoice['value']
print 'Scadent: %s' % datetime.fromtimestamp(float(invoice['scadent']['$id'][5:])).strftime('%d.%m.%Y')
print 'Status: %s' % invoice['status']
print 'Comments: %s\n' % invoice['comments']
1 change: 1 addition & 0 deletions rds/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from api import RDS
114 changes: 114 additions & 0 deletions rds/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import requests

class RDS():
BASE_URL = 'https://digicare.rcs-rds.ro',
HEADERS = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'digicare.rcs-rds.ro',
'Origin': 'https://digicare.rcs-rds.ro',
'Referer': 'https://digicare.rcs-rds.ro/'
}

def __init__(self, username, password):
self.config = dict()
self.config['username'] = username
self.config['password'] = password

self.session = requests.Session()
self.login()

def login(self):
'''
Authenticates user with username and password.
'''
payload = {
'do': 'call-static',
'instance': 'Client',
'args': '["%s", "%s"]' % (self.config['username'], self.config['password']),
'method': 'login',
'v': 198
}
return self.rpc(payload)

def get_news(self):
'''
Gets the lates news related to RCS&RDS activity.
'''
return self.rpc_load('/news')

def get_client_info(self):
'''
Gets client info, such as client name, type and address.
'''
return self.rpc_load('/info')

def get_account_info(self):
'''
Gets account info, such account number, email, last authentication and creation dates.
'''
return self.rpc_load('/info/account')

def get_locations(self):
'''
Gets a list of client locations.
'''
return self.rpc_load('/locations')

def get_location(self, locationId):
'''
Gets location details by location id.
'''
return self.rpc_load('Location:%s' % locationId)

def get_install_addresses(self):
'''
Gets a list of addresses where the client has services installed.
'''
return self.rpc_load('/locations/installAddresses')

def get_installed_services_at_address(self, addressId):
'''
Gets a list of services installed at a speciffic address.
'''
return self.rpc_load('Location_Address_Service:%s' % addressId)

def get_services(self):
'''
Gets a list of installed services.
'''
return self.rpc_load('/services')

def get_invoices(self):
'''
Gets a list of invoices.
'''
return self.rpc_load('/invoices')

def download_invoice(self, invoiceId):
'''
Downloads an invoice by id.
'''
return self.session.get('%s/xhr-download-invoice.php' % self.BASE_URL, headers=self.HEADERS, data={'id': invoiceId})

def rpc_load(self, id):
'''
Makes a RCP load request for the specified resource.
'''
payload = {
'do': 'load',
'id': id,
'v': 256
}
return self.rpc(payload)

def rpc(self, payload):
'''
Makes a RPC request with the specified payload.
'''
response = self.session.post('%s/rpc.php' % self.BASE_URL, headers=self.HEADERS, data=payload)
return response.json()
Empty file added test/.gitkeep
Empty file.

0 comments on commit ba1c3cf

Please sign in to comment.