Module: MavenCentral

Defined in:
lib/mvn-get/mvn-get.rb

Class Method Summary collapse

Class Method Details

.dict2id(d) ⇒ Object



41
42
43
# File 'lib/mvn-get/mvn-get.rb', line 41

def dict2id(d)
  "#{d["groupId"]}:#{d["artifactId"]}:#{d["version"]}"
end

.extract_url_from_dict(d, filetype = "pom") ⇒ Object



19
20
21
# File 'lib/mvn-get/mvn-get.rb', line 19

def extract_url_from_dict(d, filetype="pom")
  "#{MAVEN_CENTRAL_REMOTE_CONTENT}?filepath=#{d["groupId"].gsub(".", "/")}/#{d["artifactId"]}/#{d["version"]}/#{d["artifactId"]}-#{d["version"]}.#{filetype}"
end

.extract_url_from_id(id, filetype = "pom") ⇒ Object



23
24
25
# File 'lib/mvn-get/mvn-get.rb', line 23

def extract_url_from_id(id, filetype="pom")
  MavenCentral.extract_url_from_dict(id2dict(id), filetype)
end

.fetch_lastest_version(groupId, artifactId) ⇒ Object



62
63
64
# File 'lib/mvn-get/mvn-get.rb', line 62

def fetch_lastest_version(groupId, artifactId)
  id2dict(search("#{groupId}:#{artifactId}")["candidates"].sort.last)["version"]
end

.id2dict(id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mvn-get/mvn-get.rb', line 27

def id2dict(id)
  if (res = id.scan(/(.*):(.*)/)[0]) != nil
    if (res1 = id.scan(/(.*):(.*):(.*)/)[0]) != nil
      res = res1
    end
  else
    return nil
  end

  d = {}
  d["groupId"], d["artifactId"], d["version"] = res
  d
end

.request(url) ⇒ Object



66
67
68
# File 'lib/mvn-get/mvn-get.rb', line 66

def request(url)
  RestClient.get(url)
end

.search(keyword) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mvn-get/mvn-get.rb', line 45

def search(keyword)
  d = MavenCentral.id2dict(keyword)
  url = if d != nil
    "#{MAVEN_CENTRAL_SEARCH}?q=g:%22#{d["groupId"]}%22%20AND%20a:%22#{d["artifactId"]}%22%20AND%20v:%22#{d["version"]}%22&wt=json"
  else
    "#{MAVEN_CENTRAL_SEARCH}?q=#{keyword}&wt=json"
  end

  # puts url

  result = {}
  body = JSON.parse(MavenCentral.request(url))
  result["candidates"] = body["response"]["docs"].map{|x| x["id"] }
  result["suggestions"] = if body["spellcheck"] and body["spellcheck"]["suggestions"] and body["spellcheck"]["suggestions"][1] then body["spellcheck"]["suggestions"][1]["suggestion"] else  [] end
  result
end

.versionObject



15
16
17
# File 'lib/mvn-get/mvn-get.rb', line 15

def version
  "0.0.2"
end