Class: FirebaseDynamicLink::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase_dynamic_link/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute dynamic_link_domain.



5
6
7
# File 'lib/firebase_dynamic_link/client.rb', line 5

def dynamic_link_domain
  @dynamic_link_domain
end

Instance Method Details

on succeed

on failure

status >= 400
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"}}


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

def shorten_link(link, options = {})
  suffix_option = options.delete(:suffix_option)
  suffix_option ||= config.default.suffix.option
  dynamic_link_domain = options.delete(:dynamic_link_domain)
  dynamic_link_domain ||= config.default.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig, 'Dynamic link domain is empty')
  link = "#{dynamic_link_domain}?link=#{link}"
  response = connection.post(nil, {
    longDynamicLink: link,
    suffix: {
      option: suffix_option
    }
  }.to_json)
  body = JSON.parse(response.body)
  has_error = body.key?('error')
  {
    success: !has_error,
    link: has_error ? nil : body['shortLink'],
    preview_link: has_error ? nil : body['previewLink'],
    warning: has_error ? nil : body['warning'],
    error_message: has_error ? body['error']['message'] : nil,
    error_status: has_error ? body['error']['status'] : nil,
    error_code: has_error ? body['error']['code'] : nil
  }
end

#shorten_object(_json_object) ⇒ Object

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/firebase_dynamic_link/client.rb', line 37

def shorten_object(_json_object)
  raise NotImplementedError
end