lib/wcc/contentful/simple_client.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/simple_client.rb in wcc-contentful-1.2.1
- old
+ new
@@ -22,12 +22,11 @@
#
# @api Client
class SimpleClient
include WCC::Contentful::Instrumentation
- attr_reader :api_url
- attr_reader :space
+ attr_reader :api_url, :space
# Creates a new SimpleClient with the given configuration.
#
# @param [String] api_url the base URL of the Contentful API to connect to
# @param [String] space The Space ID to access
@@ -39,11 +38,11 @@
# @option options [String] environment The contentful environment to access. Defaults to 'master'.
# @option options [Boolean] no_follow_redirects If true, do not follow 300 level redirects.
# @option options [Number] rate_limit_wait_timeout The maximum time to block the thread waiting
# on a rate limit response. By default will wait for one 429 and then fail on the second 429.
def initialize(api_url:, space:, access_token:, **options)
- @api_url = URI.join(api_url, '/spaces/', space + '/')
+ @api_url = URI.join(api_url, '/spaces/', "#{space}/")
@space = space
@access_token = access_token
@adapter = SimpleClient.load_adapter(options[:connection])
@@ -55,11 +54,11 @@
# https://www.contentful.com/developers/docs/references/content-preview-api/#/introduction/api-rate-limits
@rate_limit_wait_timeout = @options[:rate_limit_wait_timeout] || 1.5
return unless options[:environment].present?
- @api_url = URI.join(@api_url, 'environments/', options[:environment] + '/')
+ @api_url = URI.join(@api_url, 'environments/', "#{options[:environment]}/")
end
# performs an HTTP GET request to the specified path within the configured
# space and environment. Query parameters are merged with the defaults and
# appended to the request.
@@ -82,19 +81,17 @@
def self.load_adapter(adapter)
case adapter
when nil
ADAPTERS.each do |a, spec|
- begin
- gem(*spec)
- return load_adapter(a)
- rescue Gem::LoadError
- next
- end
+ gem(*spec)
+ return load_adapter(a)
+ rescue Gem::LoadError
+ next
end
- raise ArgumentError, 'Unable to load adapter! Please install one of '\
- "#{ADAPTERS.values.map(&:join).join(',')}"
+ raise ArgumentError, 'Unable to load adapter! Please install one of ' \
+ "#{ADAPTERS.values.map(&:join).join(',')}"
when :faraday
require 'faraday'
::Faraday.new do |faraday|
faraday.response :logger, (Rails.logger if defined?(Rails)), { headers: false, bodies: false }
faraday.adapter :net_http
@@ -102,11 +99,11 @@
when :typhoeus
require_relative 'simple_client/typhoeus_adapter'
TyphoeusAdapter.new
else
unless adapter.respond_to?(:get)
- raise ArgumentError, "Adapter #{adapter} is not invokeable! Please "\
- "pass use one of #{ADAPTERS.keys} or create a Faraday-compatible adapter"
+ raise ArgumentError, "Adapter #{adapter} is not invokeable! Please " \
+ "pass use one of #{ADAPTERS.keys} or create a Faraday-compatible adapter"
end
adapter
end
end