url_tokenizer 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37632682630861695db478cf47ec0aa8b951e5db
4
- data.tar.gz: 3936b2f6d08570590e90d65b89e4ffec275494fa
3
+ metadata.gz: 5fdd3a419c739b8840bd1c1ea41b18b7e1a5e19e
4
+ data.tar.gz: febfe493f75ce87261502adc4c30f03ac306e209
5
5
  SHA512:
6
- metadata.gz: 11e3d98329bf193182bd5ae0d6f2b82c4e7dd21b0f25d719afda01d552e3bad01d6f9a36100c58e18838c16adf561940ad1b7576688afa2c4ab2e14d9ba4dbcf
7
- data.tar.gz: 520db75d448a1edabe65905dc51180df84b97e0e94755d862156e37a9bf5080fcd1245eed697d94cb9e457d99b79fc7499c3fd6c16cfc6c371f938f1ab9b50b1
6
+ metadata.gz: 260223b738f2c64e795f841f1c699a9c9ca364f63bf6c30b5bb8697581341f60ceef617a5c401f9dfedc18917098774d1d74aa150104d7f6e8d045471ebe6185
7
+ data.tar.gz: 75cb41236638de862a9f5f631df8bb480a8999219569adafb17c9e20eca1bd42103670bdee99b15ca3313a8d428c66482e8fc52776f6bbf59db5d05e25c19152
data/.env.sample ADDED
@@ -0,0 +1,2 @@
1
+ LL_TOKEN=secret
2
+ CDN77_TOKEN=secret
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .env
10
11
 
11
12
  *.gem
12
13
  *.rbc
data/.travis.yml CHANGED
@@ -3,16 +3,16 @@ cache: bundler
3
3
  rvm:
4
4
  - 2.2
5
5
  - 2.1
6
- - 2.0
7
- - 1.9.3
8
6
  - ruby-head
9
7
  - rbx-2
10
- - jruby-19mode
11
8
  - jruby-head
12
9
 
13
10
  matrix:
14
11
  allow_failures:
15
12
  - rvm: ruby-head
16
13
  - rvm: rbx-2
17
- - rvm: jruby-19mode
18
14
  - rvm: jruby-head
15
+
16
+ addons:
17
+ code_climate:
18
+ repo_token: bee0f6bf8955be05fd8b557f66da5e8f49b90b6c5a92b3a1a750b04bb8c939fb
data/README.md CHANGED
@@ -2,8 +2,8 @@ UrlTokenizer
2
2
  ================================
