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,229 @@
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 'date'
14
+ require 'time'
15
+
16
+ module DevCycle
17
+ class UserDataAndEventsBody
18
+ attr_accessor :events
19
+
20
+ attr_accessor :user
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'events' => :'events',
26
+ :'user' => :'user'
27
+ }
28
+ end
29
+
30
+ # Returns all the JSON keys this model knows about
31
+ def self.acceptable_attributes
32
+ attribute_map.values
33
+ end
34
+
35
+ # Attribute type mapping.
36
+ def self.openapi_types
37
+ {
38
+ :'events' => :'Array<Event>',
39
+ :'user' => :'UserData'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ ])
47
+ end
48
+
49
+ # Initializes the object
50
+ # @param [Hash] attributes Model attributes in the form of hash
51
+ def initialize(attributes = {})
52
+ if (!attributes.is_a?(Hash))
53
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DevCycle::UserDataAndEventsBody` initialize method"
54
+ end
55
+
56
+ # check to see if the attribute exists and convert string to symbol for hash key
57
+ attributes = attributes.each_with_object({}) { |(k, v), h|
58
+ if (!self.class.attribute_map.key?(k.to_sym))
59
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DevCycle::UserDataAndEventsBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
60
+ end
61
+ h[k.to_sym] = v
62
+ }
63
+
64
+ if attributes.key?(:'events')
65
+ if (value = attributes[:'events']).is_a?(Array)
66
+ self.events = value
67
+ end
68
+ end
69
+
70
+ if attributes.key?(:'user')
71
+ self.user = attributes[:'user']
72
+ end
73
+ end
74
+
75
+ # Show invalid properties with the reasons. Usually used together with valid?
76
+ # @return Array for valid properties with the reasons
77
+ def list_invalid_properties
78
+ invalid_properties = Array.new
79
+ invalid_properties
80
+ end
81
+
82
+ # Check to see if the all the properties in the model are valid
83
+ # @return true if the model is valid
84
+ def valid?
85
+ true
86
+ end
87
+
88
+ # Checks equality by comparing each attribute.
89
+ # @param [Object] Object to be compared
90
+ def ==(o)
91
+ return true if self.equal?(o)
92
+ self.class == o.class &&
93
+ events == o.events &&
94
+ user == o.user
95
+ end
96
+
97
+ # @see the `==` method
98
+ # @param [Object] Object to be compared
99
+ def eql?(o)
100
+ self == o
101
+ end
102
+
103
+ # Calculates hash code according to all attributes.
104
+ # @return [Integer] Hash code
105
+ def hash
106
+ [events, user].hash
107
+ end
108
+
109
+ # Builds the object from hash
110
+ # @param [Hash] attributes Model attributes in the form of hash
111
+ # @return [Object] Returns the model itself
112
+ def self.build_from_hash(attributes)
113
+ new.build_from_hash(attributes)
114
+ end
115
+
116
+ # Builds the object from hash
117
+ # @param [Hash] attributes Model attributes in the form of hash
118
+ # @return [Object] Returns the model itself
119
+ def build_from_hash(attributes)
120
+ return nil unless attributes.is_a?(Hash)
121
+ self.class.openapi_types.each_pair do |key, type|
122
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
123
+ self.send("#{key}=", nil)
124
+ elsif type =~ /\AArray<(.*)>/i
125
+ # check to ensure the input is an array given that the attribute
126
+ # is documented as an array but the input is not
127
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
128
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
129
+ end
130
+ elsif !attributes[self.class.attribute_map[key]].nil?
131
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
132
+ end
133
+ end
134
+
135
+ self
136
+ end
137
+
138
+ # Deserializes the data based on type
139
+ # @param string type Data type
140
+ # @param string value Value to be deserialized
141
+ # @return [Object] Deserialized data
142
+ def _deserialize(type, value)
143
+ case type.to_sym
144
+ when :Time
145
+ Time.parse(value)
146
+ when :Date
147
+ Date.parse(value)
148
+ when :String
149
+ value.to_s
150
+ when :Integer
151
+ value.to_i
152
+ when :Float
153
+ value.to_f
154
+ when :Boolean
155
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
156
+ true
157
+ else
158
+ false
159
+ end
160
+ when :Object
161
+ # generic object (usually a Hash), return directly
162
+ value
163
+ when /\AArray<(?<inner_type>.+)>\z/
164
+ inner_type = Regexp.last_match[:inner_type]
165
+ value.map { |v| _deserialize(inner_type, v) }
166
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
167
+ k_type = Regexp.last_match[:k_type]
168
+ v_type = Regexp.last_match[:v_type]
169
+ {}.tap do |hash|
170
+ value.each do |k, v|
171
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
172
+ end
173
+ end
174
+ else # model
175
+ # models (e.g. Pet) or oneOf
176
+ klass = DevCycle.const_get(type)
177
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
178
+ end
179
+ end
180
+
181
+ # Returns the string representation of the object
182
+ # @return [String] String presentation of the object
183
+ def to_s
184
+ to_hash.to_s
185
+ end
186
+
187
+ # to_body is an alias to to_hash (backward compatibility)
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_body
190
+ to_hash
191
+ end
192
+
193
+ # Returns the object in the form of hash
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_hash
196
+ hash = {}
197
+ self.class.attribute_map.each_pair do |attr, param|
198
+ value = self.send(attr)
199
+ if value.nil?
200
+ is_nullable = self.class.openapi_nullable.include?(attr)
201
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
202
+ end
203
+
204
+ hash[param] = _to_hash(value)
205
+ end
206
+ hash
207
+ end
208
+
209
+ # Outputs non-array value in the form of hash
210
+ # For object, use to_hash. Otherwise, just return the value
211
+ # @param [Object] value Any valid value
212
+ # @return [Hash] Returns the value in the form of hash
213
+ def _to_hash(value)
214
+ if value.is_a?(Array)
215
+ value.compact.map { |v| _to_hash(v) }
216
+ elsif value.is_a?(Hash)
217
+ {}.tap do |hash|
218
+ value.each { |k, v| hash[k] = _to_hash(v) }
219
+ end
220
+ elsif value.respond_to? :to_hash
221
+ value.to_hash
222
+ else
223
+ value
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ end
@@ -0,0 +1,315 @@
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 'date'
14
+ require 'time'
15
+
16
+ module DevCycle
17
+ class Variable
18
+ # unique database id
19
+ attr_accessor :_id
20
+
21
+ # Unique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
22
+ attr_accessor :key
23
+
24
+ # Variable type
25
+ attr_accessor :type
26
+
27
+ # Variable value can be a string, number, boolean, or JSON
28
+ attr_accessor :value
29
+
30
+ # Set to true if the Variable could not be fetched
31
+ attr_accessor :isDefaulted
32
+
33
+ class EnumAttributeValidator
34
+ attr_reader :datatype
35
+ attr_reader :allowable_values
36
+
37
+ def initialize(datatype, allowable_values)
38
+ @allowable_values = allowable_values.map do |value|
39
+ case datatype.to_s
40
+ when /Integer/i
41
+ value.to_i
42
+ when /Float/i
43
+ value.to_f
44
+ else
45
+ value
46
+ end
47
+ end
48
+ end
49
+
50
+ def valid?(value)
51
+ !value || allowable_values.include?(value)
52
+ end
53
+ end
54
+
55
+ # Attribute mapping from ruby-style variable name to JSON key.
56
+ def self.attribute_map
57
+ {
58
+ :'_id' => :'_id',
59
+ :'key' => :'key',
60
+ :'type' => :'type',
61
+ :'value' => :'value',
62
+ :'isDefaulted' => :'isDefaulted'
63
+ }
64
+ end
65
+
66
+ # Returns all the JSON keys this model knows about
67
+ def self.acceptable_attributes
68
+ attribute_map.values
69
+ end
70
+
71
+ # Attribute type mapping.
72
+ def self.openapi_types
73
+ {
74
+ :'_id' => :'String',
75
+ :'key' => :'String',
76
+ :'type' => :'String',
77
+ :'value' => :'Object',
78
+ :'isDefaulted' => :'Boolean'
79
+ }
80
+ end
81
+
82
+ # List of attributes with nullable: true
83
+ def self.openapi_nullable
84
+ Set.new([
85
+ ])
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ if (!attributes.is_a?(Hash))
92
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DevCycle::Variable` initialize method"
93
+ end
94
+
95
+ # check to see if the attribute exists and convert string to symbol for hash key
96
+ attributes = attributes.each_with_object({}) { |(k, v), h|
97
+ if (!self.class.attribute_map.key?(k.to_sym))
98
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DevCycle::Variable`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
99
+ end
100
+ h[k.to_sym] = v
101
+ }
102
+
103
+ if attributes.key?(:'_id')
104
+ self._id = attributes[:'_id']
105
+ end
106
+
107
+ if attributes.key?(:'key')
108
+ self.key = attributes[:'key']
109
+ end
110
+
111
+ if attributes.key?(:'type')
112
+ self.type = attributes[:'type']
113
+ end
114
+
115
+ if attributes.key?(:'value')
116
+ self.value = attributes[:'value']
117
+ end
118
+
119
+ if attributes.key?(:'isDefaulted')
120
+ self.isDefaulted = attributes[:'isDefaulted']
121
+ else
122
+ self.isDefaulted = false
123
+ end
124
+ end
125
+
126
+ # Show invalid properties with the reasons. Usually used together with valid?
127
+ # @return Array for valid properties with the reasons
128
+ def list_invalid_properties
129
+ invalid_properties = Array.new
130
+ if @_id.nil?
131
+ invalid_properties.push('invalid value for "_id", _id cannot be nil.')
132
+ end
133
+
134
+ if @key.nil?
135
+ invalid_properties.push('invalid value for "key", key cannot be nil.')
136
+ end
137
+
138
+ if @type.nil?
139
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
140
+ end
141
+
142
+ if @value.nil?
143
+ invalid_properties.push('invalid value for "value", value cannot be nil.')
144
+ end
145
+
146
+ invalid_properties
147
+ end
148
+
149
+ # Check to see if the all the properties in the model are valid
150
+ # @return true if the model is valid
151
+ def valid?
152
+ return false if @_id.nil?
153
+ return false if @key.nil?
154
+ return false if @type.nil?
155
+ type_validator = EnumAttributeValidator.new('String', ["String", "Boolean", "Number", "JSON"])
156
+ return false unless type_validator.valid?(@type)
157
+ return false if @value.nil?
158
+ true
159
+ end
160
+
161
+ # Custom attribute writer method checking allowed values (enum).
162
+ # @param [Object] type Object to be assigned
163
+ def type=(type)
164
+ validator = EnumAttributeValidator.new('String', ["String", "Boolean", "Number", "JSON"])
165
+ unless validator.valid?(type)
166
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
167
+ end
168
+ @type = type
169
+ end
170
+
171
+ # Checks equality by comparing each attribute.
172
+ # @param [Object] Object to be compared
173
+ def ==(o)
174
+ return true if self.equal?(o)
175
+ self.class == o.class &&
176
+ _id == o._id &&
177
+ key == o.key &&
178
+ type == o.type &&
179
+ value == o.value &&
180
+ isDefaulted == o.isDefaulted
181
+ end
182
+
183
+ # @see the `==` method
184
+ # @param [Object] Object to be compared
185
+ def eql?(o)
186
+ self == o
187
+ end
188
+
189
+ # Calculates hash code according to all attributes.
190
+ # @return [Integer] Hash code
191
+ def hash
192
+ [_id, key, type, value, isDefaulted].hash
193
+ end
194
+
195
+ # Builds the object from hash
196
+ # @param [Hash] attributes Model attributes in the form of hash
197
+ # @return [Object] Returns the model itself
198
+ def self.build_from_hash(attributes)
199
+ new.build_from_hash(attributes)
200
+ end
201
+
202
+ # Builds the object from hash
203
+ # @param [Hash] attributes Model attributes in the form of hash
204
+ # @return [Object] Returns the model itself
205
+ def build_from_hash(attributes)
206
+ return nil unless attributes.is_a?(Hash)
207
+ self.class.openapi_types.each_pair do |key, type|
208
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
209
+ self.send("#{key}=", nil)
210
+ elsif type =~ /\AArray<(.*)>/i
211
+ # check to ensure the input is an array given that the attribute
212
+ # is documented as an array but the input is not
213
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
214
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
215
+ end
216
+ elsif !attributes[self.class.attribute_map[key]].nil?
217
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
218
+ end
219
+ end
220
+
221
+ self
222
+ end
223
+
224
+ # Deserializes the data based on type
225
+ # @param string type Data type
226
+ # @param string value Value to be deserialized
227
+ # @return [Object] Deserialized data
228
+ def _deserialize(type, value)
229
+ case type.to_sym
230
+ when :Time
231
+ Time.parse(value)
232
+ when :Date
233
+ Date.parse(value)
234
+ when :String
235
+ value.to_s
236
+ when :Integer
237
+ value.to_i
238
+ when :Float
239
+ value.to_f
240
+ when :Boolean
241
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
242
+ true
243
+ else
244
+ false
245
+ end
246
+ when :Object
247
+ # generic object (usually a Hash), return directly
248
+ value
249
+ when /\AArray<(?<inner_type>.+)>\z/
250
+ inner_type = Regexp.last_match[:inner_type]
251
+ value.map { |v| _deserialize(inner_type, v) }
252
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
253
+ k_type = Regexp.last_match[:k_type]
254
+ v_type = Regexp.last_match[:v_type]
255
+ {}.tap do |hash|
256
+ value.each do |k, v|
257
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
258
+ end
259
+ end
260
+ else # model
261
+ # models (e.g. Pet) or oneOf
262
+ klass = DevCycle.const_get(type)
263
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
264
+ end
265
+ end
266
+
267
+ # Returns the string representation of the object
268
+ # @return [String] String presentation of the object
269
+ def to_s
270
+ to_hash.to_s
271
+ end
272
+
273
+ # to_body is an alias to to_hash (backward compatibility)
274
+ # @return [Hash] Returns the object in the form of hash
275
+ def to_body
276
+ to_hash
277
+ end
278
+
279
+ # Returns the object in the form of hash
280
+ # @return [Hash] Returns the object in the form of hash
281
+ def to_hash
282
+ hash = {}
283
+ self.class.attribute_map.each_pair do |attr, param|
284
+ value = self.send(attr)
285
+ if value.nil?
286
+ is_nullable = self.class.openapi_nullable.include?(attr)
287
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
288
+ end
289
+
290
+ hash[param] = _to_hash(value)
291
+ end
292
+ hash
293
+ end
294
+
295
+ # Outputs non-array value in the form of hash
296
+ # For object, use to_hash. Otherwise, just return the value
297
+ # @param [Object] value Any valid value
298
+ # @return [Hash] Returns the value in the form of hash
299
+ def _to_hash(value)
300
+ if value.is_a?(Array)
301
+ value.compact.map { |v| _to_hash(v) }
302
+ elsif value.is_a?(Hash)
303
+ {}.tap do |hash|
304
+ value.each { |k, v| hash[k] = _to_hash(v) }
305
+ end
306
+ elsif value.respond_to? :to_hash
307
+ value.to_hash
308
+ else
309
+ value
310
+ end
311
+ end
312
+
313
+ end
314
+
315
+ end
@@ -0,0 +1,15 @@
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
+ module DevCycle
14
+ VERSION = '1.0.0'
15
+ end
@@ -0,0 +1,47 @@
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
+ # Common files
14
+ require 'devcycle-ruby-server-sdk/api_client'
15
+ require 'devcycle-ruby-server-sdk/api_error'
16
+ require 'devcycle-ruby-server-sdk/version'
17
+ require 'devcycle-ruby-server-sdk/configuration'
18
+
19
+ # Models
20
+ require 'devcycle-ruby-server-sdk/models/error_response'
21
+ require 'devcycle-ruby-server-sdk/models/event'
22
+ require 'devcycle-ruby-server-sdk/models/feature'
23
+ require 'devcycle-ruby-server-sdk/models/inline_response201'
24
+ require 'devcycle-ruby-server-sdk/models/user_data'
25
+ require 'devcycle-ruby-server-sdk/models/user_data_and_events_body'
26
+ require 'devcycle-ruby-server-sdk/models/variable'
27
+
28
+ # APIs
29
+ require 'devcycle-ruby-server-sdk/api/devcycle_api'
30
+
31
+ module DevCycle
32
+ class << self
33
+ # Customize default settings for the SDK using block.
34
+ # DevCycle.configure do |config|
35
+ # config.username = "xxx"
36
+ # config.password = "xxx"
37
+ # end
38
+ # If no block given, return the default Configuration object.
39
+ def configure
40
+ if block_given?
41
+ yield(Configuration.default)
42
+ else
43
+ Configuration.default
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,107 @@
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 'spec_helper'
14
+ require 'json'
15
+
16
+ # Unit tests for DevCycle::DVCClient
17
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
18
+ # Please update as you see appropriate
19
+ describe 'DVCClient' do
20
+ before do
21
+ # run before each test
22
+ @api_instance = DevCycle::DVCClient.new
23
+
24
+ DevCycle.configure do |config|
25
+ # Configure API key authorization: bearerAuth
26
+ config.api_key['bearerAuth'] = 'replaceWithValidSDKKey'
27
+ end
28
+
29
+ @user_data = DevCycle::UserData.new({
30
+ user_id: 'my-user',
31
+ app_version: '1.2.3'
32
+ })
33
+ end
34
+
35
+ after do
36
+ # run after each test
37
+ end
38
+
39
+ describe 'test an instance of DevcycleApi' do
40
+ it 'should create an instance of DevcycleApi' do
41
+ expect(@api_instance).to be_instance_of(DevCycle::DVCClient)
42
+ end
43
+ end
44
+
45
+ # unit tests for get_features
46
+ # Get all features by key for user data
47
+ # @param user_data
48
+ # @param [Hash] opts the optional parameters
49
+ # @return [Hash<String, Feature>]
50
+ describe 'get_features test' do
51
+ it 'should work' do
52
+ result = @api_instance.all_features(@user_data);
53
+
54
+ expect(result.length()).to eq 1
55
+ end
56
+ end
57
+
58
+ # unit tests for get_variable_by_key
59
+ # Get variable by key for user data
60
+ # @param key Variable key
61
+ # @param user_data
62
+ # @param [Hash] opts the optional parameters
63
+ # @return [Variable]
64
+ describe 'get_variable_by_key test' do
65
+ it 'should work' do
66
+ result = @api_instance.variable("activate-flag", @user_data, false)
67
+
68
+ expect(result.isDefaulted).to eq false
69
+ end
70
+ end
71
+
72
+ # unit tests for get_variables
73
+ # Get all variables by key for user data
74
+ # @param user_data
75
+ # @param [Hash] opts the optional parameters
76
+ # @return [Hash<String, Variable>]
77
+ describe 'get_variables test' do
78
+ it 'should work' do
79
+ result = @api_instance.all_variables(@user_data);
80
+
81
+ expect(result.length()).to eq 1
82
+ end
83
+ end
84
+
85
+ # unit tests for post_events
86
+ # Post events to DevCycle for user
87
+ # @param user_data_and_events_body
88
+ # @param [Hash] opts the optional parameters
89
+ # @return [InlineResponse201]
90
+ describe 'post_events test' do
91
+ it 'should work' do
92
+ event_data = DevCycle::Event.new({
93
+ type: "my-event",
94
+ target: "some_event_target",
95
+ value: 12,
96
+ meta_data: {
97
+ myKey: "my-value"
98
+ }
99
+ })
100
+
101
+ result = @api_instance.track(@user_data, event_data)
102
+
103
+ expect(result.message).to eq "Successfully received 1 events."
104
+ end
105
+ end
106
+
107
+ end