rectifyer/script.trakt — pull request #63 by nate1280 (2013-03-11 19:09:15+00:00)
Title: Migrate to a class based traktAPI usage

- Move all traktJsonRequest calls to a traktAPI class.
- Startup notification and scrobler irregardless.
- Test account every call, save state after first successful call.
- Increase urllib2.urlopen timeout to 60 seconds, from 10 seconds. Reason for this, when checking the plugin for MediaPortal, it uses C# Webclient which has a default timeout of 100 seconds.
- Rewrite getData, and verify all error scenarios (used own host to verify).
- Make traktAPI a bit more chatty for debugging.
- Switch back to JSON username/password for authentication (either way works).
- With debug logging, add ability to hide sensitive data from log.
- Setup ability to possibly implement a queue based system for non-important calls.
- Other changes/additions i probably forgot about.

This needs a bit of testing before being merged (if it gets merged), just to make sure I didn't miss any merges, since I merged this in from my debugging folder.

I've been testing this code for the past 9 days (on my live HTPC box), and have gathered some statistics (which are pasted below).

Also, since increasing the timeout to 60 seconds, imo it seems to be a bit more stable, I haven't seen it do any retries. Also, haven't seen any 503 errors, so that part of it hasn't been thoroughly tested (would it be possible to have a test api to emulate a 503 error?)

```
API calls made: 487
Attempt 0: 487
Resposne time: min 355.00 ms, max 37206.00 ms, avg 2000.38 ms
200: 487 (avg 2000.38 ms)
Methods:
Method: account/settings (total 13, avg 1194.85 ms)
Response 200: 13 (avg 1194.85 ms)
Method: account/test (total 13, avg 7642.92 ms)
Response 200: 13 (avg 7642.92 ms)
Method: movie/library (total 1, avg 914.00 ms)
Response 200: 1 (avg 914.00 ms)
Method: movie/scrobble (total 2, avg 1885.00 ms)
Response 200: 2 (avg 1885.00 ms)
Method: movie/seen (total 8, avg 880.00 ms)
Response 200: 8 (avg 880.00 ms)
Method: movie/summary.json (total 2, avg 1687.00 ms)
Response 200: 2 (avg 1687.00 ms)
Method: movie/watching (total 19, avg 2000.11 ms)
Response 200: 19 (avg 2000.11 ms)
Method: rate/movie (total 1, avg 1541.00 ms)
Response 200: 1 (avg 1541.00 ms)
Method: show/cancelwatching (total 1, avg 1216.00 ms)
Response 200: 1 (avg 1216.00 ms)
Method: show/episode/library (total 38, avg 1744.63 ms)
Response 200: 38 (avg 1744.63 ms)
Method: show/episode/seen (total 11, avg 2016.27 ms)
Response 200: 11 (avg 2016.27 ms)
Method: show/scrobble (total 41, avg 2412.32 ms)
Response 200: 41 (avg 2412.32 ms)
Method: show/watching (total 294, avg 1848.51 ms)
Response 200: 294 (avg 1848.51 ms)
Method: user/library/movies/collection.json (total 12, avg 2253.67 ms)
Response 200: 12 (avg 2253.67 ms)
Method: user/library/movies/watched.json (total 11, avg 1295.36 ms)
Response 200: 11 (avg 1295.36 ms)
Method: user/library/shows/collection.json (total 10, avg 1592.00 ms)
Response 200: 10 (avg 1592.00 ms)
Method: user/library/shows/watched.json (total 10, avg 1538.30 ms)
Response 200: 10 (avg 1538.30 ms)
```