Class: Contentful::Client
- Inherits:
-
Object
- Object
- Contentful::Client
- Defined in:
- lib/wcc/contentful/client_ext.rb
Constant Summary collapse
- REWRITE_REGEXP =
/^(https?\:\/\/(?:\w+)\.contentful\.com\/spaces\/[^\/]+\/)(?!environments)(.+)$/
Class Method Summary collapse
- .adapter ⇒ Object
- .get_http(url, query, headers = {}, proxy = {}) ⇒ Object
- .old_get_http ⇒ Object
- .rewrite_to_environment(url, environment) ⇒ Object
Class Method Details
.adapter ⇒ Object
8 9 10 11 12 |
# File 'lib/wcc/contentful/client_ext.rb', line 8 def self.adapter @adapter ||= WCC::Contentful::SimpleClient.load_adapter(WCC::Contentful.configuration.http_adapter) || ->(url, query, headers, proxy) { old_get_http(url, query, headers, proxy) } end |
.get_http(url, query, headers = {}, proxy = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/wcc/contentful/client_ext.rb', line 14 def self.get_http(url, query, headers = {}, proxy = {}) if environment = WCC::Contentful.configuration.environment url = rewrite_to_environment(url, environment) end adapter.call(url, query, headers, proxy) end |
.old_get_http ⇒ Object
5 |
# File 'lib/wcc/contentful/client_ext.rb', line 5 alias_method :old_get_http, :get_http |
.rewrite_to_environment(url, environment) ⇒ Object
23 24 25 26 27 |
# File 'lib/wcc/contentful/client_ext.rb', line 23 def self.rewrite_to_environment(url, environment) return url unless m = REWRITE_REGEXP.match(url) File.join(m[1], 'environments', environment, m[2]) end |