Class: Linketysplit::PublicationSdk

Inherits:
Object
  • Object
show all
Defined in:
lib/linketysplit/publication_sdk.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ PublicationSdk

Returns a new instance of PublicationSdk.



9
10
11
# File 'lib/linketysplit/publication_sdk.rb', line 9

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/linketysplit/publication_sdk.rb', line 7

def api_key
  @api_key
end

Class Method Details

.get_linketysplit_enabled_meta_tag(enabled: true) ⇒ Object



41
42
43
44
# File 'lib/linketysplit/publication_sdk.rb', line 41

def self.get_linketysplit_enabled_meta_tag(enabled: true)
  content = enabled ? "true" : "false"
  "<meta property=\"linketysplit:enabled\" content=\"#{content}\" />"
end

.get_linketysplit_pricing_meta_tag(article_pricing) ⇒ Object



36
37
38
39
# File 'lib/linketysplit/publication_sdk.rb', line 36

def self.get_linketysplit_pricing_meta_tag(article_pricing)
  content = Base64.encode64(JSON.dump(article_pricing))
  "<meta property=\"linketysplit:pricing\" content=\"#{content}\" />"
end

Instance Method Details

#create_article_purchase_link(permalink, custom_pricing = nil, context = nil) ⇒ String

Creates a signed article purchase link with the given permalink.

Parameters:

  • permalink (String)

    The canonical URL of the article.

  • customPricing (Hash, nil)

    Optional. Custom pricing to be applied for this purchase link, that is, for a particular user.

    • ‘:price` [Integer] The base article price in US cents.

    • ‘:discounts` [Array<Hash>] Optional. Quantity discounts.

      • ‘:quantity` [Integer] The minimum quantity at which the discount applies.

      • ‘:price` [Integer] The unit price of the article at the given quantity.

  • context (String, nil) (defaults to: nil)

    Optional. Pass “sharing” if the user is sharing an article.

Returns:

  • (String)

    The URL of the purchase page on LinketySplit. Show the reader a link to this URL.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/linketysplit/publication_sdk.rb', line 24

def create_article_purchase_link(permalink, custom_pricing=nil, context=nil)
  payload = {
    permalink:
  }

  payload[:customPricing] = custom_pricing if custom_pricing

  payload[:context] = context if context
  token = JWT.encode payload, @api_key, "HS256"
  "https://linketysplit.com/purchase-link/#{token}"
end