コード例 #1
0
 static HomeController()
 {
     inAutomation = false;
     // Rest client that is used to exercise Particle.io api
     restClient = new RestClient(ParticleApi);
     restClient.AddDefaultUrlSegment("devicename", DeviceName);
     restClient.AddDefaultUrlSegment("accesstoken", DeviceToken);
 }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Core.cs プロジェクト: SebastiaanLubbers/Twilio
        /// <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>
        /// <param name="accountResourceSid"></param>
        public TwilioRestClient(string accountSid, string authToken, string accountResourceSid)
        {
            ApiVersion         = "2010-04-01";
            BaseUrl            = "https://api.twilio.com/";
            AccountSid         = accountSid;
            AuthToken          = authToken;
            AccountResourceSid = accountResourceSid;

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

            _client               = new RestClient();
            _client.UserAgent     = "twilio-csharp/" + version + " (.NET " + Environment.Version.ToString() + ")";
            _client.Authenticator = new HttpBasicAuthenticator(AccountSid, AuthToken);

#if FRAMEWORK
            _client.AddDefaultHeader("Accept-charset", "utf-8");
#endif

            _client.BaseUrl = string.Format("{0}{1}", BaseUrl, ApiVersion);
            _client.Timeout = 30500;

            // if acting on a subaccount, use request.AddUrlSegment("AccountSid", "value")
            // to override for that request.
            _client.AddDefaultUrlSegment("AccountSid", AccountResourceSid);
        }
コード例 #4
0
 public SamsaraApi(string accessToken, string groupId, string endpoint = "https://api.samsara.com/v1/")
 {
     _accessToken = accessToken;
     GroupId      = groupId;
     RestClient   = new RestClient(endpoint);
     RestClient.AddDefaultUrlSegment("access_token", accessToken);
 }
コード例 #5
0
        /// <summary>
        /// Tries to initializes the connection with the gateway.
        /// We need a session token given from the gateway for us to send any commands to it.
        /// </summary>
        /// <returns>True on success, false on failure</returns>
        public bool InitializeConnection()
        {
            bool retVal = false;

            lock (janus_core_lock_obj)
            {
                if (SessionToken == 0)
                {
                    RestRequest request = new RestRequest(Method.POST);
                    request.RequestFormat = DataFormat.Json;
                    dynamic obj = new ExpandoObject();
                    if (api_secret.HasValue())
                    {
                        obj.apisecret = api_secret;
                    }
                    obj.janus       = "create";
                    obj.transaction = GetNewRandomTransaction();
                    request.AddBody(obj);
                    JanusBaseResponse resp = Execute <JanusBaseResponse>(request);
                    if (resp == null || resp.janus != "success")
                    {
                        retVal = false;
                    }
                    else
                    {
                        SessionToken = resp.data.id;
                        _client.AddDefaultUrlSegment("SessionToken", SessionToken.ToString());
                        delay_timeout.Start();
                        retVal = true;
                    }
                }
            }
            return(retVal);
        }
コード例 #6
0
        public TwilioRestClient(string accountSid, string authToken, string accountResourceSid, string apiVersion, string baseUrl)
        {
            ApiVersion         = apiVersion;
            BaseUrl            = baseUrl;
            AccountSid         = accountSid;
            AuthToken          = authToken;
            AccountResourceSid = accountResourceSid;

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

            _client           = new RestClient();
            _client.UserAgent = "twilio-csharp/" + version + " (.NET PCL)";
            _client.AddDefaultHeader("Authorization", Authenticate());

            _client.AddDefaultHeader("Accept-charset", "utf-8");
            _client.BaseUrl = string.Format("{0}{1}", BaseUrl, ApiVersion);
            _client.Timeout = 30500;

            // if acting on a subaccount, use request.AddUrlSegment("AccountSid", "value")
            // to override for that request.
            _client.AddDefaultUrlSegment("AccountSid", AccountResourceSid);
        }
コード例 #7
0
ファイル: Core.cs プロジェクト: edwardt/twilio-csharp
        /// <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)
        {
            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;

            _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);
        }
コード例 #8
0
ファイル: DripClient.cs プロジェクト: ERRLSTAR/drip-dot-net
        protected virtual RestClient CreateRestClient()
        {
            var client = new RestClient(BaseUrl);

            client.AddDefaultHeader("Content-Type", "application/vnd.api+json");
            client.UserAgent = "Drip DotNet v#" + typeof(DripClient).Assembly.GetName().Version.ToString();
            client.AddDefaultUrlSegment("accountId", AccountId);
            client.AddHandler("application/vnd.api+json", new JsonDeserializer());

            if (string.IsNullOrEmpty(AccessToken))
            {
                client.Authenticator = new HttpBasicAuthenticator(ApiKey, string.Empty);
            }
            else
            {
                client.AddDefaultHeader("Authorization", "Bearer #" + AccessToken);
            }

            return(client);
        }
コード例 #9
0
ファイル: MapView.cs プロジェクト: AmandaUrsula/MapWithRoutes
        private void Initialize()
        {
            _MapView                   = new MKMapView();
            _MapView.Frame             = new RectangleF(0, 0, Frame.Width, Frame.Height);
            _MapView.ShowsUserLocation = true;
            _MapView.Delegate          = new MapViewDelegate(this);

            _RouteView       = new UIImageView();
            _RouteView.Frame = new RectangleF(0, 0, _MapView.Frame.Width, _MapView.Frame.Height);
            _RouteView.UserInteractionEnabled = false;

            this.LineColor = UIColor.FromWhiteAlpha(0.2f, 0.5f);

            _Routes = new CLLocation[] { };

            CalculateRoutesAction = CalculateRoutes;

            _Client = new RestClient(@"http://maps.googleapis.com/maps/api/directions/");
            _Client.AddDefaultUrlSegment("sensor", "false");

            _MapView.AddSubview(_RouteView);
            this.AddSubview(_MapView);
        }
コード例 #10
0
        private IRestClient CreateRestClient()
        {
            var client = new RestClient();

            client.BaseUrl = new Uri(configuration.BaseUrl);

            client.AddHandler("application/json", new RestSharpDataContractJsonDeserializer());

            client.AddDefaultParameter("key", configuration.Key, ParameterType.QueryString);
            client.AddDefaultUrlSegment("version", configuration.Version);
            if (configuration.ErrorDetail.HasValue)
            {
                client.AddDefaultUrlSegment("ed", configuration.ErrorDetail.Value.ToString());
            }
            if (configuration.SuppressStatus.HasValue)
            {
                client.AddDefaultUrlSegment("ss", configuration.SuppressStatus.Value.ToString());
            }
            if (!string.IsNullOrEmpty(configuration.OutputFormat))
            {
                client.AddDefaultUrlSegment("o", configuration.OutputFormat);
            }
            if (!string.IsNullOrEmpty(configuration.JsonpCallback))
            {
                client.AddDefaultUrlSegment("jsonp", configuration.JsonpCallback);
            }
            if (!string.IsNullOrEmpty(configuration.JsonStateObject))
            {
                client.AddDefaultUrlSegment("jsonso", configuration.JsonStateObject);
            }
            if (!string.IsNullOrEmpty(configuration.Culture))
            {
                client.AddDefaultUrlSegment("c", configuration.Culture);
            }

            return(client);
        }
コード例 #11
0
 public FixerIo(string apiKey)
 {
     this.apiKey = apiKey;
     httpClient.AddDefaultUrlSegment("access_key", this.apiKey);
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseService"/> class.
 /// </summary>
 /// <param name="authenticationService">Instance of <see cref="AuthenticationService"/>.</param>
 internal BaseService(AuthenticationService authenticationService)
 {
     _authService = authenticationService;
     _restClient  = new RestClient($"{_apiRequestBaseUrl}{{version}}/");
     _restClient.AddDefaultUrlSegment("version", _apiVersion);
 }