firebase_dynamic_link 0.1.3 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bbe6a0cad3172b77570b15cff0e5b0f2fe7f269
4
- data.tar.gz: ca41acc8781f8df96553abce36c10a4a17b3cf17
3
+ metadata.gz: 8b8833e89c026a88c4375d66c0b9eec4e0e62b3f
4
+ data.tar.gz: 32431d2b24ed100688667c1b934a17fdfa3d2b82
5
5
  SHA512:
6
- metadata.gz: db1298ece8caed00932db3a5a0e3d6182e2c1284f797fc92635eccb9aa02c79c3da00bf00383928a6376c28532fecd22bfe36068b953179083ca3d95aba20920
7
- data.tar.gz: d3b9e410ffb53da8e8b759ffe15bdd89e5764a2e5b1d104f699c3ddfc64a0328fa92e2963bc64cba32617768393f7ec140a39229bb5ae31c14b963ffb39294fd
6
+ metadata.gz: e6b997cb918cbd0a3efcf22f253576ccf626afaf7e93728c8431c42b0e1f289557d8b0e8c503a1566b5de96dcce206f1f4d7c9e2a39cf26af61f24a8898d5868
7
+ data.tar.gz: aade124ecd68188957b5b0ecae65e013f5141037ef1546f5e3b73192e36e077dd823bbf2b8489a9e93da5e44743398b17ea7e084d1372efefbf86edd225e0522
data/.rubocop.yml CHANGED
@@ -3,3 +3,144 @@ Metrics/BlockLength:
3
3
  - 'Rakefile'
4
4
  - '**/*.rake'
5
5
  - 'spec/**/*.rb'
6
+
7
+ # Prefer &&/|| over and/or.
8
+ Style/AndOr:
9
+ Enabled: true
10
+
11
+ # Do not use braces for hash literals when they are the last argument of a
12
+ # method call.
13
+ Style/BracesAroundHashParameters:
14
+ Enabled: true
15
+ EnforcedStyle: context_dependent
16
+
17
+ # Align `when` with `case`.
18
+ Layout/CaseIndentation:
19
+ Enabled: true
20
+
21
+ # Align comments with method definitions.
22
+ Layout/CommentIndentation:
23
+ Enabled: true
24
+
25
+ Layout/ElseAlignment:
26
+ Enabled: true
27
+
28
+ # Align `end` with the matching keyword or starting expression except for
29
+ # assignments, where it should be aligned with the LHS.
30
+ Layout/EndAlignment:
31
+ Enabled: true
32
+ EnforcedStyleAlignWith: variable
33
+ AutoCorrect: true
34
+
35
+ Layout/EmptyLineAfterMagicComment:
36
+ Enabled: true
37
+
38
+ # In a regular class definition, no empty lines around the body.
39
+ Layout/EmptyLinesAroundClassBody:
40
+ Enabled: true
41
+
42
+ # In a regular method definition, no empty lines around the body.
43
+ Layout/EmptyLinesAroundMethodBody:
44
+ Enabled: true
45
+
46
+ # In a regular module definition, no empty lines around the body.
47
+ Layout/EmptyLinesAroundModuleBody:
48
+ Enabled: true
49
+
50
+ Layout/FirstParameterIndentation:
51
+ Enabled: true
52
+
53
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
54
+ Style/HashSyntax:
55
+ Enabled: true
56
+
57
+ # Two spaces, no tabs (for indentation).
58
+ Layout/IndentationWidth:
59
+ Enabled: true
60
+
61
+ Layout/LeadingCommentSpace:
62
+ Enabled: true
63
+
64
+ Layout/SpaceAfterColon:
65
+ Enabled: true
66
+
67
+ Layout/SpaceAfterComma:
68
+ Enabled: true
69
+
70
+ Layout/SpaceAroundEqualsInParameterDefault:
71
+ Enabled: true
72
+
73
+ Layout/SpaceAroundKeyword:
74
+ Enabled: true
75
+
76
+ Layout/SpaceAroundOperators:
77
+ Enabled: true
78
+
79
+ Layout/SpaceBeforeComma:
80
+ Enabled: true
81
+
82
+ Layout/SpaceBeforeFirstArg:
83
+ Enabled: true
84
+
85
+ Style/DefWithParentheses:
86
+ Enabled: true
87
+
88
+ # Defining a method with parameters needs parentheses.
89
+ Style/MethodDefParentheses:
90
+ Enabled: true
91
+
92
+ Style/FrozenStringLiteralComment:
93
+ Enabled: true
94
+ EnforcedStyle: always
95
+
96
+ # Use `foo {}` not `foo{}`.
97
+ Layout/SpaceBeforeBlockBraces:
98
+ Enabled: true
99
+
100
+ # Use `foo { bar }` not `foo {bar}`.
101
+ Layout/SpaceInsideBlockBraces:
102
+ Enabled: true
103
+
104
+ # Use `{ a: 1 }` not `{a:1}`.
105
+ Layout/SpaceInsideHashLiteralBraces:
106
+ Enabled: true
107
+
108
+ Layout/SpaceInsideParens:
109
+ Enabled: true
110
+
111
+ # Check quotes usage according to lint rule below.
112
+ Style/StringLiterals:
113
+ Enabled: true
114
+ EnforcedStyle: double_quotes
115
+
116
+ # Detect hard tabs, no hard tabs.
117
+ Layout/Tab:
118
+ Enabled: true
119
+
120
+ # Blank lines should not have any spaces.
121
+ Layout/TrailingBlankLines:
122
+ Enabled: true
123
+
124
+ # No trailing whitespace.
125
+ Layout/TrailingWhitespace:
126
+ Enabled: true
127
+
128
+ # Use quotes for string literals when they are enough.
129
+ Style/UnneededPercentQ:
130
+ Enabled: true
131
+
132
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
133
+ Lint/RequireParentheses:
134
+ Enabled: true
135
+
136
+ Style/RedundantReturn:
137
+ Enabled: true
138
+ AllowMultipleReturnValues: true
139
+
140
+ Style/Semicolon:
141
+ Enabled: true
142
+ AllowAsExpressionSeparator: true
143
+
144
+ # Prefer Foo.method over Foo::method
145
+ Style/ColonMethodCall:
146
+ Enabled: true
data/Appraisals CHANGED
@@ -1,19 +1,21 @@
1
- appraise 'version-2018' do
2
- gem 'dry-configurable', '0.7.0'
3
- gem 'faraday', '0.14.0'
1
+ # frozen_string_literal: true
2
+
3
+ appraise "version-2018" do
4
+ gem "dry-configurable", "0.7.0"
5
+ gem "faraday", "0.14.0"
4
6
  end
