cdnio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cdnio.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Darío Javier Cravero
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # CDN.io
2
+
3
+ CDN.io is there to always give you get the latest version of hosted JavaScript libraries on public CDNs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cdnio'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cdnio
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ## TODO
32
+
33
+ * Test Test Test!
34
+ * Find a stable place to host it? Volunteers? :D
35
+ * If some of them actually has an API, use that instead of Nokogiri's scrapping.
36
+ * Implement Microsoft's CDN.
37
+ * Look for and implement other CDNs?
38
+ * Add funky selectors such as \*.
39
+ * Add the ability to get more than one library at a time.
40
+ * Add the ability to choose a bunch of providers too.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/cdnio.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cdnio/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cdnio"
8
+ gem.version = CDNio::VERSION
9
+ gem.date = Date.today.to_s
10
+ gem.authors = ["Darío Javier Cravero"]
11
+ gem.email = ["dario@uxtemple.com"]
12
+ gem.description = %q{CDN.io is there to always give you get the latest version of hosted JavaScript libraries on public CDNs}
13
+ gem.summary = %q{Latest CDN versions of a JS libraries made easy}
14
+ gem.homepage = 'https://github.com/dariocravero/cdnio'
15
+
16
+ gem.add_dependency('nokogiri')
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
data/lib/cdnio.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'cdnio/version'
2
+ require 'cdnio/providers'
3
+
4
+ module CDNio
5
+ class UnsupportedProviderException < Exception; end
6
+
7
+ class CDN
8
+ PROVIDERS = [:cdnjs, :google, :microsoft]
9
+
10
+ def initialize
11
+ @providers = {}
12
+ end
13
+
14
+ def latest(library, provider = :all)
15
+ provider = provider.downcase.to_sym
16
+ raise UnsupportedProviderException, provider unless (PROVIDERS.include?(provider) || provider == :all)
17
+
18
+ if provider == :all
19
+ get_missing
20
+
21
+ Hash[*PROVIDERS.map do |prov|
22
+ lib = @providers[prov].latest(library)
23
+ [prov, lib] if lib
24
+ end.flatten.compact]
25
+ else
26
+ get_provider(provider) unless @providers.include?(provider)
27
+
28
+ @providers[provider].latest(library)
29
+ end
30
+ end
31
+
32
+ def libraries(provider = :all)
33
+ provider = provider.to_sym
34
+ raise UnsupportedProviderException, provider unless (PROVIDERS.include?(provider) || provider == :all)
35
+ get_missing
36
+
37
+ Hash[*PROVIDERS.map do |prov|
38
+ [prov, @providers[prov].libraries]
39
+ end.flatten.compact]
40
+ end
41
+
42
+ private
43
+ def get_missing
44
+ PROVIDERS.map do |provider|
45
+ get_provider(provider) unless @providers.include?(provider)
46
+ end
47
+ end
48
+
49
+ def get_provider(provider)
50
+ return if @providers.include?(provider)
51
+
52
+ @providers[provider] = CDNio::Providers.const_get(provider.capitalize).new
53
+ @providers[provider].libraries
54
+ end
55
+ end # CDN
56
+ end # CDNio
@@ -0,0 +1,30 @@
1
+ module CDNio
2
+ module Providers
3
+ class Base
4
+ def latest(library)
5
+ fetch unless @libraries
6
+ @libraries.select { |l| l[:name] == library.to_s }.first
7
+ end
8
+
9
+ def libraries
10
+ fetch unless @libraries
11
+ @libraries.collect { |l| l[:name] }
12
+ end
13
+
14
+ private
15
+ def fetch(url)
16
+ return unless block_given?
17
+
18
+ require 'nokogiri'
19
+ require 'open-uri'
20
+ yield Nokogiri::HTML(open(url))
21
+
22
+ self
23
+ end
24
+ end # Base
25
+ end # Providers
26
+ end # CDNio
27
+
28
+ require 'cdnio/providers/cdnjs'
29
+ require 'cdnio/providers/google'
30
+ require 'cdnio/providers/microsoft'
@@ -0,0 +1,20 @@
1
+ module CDNio
2
+ module Providers
3
+ class Cdnjs < Base
4
+ URL = 'http://cdnjs.com'
5
+
6
+ private
7
+ def fetch
8
+ super(URL) do |doc|
9
+ @libraries = doc.css('.packages-table-container tbody tr').map do |library|
10
+ tds = library.css('td')
11
+
12
+ {:name => tds.first.at_css('a').text,
13
+ :latest_version => tds[1].at_css('.version h3').text,
14
+ :url => tds[1].xpath('text()').text.strip}
15
+ end
16
+ end
17
+ end
18
+ end # Cdnjs
19
+ end # Providers
20
+ end # CDNio
@@ -0,0 +1,20 @@
1
+ module CDNio
2
+ module Providers
3
+ class Google < Base
4
+ URL = 'https://developers.google.com/speed/libraries/devguide'
5
+
6
+ private
7
+ def fetch
8
+ super(URL) do |doc|
9
+ @libraries = doc.css('table dl dd a').map do |library_link|
10
+ libDiv = doc.css(library_link[:href])
11
+
12
+ {:name => library_link[:href].gsub('#', ''),
13
+ :latest_version => libDiv.at_css('span.versions').text.split(', ').first,
14
+ :url => Nokogiri::HTML(libDiv.at_css('code.snippet').text).at_css('script')[:src]}
15
+ end
16
+ end
17
+ end
18
+ end # Google
19
+ end # Providers
20
+ end # CDNio
@@ -0,0 +1,14 @@
1
+ module CDNio
2
+ module Providers
3
+ class Microsoft < Base
4
+ URL = 'http://www.asp.net/ajaxlibrary/CDN.ashx'
5
+
6
+ private
7
+ def fetch
8
+ # TODO Implement
9
+ @libraries = []
10
+ self
11
+ end
12
+ end # Microsoft
13
+ end # Providers
14
+ end # CDNio
@@ -0,0 +1,3 @@
1
+ module CDNio
2
+ VERSION = '0.1.0'
3
+ end
data/web/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem 'cdnio'
4
+ gem 'sinatra'
data/web/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # CDN.io web interface
2
+
3
+ A Sinatra app to serve your own CDN.io webservice.
data/web/app.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'cdnio'
4
+
5
+ module CDNio
6
+ class WebApp < Sinatra::Application
7
+ set :cdn, CDN.new
8
+
9
+ get '/', :provides => :json do
10
+ settings.cdn.libraries(params.include?(:provider) ? params[:provider] : :all).to_json
11
+ end
12
+
13
+ get '/latest/:library', :provides => :json do
14
+ library = params[:library]
15
+ provider = params.include?('provider') ? params['provider'] : :all
16
+
17
+ latest = settings.cdn.latest(library, provider)
18
+
19
+ halt 404, {:error => "Couldn't find #{library} #{provider == :all ? 'at all' : %{in #{provider}}}."}.to_json if latest.nil?
20
+
21
+ latest.to_json
22
+ end
23
+
24
+ # Start the server if ruby file executed directly
25
+ run! if app_file == $0
26
+ end # WebApp
27
+ # CDNio
28
+ end
data/web/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ # config.ru (run with rackup)
2
+ require './app'
3
+ run CDNio::WebApp
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdnio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Darío Javier Cravero
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: CDN.io is there to always give you get the latest version of hosted JavaScript
31
+ libraries on public CDNs
32
+ email:
33
+ - dario@uxtemple.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - cdnio.gemspec
44
+ - lib/cdnio.rb
45
+ - lib/cdnio/providers.rb
46
+ - lib/cdnio/providers/cdnjs.rb
47
+ - lib/cdnio/providers/google.rb
48
+ - lib/cdnio/providers/microsoft.rb
49
+ - lib/cdnio/version.rb
50
+ - web/Gemfile
51
+ - web/README.md
52
+ - web/app.rb
53
+ - web/config.ru
54
+ homepage: https://github.com/dariocravero/cdnio
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.23
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Latest CDN versions of a JS libraries made easy
78
+ test_files: []
79
+ has_rdoc: