Skip to content

Commit

Permalink
Implement API endpoint for addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeshanA committed Jun 10, 2018
1 parent e390f95 commit cf17a52
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homerate/address_api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions homerate/address_api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AddressApiConfig(AppConfig):
name = 'address_api'
3 changes: 3 additions & 0 deletions homerate/address_api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions homerate/address_api/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions homerate/address_api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf.urls import url
from . import views

urlpatterns = [
url(
# Regex to match UK postcodes
r'postcode/(?P<postcode>^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2}))/$',
views.api_request,
name='address_api')
]
13 changes: 13 additions & 0 deletions homerate/address_api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

from django.http import HttpResponse
import requests


# Create your views here.
def api_request(request, postcode):
url = 'https://api.getAddress.io/find/' + postcode
r = requests.get(url, params={
'api-key': os.environ['ADDRESS_IO_API_KEY']
})
return HttpResponse(r.text, content_type='application/json')
1 change: 1 addition & 0 deletions homerate/homerate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
path('admin/', admin.site.urls),
path('reviews/', include('reviews.urls')),
path('account/', include('profiles.urls')),
path('address_api/', include('address_api.urls')),
path('', include('homepage.urls')),
]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ libsass==0.14.5
django-compressor==2.2
django-sass-processor==0.7
Pillow==5.1.0
requests==2.18.4

0 comments on commit cf17a52

Please sign in to comment.