Class: Plagiarism::Strategies::Google

Inherits:
Engine
  • Object
show all
Defined in:
lib/plagiarism/strategries/google.rb

Constant Summary collapse

URL =
'https://www.googleapis.com/customsearch/v1'
VERSION =
'1.0'

Constants inherited from Engine

Engine::THRESHOLD

Instance Attribute Summary

Attributes inherited from Engine

#content, #params

Class Method Summary collapse

Methods inherited from Engine

exists?, #initialize, #match, #retrieve_link, #unique?, valid_segments, whitelists_regex

Constructor Details

This class inherits a constructor from Plagiarism::Strategies::Engine

Class Method Details

.fetch(content, params) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/plagiarism/strategries/google.rb', line 9

def fetch(content, params)
  Typhoeus.get URL, params: params.merge(
    key: Config.google_key,
    cx: Config.google_cx,
    q: content,
    fields: 'items(link)',
    prettyPrint: false
  )
end

.iterate(response, action = :all?) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/plagiarism/strategries/google.rb', line 19

def iterate(response, action = :all?)
  results = JSON.parse(response)['items'] || []
  results.send(action) do |r|
    uri = URI.parse URI::encode(r['link'])
    yield uri
  end
end