public BaseClient(string apiKey)
        {
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentException($"apiKey is required. You passed in {apiKey}");
            }

            ApiKey                   = apiKey;
            RestClient               = new RestClient();
            RestClient.BaseUrl       = new Uri(ApiUrl);
            RestClient.Authenticator = new HttpBasicAuthenticator(ApiKey, "");

            // AddDefaultHeader does not work for user-agent
            var libVersion = typeof(Recurly.Client).Assembly.GetName().Version;

            RestClient.UserAgent = $"Recurly/{libVersion}; .NET";

            Array.ForEach(BinaryTypes, contentType =>
                          RestClient.AddHandler(contentType, () => { return(new Recurly.FileSerializer()); })
                          );
            RestClient.AddHandler("application/json", () => { return(new JsonSerializer()); });

            // These are the default headers to send on every request
            RestClient.AddDefaultHeader("Accept", $"application/vnd.recurly.{ApiVersion}");
            RestClient.AddDefaultHeader("Content-Type", "application/json");
        }
Example #2
0
 public static void AddJsonDeserializer(this IRestClient client, IDeserializer deserializer)
 {
     client.AddHandler("application/json", deserializer);
     client.AddHandler("text/json", deserializer);
     client.AddHandler("text/x-json", deserializer);
     client.AddHandler("text/javascript", deserializer);
 }
Example #3
0
 private void InitializeSerializationHandlers(IRestClient client)
 {
     client.AddHandler("application/json", () => NewtonsoftJsonSerializer.Default);
     client.AddHandler("text/json", () => NewtonsoftJsonSerializer.Default);
     client.AddHandler("text/x-json", () => NewtonsoftJsonSerializer.Default);
     client.AddHandler("text/javascript", () => NewtonsoftJsonSerializer.Default);
     client.AddHandler("*+json", () => NewtonsoftJsonSerializer.Default);
 }
 private void ConfigureClient(string baseUri)
 {
     _defaultClient.AddHandler("application/json", NewtonsoftJsonSerializer.Default);
     _defaultClient.AddHandler("text/json", NewtonsoftJsonSerializer.Default);
     _defaultClient.AddHandler("text/x-json", NewtonsoftJsonSerializer.Default);
     _defaultClient.AddHandler("text/javascript", NewtonsoftJsonSerializer.Default);
     _defaultClient.AddHandler("*+json", NewtonsoftJsonSerializer.Default);
 }
        /// <summary>
        /// Uses the Newtonsoft.Json deserializer as deserializer for IRestClient.
        /// </summary>
        /// <param name="client">The client.</param>
        public static void UseNewtonsoftJsonDeserializer(this IRestClient client)
        {
            var deserializer = NewtonsoftJsonSerializer.Default;

            client.AddHandler("application/json", deserializer);
            client.AddHandler("text/json", deserializer);
            client.AddHandler("text/x-json", deserializer);
            client.AddHandler("text/javascript", deserializer);
            client.AddHandler("*+json", deserializer);
        }
Example #6
0
        public static IRestClient Renew()
        {
            Client = new RestSharp.RestClient(DibaServiceConfiguration.Instance.EndPoint);

            // Override with Newtonsoft JSON Handler
            Client.AddHandler("application/json", () => NewtonsoftJsonSerializer.Default);
            Client.AddHandler("text/json", () => NewtonsoftJsonSerializer.Default);
            Client.AddHandler("text/x-json", () => NewtonsoftJsonSerializer.Default);
            Client.AddHandler("text/javascript", () => NewtonsoftJsonSerializer.Default);
            Client.AddHandler("*+json", () => NewtonsoftJsonSerializer.Default);
            return(Client);
        }
Example #7
0
        public ConsentService(string appId)
        {
            this.appId = appId;
            client     = new RestClient("https://psd2.api.swedbank.com:443");

            var serializer = new RestSharpJsonNetSerializer();

            client.AddHandler("application/json", () => serializer);
            client.AddHandler("text/json", () => serializer);
            client.AddHandler("text/x-json", () => serializer);
            client.AddHandler("text/javascript", () => serializer);
            client.AddHandler("*+json", () => serializer);
        }
