Module: BranchIO::Client::Links

Included in:
BranchIO::Client
Defined in:
lib/branch_io/client/links.rb

Constant Summary collapse

"/v1/url"

Instance Method Summary collapse

Instance Method Details



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/branch_io/client/links.rb', line 15

def link(options={})
  # Load and check the link properties
  link_properties = BranchIO::LinkProperties.wrap(options)

  # Build the request
  defaults = {
      sdk: :api,
      branch_key: self.branch_key
  }
  link_json = defaults.merge(link_properties.as_json)

  # Call branch.io public API
  raw_response = self.post(LINK_PATH, link_json)

  # Wrap the result in a Response
  if raw_response.success?
    UrlResponse.new(raw_response)
  else
    ErrorResponse.new(raw_response)
  end
end

#link!(options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/branch_io/client/links.rb', line 9

def link!(options={})
  res = link(options)
  res.validate!
  res
end


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/branch_io/client/links.rb', line 103

def link_info(url)
  # Build the request URL
  encoded_url = URI.encode_www_form_component(url)
  encoded_key = URI.encode_www_form_component(branch_key)
  show_url = "#{LINK_PATH}?url=#{encoded_url}&branch_key=#{encoded_key}"

  # Call branch.io public API
  raw_response = self.get(show_url)

  # Wrap the result in a Response
  if raw_response.success?
    LinkPropertiesResponse.new(raw_response)
  else
    ErrorResponse.new(raw_response)
  end
end


97
98
99
100
101
# File 'lib/branch_io/client/links.rb', line 97

def link_info!(options={})
  res = link_info(options)
  res.validate!
  res
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/branch_io/client/links.rb', line 43

def links(options=[])
  # Load and check the links properties
  link_properties_array = options.map{ |o| BranchIO::LinkProperties.wrap(o) }

  # Build the request
  links_url = "#{LINK_PATH}/bulk/#{self.branch_key}"
  links_json = link_properties_array.map(&:as_json)

  # Call branch.io public API
  raw_response = self.post(links_url, links_json)

  # Wrap the result in a Response
  if raw_response.success?
    BulkUrlsResponse.new(raw_response)
  else
    ErrorResponse.new(raw_response)
  end
end

#links!(options = {}) ⇒ Object



37
38
39
40
41
# File 'lib/branch_io/client/links.rb', line 37

def links!(options={})
  res = links(options)
  res.validate!
  res
end


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/branch_io/client/links.rb', line 68

def update_link(url, options={})
  ensure_branch_secret_defined!

  # Load and check the links configuration properties
  link_properties = BranchIO::LinkProperties.wrap(options)

  # Build the request URL
  encoded_url = URI.encode_www_form_component(url)
  update_url = "#{LINK_PATH}?url=#{encoded_url}"

  # Build the request body
  defaults = {
      sdk: :api,
      branch_key: self.branch_key,
      branch_secret: self.branch_secret
  }
  update_json = defaults.merge(link_properties.as_json)

  # Call branch.io public API
  raw_response = self.put(update_url, update_json)

  # Wrap the result in a Response
  if raw_response.success?
    LinkPropertiesResponse.new(raw_response)
  else
    ErrorResponse.new(raw_response)
  end
end

#update_link!(options = {}) ⇒ Object



62
63
64
65
66
# File 'lib/branch_io/client/links.rb', line 62

def update_link!(options={})
  res = update_link(options)
  res.validate!
  res
end