Integration¶
Overview¶
This integration integrates with an external service, providing a Python client and utilities for common operations.
Quick Start¶
Initialize Client¶
from htk.lib.glassdoor.utils import Client
# Create client with credentials
client = Client(api_key='your_api_key')
# Or use from settings
client = Client() # Uses HTK_GLASSDOOR_API_KEY from settings
Basic Operation¶
# Get resource
resource = client.get_resource(id='resource_id')
# List resources
resources = client.list_resources(limit=10)
# Create resource
new_resource = client.create_resource(name='My Resource')
Operations¶
Read Operations¶
# Get single resource
resource = client.get(id='123')
# List resources
resources = client.list(limit=10, offset=0)
# Search
results = client.search(query='search term')
# Count
count = client.count()
Write Operations¶
# Create resource
new = client.create(name='test')
# Update resource
updated = client.update(id='123', name='new name')
# Delete resource
client.delete(id='123')
Authentication¶
Configure credentials:
# settings.py
HTK_GLASSDOOR_API_KEY = 'your_api_key'
HTK_GLASSDOOR_API_SECRET = 'your_secret'
HTK_GLASSDOOR_API_URL = 'https://api.service.com'
Response Format¶
API responses are returned as Python dictionaries or objects:
result = client.get(id='123')
print(result['name'])
print(result['created_at'])
Pagination¶
Handle paginated responses:
# Get paginated results
items = client.list(limit=100, offset=0)
# Or use iterator
for item in client.list_all():
process(item)
Caching¶
Cache responses when appropriate:
from django.core.cache import cache
def get_resource(id):
cache_key = f'resource_{id}'
resource = cache.get(cache_key)
if resource is None:
resource = client.get(id=id)
cache.set(cache_key, resource, 3600)
return resource
Configuration¶
Configure in Django settings:
# settings.py
HTK_GLASSDOOR_ENABLED = True
HTK_GLASSDOOR_API_KEY = 'your_key'
HTK_GLASSDOOR_TIMEOUT = 30
HTK_GLASSDOOR_RETRIES = 3
Best Practices¶
- Handle errors - Always handle API errors gracefully
- Respect rate limits - Don't exceed API rate limits
- Cache responses - Cache data when appropriate
- Use retries - Implement exponential backoff
- Validate input - Validate data before sending to API
- Log operations - Log API calls for debugging
- Test with sandbox - Test in sandbox before production