diff --git a/README.rst b/README.rst index 94be8b8..28f5b41 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ Post example:: from services.models import Service - service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": ""'}, parameters= '{"query_param": ""}') + service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": ""}', parameters= '{"query_param": ""}') get_data = {'': 'example_data'} header_data = {'': 'application/json'} service_response = service_example.request(get_data=get_data, header_data=header_data) @@ -36,7 +36,7 @@ Or simpler:: from services.models import Service # This headers will be use for every request to this service - service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"'}) + service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"}') # parameters will be put directly to the body of the post request to the service parameters = {'query_param': 'example_data'} service_response = service_example.request(parameters=parameters) @@ -70,7 +70,7 @@ If you want to publish information to some service but you don't want to wait yo from services.models import Service - service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"'}) + service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"}') parameters = {'query_param': 'example_data'} # max_retry is the amount of retries do you want to execute the request while the answer is a error (0 if you want to retry "forever"). # retry_interval is the amount of seconds you want to wait between retries. diff --git a/services/migrations/0002_service_verify.py b/services/migrations/0002_service_verify.py new file mode 100644 index 0000000..ee2afcc --- /dev/null +++ b/services/migrations/0002_service_verify.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.4 on 2018-12-13 10:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('services', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='service', + name='verify', + field=models.BooleanField(default=True), + ), + ] diff --git a/services/models.py b/services/models.py index 6925fee..c6917ee 100755 --- a/services/models.py +++ b/services/models.py @@ -19,6 +19,7 @@ class Service(models.Model): url = models.URLField(max_length=200, default='') method = models.CharField(max_length=20, choices=METHOD_CHOICES, default='get') timeout = models.IntegerField(blank=True, null=True, default=None) + verify = models.BooleanField(default=True) headers = models.TextField(blank=True, default='') parameters = models.TextField(blank=True, default='') service_failover = models.ManyToManyField("self", through='ServiceFailover', symmetrical=False, @@ -125,16 +126,16 @@ def get_from_service(self, url, headers, data): timeout = 10 try: if self.method == 'post': - result = requests.post(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=False) + result = requests.post(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=self.verify) elif self.method == 'get': data = urllib.parse.urlencode(data) if data: url = url + '?' + data - result = requests.get(url, headers=headers, timeout=timeout, verify=False) + result = requests.get(url, headers=headers, timeout=timeout, verify=self.verify) elif self.method == 'patch': - result = requests.patch(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=False) + result = requests.patch(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=self.verify) elif self.method == 'put': - result = requests.put(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=False) + result = requests.put(url, data=json.dumps(data), headers=headers, timeout=timeout, verify=self.verify) try: response = result.json() except: diff --git a/setup.py b/setup.py index eb4d56f..dbbd7b6 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='django-easy-services', - version='0.1', + version='0.2', packages=find_packages(), include_package_data=True, install_requires=['Django>=1.8', 'requests>=2.20.0', 'asyncio>=3.4.3'],