branch_io 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b07bcbbfa55600f273c4257643bc424463df98d
4
+ data.tar.gz: f5debc608b842ac322063a2b48be2731740164b4
5
+ SHA512:
6
+ metadata.gz: 4e3e8282deede639c610ba9611ff7853d4f5694d3bbfcde76ca462bdd27e1c075325187e67ff24199afaa9c58b1737c6d6c9461b6aa913029eb8b710eddf9a49
7
+ data.tar.gz: 97c9fa7a59d7e2be3f3088a80fa6d8137b1d94ee0852449a397b5aff7ded14f53af00c990fea436943edace7980cab09307371fb82b8fcf271cd3f9de4ccf6b9
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ .DS_Store
12
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at aurelien.noce@imagine-app.fr. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in branch_io.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Aurélien Noce
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.
@@ -0,0 +1,197 @@
1
+ # A Ruby wrapper for the [branch.io](http://branch.io) [public API](https://github.com/BranchMetrics/branch-deep-linking-public-api)
2
+
3
+ This is a simple [HTTparty](https://github.com/jnunemaker/httparty)-based gem for accessing the branch.io REST APIs,
4
+ as descried [here](https://github.com/BranchMetrics/branch-deep-linking-public-api).
5
+
6
+ It follows the exact design of the original REST API: basically links are resources you can generate and update,
7
+ provided you hold the required credentials.
8
+
9
+ **BEWARE: this gem does not (yet) cover all the API calls of the API, for now on only the link creation/update is supported**
10
+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'branch_io'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install branch_io
27
+
28
+
29
+ ## Basic Usage
30
+
31
+ To access the APIs, you need to create a `BranchIO::Client` instance, passing in your
32
+ **branch.io key** and your **branch.io secret** respectively.
33
+
34
+ ```ruby
35
+ # Create a new client
36
+ > client = BranchIO::Client.new("key_test_xxx", "secret_test_yyyy")
37
+ => #<BranchIO::Client:0x007f8e7192a2a0 @branch_key="key_test_xxx", @branch_secret="secret_test_yyy">
38
+
39
+ # Ask the server for a new link
40
+ > res = client.link(feature: "test")
41
+ => #<BranchIO::Client::UrlResponse:0x007f8e718c6a20 @response="...">
42
+
43
+ # Check for success and print the URL
44
+ > if res.success?
45
+ puts res.url
46
+ end
47
+ https://uym7.test-app.link/ABCDEFG...
48
+ ```
49
+
50
+ Please not that the `gem` reads the `BRANCH_KEY` and `BRANCH_SECRET` environment
51
+ variables by default, and provided these are defined passing them to the client is
52
+ optional:
53
+
54
+ ```ruby
55
+ # Provided BRANCH_KEY and BRANCH_SECRET are defined
56
+ > client = BranchIO::Client.new
57
+ => #<BranchIO::Client:... @branch_key="key_test_xxx", @branch_secret="secret_test_yyy">
58
+ ```
59
+
60
+ Similarly all the methods of the "default" client (the one without arguments) are made
61
+ available on the module itself:
62
+
63
+ ```ruby
64
+ # Provided BRANCH_KEY and BRANCH_SECRET are defined
65
+ > res = BranchIO.link(feature: "test") # <= same as BranchIO.new.link(...)
66
+ => #<BranchIO::Client::UrlResponse:0x007f8e718c6a20 @response="...">
67
+ ```
68
+
69
+
70
+ ## Available API calls
71
+
72
+ ### `Client#link` and `Client#link!`: Registers a [new deep linking URL](https://github.com/BranchMetrics/branch-deep-linking-public-api#creating-a-deep-linking-url)
73
+
74
+ This method registers a new deep linking URL to the `branch.io` service. The arguments
75
+ are passed to a new instance of `BranchIO::LinkProperties`.
76
+
77
+ ```ruby
78
+ # Call the service
79
+ res = client.link(
80
+ feature: "test",
81
+ channel: "test",
82
+ campaign: "test",
83
+ stage: 1,
84
+ alias: "testsingle",
85
+ type: "test",
86
+ tags: [ "test" ],
87
+ data: {
88
+ test: true
89
+ }
90
+ )
91
+
92
+ # Inspect the server response
93
+ if res.success?
94
+ puts "Successfully created URL: #{res.url}"
95
+ else
96
+ puts "Error creating URL: #{res.error}"
97
+ end
98
+ ```
99
+
100
+ _The only difference between `#link` and `#link!` is that the latter version will
101
+ raise a new `BranchIO::ErrorApiCallFailed` exception in case of an error._
102
+
103
+ ### `Client#links` and `Client#links!`: Registers a bulk of [deep linking URLs](https://github.com/BranchMetrics/branch-deep-linking-public-api#creating-a-deep-linking-url)
104
+
105
+ This method registers a bulk deep linking URLs to the `branch.io` service. The arguments
106
+ are passed to a new instances of `BranchIO::LinkProperties`.
107
+
108
+ ```ruby
109
+ # Call the service
110
+ url_configs = [
111
+ { feature: "test" }, # First link
112
+ { feature: "test", stage: 2 } # second link
113
+ # etc..
114
+ ]
115
+ res = client.links(url_configs)
116
+
117
+ # Inspect the server response
118
+ if res.success?
119
+ puts "Successfully created #{res.urls.count} URLs: #{res.urls.join(',')}"
120
+ else
121
+ puts "Error creating URLs: #{res.errors.join(',')}"
122
+
123
+ # There has been errors, but some URLs might be valid
124
+ if res.urls.count > 0
125
+ puts "Successfully created #{res.urls.count} URLs out of #{url_configs.count}: #{res.urls.join(',')}"
126
+ end
127
+ end
128
+ ```
129
+
130
+ _The only difference between `#links` and `#links!` is that the latter version will
131
+ raise a new `BranchIO::ErrorApiCallFailed` exception in case of an error._
132
+
133
+ ### `Client#link_info` and `Client#link_info!`: Registers a [new deep linking URL](https://github.com/BranchMetrics/branch-deep-linking-public-api#creating-a-deep-linking-url)
134
+
135
+ **BEWARE: this method requires the BRANCH_SECRET to be defined**
136
+
137
+ This method queries an existing link URL for its properties.
138
+
139
+ ```ruby
140
+ # Call the service
141
+ res = client.link_info("https://...")
142
+
143
+ # Inspect the server response
144
+ if res.success?
145
+ puts "Successfully retrieved link info: #{res.link_properties.to_json}"
146
+ else
147
+ puts "Error retrieving link info: #{res.error}"
148
+ end
149
+ ```
150
+
151
+ **The only difference between `#link_info` and `#link_info!` is that the latter version will
152
+ raise a new `BranchIO::ErrorApiCallFailed` exception in case of an error.**
153
+
154
+ ### `Client#update_link` and `Client#update_link!`: Registers a [new deep linking URL](https://github.com/BranchMetrics/branch-deep-linking-public-api#creating-a-deep-linking-url)
155
+
156
+ **BEWARE: this method requires the BRANCH_SECRET to be defined**
157
+
158
+ This method updates the properties of an existing link and returns the new updated
159
+ set of properties.
160
+
161
+ ```ruby
162
+ # Call the service
163
+ res = client.update_link("https://...", stage: 3)
164
+
165
+ # Inspect the server response
166
+ if res.success?
167
+ puts "Successfully updated link info: #{res.link_properties.to_json}"
168
+ else
169
+ puts "Error updating link info: #{res.error}"
170
+ end
171
+ ```
172
+
173
+ **The only difference between `#update_link` and `#update_link!` is that the latter version will
174
+ raise a new `BranchIO::ErrorApiCallFailed` exception in case of an error.**
175
+
176
+ ## Development
177
+
178
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
179
+
180
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
181
+
182
+
183
+ ## Contributing
184
+
185
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ushu/branch_io. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
186
+
187
+
188
+ ## TODO
189
+
190
+ - [ ] Add support for the `/app` API calls
191
+ - [ ] Add some docs to the code
192
+ - [ ] Write a better README...
193
+
194
+ ## License
195
+
196
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
197
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "branch_io"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'branch_io/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "branch_io"
8
+ spec.version = BranchIO::VERSION
9
+ spec.authors = ["Aurélien Noce"]
10
+ spec.email = ["aurelien.noce@imagine-app.fr"]
11
+
12
+ spec.summary = %q{A Client for the Branch.io deep linking public API}
13
+ spec.description = %q{This wrapper allows you to create and update deep links on branch.io, using the public REST API.}
14
+ spec.homepage = "https://github.com/ushu/branch_io"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty", "~> 0.13"
23
+ spec.add_development_dependency "vcr", "~> 3.0"
24
+ spec.add_development_dependency "webmock", "~> 2.1"
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,27 @@
1
+ require "branch_io/version"
2
+
3
+ module BranchIO
4
+
5
+ autoload :Client, "branch_io/client"
6
+ autoload :LinkProperties, "branch_io/link_properties"
7
+
8
+ # Default client helper methods: delegate unknown calls to a new Client instance w/ default constructor params
9
+
10
+ def self.method_missing(name, *args, &block)
11
+ default_client = Client.new
12
+ if default_client.respond_to?(name)
13
+ default_client.send(name, *args, &block)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def self.respond_to?(name)
20
+ default_client = Client.new
21
+ if default_client.respond_to?(name)
22
+ return true
23
+ end
24
+ super
25
+ end
26
+
27
+ end
@@ -0,0 +1,61 @@
1
+ require "httparty"
2
+ require "json"
3
+
4
+ # Submodules (hold the api method calls)
5
+ require_relative "client/links"
6
+
7
+ module BranchIO
8
+
9
+ class Client
10
+ class ErrorMissingBranchKey < StandardError; end
11
+
12
+ # Submodules
13
+ include Links
14
+
15
+ # Include HTTParty for requests
16
+ include HTTParty
17
+ base_uri "https://api.branch.io"
18
+
19
+ # Basic Api client
20
+ attr_reader :branch_key, :branch_secret
21
+ def initialize(branch_key=ENV["BRANCH_KEY"], branch_secret=ENV["BRANCH_SECRET"])
22
+ @branch_key = branch_key
23
+ @branch_secret = branch_secret
24
+
25
+ unless branch_key
26
+ raise ErrorMissingBranchKey.new("No Branch Key found: please provided one such key to BranchIO::Client#initialize or by setting the BRANCH_KEY environment variable")
27
+ end
28
+ end
29
+
30
+ def get(url)
31
+ self.class.get(url, headers: default_headers)
32
+ end
33
+
34
+ def post(url, data={})
35
+ body = data.to_json
36
+ self.class.post(url, body: body, headers: default_headers)
37
+ end
38
+
39
+ def put(url, data={})
40
+ body = data.to_json
41
+ self.class.put(url, body: body, headers: default_headers)
42
+ end
43
+
44
+ private
45
+
46
+ def ensure_branch_secret_defined!
47
+ unless branch_secret
48
+ raise ErrorMissingBranchKey.new("No Branch Secret found: please provided one such key to BranchIO::Client#initialize or by setting the BRANCH_SECRET environment variable")
49
+ end
50
+ end
51
+
52
+ def default_headers
53
+ {
54
+ "Content-Type" => "application/json",
55
+ "Accept" => "application/json"
56
+ }
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,123 @@
1
+ require_relative "response"
2
+
3
+ module BranchIO
4
+ class Client
5
+
6
+ module Links
7
+ LINK_PATH = "/v1/url"
8
+
9
+ def link!(options={})
10
+ res = link(options)
11
+ res.validate!
12
+ res
13
+ end
14
+
15
+ def link(options={})
16
+ # Load and check the link properties
17
+ link_properties = BranchIO::LinkProperties.wrap(options)
18
+
19
+ # Build the request
20
+ defaults = {
21
+ sdk: :api,
22
+ branch_key: self.branch_key
23
+ }
24
+ link_json = defaults.merge(link_properties.as_json)
25
+
26
+ # Call branch.io public API
27
+ raw_response = self.post(LINK_PATH, link_json)
28
+
29
+ # Wrap the result in a Response
30
+ if raw_response.success?
31
+ UrlResponse.new(raw_response)
32
+ else
33
+ ErrorResponse.new(raw_response)
34
+ end
35
+ end
36
+
37
+ def links!(options={})
38
+ res = links(options)
39
+ res.validate!
40
+ res
41
+ end
42
+
43
+ def links(options=[])
44
+ # Load and check the links properties
45
+ link_properties_array = options.map{ |o| BranchIO::LinkProperties.wrap(o) }
46
+
47
+ # Build the request
48
+ links_url = "#{LINK_PATH}/bulk/#{self.branch_key}"
49
+ links_json = link_properties_array.map(&:as_json)
50
+
51
+ # Call branch.io public API
52
+ raw_response = self.post(links_url, links_json)
53
+
54
+ # Wrap the result in a Response
55
+ if raw_response.success?
56
+ BulkUrlsResponse.new(raw_response)
57
+ else
58
+ ErrorResponse.new(raw_response)
59
+ end
60
+ end
61
+
62
+ def update_link!(options={})
63
+ res = update_link(options)
64
+ res.validate!
65
+ res
66
+ end
67
+
68
+ def update_link(url, options={})
69
+ ensure_branch_secret_defined!
70
+
71
+ # Load and check the links configuration properties
72
+ link_properties = BranchIO::LinkProperties.wrap(options)
73
+
74
+ # Build the request URL
75
+ encoded_url = URI.encode_www_form_component(url)
76
+ update_url = "#{LINK_PATH}?url=#{encoded_url}"
77
+
78
+ # Build the request body
79
+ defaults = {
80
+ sdk: :api,
81
+ branch_key: self.branch_key,
82
+ branch_secret: self.branch_secret
83
+ }
84
+ update_json = defaults.merge(link_properties.as_json)
85
+
86
+ # Call branch.io public API
87
+ raw_response = self.put(update_url, update_json)
88
+
89
+ # Wrap the result in a Response
90
+ if raw_response.success?
91
+ LinkPropertiesResponse.new(raw_response)
92
+ else
93
+ ErrorResponse.new(raw_response)
94
+ end
95
+ end
96
+
97
+ def link_info!(options={})
98
+ res = link_info(options)
99
+ res.validate!
100
+ res
101
+ end
102
+
103
+ def link_info(url)
104
+ # Build the request URL
105
+ encoded_url = URI.encode_www_form_component(url)
106
+ encoded_key = URI.encode_www_form_component(branch_key)
107
+ show_url = "#{LINK_PATH}?url=#{encoded_url}&branch_key=#{encoded_key}"
108
+
109
+ # Call branch.io public API
110
+ raw_response = self.get(show_url)
111
+
112
+ # Wrap the result in a Response
113
+ if raw_response.success?
114
+ LinkPropertiesResponse.new(raw_response)
115
+ else
116
+ ErrorResponse.new(raw_response)
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,107 @@
1
+ module BranchIO
2
+ class Client
3
+ class ErrorApiCallFailed < StandardError
4
+ attr_reader :response
5
+ def initialize(response)
6
+ @response = response
7
+ super("API call failed")
8
+ end
9
+ end
10
+
11
+ class Response
12
+ attr_reader :response
13
+
14
+ def initialize(response)
15
+ @response = response
16
+ end
17
+
18
+ def request
19
+ response.request
20
+ end
21
+
22
+ def success?
23
+ response.success?
24
+ end
25
+
26
+ def failure?
27
+ !success?
28
+ end
29
+
30
+ def validate!
31
+ raise ErrorApiCallFailed.new(self) unless success?
32
+ end
33
+
34
+ def json
35
+ response.parsed_response
36
+ end
37
+ end
38
+
39
+ class UrlResponse < Response
40
+ def success?
41
+ true
42
+ end
43
+
44
+ def url
45
+ json["url"]
46
+ end
47
+ end
48
+
49
+ class ErrorResponse < Response
50
+ def success?
51
+ false
52
+ end
53
+
54
+ def code
55
+ json["code"]
56
+ end
57
+
58
+ def error
59
+ json["error"]
60
+ end
61
+ end
62
+
63
+ class BulkUrlsResponse < Response
64
+ def success?
65
+ responses.all?(&:success?)
66
+ end
67
+
68
+ def urls
69
+ successful_responses.map(&:url)
70
+ end
71
+
72
+ def errors
73
+ erroneous_responses.map(&:error)
74
+ end
75
+
76
+ def successful_responses
77
+ responses.select(&:success?)
78
+ end
79
+
80
+ def erroneous_responses
81
+ responses.reject(&:success?)
82
+ end
83
+
84
+ def responses
85
+ @responses ||= json.map do |url_info|
86
+ # below the EmbeddedResponseWrapper(s) act as a dummp HTTParty response
87
+ if url_info.has_key?("error")
88
+ ErrorResponse.new(EmbeddedResponseWrapper.new(url_info))
89
+ else
90
+ UrlResponse.new(EmbeddedResponseWrapper.new(url_info))
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ class EmbeddedResponseWrapper < Struct.new(:parsed_response); end
98
+ end
99
+
100
+ class LinkPropertiesResponse < Response
101
+ def link_properties
102
+ @link_properties ||= BranchIO::LinkProperties.new(json)
103
+ end
104
+ end
105
+
106
+ end
107
+ end
@@ -0,0 +1,58 @@
1
+ module BranchIO
2
+
3
+ class LinkProperties
4
+ attr_reader :tags
5
+ attr_reader :channel
6
+ attr_reader :feature
7
+ attr_reader :campaign
8
+ attr_reader :stage
9
+ attr_reader :alias
10
+ attr_reader :type
11
+ attr_reader :data
12
+
13
+ def self.wrap(options)
14
+ if options.kind_of?(LinkProperties)
15
+ options
16
+ else
17
+ new(options)
18
+ end
19
+ end
20
+
21
+ def initialize(options={})
22
+ @tags = options.delete(:tags) ||options.delete("tags")
23
+ @channel = options.delete(:channel) || options.delete("channel")
24
+ @feature = options.delete(:feature) || options.delete("feature")
25
+ @campaign = options.delete(:campaign) || options.delete("campaign")
26
+ @stage = options.delete(:stage) || options.delete("stage")
27
+ @alias = options.delete(:alias) || options.delete("alias")
28
+ @type = options.delete(:type) || options.delete("type")
29
+ @data = options.delete(:data) || options.delete("data")
30
+
31
+ unless options.empty?
32
+ raise ErrorInvalidParameters.new(options.keys)
33
+ end
34
+ end
35
+
36
+ def as_json
37
+ json = {}
38
+ json[:tags] = tags if tags
39
+ json[:channel] = channel if channel
40
+ json[:feature] = feature if feature
41
+ json[:campaign] = campaign if campaign
42
+ json[:stage] = stage if stage
43
+ json[:alias] = self.alias if self.alias
44
+ json[:type] = type if type
45
+ json[:data] = data if data
46
+ json
47
+ end
48
+
49
+ class ErrorInvalidParameters < StandardError
50
+ attr_reader :parameters
51
+ def initialize(parameters)
52
+ @parameters = parameters
53
+ super("Invalid parameters for BranchIO::LinkProperties: \"#{@parameters.join(", ")}\"")
54
+ end
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ module BranchIO
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: branch_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aurélien Noce
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: This wrapper allows you to create and update deep links on branch.io,
98
+ using the public REST API.
99
+ email:
100
+ - aurelien.noce@imagine-app.fr
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - branch_io.gemspec
117
+ - lib/branch_io.rb
118
+ - lib/branch_io/client.rb
119
+ - lib/branch_io/client/links.rb
120
+ - lib/branch_io/client/response.rb
121
+ - lib/branch_io/link_properties.rb
122
+ - lib/branch_io/version.rb
123
+ homepage: https://github.com/ushu/branch_io
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A Client for the Branch.io deep linking public API
147
+ test_files: []