lib/codestatus/package_resolvers/npm_resolver.rb in codestatus-0.1.2 vs lib/codestatus/package_resolvers/npm_resolver.rb in codestatus-0.1.3
- old
+ new
@@ -5,31 +5,42 @@
class NpmResolver < Base
NPM_REGISTRY_ENDPOINT = 'https://registry.npmjs.org/'.freeze
private
+ def found?
+ package_info
+ end
+
def urls
[
bugs_url,
repository_url,
homepage_url,
].compact
end
def bugs_url
- package_info.dig('bugs', 'url')
+ package_info&.dig('bugs', 'url')
end
def homepage_url
- package_info.dig('homepage')
+ package_info&.dig('homepage')
end
def repository_url
- package_info.dig('repository', 'url')
+ package_info&.dig('repository', 'url')
end
def package_info
- @package_info ||= JSON.parse(client.get(package_uri))
+ @package_info ||= request(package_uri)
+ end
+
+ def request(uri)
+ response = client.get(uri)
+ JSON.parse(response)
+ rescue RestClient::NotFound
+ nil
end
def client
RestClient
end