How peranetwork/viewstats-api works
Project type and purpose
• This is a language‐library (PHP) that provides a wrapper around an external REST API (ViewStats).
• Its purpose is to simplify authentication, request/response handling, decryption, and logging for consumers of the ViewStats service.
File structure
• Top‐level files: composer.json/lock (dependency config), README.md, .gitignore
• public/index.php – a minimal example / entrypoint (not part of core library)
• src/
– Exceptions/ (APIException, DecryptionException)
– Logger.php (log writer)
– ViewStatsAPI.php (main façade)
README for insights
• Core components mentioned: authentication, GET/POST methods, error handling, decryption (AES-256-GCM), logging (debug.log).
• External dependency: cURL + OpenSSL, external ViewStats REST endpoints.
Main components & interactions
a. Consumer Application
– Any PHP app that invokes the ViewStatsAPI class via Composer autoload.
b. ViewStats API Wrapper
– ViewStatsAPI façade
• Builds HTTP requests (method, path, headers with API token)
• Calls the HTTP Client (cURL)
• Feeds response to the DecryptionHandler
• Throws Exceptions on HTTP or decryption errors
– DecryptionHandler (inside ViewStatsAPI or helper)
– Error Handling (Exceptions under src/Exceptions)
– Logger (writes info, errors to debug.log)
c. External ViewStats REST API
– HTTPS endpoints for channels, stats, rankings, etc.
d. Filesystem
– debug.log in project root
Architectural patterns & design principles
• Façade pattern: ViewStatsAPI hides low‐level HTTP, auth, decryption.
• Single Responsibility:
– Logger only writes logs
– Exceptions only represent errors
– ViewStatsAPI orchestrates calls
• Dependency inversion: consumers depend on the high‐level API, not on cURL directly.