Class: LinkShrink::Shrinkers::Karmacracy
- Defined in:
- lib/link_shrink/shrinkers/karmacracy.rb
Overview
Implements Karmacracy’s URL Shortener API
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#api_query_parameter ⇒ String
Returns URL query parameters.
-
#api_url ⇒ String
Returns full api url.
-
#api_username ⇒ String
Returns API Key.
-
#api_username? ⇒ TrueClass, FalseClass
Predicate method for checking if the API key exists.
-
#base_url ⇒ String
Returns URL base for API.
- #sanitize_url(new_url) ⇒ Object
Methods inherited from Base
#api_key, #api_key?, #body_parameters, collection, #content_type, error, #generate_chart_url, #http_method, inherited, response_options, short_url
Instance Method Details
#api_query_parameter ⇒ String
Returns URL query parameters
20 21 22 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 20 def api_query_parameter "?u=#{api_username}&key=#{api_key}&format=json&url=#{url}" end |
#api_url ⇒ String
Returns full api url
26 27 28 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 26 def api_url base_url.concat api_query_parameter end |
#api_username ⇒ String
Returns API Key
38 39 40 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 38 def api_username api_username? ? ENV["#{sub_klass.upcase}_USERNAME"] : nil end |
#api_username? ⇒ TrueClass, FalseClass
Predicate method for checking if the API key exists
32 33 34 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 32 def api_username? ENV.has_key?("#{sub_klass.upcase}_USERNAME") end |
#base_url ⇒ String
Returns URL base for API
14 15 16 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 14 def base_url 'http://kcy.me/api/' end |
#sanitize_url(new_url) ⇒ Object
42 43 44 |
# File 'lib/link_shrink/shrinkers/karmacracy.rb', line 42 def sanitize_url(new_url) URI::encode(new_url) end |