Example #8
0
        ///// <summary>
        ///// Create a client.
        ///// Tls 1.2 should be added to acceptable security protocols before instantiation of any httpclient objects.
        ///// <code>ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;</code>
        ///// </summary>
        ///// <param name="client"></param>
        public KrogerClient(IRestClient client)
        {
            _client = client;
            _client.ClearHandlers();

            IDeserializer deserializer = new NewtonsoftJsonSerializer();

            _client.AddHandler(MediaTypeWithQualityHeaderValue.Parse("*/*").MediaType, deserializer);
            _client.AddHandler(MediaTypeWithQualityHeaderValue.Parse("application/json;charset=UFT-8").MediaType, deserializer);
            _client.AddDefaultHeader("Cookie", "_=_;");
            _client.BaseUrl   = BASE_URL;
            _client.UserAgent = "_/_";
        }
 public RequestSender(IRestSerializer serializer, ApplicationProperties properties,
                      IRestClient client, UnAuthorizedHandler unAuthorizedHandler)
 {
     _serializer = serializer;
     _properties = properties;
     _client     = client;
     _client.AddHandler("application/json", () => _serializer);
     _client.AddHandler("text/json", () => _serializer);
     _client.AddHandler("text/x-json", () => _serializer);
     _client.AddHandler("text/javascript", () => _serializer);
     _client.AddHandler("*+json", () => _serializer);
     _unAuthorizedHandler = unAuthorizedHandler;
 }
Example #10
0
        private void RegisterHandlers(IRestClient client)
        {
            var jsonSettings = new JsonSerializerSettings();

            jsonSettings.Converters.Add(new StringEnumConverter());

            var serializer  = JsonSerializer.Create(jsonSettings);
            var jsonHandler = new JsonNetSerializer(serializer);

            client.AddHandler("application/json", jsonHandler);
            client.AddHandler("text/json", jsonHandler);
            client.AddHandler("text/x-json", jsonHandler);
            client.AddHandler("text/javascript", jsonHandler);
            client.AddHandler("*+json", jsonHandler);
        }
Example #11
0
        public OrionClient(string baseUrl, Credentials apiCredentials)
        {
            client = new RestClient(baseUrl);
            client.Authenticator = new OrionAuthenticator(apiCredentials);
            client.ClearHandlers();

            client.AddHandler("application/json", OrionJsonSerializer.Default);
            client.AddHandler("text/json", OrionJsonSerializer.Default);
            client.AddHandler("text/x-json", OrionJsonSerializer.Default);
            client.AddHandler("text/javascript", OrionJsonSerializer.Default);
            client.AddHandler("*+json", OrionJsonSerializer.Default);

            // ICompositionFactory is the only singleton, by design.
            factory = new CompositionFactory(client);
        }
Example #12
0
        private TRestResponse ExecuteRequest <TRestResponse>(
            string url,
            Method method,
            object body,
            IRestClient client,
            IDictionary <string, object> requestParameters,
            Func <IRestRequest, TRestResponse> clientExecute)
            where TRestResponse : IRestResponse
        {
            var request = BuildRestRequest(url, method, body, requestParameters);

            //Fixed bug that prevents RestClient for adding custom headers to the request
            //https://stackoverflow.com/questions/22229393/why-is-restsharp-addheaderaccept-application-json-to-a-list-of-item
            client.ClearHandlers();
            client.AddHandler("application/json", new JsonDeserializer());

            var result = ExecuteRequestWithManualFollowRedirect(request, client, clientExecute);

            if (!result.IsSuccessful)
            {
                throw BuildBitbucketException(result);
            }

            return(result);
        }
 public PacksService(IRestClient client)
 {
     this.client    = client;
     client.BaseUrl = new Uri(ApiServerUrl);
     //This api returns a json in application/octet-stream content type
     client.AddHandler("application/octet-stream", new JsonDeserializer());
 }
