cdnget 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a718ec89571144e9875b5a5c56bd3d44fdd81f5
4
- data.tar.gz: ea19fd364267826d4228a01caef8a4ebbb394cf1
3
+ metadata.gz: 055befc004f39cde2638cf0cc31dc01e4cbc3226
4
+ data.tar.gz: 694c18db9e4128ee93119f985c66c7d4656aee27
5
5
  SHA512:
6
- metadata.gz: e4e17f3ec24c1d84314890c7f54414e36365a75ee2a5478235be2410a80d97e319617a0e880d851a4acb9ef80282cdb1656ab3cae227304d34d67382a19083d7
7
- data.tar.gz: 2e84dda3e1866b128e526e8949555f1ca90ee3a28c5465323140fdb55b40df4542b6189eafce04665ff677b8a995d1707001c80908c86238dceeb4ea3e9e2c2b
6
+ metadata.gz: 4ab7fed7ebd4a61804930cf168deb89e1b30b2326ed9ca3bd609b755236f14d2c905066a24bb39f65b7a090bb4eeffb36b43996550c651d2c6acefdcf6f28b67
7
+ data.tar.gz: dea35e5ab6ca166933650c0ff670b0e419ebc5e24b906b31ac45c492c87073cc78abd6840b556574519bacfc7881780cae21296532bca988603727fa684cd1d5
data/CHANGES.md CHANGED
@@ -2,6 +2,12 @@ Changes
2
2
  =======
3
3
 
4
4
 
5
+ Release 0.3.0 (2016-09-07)
6
+ ---------------------------
7
+
8
+ * Change to read data from https://api.cdnjs.com/ .
9
+
10
+
5
11
  Release 0.2.0 (2016-07-11)
6
12
  --------------------------
7
13
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  CDNget
2
2
  ======
3
3
 
4
- ($Release: 0.2.0 $)
4
+ ($Release: 0.3.0 $)
5
5
 
6
6
  CDNget is a utility script to download files from CDNJS, jsDelivr or Google.
7
7
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
 
5
- RELEASE = '$Release: 0.2.0 $'.split()[1]
5
+ RELEASE = '$Release: 0.3.0 $'.split()[1]
6
6
  COPYRIGHT = 'copyright(c) 2016 kuwata-lab.com all rights reserved'
7
7
  LICENSE = 'MIT License'
8
8
 
data/bin/cdnget CHANGED
@@ -24,7 +24,7 @@ require 'fileutils'
24
24
  module CDNGet
25
25
 
26
26
 
27
- RELEASE = '$Release: 0.2.0 $'.split()[1]
27
+ RELEASE = '$Release: 0.3.0 $'.split()[1]
28
28
 
29
29
  CLASSES = []
30
30
 
@@ -114,14 +114,20 @@ module CDNGet
114
114
 
115
115
  def fetch(url, library=nil)
116
116
  begin
117
- html = open(url, 'rb') {|f| f.read() }
117
+ json_str = open(url, 'rb') {|f| f.read() }
118
118
  if library
119
- html =~ /<h1\b.*?>(.*?)<\/h1>/ or
120
- raise CommandError.new("#{library}: Library not found.")
121
- library == $1.strip() or
122
- raise CommandError.new("#{library}: Library not found (maybe '#{$1.strip()}'?).")
119
+ if json_str == "{}"
120
+ if library.end_with?('js')
121
+ maybe = library.end_with?('.js') \
122
+ ? library.sub('.js', 'js') \
123
+ : library.sub(/js$/, '.js')
124
+ raise CommandError.new("#{library}: Library not found (maybe '#{maybe}'?).")
125
+ else
126
+ raise CommandError.new("#{library}: Library not found.")
127
+ end
128
+ end
123
129
  end
124
- return html
130
+ return json_str
125
131
  rescue OpenURI::HTTPError => ex
126
132
  raise HttpError.new("GET #{url} : #{ex.message}")
127
133
  end
@@ -130,53 +136,38 @@ module CDNGet
130
136
 
131
137
  def list
132
138
  libs = []
133
- html = fetch("https://cdnjs.com/libraries")
134
- html.scan(/<td\b(.*?)<\/td>/m) do |str,|
135
- name = desc = nil
136
- name = $1 if str =~ /href="\/libraries\/([-.\w]+)">\s*\1\s*<\/a>/
137
- desc = $1.strip if str =~ /<div style="display: none;">(.*?)<\/div>/m
138
- libs << {name: name, desc: desc} if name
139
- end
139
+ jstr = fetch("https://api.cdnjs.com/libraries?fields=name,description")
140
+ jdata = JSON.parse(jstr)
141
+ libs = jdata['results'].collect {|d| {name: d['name'], desc: d['description']} }
140
142
  return libs.sort_by {|d| d[:name] }.uniq
141
143
  end
142
144
 
143
145
  def find(library)
144
146
  validate(library, nil)
