class WinewooCore::Services::ElasticSearch::NewsServices

Public Class Methods

new(with_error=false) click to toggle source
# File lib/winewoo_core/services/elastic_search/news_services.rb, line 6
def initialize(with_error=false)
  @client = Elasticsearch::Client.new host: 'reco.kasual.biz:9200'
  @with_error = with_error
end

Public Instance Methods

fetch_news(page, per_page) click to toggle source
# File lib/winewoo_core/services/elastic_search/news_services.rb, line 12
def fetch_news(page, per_page)
  from = page * per_page
  size = per_page
  raw = @client.search index: "my_twitter_river",
    body: request_body(from, size)

  Parsers::NewsParser.parse(raw["hits"]["hits"], @with_error)
end
post_news(news_entry) click to toggle source
# File lib/winewoo_core/services/elastic_search/news_services.rb, line 22
def post_news(news_entry)
  @client.index index: "my_twitter_river",
    type: "winewoo_action",
    body: news_entry.to_h
end

Private Instance Methods

request_body(from, size) click to toggle source
# File lib/winewoo_core/services/elastic_search/news_services.rb, line 31
def request_body(from, size)
  {
    sort: [ { "created_at" => { order: "desc" } } ],
    from: from,
    size: size
  }
end