lib/wcc/contentful/simple_client.rb in wcc-contentful-0.2.1 vs lib/wcc/contentful/simple_client.rb in wcc-contentful-0.2.2

- old
+ new

@@ -21,10 +21,13 @@ @get_http = SimpleClient.load_adapter(options[:adapter]) @options = options @query_defaults = {} @query_defaults[:locale] = @options[:default_locale] if @options[:default_locale] + + return unless env = options[:environment] + @api_url = URI.join(@api_url, 'environments/', env + '/') end def get(path, query = {}) url = URI.join(@api_url, path) @@ -97,10 +100,14 @@ access_token: access_token, **options ) end + def client_type + 'cdn' + end + ## # Gets an entry by ID def entry(key, query = {}) resp = get("entries/#{key}", query) resp.assert_ok! @@ -153,24 +160,40 @@ resp.assert_ok! end end class Management < SimpleClient - def initialize(management_token:, **options) + def initialize(space:, management_token:, **options) super( api_url: options[:api_url] || 'https://api.contentful.com', - space: options[:space] || '/', + space: space, access_token: management_token, **options ) end - def content_types(space: nil, **query) - space ||= @space - raise ArgumentError, 'please provide a space ID' if space.nil? + def client_type + 'management' + end - resp = get("/spaces/#{space}/content_types", query) + def content_types(**query) + resp = get('content_types', query) resp.assert_ok! + end + end + + class Preview < Cdn + def initialize(space:, preview_token:, **options) + super( + api_url: options[:api_url] || 'https://preview.contentful.com/', + space: space, + access_token: preview_token, + **options + ) + end + + def client_type + 'preview' end end end end