3
3
  [![Build Status](https://travis-ci.org/AlexParamonov/url_tokenizer.png?branch=master)](https://travis-ci.org/AlexParamonov/url_tokenizer)
4
4
  [![Gemnasium Build Status](https://gemnasium.com/AlexParamonov/url_tokenizer.png)](http://gemnasium.com/AlexParamonov/url_tokenizer)
5
- [![Coverage Status](https://coveralls.io/repos/AlexParamonov/url_tokenizer/badge.png?branch=master)](https://coveralls.io/r/AlexParamonov/url_tokenizer?branch=master)
6
5
  [![Gem Version](https://badge.fury.io/rb/url_tokenizer.png)](http://badge.fury.io/rb/url_tokenizer)
6
+ [![Test Coverage](https://codeclimate.com/github/AlexParamonov/url_tokenizer/badges/coverage.svg)](https://codeclimate.com/github/AlexParamonov/url_tokenizer/coverage)
7
7
  [![Code Climate](https://codeclimate.com/github/AlexParamonov/url_tokenizer.png)](https://codeclimate.com/github/AlexParamonov/url_tokenizer)
8
8
 
9
9
  Tokenize url by variety of providers
@@ -32,14 +32,11 @@ Or install it yourself as:
32
32
 
33
33
  $ gem install url_tokenizer
34
34
 
35
- You'll need UrlTokenizer provider gems as well:
36
-
37
- $ gem install url_tokenizer-provider-limelight
35
+ UrlTokenizer gem has Limelight and CDN77 providers bundled.
38
36
 
39
37
  Requirements
40
38
  ------------
41
- 1. Ruby >= 1.9
42
- 1. UrlTokenizer gem
39
+ 1. Ruby >= 2.1
43
40
 
44
41
  Usage
45
42
  ------------
@@ -47,14 +44,15 @@ Usage
47
44
  Register provider using `UrlTokenizer.register`
48
45
 
49
46
  ``` ruby
50
- UrlTokenizer.register 'LL' => UrlTokenizer::Provider::Limelight
47
+ require 'url_tokenizer/limelight'
48
+ UrlTokenizer.register 'LL' => UrlTokenizer::Limelight.new('super_secret_key')
51
49
  ```
52
50
 
53
51
  Obtain provider and tokenize url:
54
52
 
55
53
  ``` ruby
56
- tokenizer = UrlTokenizer.provider('LL', key: 'super_secret_key')
57
- tokenizer.call url, expire_in: 1.hour
54
+ tokenizer = UrlTokenizer.provider 'LL'
55
+ tokenizer.call url, expires_in: 1.hour
58
56
  ```
59
57
 
60
58
  Contacts
@@ -70,11 +68,8 @@ tested with Ruby:
70
68
 
71
69
  * 2.2
72
70
  * 2.1
73
- * 2.0
74
- * 1.9.3
75
71
  * ruby-head
76
72
  * rbx-2
77
- * jruby-19mode
78
73
  * jruby-head
79
74
 
80
75
  See [build history](http://travis-ci.org/#!/AlexParamonov/url_tokenizer/builds)
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require 'rspec/core/rake_task'
4
+ namespace :ci do
5
+ desc "Run tests on CI"
6
+ RSpec::Core::RakeTask.new('all') do |t|
7
+ t.verbose = true
8
+ end
9
+ end
10
+
11
+ task :default => "ci:all"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -0,0 +1,37 @@
1
+ require 'uri'
2
+ require 'digest'
3
+ require 'base64'
4
+ require_relative 'provider'
5
+
6
+ module UrlTokenizer
7
+ class CDN77 < Provider
8
+ def call(input_url, **options)
9
+ uri = URI.parse input_url
10
+ path = uri.path
11
+ return if path.empty? || path == '/'
12
+
13
+ expiration = expiration_date(options[:expires_in])
14
+ token = digest [expiration, path, key].compact.join
15
+ token = [token, expiration].compact.join ','
16
+
17
+ uri.query = build_query secure: token
18
+ uri.to_s
19
+ end
20
+
21
+ private
22
+ def expiration_date(expires_in)
23
+ Time.now.utc.to_i + expires_in.to_i if expires_in
24
+ end
25
+
26
+ def digest(url)
27
+ md5 = Digest::MD5.digest url
28
+ Base64.urlsafe_encode64(md5)
29
+ end
30
+
31
+ def build_query(provider_options)
32
+ provider_options.reduce([]) do |query, (key, value)|
33
+ query << "#{ key }=#{ value }"
34
+ end.join '&'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require 'digest'
4
+ require_relative 'provider'
5
+ require 'facets/hash/symbolize_keys'
6
+
7
+ module UrlTokenizer
8
+ class Limelight < Provider
9
+ PARAMS = %i[e h p cf cd]
10
+
11
+ def call(input_url, **options)
12
+ uri = URI.parse input_url
13
+ folder = File.dirname input_url
14
+
15
+ provider_options = build_options options, url: folder, uri: uri
16
+
17
+ query_string = URI.encode_www_form provider_options
18
+ url_to_encode = [folder, query_string].join '?'
19
+
20
+ provider_options[:h] = digest url_to_encode
21
+
22
+ uri.query = URI.encode_www_form provider_options
23
+ uri.to_s
24
+ end
25
+
26
+ private
27
+ def build_options(token_options, url:, uri:)
28
+ server_params = {
29
+ p: url.length,
30
+ e: expiration_date(token_options[:expires_in]),
31
+ }.delete_if { |k, v| v.nil? }
32
+
33
+ cookie_params = {
34
+ cd: token_options[:cd],
35
+ cf: expiration_date(token_options[:cf]),
36
+ }.delete_if { |k, v| v.nil? }
37
+
38
+ server_params.delete :e if cookie_params.any?
39
+
40
+ url_params(uri)
41
+ .merge(server_params)
42
+ .merge(cookie_params)
43
+ end
44
+
45
+ def url_params(uri)
46
+ return {} if uri.query.nil?
47
+
48
+ CGI.parse(uri.query).symbolize_keys.tap do |params|
49
+ PARAMS.each do |param|
50
+ params.delete param
51
+ end
52
+ end
53
+ end
54
+
55
+ def expiration_date(expires_in)
56
+ Time.now.utc.to_i + expires_in.to_i if expires_in
57
+ end
58
+
59
+ def digest(url)
60
+ Digest::MD5.hexdigest "#{ key }#{ url }"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ module UrlTokenizer
2
+ class Provider
3
+ def initialize(key, **provider_options)
4
+ @key = key
5
+ @provider_options = provider_options
6
+ end
7
+
8
+ def call(input_url, **options)
9
+ input_url
10
+ end
11
+
12
+ private
13
+ attr_reader :key, :provider_options
14
+ end
15
+ end
data/lib/url_tokenizer.rb CHANGED
@@ -1,14 +1,17 @@
1
+ require_relative 'url_tokenizer/provider'
2
+ require 'facets/hash/symbolize_keys'
3
+
1
4
  module UrlTokenizer
2
5
  Error = Class.new StandardError
3
6
  class << self
4
- def provider(name, key: nil)
5
- providers.fetch(name) do
7
+ def provider(name)
8
+ providers.fetch(name.to_sym) do
6
9
  raise Error, "unknown provider '#{ name }'"
7
- end.new key
10
+ end
8
11
  end
9
12
 
10
13
  def register(provider_hash)
11
- providers.merge! provider_hash
14
+ providers.merge! provider_hash.symbolize_keys
12
15
  end
13
16
 
14
17
  private
@@ -17,7 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.8"
20
+ spec.add_dependency "facets"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.0"
21
23
  spec.add_development_dependency "rake", "~> 10.0"
22
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "dotenv"
26
+ spec.add_development_dependency "codeclimate-test-reporter"
23
27
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_tokenizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Paramonov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-12 00:00:00.000000000 Z
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: facets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.8'
33
+ version: '1.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.8'
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: Tokenize url by variety of providers.
56
98
  email:
57
99
  - alexander.n.paramonov@gmail.com
@@ -59,6 +101,7 @@ executables: []
59
101
  extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
104
+ - ".env.sample"
62
105
  - ".gitignore"
63
106
  - ".rspec"
64
107
  - ".travis.yml"
@@ -70,6 +113,9 @@ files:
70
113
  - bin/console
71
114
  - bin/setup
72
115
  - lib/url_tokenizer.rb
116
+ - lib/url_tokenizer/cdn77.rb
117
+ - lib/url_tokenizer/limelight.rb
118
+ - lib/url_tokenizer/provider.rb
73
119
  - url_tokenizer.gemspec
74
120
  homepage: http://github.com/AlexParamonov/url_tokenizer
75
121
  licenses: