deeplink 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 591669474c391937e578ba03c7762a0699424ba7
4
+ data.tar.gz: ddb34acead4d79bf479fe392ae9a5a32e8cb5990
5
+ SHA512:
6
+ metadata.gz: 7547e522241a24c91b939570490cbb41d4950a21c898b374d08e0093265c310a8093033feec8c68dc4e8b9aeab9d12bd3ae6a68496f8eb739f2bb97b7fa3f54e
7
+ data.tar.gz: ee81abdf9edfba560870cd314096a8a57c8f4267f7fbffdbee3c60c79a84609cfa172d4ab3addf33d0842e251a45014e58a9691673e2caa9eb7d95bd3b4477ef
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.2
7
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deeplink.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ricardo Otero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Deeplink
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/deeplink`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'deeplink'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install deeplink
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deeplink.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deeplink'
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/deeplink.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'deeplink/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'deeplink'
9
+ spec.version = Deeplink::VERSION
10
+ spec.authors = ['Ricardo Otero']
11
+ spec.email = ['oterosantos@gmail.com']
12
+
13
+ spec.summary = 'Gem to manage deep links parsing.'
14
+ spec.description = 'It mitigates the lack of support for mobile deep links on the URI module.'
15
+ spec.homepage = 'https://github.com/rikas/deeplink'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.4.0', '>= 3.4.0'
26
+ spec.add_development_dependency 'pry', '~> 0.10.3'
27
+ end
data/lib/deeplink.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'uri'
2
+ require 'deeplink/link'
3
+ require 'deeplink/version'
4
+
5
+ module Deeplink
6
+ def self.parse(link)
7
+ Link.new(link)
8
+ end
9
+ end
@@ -0,0 +1,73 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+
4
+ module Deeplink
5
+ class Link
6
+ attr_accessor :scheme, :path, :query
7
+
8
+ def initialize(uri)
9
+ uri = parse(uri) unless uri.kind_of?(URI)
10
+
11
+ self.scheme = uri.scheme
12
+ self.path = uri.path
13
+ self.query = sanitize(parse_query(uri.query)) if uri.query
14
+ end
15
+
16
+ def add_query(hash)
17
+ self.query ||= {}
18
+
19
+ query.merge!(sanitize(hash))
20
+ end
21
+
22
+ def remove_query(key)
23
+ return unless query
24
+
25
+ query.delete(key.to_sym)
26
+ end
27
+
28
+ def has_query?
29
+ return false unless query
30
+
31
+ !query.empty?
32
+ end
33
+
34
+ def to_s
35
+ string = "#{scheme}:/#{path}"
36
+
37
+ if has_query?
38
+ query_string = query.map { |key, value| "#{key}=#{value}" }.join('&')
39
+ string << "?#{query_string}"
40
+ end
41
+
42
+ string
43
+ end
44
+
45
+ private
46
+
47
+ def parse(string)
48
+ # Because URI is dumb and thinks that every uri needs to have a host. Adding an extra slash
49
+ # we are basically tricking URI to think that host is nil (and avoid errors).
50
+ uri = string.sub(%r{://}, ':///')
51
+
52
+ URI.parse(uri)
53
+ end
54
+
55
+ def sanitize(hash)
56
+ sanitized = {}
57
+
58
+ hash.each_key do |key|
59
+ value = hash[key].is_a?(String) ? CGI.escape(hash[key]) : hash[key].to_s
60
+
61
+ sanitized[key.to_sym] = value
62
+ end
63
+
64
+ sanitized
65
+ end
66
+
67
+ def parse_query(query_str)
68
+ return unless query_str
69
+
70
+ query_str.scan(/([[:alnum:]]+)=([[:alnum:]]+)/).to_h
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Deeplink
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deeplink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Otero
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.4.0
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.4.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: 3.4.0
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: pry
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.10.3
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.10.3
75
+ description: It mitigates the lack of support for mobile deep links on the URI module.
76
+ email:
77
+ - oterosantos@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - ".ruby-version"
85
+ - ".travis.yml"
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - deeplink.gemspec
93
+ - lib/deeplink.rb
94
+ - lib/deeplink/link.rb
95
+ - lib/deeplink/version.rb
96
+ homepage: https://github.com/rikas/deeplink
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Gem to manage deep links parsing.
120
+ test_files: []