firebase_dynamic_link 0.1.1 → 0.1.2
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/Gemfile.lock +1 -1
- data/README.md +9 -19
- data/gemfiles/version_2016.gemfile.lock +4 -2
- data/gemfiles/version_2017a.gemfile.lock +4 -2
- data/gemfiles/version_2017b.gemfile.lock +4 -2
- data/gemfiles/version_2018.gemfile.lock +4 -2
- data/lib/firebase_dynamic_link.rb +7 -0
- data/lib/firebase_dynamic_link/client.rb +48 -18
- data/lib/firebase_dynamic_link/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68097ad4857f4630938203f52a41e070468ca86b
|
4
|
+
data.tar.gz: 10e4a64a80f75e0f14e8ea567ccbb08615e41977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76edc91a6a5c37bbc4e5a6822523cc38c76a57fedc0ca29d0bf51900ba2e392aee4984516d89f5f88071ccb9a9d164be8a6fefbd97bf00a420d8e520e01f49aa
|
7
|
+
data.tar.gz: 1e944261c7925b97325f7ab728007f5b74d208d7ddde5c6ad7c30fa8a82af62ebf2d51189c8a925a15eaf4cadcde1b447388c5727ae9bc4a31c0d9175d93d62d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,12 +40,17 @@ FirebaseDynamicLink.configure do |config|
|
|
40
40
|
config.default.suffix.option = 'SHORTEN' or 'UNGUESSABLE'
|
41
41
|
|
42
42
|
config.default.dynamic_link_domain = 'http://xyz.app.goo.gl'
|
43
|
+
|
44
|
+
config.timeout = 3 # timeout and open timeout for global request
|
45
|
+
config.open_timeout = 3
|
43
46
|
end
|
44
47
|
|
45
48
|
client = FirebaseDynamicLink::Client.new
|
46
49
|
options = {
|
47
|
-
suffix_option: '' # to override default suffix default config
|
48
|
-
dynamic_link_domain: '' # to override default dynamic_link_domain default config
|
50
|
+
suffix_option: '', # to override default suffix default config
|
51
|
+
dynamic_link_domain: '', # to override default dynamic_link_domain default config
|
52
|
+
timeout: 10, # timeout and open timeout for each request
|
53
|
+
open_timeout: 10
|
49
54
|
}
|
50
55
|
result = client.shorten_link(link, options)
|
51
56
|
# options argument is optional
|
@@ -56,7 +61,6 @@ if request successful, then the result should be like following hash object
|
|
56
61
|
|
57
62
|
```ruby
|
58
63
|
{
|
59
|
-
:success=>true,
|
60
64
|
:link=>"https://--.app.goo.gl/ukph",
|
61
65
|
:preview_link=>"https://--.app.goo.gl/ukph?d=1",
|
62
66
|
:warning=>[
|
@@ -69,25 +73,11 @@ if request successful, then the result should be like following hash object
|
|
69
73
|
{
|
70
74
|
"warningCode"=>"..."
|
71
75
|
}
|
72
|
-
]
|
73
|
-
:error_message=>nil,
|
74
|
-
:error_status=>nil,
|
75
|
-
:error_code=>nil
|
76
|
+
]
|
76
77
|
}
|
77
78
|
```
|
78
79
|
|
79
|
-
otherwise
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
{ :success=>false,
|
83
|
-
:link=>nil,
|
84
|
-
:preview_link=>nil,
|
85
|
-
:warning=>nil,
|
86
|
-
:error_message=>"Long link is not parsable: ...",
|
87
|
-
:error_status=>"INVALID_ARGUMENT",
|
88
|
-
:error_code=>400
|
89
|
-
}
|
90
|
-
```
|
80
|
+
otherwise it raises FirebaseDynamicLink::ConnectionError exception, with message = http error message
|
91
81
|
|
92
82
|
# NOTE
|
93
83
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
firebase_dynamic_link (0.1.
|
4
|
+
firebase_dynamic_link (0.1.2)
|
5
|
+
dry-configurable (~> 0.5, >= 0.5.0)
|
6
|
+
faraday (~> 0.9, >= 0.9.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
@@ -44,7 +46,7 @@ PLATFORMS
|
|
44
46
|
ruby
|
45
47
|
|
46
48
|
DEPENDENCIES
|
47
|
-
appraisal
|
49
|
+
appraisal (~> 2.2.0)
|
48
50
|
bundler (~> 1.16)
|
49
51
|
dotenv (~> 2.2, >= 2.2.2)
|
50
52
|
dry-configurable (= 0.5.0)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
firebase_dynamic_link (0.1.
|
4
|
+
firebase_dynamic_link (0.1.2)
|
5
|
+
dry-configurable (~> 0.5, >= 0.5.0)
|
6
|
+
faraday (~> 0.9, >= 0.9.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
@@ -44,7 +46,7 @@ PLATFORMS
|
|
44
46
|
ruby
|
45
47
|
|
46
48
|
DEPENDENCIES
|
47
|
-
appraisal
|
49
|
+
appraisal (~> 2.2.0)
|
48
50
|
bundler (~> 1.16)
|
49
51
|
dotenv (~> 2.2, >= 2.2.2)
|
50
52
|
dry-configurable (= 0.6.0)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
firebase_dynamic_link (0.1.
|
4
|
+
firebase_dynamic_link (0.1.2)
|
5
|
+
dry-configurable (~> 0.5, >= 0.5.0)
|
6
|
+
faraday (~> 0.9, >= 0.9.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
@@ -44,7 +46,7 @@ PLATFORMS
|
|
44
46
|
ruby
|
45
47
|
|
46
48
|
DEPENDENCIES
|
47
|
-
appraisal
|
49
|
+
appraisal (~> 2.2.0)
|
48
50
|
bundler (~> 1.16)
|
49
51
|
dotenv (~> 2.2, >= 2.2.2)
|
50
52
|
dry-configurable (= 0.6.0)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
firebase_dynamic_link (0.1.
|
4
|
+
firebase_dynamic_link (0.1.2)
|
5
|
+
dry-configurable (~> 0.5, >= 0.5.0)
|
6
|
+
faraday (~> 0.9, >= 0.9.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
@@ -44,7 +46,7 @@ PLATFORMS
|
|
44
46
|
ruby
|
45
47
|
|
46
48
|
DEPENDENCIES
|
47
|
-
appraisal
|
49
|
+
appraisal (~> 2.2.0)
|
48
50
|
bundler (~> 1.16)
|
49
51
|
dotenv (~> 2.2, >= 2.2.2)
|
50
52
|
dry-configurable (= 0.7.0)
|
@@ -7,6 +7,7 @@ module FirebaseDynamicLink
|
|
7
7
|
extend Dry::Configurable
|
8
8
|
|
9
9
|
class InvalidConfig < StandardError; end
|
10
|
+
class ConnectionError < StandardError; end
|
10
11
|
|
11
12
|
# You can change it to
|
12
13
|
# FirebaseDynamicLink.adapter = :patron
|
@@ -19,6 +20,12 @@ module FirebaseDynamicLink
|
|
19
20
|
|
20
21
|
setting :api_key
|
21
22
|
|
23
|
+
# Timeout default setting is 3 seconds
|
24
|
+
setting :timeout, 3
|
25
|
+
|
26
|
+
# Open timeout default setting is 3 seconds
|
27
|
+
setting :open_timeout, 3
|
28
|
+
|
22
29
|
# This domain will be used if dynamic_link_domain setting is nil
|
23
30
|
# it raises error if both of settings are nil
|
24
31
|
setting :default do
|
@@ -8,28 +8,24 @@ module FirebaseDynamicLink
|
|
8
8
|
# status >= 400
|
9
9
|
# body {"error"=>{"code"=>400, "message"=>"Long link is not parsable: https://k4mu4.app.goo.gl?link=abcde [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]", "status"=>"INVALID_ARGUMENT"}}
|
10
10
|
def shorten_link(link, options = {})
|
11
|
+
build_connection_options(connection, options)
|
12
|
+
|
11
13
|
suffix_option = options.delete(:suffix_option)
|
12
14
|
suffix_option ||= config.default.suffix.option
|
13
|
-
|
14
|
-
dynamic_link_domain ||= config.default.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig, 'Dynamic link domain is empty')
|
15
|
-
link = "#{dynamic_link_domain}?link=#{link}"
|
15
|
+
|
16
16
|
response = connection.post(nil, {
|
17
|
-
longDynamicLink: link,
|
17
|
+
longDynamicLink: build_link(link, options),
|
18
18
|
suffix: {
|
19
19
|
option: suffix_option
|
20
20
|
}
|
21
21
|
}.to_json)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
error_message: has_error ? body['error']['message'] : nil,
|
30
|
-
error_status: has_error ? body['error']['status'] : nil,
|
31
|
-
error_code: has_error ? body['error']['code'] : nil
|
32
|
-
}
|
22
|
+
if response.status.between?(200, 299)
|
23
|
+
render_success(response)
|
24
|
+
else
|
25
|
+
raise_error(response)
|
26
|
+
end
|
27
|
+
rescue Faraday::ConnectionFailed => e
|
28
|
+
raise FirebaseDynamicLink::ConnectionError, e.message
|
33
29
|
end
|
34
30
|
|
35
31
|
def shorten_object(_json_object)
|
@@ -38,10 +34,21 @@ module FirebaseDynamicLink
|
|
38
34
|
|
39
35
|
private
|
40
36
|
|
37
|
+
def build_link(link, options)
|
38
|
+
dynamic_link_domain = options.delete(:dynamic_link_domain)
|
39
|
+
dynamic_link_domain ||= config.default.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig, 'Dynamic link domain is empty')
|
40
|
+
"#{dynamic_link_domain}?link=#{link}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_connection_options(c, options)
|
44
|
+
c.options.timeout = 1 if options.key?(:timeout)
|
45
|
+
c.options.open_timeout = 1 if options.key?(:open_timeout)
|
46
|
+
c
|
47
|
+
end
|
48
|
+
|
41
49
|
def connection
|
42
|
-
|
43
|
-
|
44
|
-
con
|
50
|
+
@connection ||= Faraday::Connection.new(url: end_point,
|
51
|
+
headers: { 'Content-Type' => 'application/json' })
|
45
52
|
end
|
46
53
|
|
47
54
|
def config
|
@@ -51,5 +58,28 @@ module FirebaseDynamicLink
|
|
51
58
|
def end_point
|
52
59
|
"https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=#{config.api_key}"
|
53
60
|
end
|
61
|
+
|
62
|
+
def raise_error(response)
|
63
|
+
message = response.reason_phrase if response.respond_to?(:reason_phrase)
|
64
|
+
if message.nil?
|
65
|
+
message = begin
|
66
|
+
body = JSON.parse(response.body)
|
67
|
+
body['error']['message']
|
68
|
+
rescue
|
69
|
+
response.body
|
70
|
+
end
|
71
|
+
end
|
72
|
+
raise FirebaseDynamicLink::ConnectionError, message
|
73
|
+
end
|
74
|
+
|
75
|
+
def render_success(response)
|
76
|
+
body = JSON.parse(response.body)
|
77
|
+
has_error = body.key?('error')
|
78
|
+
{
|
79
|
+
link: has_error ? nil : body['shortLink'],
|
80
|
+
preview_link: has_error ? nil : body['previewLink'],
|
81
|
+
warning: has_error ? nil : body['warning']
|
82
|
+
}
|
83
|
+
end
|
54
84
|
end
|
55
85
|
end
|