class CDNGet::JSDelivr
Constants
- API_URL
- CODE
- SITE_URL
Public Instance Methods
find(library)
click to toggle source
# File lib/cdnget.rb, line 191 def find(library) validate(library, nil) json = fetch("#{API_URL}?name=#{library}&fields=name,description,homepage,versions") arr = JSON.load(json) d = arr.first or raise CommandError.new("#{library}: Library not found.") return { name: d['name'], desc: d['description'], site: d['homepage'], versions: d['versions'], } end
get(library, version)
click to toggle source
# File lib/cdnget.rb, line 205 def get(library, version) validate(library, version) baseurl = "https://cdn.jsdelivr.net/#{library}/#{version}" url = "#{API_URL}/#{library}/#{version}" json = fetch("#{API_URL}/#{library}/#{version}") files = JSON.load(json) ! files.empty? or raise CommandError.new("#{library}: Library not found.") urls = files.collect {|x| "#{baseurl}/#{x}" } return { name: library, version: version, urls: urls, files: files, baseurl: baseurl, } end
list()
click to toggle source
# File lib/cdnget.rb, line 183 def list json = fetch("#{API_URL}?fields=name,description,homepage") arr = JSON.load(json) return arr.collect {|d| {name: d["name"], desc: d["description"], site: d["homepage"] } } end