Class: WinewooCore::Services::ElasticSearch::NewsServices

Inherits:
Object
  • Object
show all
Defined in:
lib/winewoo_core/services/elastic_search/news_services.rb

Instance Method Summary collapse

Constructor Details

#initialize(with_error = false) ⇒ NewsServices

Returns a new instance of NewsServices.



6
7
8
9
# 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

Instance Method Details

#fetch_news(page, per_page) ⇒ Object



12
13
14
15
16
17
18
19
# 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) ⇒ Object



22
23
24
25
26
# 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