13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/cdnjs.rb', line 13
def initialize(lib_name, version = nil, content = true)
return false unless lib_name
@result = {}
cdnjs_url_pkg = "#{@@cdnjsroot_github}#{lib_name}/package.json"
raw_content = nil
begin
distant = open(cdnjs_url_pkg).read
rescue => e
@result[:error] = e; return
end
content = JSON.parse(distant)
version = version || content['version']
version = version.to_s
filename = content['filename']
raw_file_url = "#{@@cdnjsroot}#{lib_name}/#{version}/#{filename}"
if content
begin
raw_content = open(raw_file_url).read
rescue => e
@result[:error] = e; return
end
end
@result = {
:lib => lib_name,
:version => version,
:file_url => raw_file_url,
:content => raw_content,
:response => content,
}
end
|