Class: Awesm::Url

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/awesm/url.rb

Constant Summary collapse

PATH =
'/url'
REQUIRED_SHARE_PARAMS =
[:url, :key, :tool, :channel, :destination].freeze

Class Method Summary collapse

Class Method Details

.create(params = {}) ⇒ Object

Right now this method only supports the json format


7
8
9
# File 'lib/awesm/url.rb', line 7

def self.create(params = {})
  call_api("#{Awesm::HOST}#{PATH}.json", params)
end

.share(params = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/awesm/url.rb', line 11

def self.share(params = {})
  if required_params_present?(REQUIRED_SHARE_PARAMS, params)
    options = params.clone
    options = options.delete_if{|key,value| REQUIRED_SHARE_PARAMS.include?(key) }
    query = options.map{|k,v| "#{k}=#{v}"}.join('&')
    share_url = "#{Awesm::HOST}#{PATH}/share?v=3&url=#{params[:url]}&key=#{params[:key]}&tool=#{params[:tool]}&channel=#{params[:channel]}&destination=#{params[:destination]}"
    share_url += "&#{query}" if query.length > 0
    share_url
  end
end

.static(params = {}) ⇒ Object

Right now this method only supports the json format


23
24
25
# File 'lib/awesm/url.rb', line 23

def self.static(params = {})
  call_api("#{Awesm::HOST}#{PATH}/static.json", params)
end

.update(awesm_id, params) ⇒ Object


27
28
29
# File 'lib/awesm/url.rb', line 27

def self.update(awesm_id, params)
  call_api("#{Awesm::HOST}#{PATH}/update/#{awesm_id}.json", params)
end