Class: Alfi::Providers::Maven

Inherits:
Base
  • Object
show all
Defined in:
lib/alfi/providers/maven.rb

Instance Method Summary collapse

Methods inherited from Base

#add_repo_to_list, #add_suggestions, #add_to_list, #initialize

Constructor Details

This class inherits a constructor from Alfi::Providers::Base

Instance Method Details

#callObject



6
7
8
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
# File 'lib/alfi/providers/maven.rb', line 6

def call
  if @search_type.empty? || @search_type.include?('m')
    begin
      response = @http.request(@request)
    rescue SocketError
      puts "Internet Connection not available".red
      exit 1
    end

    if response.code == '200'
      result = JSON.parse(response.body)

      num_results = result['response']['numFound']

      if num_results == 0
        suggestions = (result['spellcheck']['suggestions'].last || {})['suggestion']
        add_suggestions(suggestions) if suggestions
      else
        add_to_list "  # #{'-'*20}Maven.org#{'-'*20}"
        add_to_list '  # mavenCentral()'
      end
      result['response']['docs'].each { |doc| add_repo_to_list "#{doc['id']}:#{doc['latestVersion']}" }
    else
      puts "Error: #{response.code}\n#{response}".red
      exit 1
    end
  end
end

#query_url(query) ⇒ Object



2
3
4
# File 'lib/alfi/providers/maven.rb', line 2

def query_url(query)
  "http://search.maven.org/solrsearch/select?q=#{query}&rows=350&wt=json"
end