deeplink 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +57 -7
- data/lib/deeplink/link.rb +47 -7
- data/lib/deeplink/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e468ffce5a2691ac6e00b5b957d16c96aa72bd4
|
4
|
+
data.tar.gz: 876f5c92a4b2bf16b90d6be67c0cf55712499566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c80a0ef10ca309cca35442aa434abf16781e162e4f125925a451d2010daddfe53d706b6ceb0c54a6b236b18634b790381cfba2d3251587eed38431ec4fe7fc2
|
7
|
+
data.tar.gz: adac2c472a8f1cdbf4039655acf8059a2b61bdc7acb47cfeac915d40e7d1af9bc692350e8b011bb01a17714babb290f63af1792effbab44e1a88fe02f0bc6678
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Deeplink
|
2
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
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -22,7 +18,62 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
## Usage
|
24
20
|
|
25
|
-
|
21
|
+
### Parsing a deep link
|
22
|
+
|
23
|
+
Just call `Deeplink.parse` with a deep link String and then you can read the scheme and path.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
deeplink = Deeplink.parse('foursquare://checkins/12932')
|
27
|
+
|
28
|
+
deeplink.scheme # => "foursquare"
|
29
|
+
deeplink.path # => "/checkins/12932"
|
30
|
+
deeplink.to_s # => "foursquare://checkins/12932"
|
31
|
+
```
|
32
|
+
|
33
|
+
### Query string
|
34
|
+
|
35
|
+
To get the query parameters of a link use `query` method.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
deeplink = Deeplink.parse('foursquare://checkins/209823?test=true')
|
39
|
+
|
40
|
+
deeplink.query # => { :test => "true" }
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Adding a query parameter
|
44
|
+
|
45
|
+
You can add one or more query parameters sending a Hash to `add_query`.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
deeplink = Deeplink.parse('foursquare://checkins/20982')
|
49
|
+
|
50
|
+
deeplink.add_query(foo: 'bar') # => { :foo => "bar" }
|
51
|
+
deeplink.to_s # => "foursquare://checkins/20982?foo=bar"
|
52
|
+
|
53
|
+
deeplink = Deeplink.parse('foursquare://checkins/20982')
|
54
|
+
|
55
|
+
deeplink.add_query(foo: 'bar', biz: 'baz') # => { :foo => "bar", :biz => "baz" }
|
56
|
+
deeplink.to_s # => "foursquare://checkins/20982?foo=bar&biz=baz"
|
57
|
+
```
|
58
|
+
|
59
|
+
#### Removing a query parameter
|
60
|
+
|
61
|
+
To remove query parameters call `remove_query` with the key (or list of keys) that you want to
|
62
|
+
remove. The method will return the value of the deleted key(s).
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
deeplink = Deeplink.parse('foursquare://checkins/20982?foo=bar')
|
66
|
+
|
67
|
+
deeplink.remove_query(:foo) # => "bar"
|
68
|
+
deeplink.to_s # => "foursquare://checkins/20982"
|
69
|
+
```
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
deeplink = Deeplink.parse('foursquare://checkins/20982?foo=bar&fu=baz')
|
73
|
+
|
74
|
+
deeplink.remove_query(:foo, :fu) # => ["bar", "baz"]
|
75
|
+
deeplink.to_s # => "foursquare://checkins/20982"
|
76
|
+
```
|
26
77
|
|
27
78
|
## Development
|
28
79
|
|
@@ -32,10 +83,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
83
|
|
33
84
|
## Contributing
|
34
85
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rikas/deeplink.
|
36
87
|
|
37
88
|
|
38
89
|
## License
|
39
90
|
|
40
91
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/lib/deeplink/link.rb
CHANGED
@@ -3,34 +3,74 @@ require 'cgi'
|
|
3
3
|
|
4
4
|
module Deeplink
|
5
5
|
class Link
|
6
|
-
attr_accessor :scheme, :path
|
6
|
+
attr_accessor :scheme, :path
|
7
|
+
|
8
|
+
# To add and remove items to the query string use #add_query and #remove_query
|
9
|
+
attr_reader :query
|
7
10
|
|
8
11
|
def initialize(uri)
|
9
|
-
uri = parse(uri)
|
12
|
+
uri = parse(uri)
|
10
13
|
|
11
14
|
self.scheme = uri.scheme
|
12
15
|
self.path = uri.path
|
13
|
-
|
16
|
+
|
17
|
+
@query = sanitize(parse_query(uri.query)) if uri.query
|
14
18
|
end
|
15
19
|
|
20
|
+
# Add query parameters to the link. You can add one or more parameters since this method
|
21
|
+
# receives a hash.
|
22
|
+
#
|
23
|
+
# === Example
|
24
|
+
#
|
25
|
+
# deeplink = Deeplink.parse("link://directions")
|
26
|
+
#
|
27
|
+
# deeplink.add_query(lat: 38.7179233, lon: -9.150129)
|
28
|
+
#
|
29
|
+
# deeplink.to_s # => "link://directions?lat=38.7179233&lon=-9.150129"
|
16
30
|
def add_query(hash)
|
17
|
-
|
31
|
+
@query ||= {}
|
18
32
|
|
19
|
-
query.merge!(sanitize(hash))
|
33
|
+
@query.merge!(sanitize(hash))
|
20
34
|
end
|
21
35
|
|
22
|
-
|
36
|
+
# Removes query parameters by its keys. You can remove one or more parameters, sending a list of
|
37
|
+
# keys.
|
38
|
+
#
|
39
|
+
# === Example
|
40
|
+
#
|
41
|
+
# deeplink = Deeplink.parse("link://directions?lat=38.7179233&lon=-9.150129&test=true")
|
42
|
+
#
|
43
|
+
# deeplink.remove_query(:test) # => "true"
|
44
|
+
#
|
45
|
+
# deeplink.remove_query(:lat, :lon) # => [38.7179233, -9.150129]
|
46
|
+
def remove_query(*keys)
|
23
47
|
return unless query
|
24
48
|
|
25
|
-
|
49
|
+
if keys.size > 1
|
50
|
+
keys.map { |key| query.delete(key.to_sym) }
|
51
|
+
else
|
52
|
+
query.delete(keys.first.to_sym)
|
53
|
+
end
|
26
54
|
end
|
27
55
|
|
56
|
+
# Returns true if the link has a query string or false otherwise
|
57
|
+
#
|
58
|
+
# === Example
|
59
|
+
#
|
60
|
+
# deeplink = Deeplink.parse("link://directions")
|
61
|
+
#
|
62
|
+
# deeplink.has_query? # => false
|
63
|
+
#
|
64
|
+
# deeplink.add_query(foo: "bar") # => { :foo => "bar" }
|
65
|
+
#
|
66
|
+
# deeplink.has_query? # => true
|
28
67
|
def has_query?
|
29
68
|
return false unless query
|
30
69
|
|
31
70
|
!query.empty?
|
32
71
|
end
|
33
72
|
|
73
|
+
# Returns the link as a String
|
34
74
|
def to_s
|
35
75
|
string = "#{scheme}:/#{path}"
|
36
76
|
|
data/lib/deeplink/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deeplink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,3 +118,4 @@ signing_key:
|
|
118
118
|
specification_version: 4
|
119
119
|
summary: Gem to manage deep links parsing.
|
120
120
|
test_files: []
|
121
|
+
has_rdoc:
|