Module: Camper::UrlUtils
- Defined in:
- lib/camper/url_utils.rb
Overview
Defines methods related to url operations.
Class Method Summary collapse
- .basecamp_url?(url) ⇒ Boolean
-
.transform(url) ⇒ String
Utility method for transforming Basecamp Web URLs into API URIs e.g ‘3.basecamp.com/1/buckets/2/todos/3’ will be converted into ‘3.basecampapi.com/1/buckets/2/todos/3.json’.
Class Method Details
.basecamp_url?(url) ⇒ Boolean
6 7 8 9 10 11 12 |
# File 'lib/camper/url_utils.rb', line 6 def self.basecamp_url?(url) return false if url.nil? || !url.is_a?(String) || url == '' transformed_url = UrlUtils.transform(url) transformed_url.match?(%r{#{Configuration.base_api_endpoint}/\d+/.*}) end |
.transform(url) ⇒ String
Utility method for transforming Basecamp Web URLs into API URIs e.g ‘3.basecamp.com/1/buckets/2/todos/3’ will be converted into ‘3.basecampapi.com/1/buckets/2/todos/3.json’
20 21 22 23 24 |
# File 'lib/camper/url_utils.rb', line 20 def self.transform(url) api_url = url.gsub('3.basecamp.com', '3.basecampapi.com') api_url.gsub!('.json', '') "#{api_url}.json" end |