Class: Search

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

Instance Method Summary collapse

Constructor Details

#initialize(keyword) ⇒ Search

Returns a new instance of Search.



5
6
7
# File 'lib/Search.rb', line 5

def initialize(keyword)
  @keyword = keyword
end

Instance Method Details

#searchingObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/Search.rb', line 9

def searching
  puts @keyword
  puts '************************************************'
  puts ' ......searching < '<<@keyword.chomp<<' > .......'
  puts '************************************************'
  sessionId = Random.rand(110000)
  uri = 'http://gradleplease.appspot.com/search?q='<<@keyword.chomp<<'&session='<<sessionId.to_s
  # puts uri
  html_response = nil
  open(uri) do |http|
 html_response = http.read
  end
  if(html_response.length == 0)
    return
  end
  # puts html_response
  tag ='searchCallback('
  sstart = tag.length
  send = html_response.length-1 - sstart
  result = html_response[sstart,send]
  # puts result
  json_obj = JSON.parse(result)
  docs = json_obj['response']['docs']
  if(docs.length == 0)
    puts '*** not found ***'
    return
  end  
  firstRes = nil
  puts ''
  puts '************'
  puts 'result:::::::::'
  puts '--------------------------------------'
  docs.each do |item|
    p item["id"] << ":" << item['latestVersion']
    if firstRes == nil
      firstRes = item["id"] << ":" << item['latestVersion']
    end
  end  
  puts '--------------------------------------'  

  puts ''
  puts '************* copy this to your project build file *************' 
  puts '' 
  puts 'dependencies {'
  puts         'compile '<<"'"<<firstRes<<"'"
  puts '}'
  puts ''
  puts '************* ------- searching end -------------- *************'
  puts ''

end