klaviyo 2.0.9 → 2.0.8

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: f20097f9b9538503cc8f541dd7e6d71c6c70904e51fdd59f636670f56d0b53c5
4
- data.tar.gz: 98032c0e8a4ac60b16501495b71d35ce09bd28bd62fce4c49392448929555ffa
3
+ metadata.gz: b02aaf0e72a06b6d2bf999e9279a8b6c20c0f4f7652275fea1981ea0ab0683c5
4
+ data.tar.gz: 4b2ac021105853944c5bdbf47efa268addda7b1006f2683be04cadefb4db7ecc
5
5
  SHA512:
6
- metadata.gz: e4f99398385906828f37a4e1f25f05ca76493a905d526177da2cc189301fba84adc76551711213c85003337b0278d0cade9c8ba52e0c0726176465fd2c8132cd
7
- data.tar.gz: e109724a853cbf44a3546298fdfc04037a9cfb748b72a3edd96fab1475e209a3ea67c697ce940ff54d6aac57120f37aa853076398c016995b1b4b11f70279694
6
+ metadata.gz: 561d598fa79624b0a2e271efb64676d55f39f09ca4ee787097061006f865f08f14d12faa49da7eea2a28523c3c0d96ed727feff2b40924b3965b1b1b234fb727
7
+ data.tar.gz: 934fe573a195fa8e307fc1c4383f810965d0b2636e81d8a442ece9c5b613ddef4d3eb3a1d5a159a82328edbb12cd0c87ab071a27ce5d7d57f2e8d7060a29433b
data/klaviyo.gemspec CHANGED
@@ -2,8 +2,8 @@ files = ['klaviyo.gemspec', '{lib}/**/**/*'].map {|f| Dir[f]}.flatten
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'klaviyo'
5
- s.version = '2.0.9'
6
- s.date = '2021-07-30'
5
+ s.version = '2.0.8'
6
+ s.date = '2021-04-28'
7
7
  s.summary = 'You heard us, a Ruby wrapper for the Klaviyo API'
8
8
  s.description = 'Ruby wrapper for the Klaviyo API'
9
9
  s.authors = ['Klaviyo Team']
@@ -4,15 +4,12 @@ module Klaviyo
4
4
  #
5
5
  # @kwarg :id [String] the customer or profile id
6
6
  # @kwarg :email [String] the customer or profile email
7
- # @kwarg :phone_number [String] the customer or profile phone number
8
7
  # @kwarg :properties [Hash] properties of the profile to add or update
9
- # @kwargs :method [String] the HTTP method to use for the request. Accepts 'get' or 'post'. Defaults to 'get'.
10
8
  def self.identify(kwargs = {})
11
9
  defaults = {:id => nil,
12
10
  :email => nil,
13
11
  :phone_number => nil,
14
- :properties => {},
15
- :method => HTTP_GET
12
+ :properties => {}
16
13
  }
17
14
  kwargs = defaults.merge(kwargs)
18
15
 
@@ -30,7 +27,7 @@ module Klaviyo
30
27
  :properties => properties
31
28
  }
32
29
 
33
- public_request(kwargs[:method], 'identify', **params)
30
+ public_request(HTTP_GET, 'identify', **params)
34
31
  end
35
32
 
36
33
  # Used for tracking events and customer behaviors
@@ -42,7 +39,6 @@ module Klaviyo
42
39
  # @kwarg :properties [Hash] properties of the event
43
40
  # @kwargs :customer_properties [Hash] properties of the customer or profile
44
41
  # @kwargs :time [Integer] timestamp of the event
45
- # @kwargs :method [String] the HTTP method to use for the request. Accepts 'get' or 'post'. Defaults to 'get'.
46
42
  def self.track(event, kwargs = {})
47
43
  defaults = {
48
44
  :id => nil,
@@ -50,8 +46,7 @@ module Klaviyo
50
46
  :phone_number => nil,
51
47
  :properties => {},
52
48
  :customer_properties => {},
53
- :time => nil,
54
- :method => HTTP_GET
49
+ :time => nil
55
50
  }
56
51
 
57
52
  kwargs = defaults.merge(kwargs)
@@ -73,7 +68,7 @@ module Klaviyo
73
68
  }
74
69
  params[:time] = kwargs[:time] if kwargs[:time]
75
70
 
76
- public_request(kwargs[:method], 'track', **params)
71
+ public_request(HTTP_GET, 'track', **params)
77
72
  end
78
73
 
79
74
  def self.track_once(event, kwargs = {})
@@ -40,21 +40,10 @@ module Klaviyo
40
40
  end
41
41
 
42
42
  def self.public_request(method, path, **kwargs)
43
- check_public_api_key_is_valid()
44
- if method == HTTP_GET
45
- params = build_params(kwargs)
46
- url = "#{BASE_API_URL}/#{path}?#{params}"
47
- res = Faraday.get(url).body
48
- elsif method == HTTP_POST
49
- url = URI("#{BASE_API_URL}/#{path}")
50
- response = Faraday.post(url) do |req|
51
- req.headers['Content-Type'] = CONTENT_URL_FORM
52
- req.headers['Accept'] = 'text/html'
53
- req.body = {data: "#{kwargs.to_json}"}
54
- end
55
- else
56
- raise KlaviyoError.new(INVALID_HTTP_METHOD)
57
- end
43
+ check_public_api_key_exists()
44
+ params = build_params(kwargs)
45
+ url = "#{BASE_API_URL}/#{path}?#{params}"
46
+ res = Faraday.get(url).body
58
47
  end
59
48
 
60
49
  def self.v1_request(method, path, content_type: CONTENT_JSON, **kwargs)
@@ -107,16 +96,10 @@ module Klaviyo
107
96
  end
108
97
  end
109
98
 
110
- def self.check_public_api_key_is_valid()
99
+ def self.check_public_api_key_exists()
111
100
  if !Klaviyo.public_api_key
112
101
  raise KlaviyoError.new(NO_PUBLIC_API_KEY_ERROR)
113
102
  end
114
- if ( Klaviyo.public_api_key =~ /pk_\w{34}$/ ) == 0
115
- raise KlaviyoError.new(PRIVATE_KEY_AS_PUBLIC)
116
- end
117
- if ( Klaviyo.public_api_key =~ /\w{6}$/ ) != 0
118
- raise KlaviyoError.new(INCORRECT_PUBLIC_API_KEY_LENGTH)
119
- end
120
103
  end
121
104
 
122
105
  def self.encode_params(kwargs)
@@ -24,7 +24,4 @@ module Klaviyo
24
24
  NO_PUBLIC_API_KEY_ERROR = 'Please provide your Public API key for this request'
25
25
  REQUIRED_ARG_ERROR = 'You must identify a user by email, ID or phone_number'
26
26
  INVALID_ID_TYPE_ERROR = 'Invalid id_type provided, must be one of: email, phone_number, person_id'
27
- PRIVATE_KEY_AS_PUBLIC = 'Private API key added in place of Public API key'
28
- INCORRECT_PUBLIC_API_KEY_LENGTH = 'Public API Key must be 6 characters'
29
- INVALID_HTTP_METHOD = 'Invalid HTTP method present, please use "get" or "post"'
30
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaviyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaviyo Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-30 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json