iterable-api-client 0.5.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bin/tapioca +27 -0
- data/lib/iterable/api_resource.rb +7 -0
- data/lib/iterable/bulk_catalog_items.rb +13 -3
- data/lib/iterable/campaigns.rb +22 -5
- data/lib/iterable/catalog_field_mappings.rb +10 -1
- data/lib/iterable/catalog_items.rb +15 -0
- data/lib/iterable/catalogs.rb +7 -0
- data/lib/iterable/channels.rb +3 -0
- data/lib/iterable/commerce.rb +16 -0
- data/lib/iterable/config.rb +6 -0
- data/lib/iterable/csv_exporter.rb +3 -0
- data/lib/iterable/device.rb +14 -0
- data/lib/iterable/email.rb +17 -1
- data/lib/iterable/email_templates.rb +20 -0
- data/lib/iterable/events.rb +24 -0
- data/lib/iterable/experiments.rb +18 -5
- data/lib/iterable/export.rb +35 -6
- data/lib/iterable/in_app.rb +35 -6
- data/lib/iterable/json_exporter.rb +3 -0
- data/lib/iterable/lists.rb +29 -3
- data/lib/iterable/message_types.rb +3 -0
- data/lib/iterable/metadata.rb +3 -0
- data/lib/iterable/metadata_table.rb +22 -1
- data/lib/iterable/push.rb +24 -2
- data/lib/iterable/push_templates.rb +20 -0
- data/lib/iterable/request.rb +31 -0
- data/lib/iterable/response.rb +16 -2
- data/lib/iterable/templates.rb +24 -0
- data/lib/iterable/users.rb +80 -0
- data/lib/iterable/workflows.rb +11 -0
- data/lib/iterable-api-client.rb +6 -1
- data/lib/iterable.rb +15 -1
- data/lib/iterable_api_client.rb +3 -1
- data.tar.gz.sig +0 -0
- metadata +17 -240
- metadata.gz.sig +0 -0
data/lib/iterable/export.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -54,9 +56,19 @@ module Iterable
|
|
54
56
|
# @param only_fields [Array[String]] Array of fields to only export
|
55
57
|
# @param omit_fields [Array[String]] Array of fields to omit
|
56
58
|
# @param data_fields [Hash] Additional device data fields
|
59
|
+
# @param campaign_id [String] The ID of the campaign
|
57
60
|
# @param conf [Iterable::Config] A config to optionally pass for requests
|
58
61
|
#
|
59
62
|
# @return [Iterable::Export]
|
63
|
+
sig do
|
64
|
+
params(
|
65
|
+
data_type: String,
|
66
|
+
only_fields: T::Array[String],
|
67
|
+
omit_fields: T::Array[String],
|
68
|
+
campaign_id: T.nilable(String),
|
69
|
+
conf: T.nilable(Iterable::Config)
|
70
|
+
).void
|
71
|
+
end
|
60
72
|
def initialize(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil) # rubocop:disable Metrics/ParameterLists
|
61
73
|
@data_type = data_type
|
62
74
|
@only_fields = only_fields
|
@@ -71,6 +83,7 @@ module Iterable
|
|
71
83
|
# @example Formats are currently csv or json
|
72
84
|
#
|
73
85
|
# @return [Exception] Raises an exception
|
86
|
+
sig { overridable.returns(String) }
|
74
87
|
def format
|
75
88
|
raise '#format must be implemented in child class'
|
76
89
|
end
|
@@ -83,6 +96,12 @@ module Iterable
|
|
83
96
|
# @param end_time [Time] The end time of the data to export
|
84
97
|
#
|
85
98
|
# @return [Iterable::Response] A response object
|
99
|
+
sig do
|
100
|
+
params(
|
101
|
+
start_time: Time,
|
102
|
+
end_time: Time
|
103
|
+
).returns(Iterable::Response)
|
104
|
+
end
|
86
105
|
def export(start_time, end_time)
|
87
106
|
params = {
|
88
107
|
startDateTime: start_time.strftime(Iterable::Export::DATE_FORMAT),
|
@@ -98,32 +117,42 @@ module Iterable
|
|
98
117
|
# @param range [Iterable::Export::RANGES] A valid range to export data for
|
99
118
|
#
|
100
119
|
# @return [Iterable::Response] A response object
|
120
|
+
sig do
|
121
|
+
params(
|
122
|
+
range: String
|
123
|
+
).returns(Iterable::Response)
|
124
|
+
end
|
101
125
|
def export_range(range = Iterable::Export::TODAY)
|
102
126
|
params = { range: range }
|
103
127
|
Iterable.request(conf, base_path, request_params(params)).get
|
104
128
|
end
|
105
129
|
|
130
|
+
sig { returns(String) }
|
106
131
|
protected def base_path
|
107
132
|
"/export/data.#{format}"
|
108
133
|
end
|
109
134
|
|
135
|
+
sig { params(params: Hash).returns(Hash) }
|
110
136
|
protected def request_params(params = {})
|
111
137
|
default_params.merge params
|
112
138
|
end
|
113
139
|
|
140
|
+
sig { returns(T::Boolean) }
|
114
141
|
protected def only_fields?
|
115
|
-
|
142
|
+
only_fields.length.to_i.positive?
|
116
143
|
end
|
117
144
|
|
145
|
+
sig { returns(T::Boolean) }
|
118
146
|
protected def omit_fields?
|
119
|
-
|
147
|
+
omit_fields.length.to_i.positive?
|
120
148
|
end
|
121
149
|
|
150
|
+
sig { returns(Hash) }
|
122
151
|
protected def default_params
|
123
|
-
params = { dataTypeName:
|
124
|
-
params[:onlyFields] =
|
125
|
-
params[:omitFields] =
|
126
|
-
params[:campaignId] =
|
152
|
+
params = { dataTypeName: data_type }
|
153
|
+
params[:onlyFields] = only_fields if only_fields?
|
154
|
+
params[:omitFields] = omit_fields.join(',') if omit_fields?
|
155
|
+
params[:campaignId] = campaign_id if campaign_id
|
127
156
|
params
|
128
157
|
end
|
129
158
|
end
|
data/lib/iterable/in_app.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -20,6 +22,13 @@ module Iterable
|
|
20
22
|
# @param attrs [Hash] Hash of query attributes like platform, SDKVersion, etc.
|
21
23
|
#
|
22
24
|
# @return [Iterable::Response] A response object
|
25
|
+
sig do
|
26
|
+
params(
|
27
|
+
email: String,
|
28
|
+
count: Integer,
|
29
|
+
attrs: T.any(Integer, String)
|
30
|
+
).returns(Iterable::Response)
|
31
|
+
end
|
23
32
|
def messages_for_email(email, count: 1, **attrs)
|
24
33
|
attrs[:email] = email
|
25
34
|
attrs[:count] = count
|
@@ -30,11 +39,18 @@ module Iterable
|
|
30
39
|
#
|
31
40
|
# Get in-app messages for a user by user_id
|
32
41
|
#
|
33
|
-
# @param
|
42
|
+
# @param user_id [String] *required* ID of user who received the message to view.
|
34
43
|
# @param count [Integer] Number of messages to return, defaults to 1
|
35
44
|
# @param attrs [Hash] Hash of query attributes like platform, SDKVersion, etc.
|
36
45
|
#
|
37
46
|
# @return [Iterable::Response] A response object
|
47
|
+
sig do
|
48
|
+
params(
|
49
|
+
user_id: T.any(String, Integer),
|
50
|
+
count: Integer,
|
51
|
+
attrs: T.any(Integer, String)
|
52
|
+
).returns(Iterable::Response)
|
53
|
+
end
|
38
54
|
def messages_for_user_id(user_id, count: 1, **attrs)
|
39
55
|
attrs[:userId] = user_id
|
40
56
|
attrs[:count] = count
|
@@ -46,12 +62,18 @@ module Iterable
|
|
46
62
|
# Send an In-App notification to a specific user. User Email or ID along
|
47
63
|
# with campaign ID must be provided
|
48
64
|
#
|
49
|
-
# @param email [String] (optional) User email used to identify user
|
50
65
|
# @param campaign_id [Integer] Campaign ID
|
51
66
|
# @param attrs [Hash] Additional data to update or add
|
67
|
+
# @param email [String] (optional) User email used to identify user
|
52
68
|
#
|
53
69
|
# @return [Iterable::Response] A response object
|
54
|
-
|
70
|
+
sig do
|
71
|
+
params(
|
72
|
+
campaign_id: T.any(String, Integer),
|
73
|
+
attrs: T::Hash[T.any(Symbol, String), T.any(Integer, String)],
|
74
|
+
email: T.nilable(String)
|
75
|
+
).returns(Iterable::Response)
|
76
|
+
end
|
55
77
|
def target(campaign_id:, attrs: {}, email: nil)
|
56
78
|
attrs['recipientEmail'] = email if email
|
57
79
|
attrs['campaignId'] = campaign_id
|
@@ -64,20 +86,27 @@ module Iterable
|
|
64
86
|
# Must include either an email address AND campaignId, or
|
65
87
|
# just a scheduledMessageId provided in the attrs
|
66
88
|
#
|
67
|
-
# @param
|
68
|
-
# @param campaignId [Integer] campaignID used to cancel push
|
89
|
+
# @param campaign_id [Integer] campaignID used to cancel push
|
69
90
|
# @param attrs [Hash] Additional data to update or add
|
91
|
+
# @param email [String] User email to cancel push
|
70
92
|
#
|
71
93
|
# @return [Iterable::Response] A response object
|
72
94
|
#
|
73
95
|
# @note An email or UserId is required
|
96
|
+
sig do
|
97
|
+
params(
|
98
|
+
campaign_id: T.nilable(T.any(String, Integer)),
|
99
|
+
attrs: T::Hash[T.any(Symbol, String), T.any(Integer, String)],
|
100
|
+
email: T.nilable(String)
|
101
|
+
).returns(Iterable::Response)
|
102
|
+
end
|
74
103
|
def cancel(campaign_id: nil, attrs: {}, email: nil)
|
75
104
|
attrs['email'] = email if email
|
76
105
|
attrs['campaignId'] = campaign_id if campaign_id
|
77
106
|
Iterable.request(conf, '/push/cancel').post(attrs)
|
78
107
|
end
|
79
108
|
|
80
|
-
private def messages(
|
109
|
+
private def messages(attrs = {})
|
81
110
|
Iterable.request(conf, '/inApp/getMessages', attrs).get
|
82
111
|
end
|
83
112
|
end
|
data/lib/iterable/lists.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -17,6 +19,7 @@ module Iterable
|
|
17
19
|
# Get all lists
|
18
20
|
#
|
19
21
|
# @return [Iterable::Response] A response object
|
22
|
+
sig { returns(Iterable::Response) }
|
20
23
|
def all
|
21
24
|
Iterable.request(conf, '/lists').get
|
22
25
|
end
|
@@ -28,6 +31,7 @@ module Iterable
|
|
28
31
|
# @param name [String] The name of the list to create
|
29
32
|
#
|
30
33
|
# @return [Iterable::Response] A response object
|
34
|
+
sig { params(name: String).returns(Iterable::Response) }
|
31
35
|
def create(name)
|
32
36
|
Iterable.request(conf, '/lists').post(name: name)
|
33
37
|
end
|
@@ -36,9 +40,10 @@ module Iterable
|
|
36
40
|
#
|
37
41
|
# Delete an existing list given a list id
|
38
42
|
#
|
39
|
-
# @param
|
43
|
+
# @param list_id [String|Integer] The id of the list to delete
|
40
44
|
#
|
41
45
|
# @return [Iterable::Response] A response object
|
46
|
+
sig { params(list_id: T.any(String, Integer)).returns(Iterable::Response) }
|
42
47
|
def delete(list_id)
|
43
48
|
Iterable.request(conf, "/lists/#{list_id}").delete
|
44
49
|
end
|
@@ -50,6 +55,7 @@ module Iterable
|
|
50
55
|
# @param list_id [String|Integer] The id of the list
|
51
56
|
#
|
52
57
|
# @return [Iterable::Response] A response object
|
58
|
+
sig { params(list_id: T.any(String, Integer)).returns(Iterable::Response) }
|
53
59
|
def users(list_id)
|
54
60
|
Iterable.request(conf, '/lists/getUsers', listId: list_id).get
|
55
61
|
end
|
@@ -59,9 +65,19 @@ module Iterable
|
|
59
65
|
# Subscribe users to a list
|
60
66
|
#
|
61
67
|
# @param list_id [String|Integer] The id of the list
|
62
|
-
# @param
|
68
|
+
# @param subscribers [Array[Hash]] An array of hashes of user emails and data fields
|
63
69
|
#
|
64
70
|
# @return [Iterable::Response] A response object
|
71
|
+
sig do
|
72
|
+
params(
|
73
|
+
list_id: T.any(String, Integer),
|
74
|
+
subscribers: T::Array[
|
75
|
+
T::Hash[
|
76
|
+
T.any(Symbol, String), T.any(Symbol, String)
|
77
|
+
]
|
78
|
+
]
|
79
|
+
).returns(Iterable::Response)
|
80
|
+
end
|
65
81
|
def subscribe(list_id, subscribers = [])
|
66
82
|
attrs = {
|
67
83
|
listId: list_id,
|
@@ -75,9 +91,19 @@ module Iterable
|
|
75
91
|
# Subscribe users to a list
|
76
92
|
#
|
77
93
|
# @param list_id [String|Integer] The id of the list
|
78
|
-
# @param
|
94
|
+
# @param subscribers [Array[Hash]] An array of hashes with an email
|
79
95
|
#
|
80
96
|
# @return [Iterable::Response] A response object
|
97
|
+
sig do
|
98
|
+
params(
|
99
|
+
list_id: T.any(String, Integer),
|
100
|
+
subscribers: T::Array[
|
101
|
+
T::Hash[
|
102
|
+
T.any(Symbol, String), T.any(Symbol, String)
|
103
|
+
]
|
104
|
+
]
|
105
|
+
).returns(Iterable::Response)
|
106
|
+
end
|
81
107
|
def unsubscribe(list_id, subscribers = [])
|
82
108
|
attrs = {
|
83
109
|
listId: list_id,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -24,6 +26,7 @@ module Iterable
|
|
24
26
|
# Get all message_types
|
25
27
|
#
|
26
28
|
# @return [Iterable::Response] A response object
|
29
|
+
sig { returns(Iterable::Response) }
|
27
30
|
def all
|
28
31
|
Iterable.request(conf, '/messageTypes').get
|
29
32
|
end
|
data/lib/iterable/metadata.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -22,6 +24,12 @@ module Iterable
|
|
22
24
|
# @param conf [Iterable::Config] A config to optionally pass for requests
|
23
25
|
#
|
24
26
|
# @return [Iterable::MetadataTable]
|
27
|
+
sig do
|
28
|
+
params(
|
29
|
+
name: String,
|
30
|
+
conf: T.nilable(Iterable::Config)
|
31
|
+
).void
|
32
|
+
end
|
25
33
|
def initialize(name, conf = nil)
|
26
34
|
@name = name
|
27
35
|
super conf
|
@@ -31,9 +39,10 @@ module Iterable
|
|
31
39
|
#
|
32
40
|
# Get metadata table keys
|
33
41
|
#
|
34
|
-
# @
|
42
|
+
# @param next_marker [String] next result set id if more hits exist
|
35
43
|
#
|
36
44
|
# @return [Iterable::Response] A response object
|
45
|
+
sig { params(next_marker: T.nilable(String)).returns(Iterable::Response) }
|
37
46
|
def list_keys(next_marker = nil)
|
38
47
|
params = {}
|
39
48
|
params['nextMarker'] = next_marker if next_marker
|
@@ -45,6 +54,7 @@ module Iterable
|
|
45
54
|
# Delete metadata table
|
46
55
|
#
|
47
56
|
# @return [Iterable::Response] A response object
|
57
|
+
sig { returns(Iterable::Response) }
|
48
58
|
def delete
|
49
59
|
Iterable.request(conf, base_path).delete
|
50
60
|
end
|
@@ -57,6 +67,15 @@ module Iterable
|
|
57
67
|
# @param value [Hash] Value of metadata key as a hash of key/value data
|
58
68
|
#
|
59
69
|
# @return [Iterable::Response] A response object
|
70
|
+
sig do
|
71
|
+
params(
|
72
|
+
key: String,
|
73
|
+
value: T::Hash[
|
74
|
+
T.any(Symbol, String),
|
75
|
+
T.any(T::Boolean, String, Float, Integer)
|
76
|
+
]
|
77
|
+
).returns(Iterable::Response)
|
78
|
+
end
|
60
79
|
def add(key, value = {})
|
61
80
|
Iterable.request(conf, base_path(key)).put(value: value)
|
62
81
|
end
|
@@ -68,6 +87,7 @@ module Iterable
|
|
68
87
|
# @param key [String] Key of metadata to get
|
69
88
|
#
|
70
89
|
# @return [Iterable::Response] A response object
|
90
|
+
sig { params(key: String).returns(Iterable::Response) }
|
71
91
|
def get(key)
|
72
92
|
Iterable.request(conf, base_path(key)).get
|
73
93
|
end
|
@@ -79,6 +99,7 @@ module Iterable
|
|
79
99
|
# @param key [String] Key of metadata to delete
|
80
100
|
#
|
81
101
|
# @return [Iterable::Response] A response object
|
102
|
+
sig { params(key: String).returns(Iterable::Response) }
|
82
103
|
def remove(key)
|
83
104
|
Iterable.request(conf, base_path(key)).delete
|
84
105
|
end
|
data/lib/iterable/push.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -13,11 +15,21 @@ module Iterable
|
|
13
15
|
#
|
14
16
|
# Send a push notification to a specific user
|
15
17
|
#
|
16
|
-
# @param email [String] (optional) User email used to identify user
|
17
18
|
# @param campaign_id [Integer] Campaign ID
|
19
|
+
# @param email [String] (optional) User email used to identify user
|
18
20
|
# @param attrs [Hash] Additional data to update or add
|
19
21
|
#
|
20
22
|
# @return [Iterable::Response] A response object
|
23
|
+
sig do
|
24
|
+
params(
|
25
|
+
campaign_id: T.any(String, Integer),
|
26
|
+
email: T.nilable(String),
|
27
|
+
attrs: T::Hash[
|
28
|
+
T.any(Symbol, String),
|
29
|
+
T.any(T::Boolean, String, Integer, Float)
|
30
|
+
]
|
31
|
+
).returns(Iterable::Response)
|
32
|
+
end
|
21
33
|
def target(campaign_id:, email: nil, attrs: {})
|
22
34
|
attrs['recipientEmail'] = email if email
|
23
35
|
attrs['campaignId'] = campaign_id
|
@@ -31,12 +43,22 @@ module Iterable
|
|
31
43
|
# just a scheduledMessageId provided in the attrs
|
32
44
|
#
|
33
45
|
# @param email [String] User email to cancel push
|
34
|
-
# @param
|
46
|
+
# @param campaign_id [Integer] campaignID used to cancel push
|
35
47
|
# @param attrs [Hash] Additional data to update or add
|
36
48
|
#
|
37
49
|
# @return [Iterable::Response] A response object
|
38
50
|
#
|
39
51
|
# @note An email or UserId is required
|
52
|
+
sig do
|
53
|
+
params(
|
54
|
+
email: T.nilable(String),
|
55
|
+
campaign_id: T.nilable(T.any(String, Integer)),
|
56
|
+
attrs: T::Hash[
|
57
|
+
T.any(Symbol, String),
|
58
|
+
T.any(T::Boolean, String, Integer, Float)
|
59
|
+
]
|
60
|
+
).returns(Iterable::Response)
|
61
|
+
end
|
40
62
|
def cancel(email: nil, campaign_id: nil, attrs: {})
|
41
63
|
attrs['email'] = email if email
|
42
64
|
attrs['campaignId'] = campaign_id if campaign_id
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -20,6 +22,15 @@ module Iterable
|
|
20
22
|
# @param params [Hash] Additional params to use such as locale
|
21
23
|
#
|
22
24
|
# @return [Iterable::Response] A response object
|
25
|
+
sig do
|
26
|
+
params(
|
27
|
+
template_id: T.any(String, Integer),
|
28
|
+
params: T::Hash[
|
29
|
+
T.any(Symbol, String),
|
30
|
+
T.any(T::Boolean, String, Integer, Float)
|
31
|
+
]
|
32
|
+
).returns(Iterable::Response)
|
33
|
+
end
|
23
34
|
def get(template_id, params = {})
|
24
35
|
params['templateId'] = template_id
|
25
36
|
Iterable.request(conf, '/templates/push/get', params).get
|
@@ -46,6 +57,15 @@ module Iterable
|
|
46
57
|
# @param attrs [Hash] Update attributes
|
47
58
|
#
|
48
59
|
# @return [Iterable::Response] A response object
|
60
|
+
sig do
|
61
|
+
params(
|
62
|
+
client_template_id: T.any(String, Integer),
|
63
|
+
attrs: T::Hash[
|
64
|
+
T.any(Symbol, String),
|
65
|
+
T.any(T::Boolean, String, Integer, Float)
|
66
|
+
]
|
67
|
+
).returns(Iterable::Response)
|
68
|
+
end
|
49
69
|
def upsert(client_template_id, attrs = {})
|
50
70
|
attrs['clientTemplateId'] = client_template_id
|
51
71
|
Iterable.request(conf, '/templates/push/upsert').post(attrs)
|
data/lib/iterable/request.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
1
3
|
require 'openssl'
|
2
4
|
require 'uri'
|
3
5
|
|
4
6
|
module Iterable
|
5
7
|
# @!visibility private
|
6
8
|
class Request
|
9
|
+
extend T::Sig
|
10
|
+
|
7
11
|
DEFAULT_OPTIONS = {
|
8
12
|
use_ssl: true,
|
9
13
|
verify_ssl: true,
|
@@ -15,6 +19,13 @@ module Iterable
|
|
15
19
|
'content-type' => 'application/json'
|
16
20
|
}.freeze
|
17
21
|
|
22
|
+
sig do
|
23
|
+
params(
|
24
|
+
config: Iterable::Config,
|
25
|
+
path: String,
|
26
|
+
params: Hash
|
27
|
+
).void
|
28
|
+
end
|
18
29
|
def initialize(config, path, params = {})
|
19
30
|
@config = config
|
20
31
|
@uri = build_uri(path, params)
|
@@ -22,22 +33,27 @@ module Iterable
|
|
22
33
|
setup_http(@net)
|
23
34
|
end
|
24
35
|
|
36
|
+
sig { params(headers: Hash).returns(Iterable::Response) }
|
25
37
|
def get(headers = {})
|
26
38
|
execute :get, {}, headers
|
27
39
|
end
|
28
40
|
|
41
|
+
sig { params(body: Hash, headers: Hash).returns(Iterable::Response) }
|
29
42
|
def post(body = {}, headers = {})
|
30
43
|
execute :post, body, headers
|
31
44
|
end
|
32
45
|
|
46
|
+
sig { params(body: Hash, headers: Hash).returns(Iterable::Response) }
|
33
47
|
def put(body = {}, headers = {})
|
34
48
|
execute :put, body, headers
|
35
49
|
end
|
36
50
|
|
51
|
+
sig { params(body: Hash, headers: Hash).returns(Iterable::Response) }
|
37
52
|
def patch(body = {}, headers = {})
|
38
53
|
execute :patch, body, headers
|
39
54
|
end
|
40
55
|
|
56
|
+
sig { params(body: Hash, headers: Hash).returns(Iterable::Response) }
|
41
57
|
def delete(body = {}, headers = {})
|
42
58
|
execute :delete, body, headers
|
43
59
|
end
|
@@ -48,6 +64,13 @@ module Iterable
|
|
48
64
|
transmit http
|
49
65
|
end
|
50
66
|
|
67
|
+
sig do
|
68
|
+
params(
|
69
|
+
verb: Symbol,
|
70
|
+
body: Hash,
|
71
|
+
headers: Hash
|
72
|
+
).returns(Net::HTTPRequest)
|
73
|
+
end
|
51
74
|
private def connection(verb, body = {}, headers = {})
|
52
75
|
conn_headers = DEFAULT_HEADERS.dup.merge(headers)
|
53
76
|
conn_headers['Api-Key'] = @config.token if @config.token
|
@@ -56,6 +79,11 @@ module Iterable
|
|
56
79
|
req
|
57
80
|
end
|
58
81
|
|
82
|
+
sig do
|
83
|
+
params(
|
84
|
+
http: T.any(Net::HTTP, Net::HTTP::Post, Net::HTTP::Get, Net::HTTP::Put, Net::HTTP::Patch, Net::HTTP::Delete)
|
85
|
+
).void
|
86
|
+
end
|
59
87
|
private def setup_http(http)
|
60
88
|
DEFAULT_OPTIONS.dup.each do |option, value|
|
61
89
|
setter = "#{option.to_sym}="
|
@@ -74,6 +102,7 @@ module Iterable
|
|
74
102
|
Net::HTTP.new(@uri.hostname, @uri.port, nil, nil, nil, nil)
|
75
103
|
end
|
76
104
|
|
105
|
+
sig { params(req: Net::HTTPRequest).returns(Iterable::Response) }
|
77
106
|
private def transmit(req)
|
78
107
|
response = nil
|
79
108
|
@net.start do |http|
|
@@ -82,6 +111,7 @@ module Iterable
|
|
82
111
|
handle_response response
|
83
112
|
end
|
84
113
|
|
114
|
+
sig { params(response: Net::HTTPResponse).returns(Iterable::Response) }
|
85
115
|
private def handle_response(response)
|
86
116
|
redirected = response.is_a?(Net::HTTPRedirection) || response.code == '303'
|
87
117
|
if redirected && response['location']
|
@@ -91,6 +121,7 @@ module Iterable
|
|
91
121
|
end
|
92
122
|
end
|
93
123
|
|
124
|
+
sig { params(response: Net::HTTPResponse).returns(URI) }
|
94
125
|
private def uri_for_redirect(response)
|
95
126
|
uri = @config.uri
|
96
127
|
redirect_uri = URI(response['location'])
|
data/lib/iterable/response.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
module Iterable
|
@@ -6,12 +8,18 @@ module Iterable
|
|
6
8
|
# Response class is used to get access to raw HTTP request info
|
7
9
|
class Response
|
8
10
|
extend Forwardable
|
11
|
+
extend T::Sig
|
9
12
|
|
10
13
|
def_delegators :@resp, :code, :message, :uri, :[]
|
11
14
|
|
12
15
|
attr_reader :body
|
13
16
|
|
14
17
|
# @!visibility private
|
18
|
+
sig do
|
19
|
+
params(
|
20
|
+
resp: Net::HTTPResponse
|
21
|
+
).void
|
22
|
+
end
|
15
23
|
def initialize(resp)
|
16
24
|
@resp = resp
|
17
25
|
@body = parsed_body
|
@@ -19,8 +27,9 @@ module Iterable
|
|
19
27
|
|
20
28
|
##
|
21
29
|
#
|
22
|
-
# Convenience method to determine if request was
|
30
|
+
# Convenience method to determine if request was successful or not
|
23
31
|
# @return [Boolean]
|
32
|
+
sig { returns(T::Boolean) }
|
24
33
|
def success?
|
25
34
|
case @resp.code.to_i
|
26
35
|
when (200..299) then true
|
@@ -34,9 +43,14 @@ module Iterable
|
|
34
43
|
# if unable to parse.
|
35
44
|
#
|
36
45
|
# @return [Hash,Array,String] A parsed JSON object or the original response body
|
46
|
+
sig do
|
47
|
+
returns(
|
48
|
+
T.nilable(T.any(Hash, Array, String))
|
49
|
+
)
|
50
|
+
end
|
37
51
|
private def parsed_body
|
38
52
|
response_body = @resp.body
|
39
|
-
MultiJson.load
|
53
|
+
MultiJson.load(response_body)
|
40
54
|
rescue MultiJson::ParseError
|
41
55
|
response_body
|
42
56
|
end
|
data/lib/iterable/templates.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Iterable
|
2
4
|
##
|
3
5
|
#
|
@@ -22,13 +24,35 @@ module Iterable
|
|
22
24
|
|
23
25
|
##
|
24
26
|
#
|
27
|
+
#
|
25
28
|
# Get all templates
|
26
29
|
#
|
27
30
|
# @return [Iterable::Response] A response object
|
31
|
+
sig do
|
32
|
+
params(
|
33
|
+
params: T::Hash[
|
34
|
+
T.any(Symbol, String),
|
35
|
+
T.any(T::Boolean, Integer, String, Float)
|
36
|
+
]
|
37
|
+
).returns(Iterable::Response)
|
38
|
+
end
|
28
39
|
def all(params = {})
|
29
40
|
Iterable.request(conf, '/templates', params).get
|
30
41
|
end
|
31
42
|
|
43
|
+
##
|
44
|
+
#
|
45
|
+
#
|
46
|
+
# Get a template by client template ID
|
47
|
+
#
|
48
|
+
# @param client_template_id [String|Integer] The client template ID to find by
|
49
|
+
#
|
50
|
+
# @return [Iterable::Response] A response object
|
51
|
+
sig do
|
52
|
+
params(
|
53
|
+
client_template_id: T.any(String, Integer)
|
54
|
+
).returns(Iterable::Response)
|
55
|
+
end
|
32
56
|
def for_client_template_id(client_template_id)
|
33
57
|
params = { clientTemplateId: client_template_id }
|
34
58
|
Iterable.request(conf, '/templates/getByClientTemplateId', params).get
|