Example #14
0
 public CitiesWheatherService()
 {
     restClient = new RestClient(FORECAST_ENDPOINT);
     restClient.AddHandler("application/json", new DynamicJsonDeserializer());
     restClient.AddDefaultQueryParameter("appid", API_KEY);
     restClient.AddDefaultQueryParameter("units", "metric");
 }
Example #15
0
        public ApplicationViewModel()
        {
            RequestFactory = new RestRequestFactory();
            RestClient     = new RestClient("http://164.132.63.49/musicdb/api");
            var jsonSerializer = NewtonsoftJsonSerializer.Default;

            RestClient.AddHandler("application/json", jsonSerializer);
            RestClient.AddHandler("text/json", jsonSerializer);
            RestClient.AddHandler("text/x-json", jsonSerializer);
            RestClient.AddHandler("text/javascript", jsonSerializer);
            RestClient.AddHandler("*+json", jsonSerializer);

            History = new BrowsingHistory(this);
            //dataProvider = new BackendResponseDataProvider();
            //CurrentViewModel = new HomeViewModel(this, dataProvider);
            CurrentViewModel = new LoginViewModel(this, dataProvider);
        }
Example #16
0
 public SwiftRestClient(IRestClient restClient)
 {
     if (restClient == null)
     {
         throw new ArgumentNullException("restClient");
     }
     this.restClient = restClient;
     restClient.AddHandler("application/json", new JsonDeserializer());
 }
Example #17
0
        private void AddResponseHandlers(IRestClient client, RestClientParameters restClientParameters)
        {
            var contentType = DataFormatHelper.ToContentType(restClientParameters.ResponseDataFormat);

            if (contentType != null)
            {
                client.AddHandler(contentType, () => restClientParameters.ResponseDataDeserializer);
            }
        }
Example #18
0
        public RestSharpIdentityModelClient(Options options, Authenticator authenticator = null)
        {
            if (ReferenceEquals(null, options))
            {
                throw new ArgumentNullException(nameof(options));
            }
            this.options = options;

            this.authenticator = authenticator;

            client = new RestClient(options.ApiAddress);
            client.ClearHandlers();
            client.AddHandler("application/json", options.JsonSerializer);
            client.AddHandler("text/json", options.JsonSerializer);
            client.AddHandler("text/x-json", options.JsonSerializer);
            client.AddHandler("text/javascript", options.JsonSerializer);
            client.AddHandler("*+json", options.JsonSerializer);
        }
        protected void SetJsonHandler(IRestClient client)
        {
            var jsonHandlerType = "application/json";

            client.ClearHandlers();
            var jsonDeserializer = new JsonNetDeseralizer(JsonSettings);

            client.AddHandler(jsonHandlerType, jsonDeserializer);
        }
        /// <summary>
        /// Configure a <see cref="IRestClient"/> instance to be compatible with the style of requests done by the <see cref="RequestExecutor"/>
        /// </summary>
        /// <param name="client">The client to configure</param>
        public virtual void ConfigureRestClient(IRestClient client)
        {
            //Fixed bug that prevents RestClient for adding custom headers to the request
            //https://stackoverflow.com/questions/22229393/why-is-restsharp-addheaderaccept-application-json-to-a-list-of-item
            client.ClearHandlers();
            client.AddHandler("application/json", new JsonDeserializer());

            client.FollowRedirects = false;
        }
Example #21
0
        internal TwitterProvider(ProviderConfig config, IRestClientFactory restClientFactory, string defaultRedirectTemplate, string defaultCallbackTemplate) : base(config, defaultRedirectTemplate, defaultCallbackTemplate)
        {
            _baseUrl = "https://api.twitter.com";

            // Todo: If not all methods need client, perhaps don't always init it
            _restClient = restClientFactory.Create(_baseUrl);
            _restClient.AddHandler("text/html", TwitterHtmlTextSerializer.CreateDefault());

            _apiDetails = config.Api;
        }
