module MavenCentral
Public Instance Methods
dict2id(d)
click to toggle source
# 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")
click to toggle source
# 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")
click to toggle source
# 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)
click to toggle source
# File lib/mvn-get/mvn-get.rb, line 60 def fetch_lastest_version(groupId, artifactId) id2dict(search("#{groupId}:#{artifactId}")["candidates"].sort.last)["version"] end
id2dict(id)
click to toggle source
# 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)
click to toggle source
# File lib/mvn-get/mvn-get.rb, line 64 def request(url) RestClient.get(url) end
search(keyword)
click to toggle source
# 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 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
version()
click to toggle source
# File lib/mvn-get/mvn-get.rb, line 15 def version "0.0.4" end