Repository: Sygic/sygic-maps-services-python

Issue:
There is no way to specify NAM / EU regions for geocoding.

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..6410fb5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,11 @@
+language: python
+
+matrix:
+  include:
+    - { python: '3.6', env: TOXENV=py36 }
+
+install:
+  - pip install tox
+
+script:
+  - tox
\ No newline at end of file
diff --git a/README.md b/README.md
index 856e6d1..c6255e4 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Example of using Sygic [Geocoding API](https://www.sygic.com/developers/maps-api
 ### Client initialization
 
 ```python
-import sygicmaps as s 
+import sygicmaps.client as s 
 
 # Create a client with your API key 
 client = s.Client(key='Your API key')
diff --git a/sygicmaps/client.py b/sygicmaps/client.py
index 9e93c78..fe95913 100644
--- a/sygicmaps/client.py
+++ b/sygicmaps/client.py
@@ -6,16 +6,23 @@ import requests
 from sygicmaps.input import Input
 
 
-SERVICES_URL = "https://eu-geocoding.api.sygic.com/v0/api/"
+SERVICES_URL = "https://{}-geocoding.api.sygic.com"
 
-GEOCODE_BATCH_URL_PATH = "batch/geocode"
+GEOCODE_URL_PATH = "/v0/api/geocode"
+GEOCODE_BATCH_URL_PATH = "/v0/api/batch/geocode"
+REVERSE_GEOCODE_URL_PATH = "/v0/api/reversegeocode"
 
 
 class Client(object):
-    def __init__(self, key=None):
+    def __init__(self, key=None, region='eu', custom_url=None):
         if not key:
             raise ValueError("API key is not set.")
 
+        if not custom_url:
+            self.services_url = SERVICES_URL.format(region)
+        else:
+            self.services_url = custom_url
+
         self.session = requests.Session()
         self.key = key
 
@@ -51,7 +58,7 @@ class Client(object):
 
         requests_method = self.session.get
 
-        url = SERVICES_URL + "/geocode"
+        url = self.services_url + GEOCODE_URL_PATH
         response = requests_method(url, params=params)
         body = response.json()
 
@@ -68,7 +75,7 @@ class Client(object):
 
         requests_method = self.session.get
 
-        url = SERVICES_URL + "/reversegeocode"
+        url = self.services_url + REVERSE_GEOCODE_URL_PATH
         response = requests_method(url, params=params)
         body = response.json()
 
@@ -90,7 +97,7 @@ class Client(object):
         post_data = list(json.loads(json_string))
         post_data = list(map(self.__remove_nulls, post_data))
 
-        url = SERVICES_URL + GEOCODE_BATCH_URL_PATH
+        url = self.services_url + GEOCODE_BATCH_URL_PATH
         params = {"key": self.key}
         post_body = json.dumps(post_data)
         r = requests.post(url, data=post_body, params=params, headers={'Content-type': 'application/json'})
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..c8233f7
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,6 @@
+[tox]
+envlist = py36
+
+[testenv]
+deps = -rrequirements_tests.txt
+commands = nosetests
\ No newline at end of file


Test patch:
diff --git a/requirements_tests.txt b/requirements_tests.txt
new file mode 100644
index 0000000..aa5d1ac
--- /dev/null
+++ b/requirements_tests.txt
@@ -0,0 +1,2 @@
+nose
+requests_mock
\ No newline at end of file
diff --git a/test/client_tests.py b/test/client_tests.py
new file mode 100644
index 0000000..86f7ce5
--- /dev/null
+++ b/test/client_tests.py
@@ -0,0 +1,66 @@
+import sygicmaps as c
+import requests_mock
+import unittest as ut
+import json
+
+
+class ClientTests(ut.TestCase):
+    def __get_sample_response_json(self):
+        sample_response_json = """ {
+            "results": [
+                {
+                    "location": {
+                        "country": "Germany",
+                        "city": "Berlin",
+                        "street": "Bernauer Straße",
+                        "house_number": "36",
+                        "zip": "13355",
+                        "admin_level_1": "Berlin"
+                    },
+                    "geometry": {
+                        "lat": 52.53874,
+                        "lon": 13.39849
+                    },
+                    "confidence": 0.25454903381642513,
+                    "distance": 0
+                }
+            ],
+            "status": "OK",
+            "copyright": "© 2018 Sygic a.s."
+        }   """
+        return json.loads(sample_response_json)
+
+
+    @requests_mock.mock()
+    def test_default_call(self, m):
+        response_json = self.__get_sample_response_json()
+
+        print(response_json)
+        response_json_str = json.dumps(response_json)
+        response_results_json_str = json.dumps(response_json['results'])
+
+        m.get('https://eu-geocoding.api.sygic.com/v0/api/geocode', text=response_json_str)
+
+        client = c.Client(key="test-key")
+        result = client.geocode("Zochova 10 Bratislava")
+
+        result_json = json.dumps(result)
+
+        self.assertEqual(response_results_json_str, result_json)
+
+    @requests_mock.mock()
+    def test_region_parameter(self, m):
+        response_json = self.__get_sample_response_json()
+
+        print(response_json)
+        response_json_str = json.dumps(response_json)
+        response_results_json_str = json.dumps(response_json['results'])
+
+        m.get('https://na-geocoding.api.sygic.com/v0/api/geocode', text=response_json_str)
+
+        client = c.Client(key="test-key", region="na")
+        result = client.geocode("Zochova 10 Bratislava")
+
+        result_json = json.dumps(result)
+
+        self.assertEqual(response_results_json_str, result_json)
\ No newline at end of file