Class: InovaDynamicLink::Branch
- Inherits:
-
Object
- Object
- InovaDynamicLink::Branch
- Defined in:
- lib/inova_dynamic_link/branch.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{"Content-Type": "application/json"}
- BRANCH_URI =
"https://api2.branch.io/v1/url"
Instance Attribute Summary collapse
-
#branch_access_token ⇒ Object
readonly
Returns the value of attribute branch_access_token.
-
#branch_app_id ⇒ Object
readonly
Returns the value of attribute branch_app_id.
-
#branch_key ⇒ Object
readonly
Returns the value of attribute branch_key.
-
#branch_secret ⇒ Object
readonly
Returns the value of attribute branch_secret.
Instance Method Summary collapse
-
#bulk_create(branch_link_configuration_array) ⇒ Object
branch_link_configuration_array is an array of InovaDynamicLink::BranchLinkConfiguration.
-
#create(branch_link_configuration) ⇒ Object
accepts InovaDynamicLink::BranchLinkConfiguration object as an argument.
- #delete(url) ⇒ Object
- #get(url) ⇒ Object
-
#initialize ⇒ Branch
constructor
A new instance of Branch.
Constructor Details
#initialize ⇒ Branch
Returns a new instance of Branch.
14 15 16 17 18 19 20 |
# File 'lib/inova_dynamic_link/branch.rb', line 14 def initialize InovaDynamicLink.configuration.validate! @branch_key = InovaDynamicLink.configuration.branch_key @branch_secret = InovaDynamicLink.configuration.branch_secret @branch_access_token = InovaDynamicLink.configuration.branch_access_token @branch_app_id = InovaDynamicLink.configuration.branch_app_id end |
Instance Attribute Details
#branch_access_token ⇒ Object (readonly)
Returns the value of attribute branch_access_token.
12 13 14 |
# File 'lib/inova_dynamic_link/branch.rb', line 12 def branch_access_token @branch_access_token end |
#branch_app_id ⇒ Object (readonly)
Returns the value of attribute branch_app_id.
12 13 14 |
# File 'lib/inova_dynamic_link/branch.rb', line 12 def branch_app_id @branch_app_id end |
#branch_key ⇒ Object (readonly)
Returns the value of attribute branch_key.
12 13 14 |
# File 'lib/inova_dynamic_link/branch.rb', line 12 def branch_key @branch_key end |
#branch_secret ⇒ Object (readonly)
Returns the value of attribute branch_secret.
12 13 14 |
# File 'lib/inova_dynamic_link/branch.rb', line 12 def branch_secret @branch_secret end |
Instance Method Details
#bulk_create(branch_link_configuration_array) ⇒ Object
branch_link_configuration_array is an array of InovaDynamicLink::BranchLinkConfiguration
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inova_dynamic_link/branch.rb', line 39 def bulk_create(branch_link_configuration_array) branch_link_configuration_array = [branch_link_configuration_array].compact_blank unless branch_link_configuration_array.is_a?(Array) raise ArgumentError, "argument hash array cannot be empty" if branch_link_configuration_array.empty? unless branch_link_configuration_array.all? { |o| o.is_a?(InovaDynamicLink::BranchLinkConfiguration) } raise ArgumentError, "argument must be an array of InovaDynamicLink::BranchLinkConfiguration" end config_hash_array = branch_link_configuration_array.map { |config| config.to_hash } response = HTTParty.post(BRANCH_URI + "/bulk/" + @branch_key, headers: DEFAULT_HEADERS, body: config_hash_array.to_json) raise HTTParty::ResponseError, response unless response.code == 200 JSON.parse(response.body).map { |resp| resp["url"] } end |
#create(branch_link_configuration) ⇒ Object
accepts InovaDynamicLink::BranchLinkConfiguration object as an argument
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/inova_dynamic_link/branch.rb', line 25 def create(branch_link_configuration) raise ArgumentError, "argument must be a InovaDynamicLink::BranchLinkConfiguration" unless branch_link_configuration.is_a?(InovaDynamicLink::BranchLinkConfiguration) body = { branch_key: @branch_key }.merge(branch_link_configuration.to_hash) response = HTTParty.post(BRANCH_URI, headers: DEFAULT_HEADERS, body: body.to_json) json_resp = JSON.parse(response.body) raise HTTParty::ResponseError, json_resp["error"]["message"] if json_resp["error"].present? raise HTTParty::ResponseError, json_resp unless response.code == 200 json_resp["url"] end |
#delete(url) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/inova_dynamic_link/branch.rb', line 59 def delete(url) validate_url(url) response = HTTParty.delete(BRANCH_URI + "?url=#{url}&app_id=#{@branch_app_id}", headers: DEFAULT_HEADERS.merge({"Access-Token": @branch_access_token})) raise HTTParty::ResponseError, "Error deleting dynamic link" unless response.code == 200 json_resp = JSON.parse(response.body) raise HTTParty::ResponseError, json_resp["error"]["message"] if json_resp["error"].present? json_resp end |
#get(url) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/inova_dynamic_link/branch.rb', line 51 def get(url) validate_url(url) HTTParty.get(BRANCH_URI + "?url=#{url}&branch_key=#{@branch_key}", headers: DEFAULT_HEADERS) raise HTTParty::ResponseError, response["error"]["message"] if response["error"].present? raise HTTParty::ResponseError, "404 Not Found" unless response.code == 200 JSON.parse(response.body) end |