Example #22
0
 public CitiesService()
 {
     restClient = new RestClient(FORECAST_ENDPOINT);
     restClient.AddHandler("application/json", new DynamicJsonDeserializer());
     restClientLogin = new RestClient(AUTHENTICATION_LOGIN_ENDPOINT);
     restClientLogin.AddHandler("application/json", new DynamicJsonDeserializer());
     restClientRegister = new RestClient(AUTHENTICATION_REGISTER_ENDPOINT);
     restClientRegister.AddHandler("application/json", new DynamicJsonDeserializer());
     restClientFavCities = new RestClient(AUTHENTICATION_FAVCITIES_ENDPOINT);
     restClientFavCities.AddHandler("application/json", new DynamicJsonDeserializer());
 }
        public NameComClient(IRestClient client, string userName, string token)
        {
            _client = client;
            _client.AddDefaultHeader("Api-Username", userName);
            _client.AddDefaultHeader("Api-Token", token);

            //server returns invalid header for json content
            //Content-Type: text/html; charset=UTF-8
            //instead of
            //Content-Type: application/json; charset=UTF-8
            _client.RemoveHandler("text/html");
            _client.AddHandler("text/html", new JsonDeserializer());
        }
Example #24
0
        public ApiRequest(string username, string authenticationToken)
        {
            _client = new RestClient
            {
                BaseUrl       = new Uri(string.Format("https://{0}.highrisehq.com", username)),
                Authenticator = new HttpBasicAuthenticator(authenticationToken, "X")
            };

#if DEBUG
            _client.RemoveHandler("application/xml");
            _client.AddHandler("application/xml", (IDeserializer) new XmlDebuggingDeserializer());

            _client.RemoveHandler("text/xml");
            _client.AddHandler("text/xml", (IDeserializer) new XmlDebuggingDeserializer());

            _client.RemoveHandler("*+xml");
            _client.AddHandler("*+xml", (IDeserializer) new XmlDebuggingDeserializer());

            _client.RemoveHandler("*");
            _client.AddHandler("*", (IDeserializer) new XmlDebuggingDeserializer());
#endif
        }
Example #25
0
 private void AddHandlers()
 {
     _restClient.AddHandler("text/html", RestSharpNewtonsoftJsonSerializer.Default);
     _restClient.AddHandler("application/json", RestSharpNewtonsoftJsonSerializer.Default);
     _restClient.AddHandler("text/json", RestSharpNewtonsoftJsonSerializer.Default);
     _restClient.AddHandler("text/x-json", RestSharpNewtonsoftJsonSerializer.Default);
     _restClient.AddHandler("text/javascript", RestSharpNewtonsoftJsonSerializer.Default);
     _restClient.AddHandler("*+json", RestSharpNewtonsoftJsonSerializer.Default);
 }
Example #26
0
        public static void AddNewtonsoftResponseHandler(this IRestClient restClient, NewtonsoftRestsharpJsonSerializer serializer)
        {
            string[] contentTypes = new string[]
            {
                "application/json",
                "text/json",
                "text/x-json",
                "text/javascript",
                "*+json"
            };

            foreach (var contentType in contentTypes)
            {
                restClient.AddHandler(contentType, serializer);
            }
        }
Example #27
0
        public BaseClient(string baseUrl, ICacheService cache, IEnumerable <string> contentTypes, IDeserializer deserializer, IAuthenticator authenticator, ILoggerFactory loggerFactory)
        {
            _cache  = cache;
            _logger = loggerFactory.CreateLogger <BaseClient>();

            _restClient = new RestClient()
            {
                BaseUrl       = new Uri(baseUrl),
                Authenticator = authenticator
            };

            foreach (string contentType in contentTypes)
            {
                _restClient.AddHandler(contentType, () => deserializer);
            }
        }
Example #28
0
 public void AddHandler(string contentType, Func <IDeserializer> deserializerFactory)
 {
     _innerService.AddHandler(contentType, deserializerFactory);
 }
 public void AddHandler(string contentType, IDeserializer deserializer)
 {
     _innerService.AddHandler(contentType, deserializer);
 }
Example #30
0
 public HttpClient()
 {
     _client.AddHandler("application/json", new NewtonsoftJsonSerializer());
 }