Module: Shared::Api
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/shared/api.rb
Class Method Summary collapse
- .api_link(ar, id = nil) ⇒ Object
- .host ⇒ Object
- .image_link(image) ⇒ Object
- .shorten_url(long_url) ⇒ Object
- .sound_link(sound) ⇒ Object
Class Method Details
.api_link(ar, id = nil) ⇒ Object
13 14 15 16 17 18 |
# File 'app/models/concerns/shared/api.rb', line 13 def self.api_link(ar, id = nil) s = host return s + '/api/v1/' if ar.nil? "#{s}/api/v1/#{ar.class.base_class.name.downcase.pluralize}/#{id || ar.id}" end |
.host ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/models/concerns/shared/api.rb', line 4 def self.host s = ENV['SERVER_NAME'] if s.nil? 'http://127.0.0.1:3000' else 'https://' + s end end |
.image_link(image) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/concerns/shared/api.rb', line 20 def self.image_link(image) s = host return s if image.nil? long = "#{s}/#{image.image_file.url(:original)}" shorten_url(long) end |
.shorten_url(long_url) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/shared/api.rb', line 38 def self.shorten_url(long_url) s = host return s if long_url.nil? # Stores long <-> short in db. short_key = Shortener::ShortenedUrl.generate(long_url).unique_key "#{s}/s/#{short_key}" end |
.sound_link(sound) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/models/concerns/shared/api.rb', line 29 def self.sound_link(sound) s = host return s if sound.nil? long = "#{s}/#{Rails.application.routes.url_helpers.rails_blob_path(Sound.last.sound_file, only_path: true)}" shorten_url(long) end |