Class: SeoParams::Yandex

Inherits:
Object
  • Object
show all
Defined in:
lib/seo_params/yandex.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Yandex

Returns a new instance of Yandex.



9
10
11
12
# File 'lib/seo_params/yandex.rb', line 9

def initialize(url)
  url.match(/^(https?:\/\/)/) ? @url = url : @url = 'http://' + url
  @host = URI(@url).host
end

Instance Method Details

#ticObject



15
16
17
18
19
# File 'lib/seo_params/yandex.rb', line 15

def tic
  query = Nokogiri::XML(open("http://bar-navig.yandex.ru/u?ver=2&show=32&url=#{@url}"))
  tic = query.xpath('//@value')
  tic.to_s.to_i
end

#yandex_pagesObject



21
22
23
24
25
# File 'lib/seo_params/yandex.rb', line 21

def yandex_pages
  pages = ask_yandex(@url)
  (pages.is_a? String) ? (@url = pages; pages = ask_yandex(pages); ) : pages
  pages
end

#yandex_position(user, key, lr, keywords, num) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/seo_params/yandex.rb', line 27

def yandex_position(user, key, lr, keywords, num)

  uri = URI.parse "http://xmlsearch.yandex.ru/xmlsearch?user=#{user}&key=#{key}&lr=#{lr}"

  h = Hash.new

  EventMachine.synchrony do
    EM::Synchrony::FiberIterator.new(keywords, keywords.size).each do |keyword|
      request = EventMachine::HttpRequest.new(uri)
      response = request.post(:body => xml_request(keyword, num))

      result = parse_results(response)

      (result.is_a? Hash) ? (h.merge! result) : (h[keyword] = result)

    end

    EventMachine.stop
  end

  h

end