PageRenderTime 65ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/WP7UserVoice/UVLib/UserVoiceAPI.cs

#
C# | 96 lines | 82 code | 13 blank | 1 comment | 3 complexity | 8a2f75b4a2a69238d17020008e454b8a MD5 | raw file
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Xml.Linq;
  8. using System.Diagnostics;
  9. using RedBit.UserVoice.OAuth;
  10. using Hammock.Authentication.OAuth;
  11. using Hammock;
  12. using Newtonsoft.Json;
  13. using Newtonsoft.Json.Linq;
  14. using Hammock.Web;
  15. using Hammock.Streaming;
  16. using System.IO.IsolatedStorage;
  17. using RedBit.UserVoice.Services;
  18. namespace RedBit.UserVoice
  19. {
  20. public class UserVoiceAPI
  21. {
  22. public static UserVoiceAPI Default = new UserVoiceAPI();
  23. //TODO: double check performance here and possibly change to seperate file and binary serialization
  24. private static IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
  25. internal static string Key { get; set; }
  26. internal static string Secret { get; set; }
  27. internal static string AppName { get; set; }
  28. private static RequestToken m_accessToken = null;
  29. public static RequestToken AccessToken
  30. {
  31. get { return m_accessToken; }
  32. set
  33. {
  34. m_accessToken = value;
  35. if (m_accessToken == null)
  36. {
  37. appSettings.Remove("access_token");
  38. appSettings.Remove("access_secret");
  39. }
  40. else
  41. {
  42. appSettings["access_token"] = m_accessToken.Key;
  43. appSettings["access_secret"] = m_accessToken.Secret;
  44. }
  45. appSettings.Save();
  46. }
  47. }
  48. private UserVoiceAPI()
  49. {
  50. }
  51. private OAuthCredentials BuildCredentials()
  52. {
  53. var credentials = new OAuthCredentials
  54. {
  55. Type = OAuthType.ProtectedResource,
  56. SignatureMethod = OAuthSignatureMethod.HmacSha1,
  57. ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
  58. ConsumerKey = Key,
  59. ConsumerSecret = Secret,
  60. };
  61. return credentials;
  62. }
  63. public static void Initalize(string key, string secret, string appName)
  64. {
  65. Key = key;
  66. Secret = secret;
  67. AppName = appName;
  68. checkForAccessToken();
  69. }
  70. private static void checkForAccessToken()
  71. {
  72. if (appSettings.Contains("access_token"))
  73. {
  74. var rt = new RequestToken
  75. {
  76. Key = appSettings["access_token"].ToString(),
  77. Secret = appSettings["access_secret"].ToString()
  78. };
  79. AccessToken = rt;
  80. }
  81. }
  82. }
  83. }