예제 #1
0
 /// <summary>Initializes a new instance of the <see cref="RebrandlyRequest"/> class.</summary>
 /// <param name="client">The client creating the request.</param>
 /// <param name="method">The HTTP method.</param>
 /// <param name="path">The path of the request.</param>
 /// <param name="options">The parameters of the request.</param>
 /// <param name="requestOptions">The special modifiers of the request.</param>
 public RebrandlyRequest(IRebrandlyClient client, HttpMethod method, string path, BaseOptions options, RequestOptions requestOptions)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     this.options        = options;
     Method              = method;
     Uri                 = BuildUri(client, method, path, options, requestOptions);
     AuthorizationHeader = BuildAuthorizationHeader(client);
 }
예제 #2
0
        private static AuthenticationHeaderValue BuildAuthorizationHeader(IRebrandlyClient client)
        {
            string apiKey = client.ApiKey;

            if (apiKey == null)
            {
                var message = "No API key provided. Set your API key using "
                              + "`RebrandlyConfiguration.ApiKey = \"<API-KEY>\"`. You can generate API keys "
                              + "from the Rebrandly Dashboard. See "
                              + "https://developers.rebrandly.com/docs/api-key-authentication for details or contact support "
                              + "at https://support.rebrandly.com/hc/en-us/requests/new if you have any questions.";
                throw new RebrandlyException(message);
            }

            return(new AuthenticationHeaderValue("apikey", apiKey));
        }
예제 #3
0
        private static Uri BuildUri(
            IRebrandlyClient client,
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(requestOptions?.BaseUrl ?? client.ApiBase);
            sb.Append(path);

            if ((method != HttpMethod.Post) && (options != null))
            {
                string queryString = FormEncoder.CreateQueryString(options);
                if (!string.IsNullOrEmpty(queryString))
                {
                    sb.Append("?");
                    sb.Append(queryString);
                }
            }

            return(new Uri(sb.ToString()));
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Service{EntityReturned}"/> class with a
 /// custom <see cref="IRebrandlyClient"/>.
 /// </summary>
 /// <param name="client">The client used by the service to send requests.</param>
 protected Service(IRebrandlyClient client)
 {
     this.client = client;
 }
예제 #5
0
 public LinkService(IRebrandlyClient client) : base(client)
 {
 }
예제 #6
0
 public ScriptService(IRebrandlyClient client) : base(client)
 {
 }
예제 #7
0
 public TagService(IRebrandlyClient client) : base(client)
 {
 }
예제 #8
0
 public AccountService(IRebrandlyClient client) : base(client)
 {
 }
예제 #9
0
 public DomainService(IRebrandlyClient client) : base(client)
 {
 }