Remove unused command, remove unused methods in hep client
This commit is contained in:
parent
ea65118d99
commit
2c771e5a97
|
|
@ -25,10 +25,6 @@ class HepClientNoTokenException(Exception):
|
||||||
|
|
||||||
class HepClient:
|
class HepClient:
|
||||||
URL = settings.HEP_URL
|
URL = settings.HEP_URL
|
||||||
HEADERS = {
|
|
||||||
'accept': 'application/json',
|
|
||||||
'content-type': 'application/json'
|
|
||||||
}
|
|
||||||
|
|
||||||
def _call(self, url, request, token, method='get', data=None):
|
def _call(self, url, request, token, method='get', data=None):
|
||||||
|
|
||||||
|
|
@ -46,7 +42,6 @@ class HepClient:
|
||||||
elif method == 'put':
|
elif method == 'put':
|
||||||
response = requests.put(request_url, data=data)
|
response = requests.put(request_url, data=data)
|
||||||
|
|
||||||
# Todo handle 401 and most important network errors
|
|
||||||
if response.status_code == 401:
|
if response.status_code == 401:
|
||||||
raise HepClientUnauthorizedException(response.status_code, response.json())
|
raise HepClientUnauthorizedException(response.status_code, response.json())
|
||||||
elif response.status_code != 200:
|
elif response.status_code != 200:
|
||||||
|
|
@ -63,13 +58,13 @@ class HepClient:
|
||||||
return response.json()['data']
|
return response.json()['data']
|
||||||
|
|
||||||
def fetch_eorders(self, request=None, token=None):
|
def fetch_eorders(self, request=None, token=None):
|
||||||
|
# self._has_credentials(request, token)
|
||||||
|
# data = {
|
||||||
|
# 'filters[product_type]': 'eLehrmittel',
|
||||||
|
# }
|
||||||
|
# response = self._call('api/partners/users/orders/search', request, token, data=data)
|
||||||
|
# return response.json()['data']
|
||||||
|
|
||||||
# self._has_credentials(request, token)
|
|
||||||
# data = {
|
|
||||||
# 'filters[product_type]': 'eLehrmittel',
|
|
||||||
# }
|
|
||||||
# response = self._call('api/partners/users/orders/search', request, token, data=data)
|
|
||||||
# return response.json()['data']
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -133,9 +128,10 @@ class HepClient:
|
||||||
if request is None and token is None:
|
if request is None and token is None:
|
||||||
raise HepClientNoTokenException
|
raise HepClientNoTokenException
|
||||||
|
|
||||||
def coupon_redeem(self, coupon, customer_id):
|
def redeem_coupon(self, coupon, customer_id, request=None, token=None):
|
||||||
|
self._has_credentials(request, token)
|
||||||
try:
|
try:
|
||||||
response = self._call(f'/rest/deutsch/V1/coupon/{coupon}/customer/{customer_id}', method='put')
|
response = self._call('api/auth/user', request, token)
|
||||||
except HepClientException:
|
except HepClientException:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -145,15 +141,6 @@ class HepClient:
|
||||||
|
|
||||||
return response_data[0]
|
return response_data[0]
|
||||||
|
|
||||||
def myskillbox_product_for_customer(self, admin_token, customer_id):
|
|
||||||
orders = self._customer_orders(admin_token, customer_id)
|
|
||||||
products = self._extract_myskillbox_products(orders)
|
|
||||||
|
|
||||||
if len(products) == 0:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return self._get_relevant_product(products)
|
|
||||||
|
|
||||||
def _extract_myskillbox_products(self, eorders):
|
def _extract_myskillbox_products(self, eorders):
|
||||||
products = []
|
products = []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
from django.conf import settings
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.management import BaseCommand
|
|
||||||
|
|
||||||
from core.hep_client import HepClient
|
|
||||||
from core.models import AdminData
|
|
||||||
from users.models import User, License
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
"Update licenses via cronjob"
|
|
||||||
|
|
||||||
hep_client = HepClient()
|
|
||||||
|
|
||||||
admin_token = AdminData.objects.get_admin_token()
|
|
||||||
hep_users = User.objects.filter(hep_id__isnull=False)
|
|
||||||
|
|
||||||
for hep_user in hep_users:
|
|
||||||
product = hep_client.myskillbox_product_for_customer(admin_token, hep_user.hep_id)
|
|
||||||
|
|
||||||
if product and License.objects.filter(licensee=hep_user, order_id=product['order_id']).count() == 0:
|
|
||||||
license = License.objects.create_license_for_role(hep_user, product['activated'], product['raw'],
|
|
||||||
product['license']['edition'], product['order_id'],
|
|
||||||
product['isbn'])
|
|
||||||
|
|
||||||
if license.is_valid():
|
|
||||||
hep_user.license_expiry_date = license.expire_date
|
|
||||||
hep_user.save()
|
|
||||||
Loading…
Reference in New Issue