5
7
 
6
- appraise 'version-2017b' do
7
- gem 'dry-configurable', '0.6.0'
8
- gem 'faraday', '0.11.0'
8
+ appraise "version-2017b" do
9
+ gem "dry-configurable", "0.6.0"
10
+ gem "faraday", "0.11.0"
9
11
  end
10
12
 
11
- appraise 'version-2017a' do
12
- gem 'dry-configurable', '0.6.0'
13
- gem 'faraday', '0.10.1'
13
+ appraise "version-2017a" do
14
+ gem "dry-configurable", "0.6.0"
15
+ gem "faraday", "0.10.1"
14
16
  end
15
17
 
16
- appraise 'version-2016' do
17
- gem 'dry-configurable', '0.5.0'
18
- gem 'faraday', '0.9.2'
18
+ appraise "version-2016" do
19
+ gem "dry-configurable", "0.5.0"
20
+ gem "faraday", "0.9.2"
19
21
  end
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in firebase_dynamic_link.gemspec
6
8
  gemspec
9
+
10
+ # group :development do
11
+ # gem 'guard'
12
+ # gem 'guard-rspec'
13
+ # end
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- firebase_dynamic_link (0.1.3)
5
- dry-configurable (~> 0.5, >= 0.5.0)
4
+ firebase_dynamic_link (1.0.0)
5
+ dry-configurable (~> 0.6, >= 0.6.0)
6
6
  faraday (~> 0.9, >= 0.9.2)
7
7
 
8
8
  GEM
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/README.md CHANGED
@@ -13,9 +13,7 @@ based on reference https://firebase.google.com/docs/reference/dynamic-links/link
13
13
 
14
14
  Add this line to your application's Gemfile:
15
15
 
16
- ```ruby
17
- gem 'firebase_dynamic_link'
18
- ```
16
+ gem 'firebase_dynamic_link'
19
17
 
20
18
  And then execute:
21
19
 
@@ -30,74 +28,108 @@ Or install it yourself as:
30
28
  ### Configure the HTTP client
31
29
 
32
30
  ```ruby
33
- FirebaseDynamicLink.configure do |config|
34
- # the adapter should be supported by Faraday
35
- # more info look at https://github.com/lostisland/faraday/tree/master/test/adapters
36
- # Faraday.default_adapter is the default adapter
37
- config.adapter = :httpclient
31
+ FirebaseDynamicLink.configure do |config|
32
+ # the adapter should be supported by Faraday
33
+ # more info look at https://github.com/lostisland/faraday/tree/master/test/adapters
34
+ # Faraday.default_adapter is the default adapter
35
+ config.adapter = :httpclient
38
36
 
39
- # required
40
- config.api_key = 'API_KEY'
37
+ # required
38
+ config.api_key = 'API_KEY'
41
39
 
42
- # default 'UNGUESSABLE'
43
- config.default.suffix.option = 'SHORT' or 'UNGUESSABLE'
40
+ # default 'UNGUESSABLE'
41
+ config.suffix_option = 'SHORT' or 'UNGUESSABLE'
44
42
 
45
- # required
46
- config.default.dynamic_link_domain = 'http://xyz.app.goo.gl'
43
+ # required, Don't put http://
44
+ config.dynamic_link_domain = 'xyz.app.goo.gl'
47
45
 
48
- # default 3 seconds
49
- config.timeout = 3
46
+ # default 3 seconds
47
+ config.timeout = 3
50
48
 
51
- # default 3 seconds
52
- config.open_timeout = 3
53
- end
49
+ # default 3 seconds
50
+ config.open_timeout = 3
51
+ end
52
+ ```
54
53
 
55
- client = FirebaseDynamicLink::Client.new
56
- options = {
57
- # optional, to override default suffix default config
58
- suffix_option: '',
54
+ ### Shorten a link
59
55
 
60
- # optional, to override default dynamic_link_domain default config
61
- dynamic_link_domain: '',
56
+ ```ruby
57
+ client = FirebaseDynamicLink::Client.new
58
+ link = "http://domain.com/path/path"
59
+ options = {
60
+ # optional, to override default suffix default config
61
+ suffix_option: '',
62
62
 
63
- # optional, timeout of each request of this instance
64
- timeout: 10,
63
+ # optional, to override default dynamic_link_domain default config
64
+ dynamic_link_domain: '',
65
65
 
66
- # optional, open timeout of each request of this instance
67
- open_timeout: 10
68
- }
66
+ # optional, timeout of each request of this instance
67
+ timeout: 10,
69
68
 
70
- # options argument is optional
71
- result = client.shorten_link(link, options)
69
+ # optional, open timeout of each request of this instance
70
+ open_timeout: 10
71
+ }
72
72
 
73
+ # options argument is optional
74
+ result = client.shorten_link(link, options)
73
75
  ```
74
76
 
75
- if request successful, then the result should be like following hash object
77
+ ### Shorten parameters
76
78
 
77
79
  ```ruby
78
- {
79
- :link=>"https://--.app.goo.gl/ukph",
80
- :preview_link=>"https://--.app.goo.gl/ukph?d=1",
81
- :warning=>[
82
- {
83
- "warningCode"=>"UNRECOGNIZED_PARAM",
84
- "warningMessage"=>"..."},
85
- {
86
- "warningCode"=>"..."
87
- },
88
- {
89
- "warningCode"=>"..."
90
- }
91
- ]
92
- }
80
+ client = FirebaseDynamicLink::Client.new
81
+ options = {
82
+ # optional, to override default suffix default config
83
+ suffix_option: '',
84
+
85
+ # optional, to override default dynamic_link_domain default config
86
+ dynamic_link_domain: '',
87
+
88
+ # optional, timeout of each request of this instance
89
+ timeout: 10,
90
+
91
+ # optional, open timeout of each request of this instance
92
+ open_timeout: 10
93
+ }
94
+
95
+ parameters = {
96
+ link: link,
97
+ android_info: {
98
+ android_package_name: name,
99
+ }
100
+ ios_info: {},
101
+ navigation_info: {},
102
+ analytics_info: {},
103
+ social_meta_tag_info: {}
104
+ }
105
+
106
+ # options argument is optional
107
+ result = client.shorten_parameters(parameters, options)
93
108
  ```
94
109
 
95
- otherwise it raises `FirebaseDynamicLink::ConnectionError`, with message = http error message
110
+ if request successful, then the result should be like following hash object
111
+
112
+ or if the request reached daily quota, client will throw `FirebaseDynamicLink::QuotaExceeded` error
96
113
 
97
- # NOTE
114
+ ```ruby
115
+ {
116
+ :link=>"https://--.app.goo.gl/ukph",
117
+ :preview_link=>"https://--.app.goo.gl/ukph?d=1",
118
+ :warning=>[
119
+ {
120
+ "warningCode"=>"UNRECOGNIZED_PARAM",
121
+ "warningMessage"=>"..."},
122
+ {
123
+ "warningCode"=>"..."
124
+ },
125
+ {
126
+ "warningCode"=>"..."
127
+ }
128
+ ]
129
+ }
130
+ ```
98
131
 
99
- this gem only implemented to shorten long dynamic link til now, next version is supposed to
100
- be able shorten a JSON object
132
+ otherwise it will throw `FirebaseDynamicLink::ConnectionError` error, with message = http error message
101
133
 
102
134
  ## Development
103
135
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "firebase_dynamic_link"
@@ -1,37 +1,39 @@
1
1
 
2
- lib = File.expand_path('../lib', __FILE__)
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("lib", __dir__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'firebase_dynamic_link/version'
6
+ require "firebase_dynamic_link/version"
5
7
 
6
8
  Gem::Specification.new do |spec|
7
- spec.name = 'firebase_dynamic_link'
9
+ spec.name = "firebase_dynamic_link"
8
10
  spec.version = FirebaseDynamicLink::VERSION
9
- spec.authors = ['M Saiqul Haq']
10
- spec.email = ['saiqulhaq@gmail.com']
11
+ spec.authors = ["M Saiqul Haq"]
12
+ spec.email = ["saiqulhaq@gmail.com"]
11
13
 
12
- spec.summary = 'Ruby client for Firebase Dynamic Link service'
14
+ spec.summary = "Ruby client for Firebase Dynamic Link service"
13
15
  spec.description = spec.summary
14
- spec.homepage = 'https://github.com/saiqulhaq/firebase_dynamic_link'
15
- spec.license = 'MIT'
16
- spec.metadata["yard.run"] = 'yri'
16
+ spec.homepage = "https://github.com/saiqulhaq/firebase_dynamic_link"
17
+ spec.license = "MIT"
18
+ spec.metadata["yard.run"] = "yri"
17
19
 
18
20
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
21
  f.match(%r{^(test|spec|features)/})
20
22
  end
21
- spec.bindir = 'exe'
23
+ spec.bindir = "exe"
22
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ['lib']
25
+ spec.require_paths = ["lib"]
24
26
 
25
- spec.add_runtime_dependency 'dry-configurable', '~> 0.5', '>= 0.5.0'
26
- spec.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.2'
27
+ spec.add_runtime_dependency "dry-configurable", "~> 0.6", ">= 0.6.0"
28
+ spec.add_runtime_dependency "faraday", "~> 0.9", ">= 0.9.2"
27
29
 
28
- spec.add_development_dependency 'appraisal', '~> 2.2.0'
29
- spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
30
- spec.add_development_dependency 'dotenv', '~> 2.2', '>= 2.2.2'
31
- spec.add_development_dependency 'bundler', '~> 1.16'
32
- spec.add_development_dependency 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'pry', '~> 0.11.3'
35
- spec.add_development_dependency 'bootsnap', '~> 1.3.0'
36
- spec.add_development_dependency 'simplecov', '>= 0.16.1'
30
+ spec.add_development_dependency "appraisal", "~> 2.2.0"
31
+ spec.add_development_dependency "bootsnap", "~> 1.3.0"
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "dotenv", "~> 2.2", ">= 2.2.2"
34
+ spec.add_development_dependency "pry", "~> 0.11.3"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "simplecov", ">= 0.16.1"
38
+ spec.add_development_dependency "vcr", "~> 4.0", ">= 4.0.0"
37
39
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "dry-configurable", "0.5.0"
5
+ gem "dry-configurable", "0.6.0"
6
6
  gem "faraday", "0.9.2"
7
7
 
8
8
  gemspec path: "../"
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- firebase_dynamic_link (0.1.3)
5
- dry-configurable (~> 0.5, >= 0.5.0)
4
+ firebase_dynamic_link (1.0.0)
5
+ dry-configurable (~> 0.6, >= 0.6.0)
6
6
  faraday (~> 0.9, >= 0.9.2)
7
7
 
8
8
  GEM
@@ -18,8 +18,8 @@ GEM
18
18
  concurrent-ruby (1.0.5)
19
19
  diff-lcs (1.3)
20
20
  docile (1.3.0)
21
- dotenv (2.2.2)
22
- dry-configurable (0.5.0)
21
+ dotenv (2.4.0)
22
+ dry-configurable (0.6.0)
23
23
  concurrent-ruby (~> 1.0)
24
24
  faraday (0.9.2)
25
25
  multipart-post (>= 1.2, < 3)
@@ -60,7 +60,7 @@ DEPENDENCIES
60
60
  bootsnap (~> 1.3.0)
61
61
  bundler (~> 1.16)
62
62
  dotenv (~> 2.2, >= 2.2.2)
63
- dry-configurable (= 0.5.0)
63
+ dry-configurable (= 0.6.0)
64
64
  faraday (= 0.9.2)
65
65
  firebase_dynamic_link!
66
66
  pry (~> 0.11.3)
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- firebase_dynamic_link (0.1.3)
5
- dry-configurable (~> 0.5, >= 0.5.0)
4
+ firebase_dynamic_link (1.0.0)
5
+ dry-configurable (~> 0.6, >= 0.6.0)
6
6
  faraday (~> 0.9, >= 0.9.2)
7
7
 
8
8
  GEM
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- firebase_dynamic_link (0.1.3)
5
- dry-configurable (~> 0.5, >= 0.5.0)
4
+ firebase_dynamic_link (1.0.0)
5
+ dry-configurable (~> 0.6, >= 0.6.0)
6
6
  faraday (~> 0.9, >= 0.9.2)
7
7
 
8
8
  GEM
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- firebase_dynamic_link (0.1.3)
5
- dry-configurable (~> 0.5, >= 0.5.0)
4
+ firebase_dynamic_link (1.0.0)
5
+ dry-configurable (~> 0.6, >= 0.6.0)
6
6
  faraday (~> 0.9, >= 0.9.2)
7
7
 
8
8
  GEM
@@ -1,40 +1,90 @@
1
- require 'dry-configurable'
2
- require 'faraday'
3
- require 'firebase_dynamic_link/client'
4
- require 'firebase_dynamic_link/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-configurable"
4
+ require "faraday"
5
+ require "firebase_dynamic_link/client"
6
+ require "firebase_dynamic_link/link_renderer"
7
+ require "firebase_dynamic_link/version"
5
8
 
6
9
  module FirebaseDynamicLink
7
10
  extend Dry::Configurable
8
11
 
12
+ # called when invalid configuration given
9
13
  class InvalidConfig < StandardError; end
14
+
15
+ # called when HTTP request failed
10
16
  class ConnectionError < StandardError; end
11
17
 
12
- # You can change it to
13
- # FirebaseDynamicLink.adapter = :patron
14
- # FirebaseDynamicLink.adapter = :httpclient
15
- # FirebaseDynamicLink.adapter = :net_http_persistent
16
- #
17
- # And get the value by
18
- # FirebaseDynamicLink.adapter
18
+ # called when Firebase says that no more quota
19
+ class QuotaExceeded < StandardError; end
20
+
21
+ # @!group Configuration
22
+ # @!method adapter
23
+ # @!scope class
24
+ # Selected Faraday HTTP adapter
25
+ # @!method adapter=(adapter_key)
26
+ # @!scope class
27
+ # Set Faraday HTTP adapter
28
+ # @param adapter_key [Symbol]
29
+ # @example
30
+ # FirebaseDynamicLink.adapter = :patron
31
+ # FirebaseDynamicLink.adapter = :httpclient
32
+ # FirebaseDynamicLink.adapter = :net_http_persistent
33
+ # @see https://github.com/lostisland/faraday/tree/master/test/adapters
34
+ # @since 0.1.0
19
35
  setting :adapter, Faraday.default_adapter
20
36
 
37
+ # @!method api_key
38
+ # @!scope class
39
+ # Given api key
40
+ # @!method api_key=(key)
41
+ # @!scope class
42
+ # Set api key
43
+ # @param key [String]
44
+ # @since 0.1.0
21
45
  setting :api_key
22
46
 
23
- # Timeout default setting is 3 seconds
47
+ # @!method timout
48
+ # Timeout default setting is 3 seconds
49
+ # @!scope class
50
+ # @!method timout=(seconds)
51
+ # @!scope class
52
+ # @param seconds [Integer]
53
+ # @since 0.1.0
54
+ # @!scope class
24
55
  setting :timeout, 3
25
56
 
26
- # Open timeout default setting is 3 seconds
57
+ # @!method open_timout
58
+ # @!scope class
59
+ # Open timeout default setting is 3 seconds
60
+ # @!method open_timout=(seconds)
61
+ # @!scope class
62
+ # @param seconds [Integer]
63
+ # @since 0.1.0
64
+ # @!scope class
27
65
  setting :open_timeout, 3
28
66
 
29
- # This domain will be used if dynamic_link_domain setting is nil
30
- # it raises error if both of settings are nil
31
- setting :default do
32
- # Firebase dynamic link domain
33
- setting(:dynamic_link_domain)
34
- setting :suffix do
35
- setting(:option, 'UNGUESSABLE') { |value|
36
- %w(SHORT UNGUESSABLE).include?(value) ? value : raise(FirebaseDynamicLink::InvalidConfig, 'default suffix option config is not valie')
37
- }
38
- end
67
+ # @!method dynamic_link_domain
68
+ # @!scope class
69
+ # Firebase dynamic link domain
70
+ # @!method dynamic_link_domain=(domain)
71
+ # @!scope class
72
+ # @param domain [String]
73
+ # @since 1.0.0
74
+ # @!scope class
75
+ setting(:dynamic_link_domain)
76
+
77
+ # @!method suffix_option
78
+ # @!scope class
79
+ # Firebase suffix option setting, default is UNGUESSABLE
80
+ # @!method suffix_option=(suffix)
81
+ # @!scope class
82
+ # @raise [FirebaseDynamicLink::InvalidConfig] if value is not one of SHORT and UNGUESSABLE
83
+ # @param suffix [String]
84
+ # @since 1.0.0
85
+ # @!scope class
86
+ setting(:suffix_option, "UNGUESSABLE") do |value|
87
+ %w[SHORT UNGUESSABLE].include?(value) ? value : raise(FirebaseDynamicLink::InvalidConfig, "default suffix option config is not valid")
39
88
  end
89
+ # @!endgroup
40
90
  end
@@ -1,85 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "firebase_dynamic_link/connection"
4
+ require "firebase_dynamic_link/link_renderer"
5
+
1
6
  module FirebaseDynamicLink
7
+ # Main class that responsible to shorten link or parameters
2
8
  class Client
3
- attr_accessor :dynamic_link_domain
9
+ extend Forwardable
4
10
 
5
- # on succeed
6
- #
7
- # on failure
8
- # status >= 400
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"}}
11
+ def initialize
12
+ @link_renderer = FirebaseDynamicLink::LinkRenderer.new
13
+ @connection = FirebaseDynamicLink::Connection.new(end_point)
14
+ end
15
+
16
+ # @param link [String] required
17
+ # @param options [Hash]
18
+ # * :timeout optional, default is FirebaseDynamicLink.config.timout
19
+ # * :open_timeout [Integer] optional, default is FirebaseDynamicLink.config.open_timout
20
+ # * :suffix_option [String] optional, default is FirebaseDynamicLink.config.suffix_option
21
+ # * :dynamic_link_domain [String] optional, default is FirebaseDynamicLink.config.dynamic_link_domain
22
+ # @return [Hash{Symbol=>String}]
23
+ # @see FirebaseDynamicLink::LinkRenderer#render LinkRenderer#render for returned Hash
10
24
  def shorten_link(link, options = {})
11
- build_connection_options(connection, options)
25
+ connection.timeout = options[:timeout] if options.key?(:timeout)
26
+ connection.open_timeout = options[:open_timeout] if options.key?(:open_timeout)
12
27
 
13
- suffix_option = options.delete(:suffix_option)
14
- suffix_option ||= config.default.suffix.option
28
+ suffix_option = options[:suffix_option] if options.key?(:suffix_option)
15
29
 
16
30
  response = connection.post(nil, {
17
31
  longDynamicLink: build_link(link, options),
18
32
  suffix: {
19
- option: suffix_option
33
+ option: suffix_option || config.suffix_option
20
34
  }
21
35
  }.to_json)
22
- if response.status.between?(200, 299)
23
- render_success(response)
24
- else
25
- raise_error(response)
26
- end
36
+ link_renderer.render(response)
27
37
  rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
28
38
  raise FirebaseDynamicLink::ConnectionError, e.message
29
39
  end
30
40
 
31
- def shorten_object(_json_object)
32
- raise NotImplementedError
33
- end
41
+ # @param params [Hash]
42
+ # * link [String]
43
+ # * android_info [Hash]
44
+ # * android_package_name [String]
45
+ # * android_fallback_link [String]
46
+ # * android_min_package_version_code [String]
47
+ # * android_link [String]
48
+ # * ios_info [Hash]
49
+ # * ios_bundle_id [String]
50
+ # * ios_fallback_link [String]
51
+ # * ios_custom_scheme [String]
52
+ # * ios_ipad_fallback_link [String]
53
+ # * ios_ipad_bundle_id [String]
54
+ # * ios_app_store_id [String]
55
+ # * navigation_info [Hash]
56
+ # * enable_forced_redirect [Boolean]
57
+ # * analytics_info [Hash]
58
+ # * google_play_analytics [Hash]
59
+ # * utm_source [String]
60
+ # * utm_medium [String]
61
+ # * utm_campaign [String]
62
+ # * utm_term [String]
63
+ # * utm_content [String]
64
+ # * gclid [String]
65
+ # * itunes_connect_analytics [Hash]
66
+ # * at [String]
67
+ # * ct [String]
68
+ # * mt [String]
69
+ # * pt [String]
70
+ # * social_meta_tag_info [Hash]
71
+ # * social_title [String]
72
+ # * social_description [String]
73
+ # * social_image_link [String]
74
+ # @example
75
+ # options = {
76
+ # suffix_option: "SHORT",
77
+ # dynamic_link_domain: 'domain' # optional
78
+ # }
79
+ #
80
+ # parameters = {
81
+ # link: link,
82
+ # android_info: {
83
+ # android_package_name: string,
84
+ # android_fallback_link: string,
85
+ # android_min_package_version_code: string,
86
+ # android_link: string
87
+ # },
88
+ # ios_info: {
89
+ # ios_bundle_id: string,
90
+ # ios_fallback_link: string,
91
+ # ios_custom_scheme: string,
92
+ # ios_ipad_fallback_link: string,
93
+ # ios_ipad_bundle_id: string,
94
+ # ios_app_store_id: string
95
+ # },
96
+ # navigation_info: {
97
+ # enable_forced_redirect: boolean,
98
+ # },
99
+ # analytics_info: {
100
+ # google_play_analytics: {
101
+ # utm_source: string,
102
+ # utm_medium: string,
103
+ # utm_campaign: string,
104
+ # utm_term: string,
105
+ # utm_content: string,
106
+ # gclid: string
107
+ # },
108
+ # itunes_connect_analytics: {
109
+ # at: string,
110
+ # ct: string,
111
+ # mt: string,
112
+ # pt: string
113
+ # }
114
+ # },
115
+ # social_meta_tag_info: {
116
+ # social_title: string,
117
+ # social_description: string,
118
+ # social_image_link: string
119
+ # }
120
+ # }
121
+ # result = instance.shorten_parameters(parameters, options)
122
+ # @return [Hash{Symbol=>String}]
123
+ # @see FirebaseDynamicLink::LinkRenderer#render LinkRenderer#render for returned Hash
124
+ def shorten_parameters(params, options = {})
125
+ connection.timeout = options[:timeout] if options.key?(:timeout)
126
+ connection.open_timeout = options[:open_timeout] if options.key?(:open_timeout)
34
127
 
35
- private
128
+ suffix_option = options[:suffix_option] if options.key?(:suffix_option)
36
129
 
37
- def build_link(link, options)
38
130
  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
131
+ dynamic_link_domain ||= config.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig, "Dynamic link domain is empty")
42
132
 
43
- def build_connection_options(c, options)
44
- c.options.timeout = options.delete(:timeout) if options.key?(:timeout)
45
- c.options.open_timeout = options.delete(:open_timeout) if options.key?(:open_timeout)
46
- c
133
+ response = connection.post(nil, {
134
+ dynamicLinkInfo: params.merge(dynamicLinkDomain: dynamic_link_domain),
135
+ suffix: {
136
+ option: suffix_option || config.suffix_option
137
+ }
138
+ }.to_json)
139
+ link_renderer.render(response)
140
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
141
+ raise FirebaseDynamicLink::ConnectionError, e.message
47
142
  end
48
143
 
49
- def connection
50
- @connection ||= Faraday::Connection.new(url: end_point,
51
- headers: { 'Content-Type' => 'application/json' })
52
- end
144
+ private
53
145
 
54
- def config
55
- ::FirebaseDynamicLink.config
56
- end
146
+ def_delegators :@link_renderer, :render_success, :raise_error
147
+ def_delegators :FirebaseDynamicLink, :config
57
148
 
58
- def end_point
59
- "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=#{config.api_key}"
60
- end
149
+ attr_reader :link_renderer, :connection
61
150
 
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
151
+ def build_link(link, options)
152
+ dynamic_link_domain = options.delete(:dynamic_link_domain)
153
+ dynamic_link_domain ||= config.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig, "Dynamic link domain is empty")
154
+ "#{dynamic_link_domain}?link=#{link}"
73
155
  end
74
156
 
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
- }
157
+ def end_point
158
+ "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=#{config.api_key}"
83
159
  end
84
160
  end
85
161
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FirebaseDynamicLink
4
+ # Responsible to do HTTP request
5
+ class Connection
6
+ extend Forwardable
7
+
8
+ # @!method post
9
+ # see Faraday::Connection#post
10
+ def_delegators :client, :post
11
+
12
+ def initialize(end_point)
13
+ @client = Faraday::Connection.new(url: end_point,
14
+ headers: { "Content-Type" => "application/json" })
15
+
16
+ client.options.timeout = FirebaseDynamicLink.config.timeout
17
+ client.options.open_timeout = FirebaseDynamicLink.config.open_timeout
18
+ end
19
+
20
+ # @see Faraday.timeout=
21
+ def timeout=(time)
22
+ client.options.timeout = time
23
+ end
24
+
25
+ # @see Faraday.timeout
26
+ def timeout
27
+ client.options.timeout
28
+ end
29
+
30
+ # @see Faraday.open_timeout=
31
+ def open_timeout=(time)
32
+ client.options.open_timeout = time
33
+ end
34
+
35
+ # @see Faraday.open_timeout
36
+ def open_timeout
37
+ client.options.open_timeout
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :client
43
+ end
44
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FirebaseDynamicLink
4
+ # Responsible to formatting output of Client#shorten_link
5
+ class LinkRenderer
6
+ # @param response [Faraday::Connection] http reponse
7
+ # @return [Hash<Symbol, String or Hash>
8
+ # @example
9
+ # {
10
+ # :link => short link result
11
+ # :preview_link => preview of short link result
12
+ # :warning => warning message by Firebase if present
13
+ # }
14
+ # @raise FirebaseDynamicLink::ConnectionError if there is something wrong with Faraday request
15
+ # @raise FirebaseDynamicLink::QuotaExceeded if request reached Google Firebase quota
16
+ def render(response)
17
+ if response.status.between?(200, 299)
18
+ render_success(response)
19
+ elsif response.status == 429
20
+ raise_limit_has_reached
21
+ else
22
+ raise_error(response)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def render_success(response)
29
+ body = JSON.parse(response.body)
30
+ return raise_error(response) if body.key?("error")
31
+ {
32
+ link: body["shortLink"],
33
+ preview_link: body["previewLink"],
34
+ warning: body["warning"]
35
+ }
36
+ end
37
+
38
+ def raise_error(response)
39
+ reason = response.reason_phrase.to_s if response.respond_to?(:reason_phrase)
40
+ message = begin
41
+ body = JSON.parse(response.body)
42
+ body["error"]["message"]
43
+ rescue JSON::ParserError, NoMethodError
44
+ response.body
45
+ end
46
+ raise FirebaseDynamicLink::ConnectionError, [reason, message].compact.join(": ")
47
+ end
48
+
49
+ def raise_limit_has_reached
50
+ raise FirebaseDynamicLink::QuotaExceeded, "Request limit has been reached"
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FirebaseDynamicLink
2
- VERSION = "0.1.3"
4
+ VERSION = "1.0.0".freeze
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase_dynamic_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - M Saiqul Haq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-28 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.6'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.5.0
22
+ version: 0.6.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.5'
29
+ version: '0.6'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.5.0
32
+ version: 0.6.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -65,25 +65,33 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: 2.2.0
67
67
  - !ruby/object:Gem::Dependency
68
- name: vcr
68
+ name: bootsnap
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '4.0'
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 4.0.0
73
+ version: 1.3.0
77
74
  type: :development
78
75
  prerelease: false
79
76
  version_requirements: !ruby/object:Gem::Requirement
80
77
  requirements:
81
78
  - - "~>"
82
79
  - !ruby/object:Gem::Version
83
- version: '4.0'
84
- - - ">="
80
+ version: 1.3.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: bundler
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
85
86
  - !ruby/object:Gem::Version
86
- version: 4.0.0
87
+ version: '1.16'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.16'
87
95
  - !ruby/object:Gem::Dependency
88
96
  name: dotenv
89
97
  requirement: !ruby/object:Gem::Requirement
@@ -105,19 +113,19 @@ dependencies:
105
113
  - !ruby/object:Gem::Version
106
114
  version: 2.2.2
107
115
  - !ruby/object:Gem::Dependency
108
- name: bundler
116
+ name: pry
109
117
  requirement: !ruby/object:Gem::Requirement
110
118
  requirements:
111
119
  - - "~>"
112
120
  - !ruby/object:Gem::Version
113
- version: '1.16'
121
+ version: 0.11.3
114
122
  type: :development
115
123
  prerelease: false
116
124
  version_requirements: !ruby/object:Gem::Requirement
117
125
  requirements:
118
126
  - - "~>"
119
127
  - !ruby/object:Gem::Version
120
- version: '1.16'
128
+ version: 0.11.3
121
129
  - !ruby/object:Gem::Dependency
122
130
  name: rake
123
131
  requirement: !ruby/object:Gem::Requirement
@@ -147,47 +155,39 @@ dependencies:
147
155
  - !ruby/object:Gem::Version
148
156
  version: '3.0'
149
157
  - !ruby/object:Gem::Dependency
150
- name: pry
158
+ name: simplecov
151
159
  requirement: !ruby/object:Gem::Requirement
152
160
  requirements:
153
- - - "~>"
161
+ - - ">="
154
162
  - !ruby/object:Gem::Version
155
- version: 0.11.3
163
+ version: 0.16.1
156
164
  type: :development
157
165
  prerelease: false
158
166
  version_requirements: !ruby/object:Gem::Requirement
159
167
  requirements:
160
- - - "~>"
168
+ - - ">="
161
169
  - !ruby/object:Gem::Version
162
- version: 0.11.3
170
+ version: 0.16.1
163
171
  - !ruby/object:Gem::Dependency
164
- name: bootsnap
172
+ name: vcr
165
173
  requirement: !ruby/object:Gem::Requirement
166
174
  requirements:
