Class: LinkshareAPI::DeepLinking

Inherits:
Object
  • Object
show all
Defined in:
lib/linkshare_api/deep_linking.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeepLinking

Returns a new instance of DeepLinking.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/linkshare_api/deep_linking.rb', line 9

def initialize
  @affiliate_id = LinkshareAPI.affiliate_id
  @base_url = LinkshareAPI::WEB_SERVICE_URIS[:deep_linking]

  if @affiliate_id.nil?
    raise AuthenticationError.new(
      "No Affilite ID. Set your Affiliate ID by using 'LinkshareAPI.affiliate_id = <AFFILIATE_ID>'. " +
      "See https://github.com/rmarescu/linkshare_api#deep-linking for details."
    )
  end
end

Instance Attribute Details

#affiliate_idObject (readonly)

Returns the value of attribute affiliate_id.



7
8
9
# File 'lib/linkshare_api/deep_linking.rb', line 7

def affiliate_id
  @affiliate_id
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



7
8
9
# File 'lib/linkshare_api/deep_linking.rb', line 7

def base_url
  @base_url
end

Instance Method Details

#build(mid, murl) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/linkshare_api/deep_linking.rb', line 21

def build(mid, murl)
  raise ArgumentError, "mid must be a Fixnum, got #{mid.class} instead" unless mid.is_a?(Fixnum)

  uri = Addressable::URI.parse(base_url)
  uri.query_values = {
    id: affiliate_id,
    mid: mid,
    murl: murl
  }
  uri.to_s
end