Class: Search
- Inherits:
-
Object
- Object
- Search
- Defined in:
- lib/Search.rb
Instance Method Summary collapse
-
#initialize(keyword) ⇒ Search
constructor
A new instance of Search.
- #searching ⇒ Object
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
#searching ⇒ Object
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/Search.rb', line 9 def searching puts @keyword puts '************************************************' puts ' ......searching < '<<@keyword.chomp<<' > .......' puts '************************************************' #http://search.maven.org/solrsearch/select?q=fresco&rows=20&wt=json uri = 'http://search.maven.org/solrsearch/select?q='<<@keyword.chomp<<'&rows=20&wt=json' # puts uri html_response = nil open(uri) do |http| html_response = http.read end if(html_response.length == 0) return end # puts html_response # puts result json_obj = JSON.parse(html_response) docs = json_obj['response']['docs'] if(docs.length == 0) puts '*** not found ***' return end firstGradleConfig = nil firstMavenConfig = nil puts '' puts '************' puts 'result:::::::::' puts '--------------------------------------' docs.each do |item| p item["id"] << ":" << item['latestVersion'] if firstGradleConfig == nil firstGradleConfig = item["id"] << ":" << item['latestVersion'] end if firstMavenConfig == nil firstMavenConfig = item end end puts '--------------------------------------' puts '----GradleConfig' puts '************* copy this to your project gradle config file *************' puts '' puts 'dependencies { compile '<<firstGradleConfig<<"'"<< '}' puts '' puts '************* ------- searching gradle end -------------- *************' puts '' puts '----MavenConfig' puts '************* copy this to your project maven config file *************' puts '' puts '<dependency> <groupId>'<<firstMavenConfig['g']<<'</groupId> <artifactId>'<<firstMavenConfig['a']<<'</artifactId> <version>'<<firstMavenConfig['latestVersion']<<'</version> <type>aar</type> </dependency>' puts '' puts '************* ------- searching maven end -------------- *************' puts '' end |