Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import ari.client
import swaggerpy.http_client
import urlparse
import urllib.parse

Client = client.Client
Client = ari.client.Client


def connect(base_url, username, password):
Expand All @@ -18,9 +18,10 @@ def connect(base_url, username, password):
:param base_url: Base URL for Asterisk HTTP server (http://localhost:8088/)
:param username: ARI username
:param password: ARI password.
:return:
:return: ARI Client instance
:rtype: ari.client.Client
"""
split = urlparse.urlsplit(base_url)
split = urllib.parse.urlsplit(base_url)
http_client = swaggerpy.http_client.SynchronousHttpClient()
http_client.set_basic_auth(split.hostname, username, password)
return Client(base_url, http_client)
return Client(base_url, http_client)
9 changes: 4 additions & 5 deletions ari/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import json
import logging
import urlparse
import urllib.parse
import swaggerpy.client

from ari.model import *
Expand All @@ -23,7 +23,7 @@ class Client(object):
"""

def __init__(self, base_url, http_client):
url = urlparse.urljoin(base_url, "ari/api-docs/resources.json")
url = urllib.parse.urljoin(base_url, "ari/api-docs/resources.json")

self.swagger = swaggerpy.client.SwaggerClient(
url, http_client=http_client)
Expand Down Expand Up @@ -192,7 +192,7 @@ def extract_objects(event, *args, **kwargs):
# If there's only one field in the schema, just pass that along
if len(obj_fields) == 1:
if obj:
obj = obj.values()[0]
obj = list(obj.values())[0]
else:
obj = None
event_cb(obj, event, *args, **kwargs)
Expand Down Expand Up @@ -295,5 +295,4 @@ def on_sound_event(self, event_type, fn, *args, **kwargs):
:param kwargs: Keyword arguments to pass to fn
"""
return self.on_object_event(event_type, fn, Sound, 'Sound',
*args, **kwargs)

*args, **kwargs)
6 changes: 3 additions & 3 deletions ari/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""Model for mapping ARI Swagger resources and operations into objects.

Expand Down Expand Up @@ -355,7 +355,7 @@ def promote(client, resp, operation_json):

response_class = operation_json['responseClass']
is_list = False
m = re.match('''List\[(.*)\]''', response_class)
m = re.match(r'''List\[(.*)\]''', response_class)
if m:
response_class = m.group(1)
is_list = True
Expand All @@ -380,4 +380,4 @@ def promote(client, resp, operation_json):
'StoredRecording': StoredRecording,
'Mailbox': Mailbox,
'DeviceState': DeviceState,
}
}