Ejemplo n.º 1
0
		/// <summary>
		/// Initializes a new client with the specified credentials.
		/// </summary>
		/// <param name="accountSid">The AccountSid to authenticate with</param>
		/// <param name="authToken">The AuthToken to authenticate with</param>
		public TwilioRestClient(string accountSid, string authToken)
		{
			ApiVersion = "2010-04-01"; 
			BaseUrl = "https://api.twilio.com/";
			AccountSid = accountSid;
			AuthToken = authToken;

			// silverlight friendly way to get current version
			//var assembly = Assembly.GetExecutingAssembly();
			//AssemblyName assemblyName = new AssemblyName(assembly.FullName);
			//var version = assemblyName.Version;

            var asmName = this.GetType().AssemblyQualifiedName;
            var versionExpression = new System.Text.RegularExpressions.Regex("Version=(?<version>[0-9.]*)");
            var m = versionExpression.Match(asmName);
            string version = String.Empty;
            if (m.Success)
            {
                version = m.Groups["version"].Value;
            }

			_client = new RestClient();
			_client.UserAgent = "twilio-csharp/" + version; 
			_client.Authenticator = new HttpBasicAuthenticator(AccountSid, AuthToken);
			_client.BaseUrl = string.Format("{0}{1}", BaseUrl, ApiVersion);

			// if acting on a subaccount, use request.AddUrlSegment("AccountSid", "value")
			// to override for that request.
			_client.AddDefaultUrlSegment("AccountSid", AccountSid); 
		}
Ejemplo n.º 2
0
 private void AuthenticateIfNeeded(RestClient client, IRestRequest request)
 {
     if (Authenticator != null)
     {
         Authenticator.Authenticate(client, request);
     }
 }