Navigation Menu

Skip to content

Commit

Permalink
Update to v1 of MetaCPAN API (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbell4 authored and jordansissel committed Jun 5, 2017
1 parent f393ca6 commit b930bcc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/fpm/package/cpan.rb
Expand Up @@ -322,8 +322,8 @@ def download(metadata, cpan_version=nil)
self.version.sub!(/^v/, '')

# Search metacpan to get download URL for this version of the module
metacpan_search_url = "http://api.metacpan.org/v0/release/_search"
metacpan_search_query = '{"query":{"match_all":{}},"filter":{"term":{"release.name":"' + "#{distribution}-#{self.version}" + '"}}}'
metacpan_search_url = "https://fastapi.metacpan.org/v1/release/_search"
metacpan_search_query = '{"fields":["download_url"],"filter":{"term":{"name":"' + "#{distribution}-#{self.version}" + '"}}}'
begin
search_response = httppost(metacpan_search_url,metacpan_search_query)
rescue Net::HTTPServerException => e
Expand All @@ -335,7 +335,7 @@ def download(metadata, cpan_version=nil)
data = search_response.body
release_metadata = JSON.parse(data)

download_url = release_metadata['hits']['hits'][0]['_source']['download_url']
download_url = release_metadata['hits']['hits'][0]['fields']['download_url']
download_path = URI.parse(download_url).path
tarball = File.basename(download_path)

Expand Down Expand Up @@ -363,7 +363,7 @@ def download(metadata, cpan_version=nil)

def search(package)
logger.info("Asking metacpan about a module", :module => package)
metacpan_url = "http://api.metacpan.org/v0/module/" + package
metacpan_url = "https://fastapi.metacpan.org/v1/module/" + package
begin
response = httpfetch(metacpan_url)
rescue Net::HTTPServerException => e
Expand Down Expand Up @@ -396,6 +396,7 @@ def httpfetch(url)
else
http = Net::HTTP.new(uri.host, uri.port)
end
http.use_ssl = uri.scheme == 'https'
response = http.request(Net::HTTP::Get.new(uri.request_uri))
case response
when Net::HTTPSuccess; return response
Expand All @@ -412,6 +413,7 @@ def httppost(url, body)
else
http = Net::HTTP.new(uri.host, uri.port)
end
http.use_ssl = uri.scheme == 'https'
response = http.post(uri.request_uri, body)
case response
when Net::HTTPSuccess; return response
Expand Down

0 comments on commit b930bcc

Please sign in to comment.