145
- html = fetch("https://cdnjs.com/libraries/#{library}", library)
146
- flagment = html.split(/<select class=".*?version-selector.*?"/, 2).last
147
- flagment = flagment.split(/<\/select>/, 2).first
148
- versions = []
149
- flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
150
- versions << ver
151
- end
152
- desc = tags = nil
153
- if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
154
- desc = $1
155
- tags = $2
156
- end
147
+ jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
148
+ jdata = JSON.parse(jstr)
157
149
  return {
158
150
  name: library,
159
- desc: desc,
160
- tags: tags,
161
- versions: versions,
151
+ desc: jdata['description'],
152
+ tags: (jdata['keywords'] || []).join(", "),
153
+ versions: jdata['assets'].collect {|d| d['version'] },
162
154
  }
163
155
  end
164
156
 
165
157
  def get(library, version)
166
158
  validate(library, version)
167
- html = fetch("https://cdnjs.com/libraries/#{library}/#{version}", library)
159
+ jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
160
+ jdata = JSON.parse(jstr)
161
+ d = jdata['assets'].find {|d| d['version'] == version } or
162
+ raise CommandError.new("#{library}/#{version}: Library or version not found.")
168
163
  baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
169
- basepat = Regexp.escape("#{library}/#{version}")
170
- files = []
171
- html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
172
- files << file.gsub(/&#x2F;/, '/')
173
- end
174
- urls = files.collect {|s| baseurl + s }
175
164
  return {
176
165
  name: library,
166
+ desc: jdata['description'],
167
+ tags: (jdata['keywords'] || []).join(", "),
177
168
  version: version,
178
- urls: urls,
179
- files: files,
169
+ urls: d['files'].collect {|s| baseurl + s },
170
+ files: d['files'],
180
171
  baseurl: baseurl,
181
172
  }
182
173
  end
@@ -503,6 +494,7 @@ END
503
494
  else
504
495
  s << "name: #{d[:name]}\n"
505
496
  s << "version: #{d[:version]}\n"
497
+ s << "desc: #{d[:desc]}\n" if d[:desc]
506
498
  s << "tags: #{d[:tags]}\n" if d[:tags]
507
499
  s << "site: #{d[:site]}\n" if d[:site]
508
500
  s << "snippet: |\n" << d[:snippet].gsub(/^/, ' ') if d[:snippet]
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |o|
4
4
  o.name = "cdnget"
5
- o.version = '$Release: 0.2.0 $'.split()[1]
5
+ o.version = '$Release: 0.3.0 $'.split()[1]
6
6
  o.authors = ["makoto kuwata"]
7
7
  o.email = ["kwa@kuwata-lab.com"]
8
8
 
@@ -24,7 +24,7 @@ require 'fileutils'
24
24
  module CDNGet
25
25
 
26
26
 
27
- RELEASE = '$Release: 0.2.0 $'.split()[1]
27
+ RELEASE = '$Release: 0.3.0 $'.split()[1]
28
28
 
29
29
  CLASSES = []
30
30
 
@@ -114,14 +114,20 @@ module CDNGet
114
114
 
115
115
  def fetch(url, library=nil)
116
116
  begin
117
- html = open(url, 'rb') {|f| f.read() }
117
+ json_str = open(url, 'rb') {|f| f.read() }
118
118
  if library
119
- html =~ /<h1\b.*?>(.*?)<\/h1>/ or
120
- raise CommandError.new("#{library}: Library not found.")
121
- library == $1.strip() or
122
- raise CommandError.new("#{library}: Library not found (maybe '#{$1.strip()}'?).")
119
+ if json_str == "{}"
120
+ if library.end_with?('js')
121
+ maybe = library.end_with?('.js') \
122
+ ? library.sub('.js', 'js') \
123
+ : library.sub(/js$/, '.js')
124
+ raise CommandError.new("#{library}: Library not found (maybe '#{maybe}'?).")
125
+ else
126
+ raise CommandError.new("#{library}: Library not found.")
127
+ end
128
+ end
123
129
  end
124
- return html
130
+ return json_str
125
131
  rescue OpenURI::HTTPError => ex
126
132
  raise HttpError.new("GET #{url} : #{ex.message}")
127
133
  end
@@ -130,53 +136,38 @@ module CDNGet
130
136
 
131
137
  def list
132
138
  libs = []
133
- html = fetch("https://cdnjs.com/libraries")
134
- html.scan(/<td\b(.*?)<\/td>/m) do |str,|
135
- name = desc = nil
136
- name = $1 if str =~ /href="\/libraries\/([-.\w]+)">\s*\1\s*<\/a>/
137
- desc = $1.strip if str =~ /<div style="display: none;">(.*?)<\/div>/m
138
- libs << {name: name, desc: desc} if name
139
- end
139
+ jstr = fetch("https://api.cdnjs.com/libraries?fields=name,description")
140
+ jdata = JSON.parse(jstr)
141
+ libs = jdata['results'].collect {|d| {name: d['name'], desc: d['description']} }
140
142
  return libs.sort_by {|d| d[:name] }.uniq
141
143
  end
142
144
 
143
145
  def find(library)
144
146
  validate(library, nil)
145
- html = fetch("https://cdnjs.com/libraries/#{library}", library)
146
- flagment = html.split(/<select class=".*?version-selector.*?"/, 2).last
147
- flagment = flagment.split(/<\/select>/, 2).first
148
- versions = []
149
- flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
150
- versions << ver
151
- end
152
- desc = tags = nil
153
- if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
154
- desc = $1
155
- tags = $2
156
- end
147
+ jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
148
+ jdata = JSON.parse(jstr)
157
149
  return {
158
150
  name: library,
159
- desc: desc,
160
- tags: tags,
161
- versions: versions,
151
+ desc: jdata['description'],
152
+ tags: (jdata['keywords'] || []).join(", "),
153
+ versions: jdata['assets'].collect {|d| d['version'] },
162
154
  }
163
155
  end
164
156
 
165
157
  def get(library, version)
166
158
  validate(library, version)
167
- html = fetch("https://cdnjs.com/libraries/#{library}/#{version}", library)
159
+ jstr = fetch("https://api.cdnjs.com/libraries/#{library}", library)
160
+ jdata = JSON.parse(jstr)
161
+ d = jdata['assets'].find {|d| d['version'] == version } or
162
+ raise CommandError.new("#{library}/#{version}: Library or version not found.")
168
163
  baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
169
- basepat = Regexp.escape("#{library}/#{version}")
170
- files = []
171
- html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
172
- files << file.gsub(/&#x2F;/, '/')
173
- end
174
- urls = files.collect {|s| baseurl + s }
175
164
  return {
176
165
  name: library,
166
+ desc: jdata['description'],
167
+ tags: (jdata['keywords'] || []).join(", "),
177
168
  version: version,
178
- urls: urls,
179
- files: files,
169
+ urls: d['files'].collect {|s| baseurl + s },
170
+ files: d['files'],
180
171
  baseurl: baseurl,
181
172
  }
182
173
  end
@@ -503,6 +494,7 @@ END
503
494
  else
504
495
  s << "name: #{d[:name]}\n"
505
496
  s << "version: #{d[:version]}\n"
497
+ s << "desc: #{d[:desc]}\n" if d[:desc]
506
498
  s << "tags: #{d[:tags]}\n" if d[:tags]
507
499
  s << "site: #{d[:site]}\n" if d[:site]
508
500
  s << "snippet: |\n" << d[:snippet].gsub(/^/, ' ') if d[:snippet]
@@ -69,10 +69,9 @@ END
69
69
 
70
70
  it "(cdnjs) lists librareis." do
71
71
  actual = CDNGet::Main.new().run("cdnjs")
72
- ok {actual} =~ /^jquery # jquery, library, ajax, framework, toolkit, popular$/
73
- ok {actual} =~ /^angular\.js # framework, mvc, AngularJS, angular, angular2, angular\.js$/
74
- ok {actual} =~ /^twitter-bootstrap # css, less, mobile-first, responsive, front-end, framework, web, twitter, bootstrap$/
75
- ok {actual} =~ /^ember\.js # ember, ember.js$/
72
+ ok {actual} =~ /^jquery # JavaScript library for DOM operations$/
73
+ ok {actual} =~ /^angular\.js # AngularJS is an MVC framework for building web applications\./
74
+ ok {actual} =~ /^ember\.js # Ember is a JavaScript framework for creating ambitious web applications that eliminates boilerplate and provides a standard application architecture\./
76
75
  end
77
76
 
78
77
  it "(google) lists librareis." do
@@ -275,6 +274,7 @@ END
275
274
  expected = <<END
276
275
  name: jquery
277
276
  version: 2.2.0
277
+ tags: jquery, library, ajax, framework, toolkit, popular
278
278
  urls:
279
279
  - https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js
280
280
  - https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js
@@ -313,14 +313,15 @@ END
313
313
  expected = <<END
314
314
  name: jquery-jcrop
315
315
  version: 0.9.12
316
+ tags: jquery, crop
316
317
  urls:
317
318
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/Jcrop.gif
318
319
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.css
319
320
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css
320
- - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js
321
- - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js
322
321
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.js
323
322
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.min.js
323
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js
324
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js
324
325
  - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.min.js
325
326
  END
326
327
  actual = CDNGet::Main.new().run("cdnjs", "jquery-jcrop", "0.9.12")
@@ -381,10 +382,10 @@ END
381
382
  #{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
382
383
  #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
383
384
  #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
384
- #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
385
- #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
386
385
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
387
386
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
387
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
388
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
388
389
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
389
390
  END
390
391
  begin
@@ -394,10 +395,10 @@ END
394
395
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif" }.file_exist?
395
396
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css" }.file_exist?
396
397
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css" }.file_exist?
397
- ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js" }.file_exist?
398
- ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js" }.file_exist?
399
398
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js" }.file_exist?
400
399
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js" }.file_exist?
400
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js" }.file_exist?
401
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js" }.file_exist?
401
402
  ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js" }.file_exist?
402
403
  ok {sout} == expected
403
404
  ensure
@@ -428,10 +429,10 @@ END
428
429
  #{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
429
430
  #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
430
431
  #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
431
- #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
432
- #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
433
432
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
434
433
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
434
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
435
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
435
436
  #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
436
437
  END
437
438
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makoto kuwata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest