inova_dynamic_link 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +116 -0
- data/Rakefile +14 -0
- data/inova_dynamic_link.gemspec +41 -0
- data/lib/generators/inova_dynamic_link/install_generator.rb +13 -0
- data/lib/generators/inova_dynamic_link/templates/inova_dynamic_link_initializer.rb +10 -0
- data/lib/inova_dynamic_link/branch.rb +74 -0
- data/lib/inova_dynamic_link/branch_link_configuration.rb +55 -0
- data/lib/inova_dynamic_link/configuration.rb +14 -0
- data/lib/inova_dynamic_link/unknown_attribute_error.rb +7 -0
- data/lib/inova_dynamic_link/version.rb +5 -0
- data/lib/inova_dynamic_link.rb +21 -0
- data/sig/inova_dynamic_link.rbs +4 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88f1da587f441baa45f5b9e555ab0cc6dff6043962e6885a2b2ad8ad5ae386e6
|
4
|
+
data.tar.gz: a49f6a6e519d25ed6f061b85b861f1ae7801fe2e21ef14462199ecfa64d87a25
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 812f27a66b5550c9274f10457870e12f8b79c53f84288eabe1b5a10abbb6dcc3bac8a50108a2d2c52f547d330fcff5b9cd02d9a80cad53cd1c8fef51f58036c8
|
7
|
+
data.tar.gz: bf0bc77d53f7db828044c2c40a4ba6a0540cb2748e930cd47c1903e1bb84994d641fc80ab729eb9c0e56d5795db308ea0eb9e546cb1bd68b2e0498e25a07890c
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ahmed.mosad@inovaeg.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Ahmed Mos`ad
|
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,116 @@
|
|
1
|
+
# InovaDynamicLink
|
2
|
+
|
3
|
+
InovaDynamicLink is a Ruby gem designed to streamline interactions with the Branch Dynamic Links service for Ruby applications. This gem provides a convenient interface for creating dynamic links using the [Branch](https://branch.io/) service.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To integrate InovaDynamicLink into your project, add the following line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'inova_dynamic_link', '~> 0.1.0'
|
11
|
+
```
|
12
|
+
|
13
|
+
Or, install the gem directly using the following command:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install inova_dynamic_link -v 0.1.0
|
17
|
+
```
|
18
|
+
|
19
|
+
## Requirements
|
20
|
+
|
21
|
+
- Ruby >= 3.1.2
|
22
|
+
- Rails >= 6.1
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```bash
|
27
|
+
rails generate inova_dynamic_link:install
|
28
|
+
```
|
29
|
+
|
30
|
+
This will generate a configuration file at config/initializers/inova_dynamic_link.rb. Open the file and set your Branch credentials:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
InovaDynamicLink.configure do |config|
|
34
|
+
# Set your Branch configuration options here
|
35
|
+
config.branch_key = "YOUR_BRANCH_KEY"
|
36
|
+
config.branch_secret = "YOUR_BRANCH_SECRET"
|
37
|
+
config.branch_access_token = "YOUR_BRANCH_ACCESS_TOKEN"
|
38
|
+
config.branch_app_id = "YOUR_BRANCH_APP_ID"
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Replace "YOUR_BRANCH_KEY", "YOUR_BRANCH_SECRET", "YOUR_BRANCH_ACCESS_TOKEN", and "YOUR_BRANCH_APP_ID" with your actual Branch credentials.
|
43
|
+
|
44
|
+
### Creating a Dynamic Link
|
45
|
+
|
46
|
+
here is an example of how to create a dynamic link:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
link_configuration = InovaDynamicLink::BranchLinkConfiguration.new(
|
50
|
+
channel: 'social',
|
51
|
+
feature: 'share',
|
52
|
+
campaign: 'spring_sale',
|
53
|
+
extra_data: { product_id: 123 }
|
54
|
+
)
|
55
|
+
dynamic_link = InovaDynamicLink::Branch.create(link_configuration)
|
56
|
+
puts "Dynamic Link: #{dynamic_link}"
|
57
|
+
```
|
58
|
+
|
59
|
+
Check out the [Branch documentation](https://help.branch.io/developers-hub/reference/createdeeplinkurl) for more information on the available configuration options.
|
60
|
+
Check out the [BranchLinkConfiguration class](https://github.com/ahmedmos3ad/inova_dynamic_link/blob/master/lib/inova_dynamic_link/branch_link_configuration.rb) for more information on the available configuration options.
|
61
|
+
|
62
|
+
### Bulk Link Creation
|
63
|
+
|
64
|
+
You can create multiple links at once using the following method:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
link_configurations = [
|
68
|
+
InovaDynamicLink::BranchLinkConfiguration.new(...),
|
69
|
+
InovaDynamicLink::BranchLinkConfiguration.new(...)
|
70
|
+
# Add more configurations as needed
|
71
|
+
]
|
72
|
+
dynamic_links = InovaDynamicLink::Branch.bulk_create(link_configurations)
|
73
|
+
puts "Dynamic Links: #{dynamic_links}"
|
74
|
+
```
|
75
|
+
|
76
|
+
### Retrieving a Dynamic Link
|
77
|
+
|
78
|
+
You can retrieve a dynamic link using the following method:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
url_to_check = "https://your.dynamic.link/url"
|
82
|
+
response = branch.get(url_to_check)
|
83
|
+
puts "Dynamic Link Information: #{response}"
|
84
|
+
```
|
85
|
+
|
86
|
+
### Deleting a Dynamic Link
|
87
|
+
|
88
|
+
You can delete a dynamic link using the following method:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
url_to_delete = "<https://your.dynamic.link/to/delete>"
|
92
|
+
result = branch.delete(url_to_delete)
|
93
|
+
puts "Delete Dynamic Link Result: #{result}"
|
94
|
+
```
|
95
|
+
|
96
|
+
### Updating a Dynamic Link
|
97
|
+
|
98
|
+
Updating a dynamic link is currently not supported by this gem, it will be added in a future release.
|
99
|
+
|
100
|
+
## Development
|
101
|
+
|
102
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
103
|
+
|
104
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/[ahmedmos3ad]/inova_dynamic_link>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[ahmedmos3ad]/inova_dynamic_link/blob/master/CODE_OF_CONDUCT.md).
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
113
|
+
|
114
|
+
## Code of Conduct
|
115
|
+
|
116
|
+
Everyone interacting in the InovaDynamicLink project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[ahmedmos3ad]/inova_dynamic_link/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "standard/rake"
|
13
|
+
|
14
|
+
task default: %i[test standard]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/inova_dynamic_link/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "inova_dynamic_link"
|
7
|
+
spec.version = InovaDynamicLink::VERSION
|
8
|
+
spec.authors = ["Ahmed Mos`ad"]
|
9
|
+
spec.email = ["ahmed.mosad@inovaeg.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby gem to manage dynamic links using branch.io."
|
12
|
+
spec.homepage = "https://github.com/ahmedmos3ad/inova_dynamic_link"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 3.1.2"
|
15
|
+
spec.add_dependency "rails", ">= 6.1"
|
16
|
+
spec.add_dependency "httparty", "~> 0.21.0"
|
17
|
+
|
18
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
|
+
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/ahmedmos3ad/inova_dynamic_link"
|
22
|
+
spec.metadata["changelog_uri"] = "https://github.com/ahmedmos3ad/inova_dynamic_link/blob/master/CHANGELOG.md"
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(__dir__) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
(File.expand_path(f) == __FILE__) ||
|
29
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
# Uncomment to register a new dependency of your gem
|
37
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
38
|
+
|
39
|
+
# For more information and examples about making a new gem, check out our
|
40
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module InovaDynamicLink
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
def create_initializer_file
|
9
|
+
copy_file "inova_dynamic_link_initializer.rb", "config/initializers/inova_dynamic_link.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
InovaDynamicLink.configure do |config|
|
2
|
+
# Set your configuration options here
|
3
|
+
# account settings > profile > copy the keys
|
4
|
+
config.branch_key = nil
|
5
|
+
config.branch_secret = nil
|
6
|
+
# account settings > user > generate access token or paste the current one
|
7
|
+
config.branch_access_token = nil
|
8
|
+
# account settings > profile > copy the app id
|
9
|
+
config.branch_app_id = nil
|
10
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module InovaDynamicLink
|
2
|
+
class Branch
|
3
|
+
require "uri"
|
4
|
+
require "httparty"
|
5
|
+
require "json"
|
6
|
+
require "active_support/core_ext/object/blank"
|
7
|
+
require "active_support/core_ext/enumerable"
|
8
|
+
|
9
|
+
DEFAULT_HEADERS = {"Content-Type": "application/json"}
|
10
|
+
BRANCH_URI = "https://api2.branch.io/v1/url"
|
11
|
+
|
12
|
+
attr_reader :branch_key, :branch_secret, :branch_access_token, :branch_app_id
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
InovaDynamicLink.configuration.validate!
|
16
|
+
@branch_key = InovaDynamicLink.configuration.branch_key
|
17
|
+
@branch_secret = InovaDynamicLink.configuration.branch_secret
|
18
|
+
@branch_access_token = InovaDynamicLink.configuration.branch_access_token
|
19
|
+
@branch_app_id = InovaDynamicLink.configuration.branch_app_id
|
20
|
+
end
|
21
|
+
|
22
|
+
# https://help.branch.io/developers-hub/reference/createdeeplinkurl
|
23
|
+
|
24
|
+
# accepts InovaDynamicLink::BranchLinkConfiguration object as an argument
|
25
|
+
def create(branch_link_configuration)
|
26
|
+
raise ArgumentError, "argument must be a InovaDynamicLink::BranchLinkConfiguration" unless branch_link_configuration.is_a?(InovaDynamicLink::BranchLinkConfiguration)
|
27
|
+
body = {
|
28
|
+
branch_key: @branch_key,
|
29
|
+
}.merge(branch_link_configuration.to_hash)
|
30
|
+
|
31
|
+
response = HTTParty.post(BRANCH_URI, headers: DEFAULT_HEADERS, body: body.to_json)
|
32
|
+
json_resp = JSON.parse(response.body)
|
33
|
+
raise HTTParty::ResponseError, json_resp["error"]["message"] if json_resp["error"].present?
|
34
|
+
raise HTTParty::ResponseError, json_resp unless response.code == 200
|
35
|
+
json_resp["url"]
|
36
|
+
end
|
37
|
+
# branch_link_configuration_array is an array of InovaDynamicLink::BranchLinkConfiguration
|
38
|
+
def bulk_create(branch_link_configuration_array)
|
39
|
+
branch_link_configuration_array = [branch_link_configuration_array].compact_blank unless branch_link_configuration_array.is_a?(Array)
|
40
|
+
raise ArgumentError, "argument hash array cannot be empty" if branch_link_configuration_array.empty?
|
41
|
+
unless branch_link_configuration_array.all? { |o| o.is_a?(InovaDynamicLink::BranchLinkConfiguration) }
|
42
|
+
raise ArgumentError, "argument must be an array of InovaDynamicLink::BranchLinkConfiguration"
|
43
|
+
end
|
44
|
+
config_hash_array = branch_link_configuration_array.map{|config| config.to_hash}
|
45
|
+
response = HTTParty.post(BRANCH_URI + "/bulk/" + @branch_key, headers: DEFAULT_HEADERS, body: config_hash_array.to_json)
|
46
|
+
raise HTTParty::ResponseError, response unless response.code == 200
|
47
|
+
JSON.parse(response.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get(url)
|
51
|
+
validate_url(url)
|
52
|
+
HTTParty.get(BRANCH_URI + "?url=#{url}&branch_key=#{@branch_key}", headers: DEFAULT_HEADERS)
|
53
|
+
raise HTTParty::ResponseError, response["error"]["message"] if response["error"].present?
|
54
|
+
raise HTTParty::ResponseError, "404 Not Found" unless response.code == 200
|
55
|
+
JSON.parse(response.body)
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete(url)
|
59
|
+
validate_url(url)
|
60
|
+
response = HTTParty.delete(BRANCH_URI + "?url=#{url}&app_id=#{@branch_app_id}", headers: DEFAULT_HEADERS.merge({"Access-Token": @branch_access_token}))
|
61
|
+
raise HTTParty::ResponseError, "Error deleting dynamic link" unless response.code == 200
|
62
|
+
json_resp = JSON.parse(response.body)
|
63
|
+
raise HTTParty::ResponseError, json_resp["error"]["message"] if json_resp["error"].present?
|
64
|
+
json_resp
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def validate_url(url)
|
70
|
+
uri = URI.parse(url)
|
71
|
+
raise URI::InvalidURIError, "Invalid URL" unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
require "active_support/core_ext/enumerable"
|
3
|
+
|
4
|
+
module InovaDynamicLink
|
5
|
+
class BranchLinkConfiguration
|
6
|
+
attr_accessor :channel, :feature, :stage, :campaign, :tags, :link_alias, :type, :duration, :fallback_url,
|
7
|
+
:desktop_url, :ios_url, :android_url, :huawei_url, :windows_phone_url, :web_only, :desktop_web_only,
|
8
|
+
:mobile_web_only, :after_click_url, :afterclick_desktop_url, :deeplink_path, :extra_data
|
9
|
+
|
10
|
+
def initialize(**attributes)
|
11
|
+
attributes = {
|
12
|
+
tags: {},
|
13
|
+
type: 0,
|
14
|
+
duration: 7200,
|
15
|
+
**attributes
|
16
|
+
}
|
17
|
+
raise ArgumentError, "extra_data must be a hash" if attributes[:extra_data] && !attributes[:extra_data].is_a?(Hash)
|
18
|
+
attributes.each do |key, value|
|
19
|
+
if respond_to?(:"#{key}=")
|
20
|
+
send(:"#{key}=", value)
|
21
|
+
else
|
22
|
+
raise InovaDynamicLink::UnknownAttributeError.new(key)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{
|
29
|
+
channel: channel,
|
30
|
+
feature: feature,
|
31
|
+
stage: stage,
|
32
|
+
campaign: campaign,
|
33
|
+
tags: tags,
|
34
|
+
alias: link_alias,
|
35
|
+
type: type,
|
36
|
+
duration: duration,
|
37
|
+
data: {
|
38
|
+
"$fallback_url": fallback_url,
|
39
|
+
"$desktop_url": desktop_url,
|
40
|
+
"$ios_url": ios_url,
|
41
|
+
"$android_url": android_url,
|
42
|
+
"$huawei_url": huawei_url,
|
43
|
+
"$windows_phone_url": windows_phone_url,
|
44
|
+
"$web_only": web_only,
|
45
|
+
"$desktop_web_only": desktop_web_only,
|
46
|
+
"$mobile_web_only": mobile_web_only,
|
47
|
+
"$after_click_url": after_click_url,
|
48
|
+
"$afterclick_desktop_url": afterclick_desktop_url,
|
49
|
+
"$deeplink_path": deeplink_path,
|
50
|
+
**extra_data
|
51
|
+
}.compact_blank
|
52
|
+
}.compact_blank
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module InovaDynamicLink
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :branch_key, :branch_secret, :branch_access_token, :branch_app_id
|
4
|
+
|
5
|
+
def validate!
|
6
|
+
required_attributes = [:branch_key, :branch_secret, :branch_access_token, :branch_app_id]
|
7
|
+
|
8
|
+
required_attributes.each do |attribute|
|
9
|
+
value = send(attribute)
|
10
|
+
raise ArgumentError, "#{attribute} is required in the configuration" if value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "inova_dynamic_link/version"
|
4
|
+
require_relative "inova_dynamic_link/configuration"
|
5
|
+
require_relative "inova_dynamic_link/branch"
|
6
|
+
require_relative "inova_dynamic_link/branch_link_configuration"
|
7
|
+
require_relative "inova_dynamic_link/unknown_attribute_error"
|
8
|
+
|
9
|
+
module InovaDynamicLink
|
10
|
+
class Error < StandardError; end
|
11
|
+
# Your code goes here...
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inova_dynamic_link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ahmed Mos`ad
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.21.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.21.0
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- ahmed.mosad@inovaeg.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".standard.yml"
|
49
|
+
- CHANGELOG.md
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- inova_dynamic_link.gemspec
|
55
|
+
- lib/generators/inova_dynamic_link/install_generator.rb
|
56
|
+
- lib/generators/inova_dynamic_link/templates/inova_dynamic_link_initializer.rb
|
57
|
+
- lib/inova_dynamic_link.rb
|
58
|
+
- lib/inova_dynamic_link/branch.rb
|
59
|
+
- lib/inova_dynamic_link/branch_link_configuration.rb
|
60
|
+
- lib/inova_dynamic_link/configuration.rb
|
61
|
+
- lib/inova_dynamic_link/unknown_attribute_error.rb
|
62
|
+
- lib/inova_dynamic_link/version.rb
|
63
|
+
- sig/inova_dynamic_link.rbs
|
64
|
+
homepage: https://github.com/ahmedmos3ad/inova_dynamic_link
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
allowed_push_host: https://rubygems.org
|
69
|
+
homepage_uri: https://github.com/ahmedmos3ad/inova_dynamic_link
|
70
|
+
source_code_uri: https://github.com/ahmedmos3ad/inova_dynamic_link
|
71
|
+
changelog_uri: https://github.com/ahmedmos3ad/inova_dynamic_link/blob/master/CHANGELOG.md
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.1.2
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Ruby gem to manage dynamic links using branch.io.
|
91
|
+
test_files: []
|