Class: Goldencobra::ArticleAdapter

Inherits:
Object
  • Object
show all
Defined in:
app/adapters/goldencobra/article_adapter.rb

Class Method Summary collapse

Class Method Details

.find(url, options = {}) ⇒ Integer

Alias method for find_by_url

Parameters:

Returns:

  • (Integer)

    ArticleID



12
13
14
# File 'app/adapters/goldencobra/article_adapter.rb', line 12

def find(url, options = {})
  find_by_url(url, options)
end

.find_by_id(article_id) ⇒ Object

find an goldencobra article by a given ArticleID

Parameters:

  • article_id (Integer)

Returns:

  • (Object)

    Goldencobra::Article



45
46
47
# File 'app/adapters/goldencobra/article_adapter.rb', line 45

def find_by_id(article_id)
  Goldencobra::Article.find_by_id(article_id)
end

.find_by_url(url, follow_redirection: false) ⇒ Integer

find an article id by a given url If you use this method in a controller, the controller should redirect to a redirection.

If you use this method somewhere else, you should activate follow_redirection:true to be sure you get the right article

Parameters:

Returns:

  • (Integer)

    ID of an article



27
28
29
30
31
# File 'app/adapters/goldencobra/article_adapter.rb', line 27

def find_by_url(url, follow_redirection: false)
  url_to_search = cleanup_url(url)
  url_to_search = follow_redirections(url_to_search) if follow_redirection
  Goldencobra::ArticleUrl.where(url: url_to_search).pluck(:article_id).first
end

.find_url_by_id(search_id) ⇒ Array

find an url by a given ID

Parameters:

  • search_id (Integer)

Returns:

  • (Array)

    list of urls



37
38
39
# File 'app/adapters/goldencobra/article_adapter.rb', line 37

def find_url_by_id(search_id)
  Goldencobra::ArticleUrl.where(article_id: search_id).pluck(:url)
end