예제 #1
0
    public Translator(Options options)
    {
        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        Options = options;

        var configuration = new NStackConfiguration
        {
            ApiKey        = options.ApiKey,
            ApplicationId = options.ApplicationId,
            BaseUrl       = options.BaseUrl
        };

        Repository = new Repository(configuration);
    }
예제 #2
0
    public NStackRepository(NStackConfiguration configuration)
    {
        if (configuration == null)
        {
            throw new ArgumentNullException(nameof(configuration));
        }

        if (string.IsNullOrWhiteSpace(configuration.ApiKey))
        {
            throw new ArgumentNullException(configuration.ApiKey);
        }

        if (string.IsNullOrWhiteSpace(configuration.ApplicationId))
        {
            throw new ArgumentNullException(configuration.ApplicationId);
        }

        if (string.IsNullOrWhiteSpace(configuration.BaseUrl))
        {
            throw new ArgumentNullException(configuration.BaseUrl);
        }

        var options = new RestClientOptions(configuration.BaseUrl);

        Client = new RestClient(options);
        Client.UseSystemTextJson(new JsonSerializerOptions
        {
            PropertyNameCaseInsensitive = true,
            Converters =
            {
                new JsonStringEnumConverter()
            }
        });

        Client.AddDefaultHeaders(new Dictionary <string, string>
        {
            { "X-Application-Id", configuration.ApplicationId },
            { "X-Rest-Api-Key", configuration.ApiKey }
        });
    }
예제 #3
0
 internal Repository(NStackConfiguration configuration) : base(configuration)
 {
 }