167
175
  - - "~>"
168
176
  - !ruby/object:Gem::Version
169
- version: 1.3.0
170
- type: :development
171
- prerelease: false
172
- version_requirements: !ruby/object:Gem::Requirement
173
- requirements:
174
- - - "~>"
175
- - !ruby/object:Gem::Version
176
- version: 1.3.0
177
- - !ruby/object:Gem::Dependency
178
- name: simplecov
179
- requirement: !ruby/object:Gem::Requirement
180
- requirements:
177
+ version: '4.0'
181
178
  - - ">="
182
179
  - !ruby/object:Gem::Version
183
- version: 0.16.1
180
+ version: 4.0.0
184
181
  type: :development
185
182
  prerelease: false
186
183
  version_requirements: !ruby/object:Gem::Requirement
187
184
  requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '4.0'
188
188
  - - ">="
189
189
  - !ruby/object:Gem::Version
190
- version: 0.16.1
190
+ version: 4.0.0
191
191
  description: Ruby client for Firebase Dynamic Link service
192
192
  email:
193
193
  - saiqulhaq@gmail.com
@@ -204,6 +204,7 @@ files:
204
204
  - CODE_OF_CONDUCT.md
205
205
  - Gemfile
206
206
  - Gemfile.lock
207
+ - Guardfile
207
208
  - LICENSE.txt
208
209
  - README.md
209
210
  - Rakefile
@@ -221,6 +222,8 @@ files:
221
222
  - gemfiles/version_2018.gemfile.lock
222
223
  - lib/firebase_dynamic_link.rb
223
224
  - lib/firebase_dynamic_link/client.rb
225
+ - lib/firebase_dynamic_link/connection.rb
226
+ - lib/firebase_dynamic_link/link_renderer.rb
224
227
  - lib/firebase_dynamic_link/version.rb
225
228
  homepage: https://github.com/saiqulhaq/firebase_dynamic_link
226
229
  licenses: