Class: SL::IsgdSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/searches/isgd.rb

Overview

is.gd link shortening

Class Method Summary collapse

Class Method Details

.isgd_shorten(url, title = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/searchlink/searches/isgd.rb', line 28

def isgd_shorten(url, title = nil)
  long_url = url.dup

  data = Curl::Json.new("https://is.gd/create.php?format=json&url=#{CGI.escape(long_url)}", symbolize_names: true)

  if data.json.key?('errorcode')
    SL.add_error('Error creating is.gd url', data.json[:errorcode])
    return [false, title, link_text]
  end

  link = data.json[:shorturl]
  rtitle = SL::URL.title(long_url)
  title = rtitle
  link_text = rtitle if link_text == '' && !SL.titleize
  [link, title, link_text]
end

.search(_, search_terms, link_text) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/searchlink/searches/isgd.rb', line 16

def search(_, search_terms, link_text)
  if SL::URL.url?(search_terms)
    link = search_terms
  else
    link, rtitle = SL.ddg(search_terms, link_text)
  end

  url, title = isgd_shorten(link, rtitle)
  link_text = title || url
  [url, title, link_text]
end

.settingsObject



7
8
9
10
11
12
13
14
# File 'lib/searchlink/searches/isgd.rb', line 7

def settings
  {
    trigger: "isgd",
    searches: [
      ["isgd", "is.gd Shorten"]
    ]
  }
end