deeplink 0.1.0 → 0.1.1

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: 591669474c391937e578ba03c7762a0699424ba7
4
- data.tar.gz: ddb34acead4d79bf479fe392ae9a5a32e8cb5990
3
+ metadata.gz: 3e468ffce5a2691ac6e00b5b957d16c96aa72bd4
4
+ data.tar.gz: 876f5c92a4b2bf16b90d6be67c0cf55712499566
5
5
  SHA512:
6
- metadata.gz: 7547e522241a24c91b939570490cbb41d4950a21c898b374d08e0093265c310a8093033feec8c68dc4e8b9aeab9d12bd3ae6a68496f8eb739f2bb97b7fa3f54e
7
- data.tar.gz: ee81abdf9edfba560870cd314096a8a57c8f4267f7fbffdbee3c60c79a84609cfa172d4ab3addf33d0842e251a45014e58a9691673e2caa9eb7d95bd3b4477ef
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
- TODO: Write usage instructions here
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/[USERNAME]/deeplink.
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, :query
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) unless uri.kind_of?(URI)
12
+ uri = parse(uri)
10
13
 
11
14
  self.scheme = uri.scheme
12
15
  self.path = uri.path
13
- self.query = sanitize(parse_query(uri.query)) if uri.query
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
- self.query ||= {}
31
+ @query ||= {}
18
32
 
19
- query.merge!(sanitize(hash))
33
+ @query.merge!(sanitize(hash))
20
34
  end
21
35
 
22
- def remove_query(key)
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
- query.delete(key.to_sym)
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
 
@@ -1,3 +1,3 @@
1
1
  module Deeplink
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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-12 00:00:00.000000000 Z
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: