This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
forked from btb/uw-restclients
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'aca/master' into develop
- Loading branch information
Showing
14 changed files
with
372 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Contains UW Libraries Currics DAO implementations. | ||
""" | ||
|
||
from django.conf import settings | ||
from restclients.dao_implementation.live import get_con_pool, get_live_url | ||
from restclients.dao_implementation.mock import get_mockdata_url,\ | ||
post_mockdata_url, delete_mockdata_url, put_mockdata_url | ||
from restclients.mock_http import MockHTTP | ||
import re | ||
|
||
|
||
class File(object): | ||
""" | ||
The File DAO implementation returns generally static content. Use this | ||
DAO with this configuration: | ||
RESTCLIENTS_LIBCURRICS_DAO_CLASS = | ||
'restclients.dao_implementation.libraries.File' | ||
""" | ||
def getURL(self, url, headers): | ||
return get_mockdata_url("libcurrics", "file", url, headers) | ||
|
||
|
||
LIB_MAX_POOL_SIZE = 10 | ||
LIB_SOCKET_TIMEOUT = 15 | ||
|
||
|
||
class Live(object): | ||
""" | ||
This DAO provides real data. It requires further configuration, e.g. | ||
RESTCLIENTS_LIBCURRICS_HOST = '...' | ||
""" | ||
pool = None | ||
|
||
def getURL(self, url, headers): | ||
if Live.pool is None: | ||
Live.pool = get_con_pool( | ||
settings.RESTCLIENTS_LIBCURRICS_HOST, | ||
max_pool_size=LIB_MAX_POOL_SIZE) | ||
|
||
return get_live_url(Live.pool, | ||
'GET', | ||
settings.RESTCLIENTS_LIBCURRICS_HOST, | ||
url, | ||
headers=headers, | ||
service_name='libcurrics') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +0,0 @@ | ||
""" | ||
This is the interface for interacting with the UW Libraries Web Service. | ||
""" | ||
|
||
import logging | ||
from restclients.dao import Libraries_DAO | ||
from restclients.exceptions import DataFailureException | ||
from restclients.util.timer import Timer | ||
from restclients.util.log import log_info | ||
|
||
|
||
INVALID_USER_MSG = "User not found" | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_resource(url): | ||
dao = Libraries_DAO() | ||
timer = Timer() | ||
response = dao.getURL(url, {}) | ||
log_info(logger, | ||
"%s ==status==> %s" % (url, response.status), | ||
timer) | ||
|
||
if response.status != 200: | ||
raise DataFailureException(url, response.status, response.data) | ||
|
||
#'Bug' with lib API causing requests with no/invalid user to return a 200 | ||
if INVALID_USER_MSG in response.data: | ||
raise DataFailureException(url, 404, response.data) | ||
|
||
logger.debug("%s ==data==> %s" % (url, response.data)) | ||
|
||
return response.data | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
This is the interface for interacting with the UW Libraries Currics | ||
Web Service. | ||
""" | ||
|
||
import json | ||
from urllib import quote | ||
from restclients.dao import LibCurrics_DAO | ||
from restclients.exceptions import DataFailureException | ||
from restclients.models.library import SubjectGuide, Library, Librarian | ||
|
||
|
||
subject_guide_url_prefix = '/currics_db/api/v1/data/course' | ||
|
||
|
||
def get_subject_guide_for_section_params(year, quarter, curriculum_abbr, | ||
course_number, section_id=None): | ||
""" | ||
Returns a SubjectGuide model for the passed section params: | ||
year: year for the section term (4-digits) | ||
quarter: quarter (AUT, WIN, SPR, or SUM) | ||
curriculum_abbr: curriculum abbreviation | ||
course_number: course number | ||
section_id: course section identifier (optional) | ||
""" | ||
url = '%s/%s/%s/%s/%s/%s' % ( | ||
subject_guide_url_prefix, year, quarter.upper(), | ||
quote(curriculum_abbr.upper()), course_number, section_id.upper()) | ||
headers = {'Accept': 'application/json'} | ||
|
||
response = LibCurrics_DAO().getURL(url, headers) | ||
|
||
if response.status != 200: | ||
raise DataFailureException(url, response.status, response.data) | ||
|
||
data = json.loads(response.data) | ||
return _subject_guide_from_json(data['subjectGuide']) | ||
|
||
|
||
def get_subject_guide_for_section(section): | ||
""" | ||
Returns a SubjectGuide model for the passed SWS section model. | ||
""" | ||
return get_subject_guide_for_section_params( | ||
section.year, section.quarter[:3], section.curriculum_abbr, | ||
section.course_number, section.section_id) | ||
|
||
|
||
def get_subject_guide_for_canvas_course_sis_id(course_sis_id): | ||
""" | ||
Returns a SubjectGuide model for the passed Canvas course SIS ID. | ||
""" | ||
(year, quarter, curriculum_abbr, course_number, | ||
section_id) = course_sis_id.split('-', 4) | ||
return get_subject_guide_for_section_params( | ||
year, quarter[:3], curriculum_abbr, course_number, section_id) | ||
|
||
|
||
def _subject_guide_from_json(data): | ||
subject_guide = SubjectGuide() | ||
subject_guide.contact_url = data.get('askUsLink', None) | ||
subject_guide.contact_text = data.get('askUsText', None) | ||
subject_guide.discipline = data.get('discipline', None) | ||
subject_guide.librarian_url = data.get('findLibrarianLink', None) | ||
subject_guide.librarian_text = data.get('findLibrarianText', None) | ||
subject_guide.guide_url = data.get('guideLink', None) | ||
subject_guide.guide_text = data.get('guideText', None) | ||
subject_guide.faq_url = data.get('howDoILink', None) | ||
subject_guide.faq_text = data.get('howDoIText', None) | ||
subject_guide.writing_guide_url = data.get('writingGuideLink', None) | ||
subject_guide.writing_guide_text = data.get('writingGuideText', None) | ||
subject_guide.libraries = [] | ||
subject_guide.librarians = [] | ||
|
||
for libdata in data.get('libraries', []): | ||
library = Library() | ||
library.name = libdata.get('name', None) | ||
library.description = libdata.get('description', None) | ||
library.url = libdata.get('url', None) | ||
subject_guide.libraries.append(library) | ||
|
||
for libdata in data.get('librarians', []): | ||
librarian = Librarian() | ||
librarian.name = libdata.get('name', None) | ||
librarian.email = libdata.get('email', None) | ||
librarian.phone = libdata.get('telephone', None) | ||
librarian.url = libdata.get('url', None) | ||
subject_guide.librarians.append(librarian) | ||
|
||
return subject_guide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
restclients/resources/libcurrics/file/currics_db/api/v1/data/course/2015/AUT/MATH/309/A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"subjectGuide": { | ||
"askUsLink": "http://www.lib.washington.edu/about/contact", | ||
"askUsText": "UW librarians are also available to help answer your general questions by email, phone, text, or 24/7 real-time chat.", | ||
"discipline": "Mathematics", | ||
"findLibrarianLink": "http://guides.lib.uw.edu/research/subject-librarians", | ||
"findLibrarianText": "At UW Libraries, there's a dedicated librarian for Mathematics who can help you with your research needs. Get in touch with them by phone or email.", | ||
"guideLink": "http://guides.lib.uw.edu/friendly.php?s=research/math", | ||
"guideText": "Mathematics, Pure and Applied", | ||
"howDoILink": "http://guides.lib.uw.edu/research/faq", | ||
"howDoIText": "This online guide addresses common research and library tasks with short video tutorials and links to other UW help guides.", | ||
"librarians": [ | ||
{ | ||
"email": "javerage@uw.edu", | ||
"name": "J Average", | ||
"telephone": "111-111-1111", | ||
"url": "http://guides.lib.washington.edu/Javerage" | ||
}, | ||
{ | ||
"email": "baverage@uw.edu", | ||
"name": "B Average", | ||
"telephone": "111-111-1112", | ||
"url": "http://guides.lib.washington.edu/Baverage" | ||
} | ||
], | ||
"libraries": [ | ||
{ | ||
"description": "The Mathematics Research Library provides research help and access to materials in Applied Mathematics, Mathematics, and Statistics.", | ||
"name": "Mathematics Research Library", | ||
"url": "http://www.lib.washington.edu/math" | ||
} | ||
], | ||
"writingGuideLink": "http://guides.lib.uw.edu/research/citations", | ||
"writingGuideText": "Find citation style guides, citation management tools, and writing/grammar help." | ||
} | ||
} |
Oops, something went wrong.