Пример #1
0
        public static IServiceCollection AddHubspot(this IServiceCollection services, HubSpotOptions options)
        {
            if (string.IsNullOrWhiteSpace(options?.ApiKey))
            {
                throw new ArgumentNullException(nameof(HubSpotOptions.ApiKey));
            }
            if (string.IsNullOrWhiteSpace(options?.ApiUrl))
            {
                throw new ArgumentNullException(nameof(HubSpotOptions.ApiUrl));
            }

            return(services
                   .AddSingleton <IHubSpot, HubSpot>(provider => new HubSpot(options))
                   .AddSingleton <IAssociationApi, AssociationApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.Associations as AssociationApi ?? throw new NotSupportedException(nameof(IAssociationApi));
            })
                   .AddSingleton <ICompanyApi, CompanyApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.Companies as CompanyApi ?? throw new NotSupportedException(nameof(ICompanyApi));
            })
                   .AddSingleton <IContactApi, ContactApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.Contacts as ContactApi ?? throw new NotSupportedException(nameof(IContactApi));
            })
                   .AddSingleton <IDealsApi, DealsApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.Deals as DealsApi ?? throw new NotSupportedException(nameof(IDealsApi));
            })
                   .AddSingleton <IBlogPostApi, BlogPostApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.BlogPosts as BlogPostApi ?? throw new NotSupportedException(nameof(IBlogPostApi));
            })
                   .AddSingleton <ITicketsApi, TicketsApi>(provider =>
            {
                var hubspot = provider.GetRequiredService <IHubSpot>();
                return hubspot.Tickets as TicketsApi ?? throw new NotSupportedException(nameof(ITicketsApi));
            }));
        }
Пример #2
0
 /// <summary>
 /// creates a new <see cref="ContactApi"/>
 /// </summary>
 /// <param name="rest">rest client to call api</param>
 /// <param name="models">model registry used to access entity models</param>
 internal ContactApi(HubSpotOptions options, HubSpotRestClient rest, ModelRegistry models)
 {
     _options    = options;
     this.rest   = rest;
     this.models = models;
 }