devcycle-ruby-server-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ daemons (1.4.1)
5
+ ethon (0.15.0)
6
+ ffi (>= 1.15.0)
7
+ eventmachine (1.2.7)
8
+ ffi (1.15.4)
9
+ multi_json (1.15.0)
10
+ mustermann (1.1.1)
11
+ ruby2_keywords (~> 0.0.1)
12
+ rack (2.2.3)
13
+ rack-protection (2.1.0)
14
+ rack
15
+ ruby-server-sdk (1.0.1)
16
+ typhoeus (~> 1.0, >= 1.0.1)
17
+ ruby2_keywords (0.0.5)
18
+ sinatra (2.1.0)
19
+ mustermann (~> 1.0)
20
+ rack (~> 2.2)
21
+ rack-protection (= 2.1.0)
22
+ tilt (~> 2.0)
23
+ sinatra-contrib (2.1.0)
24
+ multi_json
25
+ mustermann (~> 1.0)
26
+ rack-protection (= 2.1.0)
27
+ sinatra (= 2.1.0)
28
+ tilt (~> 2.0)
29
+ thin (1.8.1)
30
+ daemons (~> 1.0, >= 1.0.9)
31
+ eventmachine (~> 1.0, >= 1.0.4)
32
+ rack (>= 1, < 3)
33
+ tilt (2.0.10)
34
+ typhoeus (1.4.0)
35
+ ethon (>= 0.9.0)
36
+
37
+ PLATFORMS
38
+ universal-darwin-20
39
+ x86_64-darwin-19
40
+
41
+ DEPENDENCIES
42
+ ruby-server-sdk
43
+ sinatra
44
+ sinatra-contrib
45
+ thin
46
+
47
+ BUNDLED WITH
48
+ 2.2.31
@@ -0,0 +1,14 @@
1
+ # DevCycle Ruby SDK Example App
2
+
3
+ This is a test application demonstrating the use of the DevCycle Ruby SDK. It uses Sinatra as
4
+ a web framework to define several routes which can be called to trigger SDK functionality.
5
+
6
+ ## Installation
7
+ Install the dependencies using bundler:
8
+ `bundle install`
9
+
10
+ ## Run
11
+ Run the application using bundler:
12
+ `bundle exec ruby app.rb <YOUR SDK TOKEN>`
13
+
14
+ A valid DevCycle SDK token must be provided.
@@ -0,0 +1,47 @@
1
+ require 'sinatra'
2
+ require "sinatra/reloader" if development?
3
+ require 'devcycle-ruby-server-sdk'
4
+
5
+ token = ARGV[0]
6
+
7
+ if !token
8
+ fail Exception, 'Must provide server SDK token'
9
+ end
10
+
11
+ DevCycle.configure do |config|
12
+ # Configure API key authorization: bearerAuth
13
+ config.api_key['bearerAuth'] = token
14
+ # config.debugging = true
15
+ end
16
+
17
+ api_instance = DevCycle::DVCClient.new
18
+ user_data = DevCycle::UserData.new({
19
+ user_id: 'my-user',
20
+ app_version: '1.2.3'
21
+ })
22
+
23
+ get '/' do
24
+ 'Hello world!'
25
+ end
26
+
27
+ get '/experiment' do
28
+ result = api_instance.variable("test-feature", user_data, false)
29
+ p result
30
+
31
+ "Your variable result is: #{result.value}"
32
+ end
33
+
34
+ get '/track-event' do
35
+ event_data = DevCycle::Event.new({
36
+ type: "my-event",
37
+ target: "some_event_target",
38
+ value: 12,
39
+ meta_data: {
40
+ myKey: "my-value"
41
+ }
42
+ })
43
+
44
+ result = api_instance.track(user_data, event_data)
45
+
46
+ p result
47
+ end
data/git_push.sh ADDED
@@ -0,0 +1,57 @@
1
+ #!/bin/sh
2
+ # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3
+ #
4
+ # Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
5
+
6
+ git_user_id=$1
7
+ git_repo_id=$2
8
+ release_note=$3
9
+ git_host=$4
10
+
11
+ if [ "$git_host" = "" ]; then
12
+ git_host="github.com"
13
+ echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14
+ fi
15
+
16
+ if [ "$git_user_id" = "" ]; then
17
+ git_user_id="GIT_USER_ID"
18
+ echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19
+ fi
20
+
21
+ if [ "$git_repo_id" = "" ]; then
22
+ git_repo_id="GIT_REPO_ID"
23
+ echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24
+ fi
25
+
26
+ if [ "$release_note" = "" ]; then
27
+ release_note="Minor update"
28
+ echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29
+ fi
30
+
31
+ # Initialize the local directory as a Git repository
32
+ git init
33
+
34
+ # Adds the files in the local repository and stages them for commit.
35
+ git add .
36
+
37
+ # Commits the tracked changes and prepares them to be pushed to a remote repository.
38
+ git commit -m "$release_note"
39
+
40
+ # Sets the new remote
41
+ git_remote=$(git remote)
42
+ if [ "$git_remote" = "" ]; then # git remote not defined
43
+
44
+ if [ "$GIT_TOKEN" = "" ]; then
45
+ echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46
+ git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47
+ else
48
+ git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
49
+ fi
50
+
51
+ fi
52
+
53
+ git pull origin master
54
+
55
+ # Pushes (Forces) the changes in the local repository up to the remote repository
56
+ echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57
+ git push origin master 2>&1 | grep -v 'To https'
@@ -0,0 +1,349 @@
1
+ =begin
2
+ #DevCycle Bucketing API
3
+
4
+ #Documents the DevCycle Bucketing API which provides and API interface to User Bucketing and for generated SDKs.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module DevCycle
16
+ class DVCClient
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+
23
+ def validate_model(model)
24
+ return if model.valid?
25
+ fail ArgumentError, "Invalid data provided for model #{model.class.name}: #{model.list_invalid_properties()}"
26
+ end
27
+
28
+ # Get all features by key for user data
29
+ # @param user_data [UserData]
30
+ # @param [Hash] opts the optional parameters
31
+ # @return [Hash<String, Feature>]
32
+ def all_features(user_data, opts = {})
33
+ if !user_data.is_a?(DevCycle::UserData)
34
+ fail ArgumentError, "user_data param must be an instance of UserData!"
35
+ end
36
+
37
+ validate_model(user_data)
38
+
39
+ data, _status_code, _headers = all_features_with_http_info(user_data, opts)
40
+ data
41
+ end
42
+
43
+ # Get all features by key for user data
44
+ # @param user_data [UserData]
45
+ # @param [Hash] opts the optional parameters
46
+ # @return [Array<(Hash<String, Feature>, Integer, Hash)>] Hash<String, Feature> data, response status code and response headers
47
+ def all_features_with_http_info(user_data, opts = {})
48
+ if @api_client.config.debugging
49
+ @api_client.config.logger.debug 'Calling API: DVCClient.all_features ...'
50
+ end
51
+ # verify the required parameter 'user_data' is set
52
+ if @api_client.config.client_side_validation && user_data.nil?
53
+ fail ArgumentError, "Missing the required parameter 'user_data' when calling DVCClient.all_features"
54
+ end
55
+ # resource path
56
+ local_var_path = '/v1/features'
57
+
58
+ # query parameters
59
+ query_params = opts[:query_params] || {}
60
+
61
+ # header parameters
62
+ header_params = opts[:header_params] || {}
63
+ # HTTP header 'Accept' (if needed)
64
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
65
+ # HTTP header 'Content-Type'
66
+ content_type = @api_client.select_header_content_type(['application/json'])
67
+ if !content_type.nil?
68
+ header_params['Content-Type'] = content_type
69
+ end
70
+
71
+ # form parameters
72
+ form_params = opts[:form_params] || {}
73
+
74
+ # http body (model)
75
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(user_data)
76
+
77
+ # return_type
78
+ return_type = opts[:debug_return_type] || 'Hash<String, Feature>'
79
+
80
+ # auth_names
81
+ auth_names = opts[:debug_auth_names] || ['bearerAuth']
82
+
83
+ new_options = opts.merge(
84
+ :operation => :"DVCClient.all_features",
85
+ :header_params => header_params,
86
+ :query_params => query_params,
87
+ :form_params => form_params,
88
+ :body => post_body,
89
+ :auth_names => auth_names,
90
+ :return_type => return_type
91
+ )
92
+
93
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
94
+ if @api_client.config.debugging
95
+ @api_client.config.logger.debug "API called: DVCClient#all_features\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
96
+ end
97
+ return data, status_code, headers
98
+ end
99
+
100
+ # Get variable by key for user data
101
+ # @param key [String] Variable key
102
+ # @param user_data [UserData]
103
+ # @param default Default value for variable if none is retrieved
104
+ # @param [Hash] opts the optional parameters
105
+ # @return [Variable]
106
+ def variable(key, user_data, default, opts = {})
107
+ if !user_data.is_a?(DevCycle::UserData)
108
+ fail ArgumentError, "user_data param must be an instance of UserData!"
109
+ end
110
+
111
+ validate_model(user_data)
112
+
113
+ data, _status_code, _headers = variable_with_http_info(key, user_data, default, opts)
114
+ data
115
+ end
116
+
117
+ # Get variable by key for user data
118
+ # @param key [String] Variable key
119
+ # @param user_data [UserData]
120
+ # @param default Default value for variable if none is retrieved
121
+ # @param [Hash] opts the optional parameters
122
+ # @return [Array<(Variable, Integer, Hash)>] Variable data, response status code and response headers
123
+ def variable_with_http_info(key, user_data, default, opts = {})
124
+ if @api_client.config.debugging
125
+ @api_client.config.logger.debug 'Calling API: DVCClient.variable ...'
126
+ end
127
+ # verify the required parameter 'key' is set
128
+ if @api_client.config.client_side_validation && key.nil?
129
+ fail ArgumentError, "Missing the required parameter 'key' when calling DVCClient.variable"
130
+ end
131
+ # verify the required parameter 'user_data' is set
132
+ if @api_client.config.client_side_validation && user_data.nil?
133
+ fail ArgumentError, "Missing the required parameter 'user_data' when calling DVCClient.variable"
134
+ end
135
+ # resource path
136
+ local_var_path = '/v1/variables/{key}'.sub('{' + 'key' + '}', CGI.escape(key.to_s))
137
+
138
+ # query parameters
139
+ query_params = opts[:query_params] || {}
140
+
141
+ # header parameters
142
+ header_params = opts[:header_params] || {}
143
+ # HTTP header 'Accept' (if needed)
144
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
145
+ # HTTP header 'Content-Type'
146
+ content_type = @api_client.select_header_content_type(['application/json'])
147
+ if !content_type.nil?
148
+ header_params['Content-Type'] = content_type
149
+ end
150
+
151
+ # form parameters
152
+ form_params = opts[:form_params] || {}
153
+
154
+ # http body (model)
155
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(user_data)
156
+
157
+ # return_type
158
+ return_type = opts[:debug_return_type] || 'Variable'
159
+
160
+ # auth_names
161
+ auth_names = opts[:debug_auth_names] || ['bearerAuth']
162
+
163
+ new_options = opts.merge(
164
+ :operation => :"DVCClient.variable",
165
+ :header_params => header_params,
166
+ :query_params => query_params,
167
+ :form_params => form_params,
168
+ :body => post_body,
169
+ :auth_names => auth_names,
170
+ :return_type => return_type
171
+ )
172
+
173
+ begin
174
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
175
+ if @api_client.config.debugging
176
+ @api_client.config.logger.debug "API called: DVCClient#variable\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
177
+ end
178
+ return data
179
+ rescue ApiError => error
180
+ if error.code != 404
181
+ @api_client.config.logger.error("Failed to retrieve variable value: #{error.message}")
182
+ end
183
+
184
+ return Variable.new(key: key, value: default, isDefaulted: true)
185
+ end
186
+ end
187
+
188
+ # Get all variables by key for user data
189
+ # @param user_data [UserData]
190
+ # @param [Hash] opts the optional parameters
191
+ # @return [Hash<String, Variable>]
192
+ def all_variables(user_data, opts = {})
193
+ if !user_data.is_a?(DevCycle::UserData)
194
+ fail ArgumentError, "user_data param must be an instance of UserData!"
195
+ end
196
+
197
+ validate_model(user_data)
198
+
199
+ data, _status_code, _headers = all_variables_with_http_info(user_data, opts)
200
+ data
201
+ end
202
+
203
+ # Get all variables by key for user data
204
+ # @param user_data [UserData]
205
+ # @param [Hash] opts the optional parameters
206
+ # @return [Array<(Hash<String, Variable>, Integer, Hash)>] Hash<String, Variable> data, response status code and response headers
207
+ def all_variables_with_http_info(user_data, opts = {})
208
+ if @api_client.config.debugging
209
+ @api_client.config.logger.debug 'Calling API: DVCClient.all_variables ...'
210
+ end
211
+ # verify the required parameter 'user_data' is set
212
+ if @api_client.config.client_side_validation && user_data.nil?
213
+ fail ArgumentError, "Missing the required parameter 'user_data' when calling DVCClient.all_variables"
214
+ end
215
+ # resource path
216
+ local_var_path = '/v1/variables'
217
+
218
+ # query parameters
219
+ query_params = opts[:query_params] || {}
220
+
221
+ # header parameters
222
+ header_params = opts[:header_params] || {}
223
+ # HTTP header 'Accept' (if needed)
224
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
225
+ # HTTP header 'Content-Type'
226
+ content_type = @api_client.select_header_content_type(['application/json'])
227
+ if !content_type.nil?
228
+ header_params['Content-Type'] = content_type
229
+ end
230
+
231
+ # form parameters
232
+ form_params = opts[:form_params] || {}
233
+
234
+ # http body (model)
235
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(user_data)
236
+
237
+ # return_type
238
+ return_type = opts[:debug_return_type] || 'Hash<String, Variable>'
239
+
240
+ # auth_names
241
+ auth_names = opts[:debug_auth_names] || ['bearerAuth']
242
+
243
+ new_options = opts.merge(
244
+ :operation => :"DVCClient.all_variables",
245
+ :header_params => header_params,
246
+ :query_params => query_params,
247
+ :form_params => form_params,
248
+ :body => post_body,
249
+ :auth_names => auth_names,
250
+ :return_type => return_type
251
+ )
252
+
253
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
254
+ if @api_client.config.debugging
255
+ @api_client.config.logger.debug "API called: DVCClient#all_variables\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
256
+ end
257
+ return data, status_code, headers
258
+ end
259
+
260
+ # Post events to DevCycle for user
261
+ # @param user_data [UserData]
262
+ # @param event_data [Event]
263
+ # @param [Hash] opts the optional parameters
264
+ # @return [InlineResponse201]
265
+ def track(user_data, event_data, opts = {})
266
+ if !user_data.is_a?(DevCycle::UserData)
267
+ fail ArgumentError, "user_data param must be an instance of UserData!"
268
+ end
269
+
270
+ validate_model(user_data)
271
+
272
+ if !event_data.is_a?(DevCycle::Event)
273
+ fail ArgumentError, "event_data param must be an instance of Event!"
274
+ end
275
+
276
+ validate_model(event_data)
277
+
278
+ data, _status_code, _headers = track_with_http_info(user_data, event_data, opts)
279
+ data
280
+ end
281
+
282
+ # Post events to DevCycle for user
283
+ # @param user_data [UserData]
284
+ # @param event_data [Event]
285
+ # @param [Hash] opts the optional parameters
286
+ # @return [Array<(InlineResponse201, Integer, Hash)>] InlineResponse201 data, response status code and response headers
287
+ def track_with_http_info(user_data, event_data, opts = {})
288
+ if @api_client.config.debugging
289
+ @api_client.config.logger.debug 'Calling API: DVCClient.post_events ...'
290
+ end
291
+ # verify the required parameter 'user_data_and_events_body' is set
292
+ if @api_client.config.client_side_validation && (user_data.nil? || event_data.nil?)
293
+ fail ArgumentError, "Missing the required parameter 'user_data_and_events_body' when calling DVCClient.post_events"
294
+ end
295
+
296
+ user_data_and_events_body = DevCycle::UserDataAndEventsBody.new({
297
+ user: user_data,
298
+ events: [event_data]
299
+ })
300
+
301
+ # resource path
302
+ local_var_path = '/v1/track'
303
+
304
+ # query parameters
305
+ query_params = opts[:query_params] || {}
306
+
307
+ # header parameters
308
+ header_params = opts[:header_params] || {}
309
+ # HTTP header 'Accept' (if needed)
310
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
311
+ # HTTP header 'Content-Type'
312
+ content_type = @api_client.select_header_content_type(['application/json'])
313
+ if !content_type.nil?
314
+ header_params['Content-Type'] = content_type
315
+ end
316
+
317
+ # form parameters
318
+ form_params = opts[:form_params] || {}
319
+
320
+ # http body (model)
321
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(user_data_and_events_body)
322
+
323
+ # if post_body.user.respond_to?(:to_hash)
324
+ # post_body.user = post_body.user.to_hash()
325
+
326
+ # return_type
327
+ return_type = opts[:debug_return_type] || 'InlineResponse201'
328
+
329
+ # auth_names
330
+ auth_names = opts[:debug_auth_names] || ['bearerAuth']
331
+
332
+ new_options = opts.merge(
333
+ :operation => :"DVCClient.post_events",
334
+ :header_params => header_params,
335
+ :query_params => query_params,
336
+ :form_params => form_params,
337
+ :body => post_body,
338
+ :auth_names => auth_names,
339
+ :return_type => return_type
340
+ )
341
+
342
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
343
+ if @api_client.config.debugging
344
+ @api_client.config.logger.debug "API called: DVCClient#post_events\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
345
+ end
346
+ return data, status_code, headers
347
+ end
348
+ end
349
+ end