lib/contentful/management/client.rb in contentful-management-0.9.0 vs lib/contentful/management/client.rb in contentful-management-1.0.0
- old
+ new
@@ -3,10 +3,18 @@
require 'contentful/management/resource_builder'
require 'contentful/management/version'
require 'contentful/management/http_client'
+require 'contentful/management/client_space_methods_factory'
+require 'contentful/management/client_api_key_methods_factory'
+require 'contentful/management/client_asset_methods_factory'
+require 'contentful/management/client_content_type_methods_factory'
+require 'contentful/management/client_entry_methods_factory'
+require 'contentful/management/client_locale_methods_factory'
+require 'contentful/management/client_webhook_methods_factory'
+
require_relative 'request'
require 'http'
require 'json'
require 'logger'
@@ -28,11 +36,15 @@
default_locale: 'en-US',
gzip_encoded: false,
logger: false,
log_level: Logger::INFO,
raise_errors: false,
- dynamic_entries: []
+ dynamic_entries: [],
+ proxy_host: nil,
+ proxy_port: nil,
+ proxy_username: nil,
+ proxy_password: nil
}
# @param [String] access_token
# @param [Hash] configuration
# @option configuration [String] :api_url
@@ -41,30 +53,97 @@
# @option configuration [Boolean] :gzip_encoded
# @option configuration [false, ::Logger] :logger
# @option configuration [::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR] :log_level
# @option configuration [Boolean] :raise_errors
# @option configuration [::Array<String>] :dynamic_entries
+ # @option configuration [String] :proxy_host
+ # @option configuration [Fixnum] :proxy_port
+ # @option configuration [String] :proxy_username
+ # @option configuration [String] :proxy_username
def initialize(access_token = nil, configuration = {})
@configuration = default_configuration.merge(configuration)
setup_logger
@access_token = access_token
@dynamic_entry_cache = {}
Thread.current[:client] = self
update_all_dynamic_entry_cache!
end
+ # Allows manipulation of spaces in context of the current client
+ # Allows listing all spaces for client and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientSpaceMethodsFactory]
+ def spaces
+ ClientSpaceMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of api keys in context of the current client
+ # Allows listing all api keys for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientApiKeyMethodsFactory]
+ def api_keys
+ ClientApiKeyMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of assets in context of the current client
+ # Allows listing all assets for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientAssetMethodsFactory]
+ def assets
+ ClientAssetMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of content types in context of the current client
+ # Allows listing all content types for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientContentTypeMethodsFactory]
+ def content_types
+ ClientContentTypeMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of entries in context of the current client
+ # Allows listing all entries for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientEntryMethodsFactory]
+ def entries
+ ClientEntryMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of locales in context of the current client
+ # Allows listing all locales for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientLocaleMethodsFactory]
+ def locales
+ ClientLocaleMethodsFactory.new(self)
+ end
+
+ # Allows manipulation of webhooks in context of the current client
+ # Allows listing all webhooks for client, creating new and finding one by id.
+ # @see _ README for details.
+ #
+ # @return [Contentful::Management::ClientWebhookMethodsFactory]
+ def webhooks
+ ClientWebhookMethodsFactory.new(self)
+ end
+
# @private
def setup_logger
@logger = configuration[:logger]
logger.level = configuration[:log_level] if logger
end
# @private
def update_all_dynamic_entry_cache!
return if configuration[:dynamic_entries].empty?
- spaces = configuration[:dynamic_entries].map { |space_id| ::Contentful::Management::Space.find(space_id) }
+ spaces = configuration[:dynamic_entries].map { |space_id| ::Contentful::Management::Space.find(self, space_id) }
update_dynamic_entry_cache_for_spaces!(spaces)
end
# @private
def update_dynamic_entry_cache_for_spaces!(spaces)
@@ -81,11 +160,11 @@
end
# @private
def update_dynamic_entry_cache!(content_types)
content_types.each do |ct|
- @dynamic_entry_cache[ct.id.to_sym] = DynamicEntry.create(ct)
+ @dynamic_entry_cache[ct.id.to_sym] = DynamicEntry.create(ct, self)
end
end
# @private
def api_version
@@ -128,32 +207,32 @@
end
# @private
def delete(request)
execute_request(request) do |url|
- self.class.delete_http(url, {}, request_headers)
+ self.class.delete_http(url, {}, request_headers, proxy_parameters)
end
end
# @private
def get(request)
execute_request(request) do |url|
- self.class.get_http(url, request.query, request_headers)
+ self.class.get_http(url, request.query, request_headers, proxy_parameters)
end
end
# @private
def post(request)
execute_request(request) do |url|
- self.class.post_http(url, request.query, request_headers)
+ self.class.post_http(url, request.query, request_headers, proxy_parameters)
end
end
# @private
def put(request)
execute_request(request) do |url|
- self.class.put_http(url, request.query, request_headers)
+ self.class.put_http(url, request.query, request_headers, proxy_parameters)
end
end
# @private
def base_url
@@ -226,9 +305,19 @@
end
# @private
def self.shared_instance
Thread.current[:client]
+ end
+
+ # @private
+ def proxy_parameters
+ {
+ host: configuration[:proxy_host],
+ port: configuration[:proxy_port],
+ username: configuration[:proxy_username],
+ password: configuration[:proxy_password]
+ }
end
end
end
end