Module: Cloudinary::Analytics
Constant Summary collapse
- QUERY_KEY =
 '_a'- ALGO_VERSION =
          
The version of the algorithm
 'B'- SDK_CODE =
          
Cloudinary Ruby SDK
 'C'- CHARS =
 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'- BINARY_PAD_SIZE =
 6
Instance Method Summary collapse
- 
  
    
      #encode_version(version)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Encodes a semVer-like version string.
 - 
  
    
      #get_key(binary_value)  ⇒ Array, Object 
    
    
  
  
  
  
  
  
  
  
  
    
Gets the key for binary value.
 - #initialize_char_codes ⇒ Object
 - 
  
    
      #int_to_padded_bin(integer, pad_num)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Converts integer to left padded binary string.
 - 
  
    
      #product(product)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the product code.
 - 
  
    
      #sdk_analytics_query_param  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Gets the SDK analytics signature query parameter.
 - 
  
    
      #sdk_analytics_signature  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Gets the SDK signature by encoding the SDK version and tech version.
 - 
  
    
      #sdk_code(sdk_code)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the SDK code.
 - 
  
    
      #sdk_version(sdk_version)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the SDK version.
 - 
  
    
      #tech_version(tech_version)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the tech version.
 
Instance Method Details
#encode_version(version) ⇒ String
Encodes a semVer-like version string.
Example:
input:      '1.24.0'
explode:    ['1','24','0']
pad:        ['01','24','00']
reverse:    ['00', '24', '01']
implode:    '002401'
int:        2401
binary:     '100101100001'
padded:     '000000100101100001'
str_split:  ['000000', '100101', '100001']
getKey:     ['A', 'l', 'h']
implode:    'Alh'
  
      116 117 118 119 120 121 122 123 124 125 126 127 128  | 
    
      # File 'lib/cloudinary/analytics.rb', line 116 def encode_version(version) parts = version.split('.') padded_parts = parts.map { |part| part.rjust(2, '0') } number = padded_parts.reverse.join.to_i padded_binary = int_to_padded_bin(number, parts.length * BINARY_PAD_SIZE) raise RangeError, 'Version must be smaller than 43.21.26' if padded_binary.length % BINARY_PAD_SIZE != 0 encoded_chars = padded_binary.chars.each_slice(BINARY_PAD_SIZE).map { |slice| get_key(slice.join) } encoded_chars.join end  | 
  
#get_key(binary_value) ⇒ Array, Object
Gets the key for binary value.
      135 136 137 138 139  | 
    
      # File 'lib/cloudinary/analytics.rb', line 135 def get_key(binary_value) @char_codes ||= initialize_char_codes @char_codes[binary_value] || '' end  | 
  
#initialize_char_codes ⇒ Object
      141 142 143 144 145  | 
    
      # File 'lib/cloudinary/analytics.rb', line 141 def initialize_char_codes char_codes = {} CHARS.chars.each_with_index { |char, idx| char_codes[int_to_padded_bin(idx, BINARY_PAD_SIZE)] = char } char_codes end  | 
  
#int_to_padded_bin(integer, pad_num) ⇒ String
Converts integer to left padded binary string.
      153 154 155  | 
    
      # File 'lib/cloudinary/analytics.rb', line 153 def int_to_padded_bin(integer, pad_num) integer.to_s(2).rjust(pad_num, '0') end  | 
  
#product(product) ⇒ void
This method returns an undefined value.
Sets the product code.
Used for integrations.
      53 54 55  | 
    
      # File 'lib/cloudinary/analytics.rb', line 53 def product(product) @product = product end  | 
  
#sdk_analytics_query_param ⇒ String
Gets the SDK analytics signature query parameter.
      25 26 27  | 
    
      # File 'lib/cloudinary/analytics.rb', line 25 def sdk_analytics_query_param "#{QUERY_KEY}=#{self.sdk_analytics_signature}" end  | 
  
#sdk_analytics_signature ⇒ String
Gets the SDK signature by encoding the SDK version and tech version.
      32 33 34 35 36 37 38 39 40 41 42  | 
    
      # File 'lib/cloudinary/analytics.rb', line 32 def sdk_analytics_signature return @signature unless @signature.nil? begin @signature = ALGO_VERSION + @product + @sdk_code + encode_version(@sdk_version) + encode_version(@tech_version) rescue RangeError @signature = 'E' end @signature end  | 
  
#sdk_code(sdk_code) ⇒ void
This method returns an undefined value.
Sets the SDK code.
Used for integrations.
      66 67 68  | 
    
      # File 'lib/cloudinary/analytics.rb', line 66 def sdk_code(sdk_code) @sdk_code = sdk_code end  | 
  
#sdk_version(sdk_version) ⇒ void
This method returns an undefined value.
Sets the SDK version.
Used for integrations.
      79 80 81  | 
    
      # File 'lib/cloudinary/analytics.rb', line 79 def sdk_version(sdk_version) @sdk_version = sdk_version end  | 
  
#tech_version(tech_version) ⇒ void
This method returns an undefined value.
Sets the tech version.
Used for integrations.
      92 93 94  | 
    
      # File 'lib/cloudinary/analytics.rb', line 92 def tech_version(tech_version) @tech_version = tech_version.split('.').first(2).join('.') end  |