kameleoon-client-ruby 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70d1fc8cd47248dd68ba217e9a860577008e008cac7e6f562ab1856b3dc24c3
4
- data.tar.gz: 03ddd4ce4f1ea480bc5adfc347c9f2168af952cc9036ce5cff494af9699a4dfe
3
+ metadata.gz: 39f1a248856acac59bccf9df044f714962c44859ac9d253cfce7d4c963506d72
4
+ data.tar.gz: 9931a050f2b2de5e761a16b276a88a47a833b8f094f6e62be29794ff4dc56fd1
5
5
  SHA512:
6
- metadata.gz: d3d39ad2e27a0312ff090f58a93cba6aa69450fd7763fbdc1375bd146bf1af909dde84815073fc7cf7d60b8aa123cb4cc139e8dee19c30aba3a88ae021475633
7
- data.tar.gz: bfb92b7c42f02fde8d90484efef51abe294eaece630e97e7d0168e7974dd89d06b9069e9226c23bc2cf25755a2c1d4e41c87d114a1093b6e391a04d440f60de7
6
+ metadata.gz: 238bbd2ccd8bd757dea1ee47326d412f5614bb031f5e6f2e27ac4f300a13455df1b9d7bcd70049324d50486db627f451ffdf46fe3805fe76cea44454e3d408af
7
+ data.tar.gz: 94660b0ffc6c5e04478362a28db232998ac38a848fa0974331f2dd9364a150eb07c8474c5b4d66b234c997de99330eda73f02e31a6be24f98b07127a7566b860
@@ -9,6 +9,8 @@ require 'rufus/scheduler'
9
9
  require 'yaml'
10
10
  require 'json'
11
11
  require 'em-synchrony'
12
+ require 'em-synchrony/em-http'
13
+ require 'em-synchrony/fiber_iterator'
12
14
  require 'objspace'
13
15
  require 'time'
14
16
 
@@ -31,6 +33,7 @@ module Kameleoon
31
33
  @default_timeout = config['default_timeout'] || default_timeout # in ms
32
34
  @interval = config['actions_configuration_refresh_interval'].to_s + 'm' || interval
33
35
  @tracking_url = config['tracking_url'] || "https://api-ssx.kameleoon.com"
36
+ @api_data_url = "https://api-data.kameleoon.com"
34
37
  @client_id = client_id || config['client_id']
35
38
  @client_secret = client_secret || config['client_secret']
36
39
  @data_maximum_size = config['visitor_data_maximum_size'] || 500 # mb
@@ -293,7 +296,7 @@ module Kameleoon
293
296
  # A feature variable can be changed easily via our web application.
294
297
  #
295
298
  # @param [String | Integer] feature_key
296
- # @param [String ] variable_key
299
+ # @param [String] variable_key
297
300
  #
298
301
  # @raise [Kameleoon::Exception::FeatureConfigurationNotFound]
299
302
  # @raise [Kameleoon::Exception::FeatureVariableNotFound]
@@ -318,6 +321,30 @@ module Kameleoon
318
321
  end
319
322
  end
320
323
 
324
+ ##
325
+ # The retrieved_data_from_remote_source method allows you to retrieve data (according to a key passed as argument)
326
+ # stored on a remote Kameleoon server. Usually data will be stored on our remote servers via the use of our Data API.
327
+ # This method, along with the availability of our highly scalable servers for this purpose, provides a convenient way
328
+ # to quickly store massive amounts of data that can be later retrieved for each of your visitors / users.
329
+ #
330
+ # @param [String] key Key you want to retrieve data. This field is mandatory.
331
+ # @param [Int] timeout Timeout for request. Equals default_timeout in a config file. This field is optional.
332
+ #
333
+ # @return [Hash] Hash object of the json object.
334
+ #
335
+ #
336
+ def retrieve_data_from_remote_source(key, timeout = @default_timeout)
337
+ connexion_options = { connect_timeout: (timeout.to_f / 1000.0) }
338
+ path = get_api_data_request_url(key)
339
+ log "Retrieve API Data connexion: #{connexion_options.inspect}"
340
+ response = get_sync(@api_data_url + path, connexion_options)
341
+ if is_successful_sync(response)
342
+ JSON.parse(response.body) unless response.nil?
343
+ else
344
+ return nil
345
+ end
346
+ end
347
+
321
348
  private
322
349
 
323
350
  API_SSX_URL = 'https://api-ssx.kameleoon.com'
@@ -582,6 +609,14 @@ module Kameleoon
582
609
  "/dataTracking?" + URI.encode_www_form(get_common_ssx_parameters(visitor_code))
583
610
  end
584
611
 
612
+ def get_api_data_request_url(key)
613
+ mapKey = {
614
+ siteCode: site_code,
615
+ key: key
616
+ }
617
+ "/data?#{URI.encode_www_form(mapKey)}"
618
+ end
619
+
585
620
  def get_feature_flag(feature_key)
586
621
  if feature_key.is_a?(String)
587
622
  feature_flag = @feature_flags.select { |ff| ff['identificationKey'] == feature_key}.first
@@ -1,5 +1,6 @@
1
1
  require "em-synchrony/em-http"
2
2
  require "kameleoon/version"
3
+ require 'net/http'
3
4
 
4
5
  module Kameleoon
5
6
  # @api private
@@ -20,6 +21,10 @@ module Kameleoon
20
21
  request(Method::POST, request_options, url, connexion_options)
21
22
  end
22
23
 
24
+ def get_sync(url = API_URL, connexion_options = {})
25
+ request_sync(Method::GET, url, connexion_options)
26
+ end
27
+
23
28
  private
24
29
 
25
30
  def request(method, request_options, url, connexion_options)
@@ -29,7 +34,22 @@ module Kameleoon
29
34
  when Method::POST then
30
35
  return EventMachine::HttpRequest.new(url, connexion_options).apost request_options
31
36
  when Method::GET then
32
- return EventMachine::HttpRequest.new(url, connexion_options).aget request_options
37
+ return EventMachine::HttpRequest.new(url, connexion_options).get request_options
38
+ else
39
+ print "Unknown request type"
40
+ return false
41
+ end
42
+ end
43
+
44
+ def request_sync(method, url, connexion_options)
45
+ request_options = {} if request_options.nil?
46
+ add_user_agent(request_options)
47
+ case method
48
+ when Method::GET then
49
+ uri = URI(url)
50
+ request = Net::HTTP.new(url)
51
+ response = Net::HTTP.get_response(uri)
52
+ response
33
53
  else
34
54
  print "Unknown request type"
35
55
  return false
@@ -40,6 +60,10 @@ module Kameleoon
40
60
  !request.nil? && request != false && /20\d/.match(request.response_header.status.to_s)
41
61
  end
42
62
 
63
+ def is_successful_sync(response)
64
+ !response.nil? && response != false && response.is_a?(Net::HTTPSuccess)
65
+ end
66
+
43
67
  def add_user_agent(request_options)
44
68
  if request_options[:head].nil?
45
69
  request_options[:head] = {'Kameleoon-Client' => 'sdk/ruby/' + Kameleoon::VERSION}
@@ -1,3 +1,3 @@
1
1
  module Kameleoon
2
- VERSION = '1.0.10'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleoon-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-28 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request