splitapi-rb 1.0.1 → 1.2.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
  SHA1:
3
- metadata.gz: 9c47e3c424787193e33b8e2c0a9136f14ae3a948
4
- data.tar.gz: e8246c77acd22d24cf5068dcfa6f8e0c8e193eb7
3
+ metadata.gz: eec601d03cbbf685c204ea7ebe8425fea35b90ec
4
+ data.tar.gz: b76629bf58ed478931126350d0b23c3c7082fa32
5
5
  SHA512:
6
- metadata.gz: 90890cef468d26fffec054497d5b0a36773c199581cc171f86699edb647f3673276224038c15d7064c28398db29921a498181b6fb563f24586320ceb3c882d42
7
- data.tar.gz: 15d89da26203e89d1c842c36dda9b6f4cd677158dc9b23cc02aed9ce53830f250b6b41dd108281012be2aefa6f87c79018f03ba0b0e35d9f63d3e0c84dc6bb01
6
+ metadata.gz: d467adfe57c0e1698f5fb788299c4457384d20c9ce040b71f70233de716b01b290494b1a464cfb7c1b4979164626cc6fe688ba388647ceea26917a8b122b802b
7
+ data.tar.gz: 9b2ee377a328b1dc70611af52094ee402c46e116dfd535344f3c81ed169d54d8d607fb7ec4cca8e0c3009a908599e090f5f9ca7996f3e0028811667b3deb0f5b
data/CHANGES CHANGED
@@ -1,3 +1,19 @@
1
+ 1.2.0
2
+
3
+ Add default uri
4
+
5
+ 1.1.1
6
+
7
+ Fix specs from being false positive, add to_h method
8
+
9
+ 1.1.0
10
+
11
+ Return DTOs instead of hashes
12
+
13
+ 1.0.2
14
+
15
+ Return "failed" and "metadata" alongside with "objects" when calling Identities#save_all
16
+
1
17
  1.0.1
2
18
 
3
19
  Use camel case instead of snake case in JSON response.
data/DetailedReadme.md CHANGED
@@ -22,7 +22,58 @@ client = SplitApi::Client.new(api_key: 'SPLIT_ADMIN_TOKEN', base_uri: 'SPLIT_IDE
22
22
 
23
23
  Now we have following models `Attributes`, `Environments`, `Identities`, `TrafficTypes`.
24
24
 
25
- ### Attributes
25
+ ### Data Objects
26
+
27
+ Models can return the following:
28
+
29
+ - true/false (when `#delete` method was called)
30
+ - `SplitApi::DataObjects::Attribute`, `SplitApi::DataObjects::Environment`, `SplitApi::DataObjects::Identify` or `SplitApi::DataObjects::DataType`
31
+ - array of the above DTOs (when `#save_all` or `#list` was called)
32
+
33
+ Data objects structure:
34
+
35
+ #### Attribute DTO
36
+ ```
37
+ #<SplitApi::DataObjects::Attribute
38
+ @description="string",
39
+ @display_name="string",
40
+ @id="string",
41
+ @is_searchable="true/false",
42
+ @organization_id="string",
43
+ @traffic_type_id="string"
44
+ >
45
+ ```
46
+
47
+ #### Environment DTOs
48
+ ```
49
+ #<SplitApi::DataObjects::Environment
50
+ @name="string",
51
+ @id="string",
52
+ >
53
+ ```
54
+
55
+ #### Identity DTO
56
+ ```
57
+ #<SplitApi::DataObjects::Identity
58
+ @values="string",
59
+ @key="string",
60
+ @environment_id="string",
61
+ @organization_id="string",
62
+ @traffic_type_id="string",
63
+ @timestamp="number"
64
+ >
65
+ ```
66
+
67
+ #### TrafficType DTO
68
+ ```
69
+ #<SplitApi::DataObjects::TrafficType
70
+ @name="string",
71
+ @id="string",
72
+ @display_attribute_id="string"
73
+ >
74
+ ```
75
+
76
+ ### Attributes model
26
77
 
27
78
  Available methods:
28
79
 
@@ -34,13 +85,7 @@ _arguments_: `traffic_type_id`
34
85
  client.attributes.list('traffic_type_id')
35
86
  # example response:
36
87
  [
37
- {
38
- "id" => "string",
39
- "traffic_type_id" => "string",
40
- "display_name" => "string",
41
- "description" => "string",
42
- "dataType" => "string"
43
- },
88
+ SplitApi::DataObjects::Attribute,
44
89
  # ...
45
90
  ]
46
91
  ```
@@ -58,14 +103,7 @@ client.attributes.save(
58
103
  data_type: "string"
59
104
  )
60
105
  # example response:
61
- {
62
- "id" => "string",
63
- "organization_id" => "string",
64
- "traffic_type_id" => "string",
65
- "display_name" => "string",
66
- "description" => "string",
67
- "data_type" => "string"
68
- }
106
+ SplitApi::DataObjects::Attribute
69
107
  ```
70
108
 
71
109
  **delete**: delete attribute by key
@@ -78,7 +116,7 @@ client.attributes.delete('traffic_type_id', 'attribute_id')
78
116
  true
79
117
  ```
80
118
 
81
- ### Environments
119
+ ### Environments model
82
120
 
83
121
  Available methods:
84
122
 
@@ -90,15 +128,12 @@ _arguments_: none
90
128
  client.environments.list
91
129
  # example response
92
130
  [
93
- {
94
- "id" => "string",
95
- "name" => "string"
96
- },
131
+ SplitApi::DataObjects::Environment,
97
132
  # ...
98
133
  ]
99
134
  ```
100
135
 
101
- ### Identities
136
+ ### Identities model
102
137
 
103
138
  Available methods:
104
139
 
@@ -116,14 +151,7 @@ client.identities.save(
116
151
  }
117
152
  )
118
153
  # example response:
119
- {
120
- "traffic_type_id" => "string",
121
- "environment_id" => "string",
122
- "key" => "string",
123
- "values" => {
124
- "key" => "value"
125
- }
126
- }
154
+ SplitApi::DataObjects::Identity
127
155
  ```
128
156
 
129
157
  **update**: update identity
@@ -140,14 +168,7 @@ client.identities.update(
140
168
  }
141
169
  )
142
170
  # example response:
143
- {
144
- "traffic_type_id" => "string",
145
- "environment_id" => "string",
146
- "key" => "string",
147
- "values" => {
148
- "key" => "value"
149
- }
150
- }
171
+ SplitApi::DataObjects::Identity
151
172
  ```
152
173
 
153
174
  **save_all**: save multiple identities
@@ -171,16 +192,11 @@ client.identities.save_all("string", "string",
171
192
  # example response:
172
193
  {
173
194
  [
174
- {
175
- "values" => { "foo" => "bar" },
176
- "key" => "string",
177
- "environment_id" => "string",
178
- "traffic_type_id" => "string",
179
- "organization_id" => "string",
180
- "timestamp" => "integer"
181
- },
195
+ SplitApi::DataObjects::Identity,
182
196
  # ...
183
- ]
197
+ ],
198
+ "failed": [],
199
+ "metadata": {}
184
200
  }
185
201
  ```
186
202
 
@@ -194,7 +210,7 @@ client.identities.delete(`traffic_type_id`, `environment_id`, `key`)
194
210
  true
195
211
  ```
196
212
 
197
- ### Traffic Types
213
+ ### Traffic Types model
198
214
 
199
215
  Available methods:
200
216
 
@@ -206,11 +222,7 @@ _arguments_: none
206
222
  client.traffic_types.list
207
223
  # example response:
208
224
  [
209
- {
210
- "id": "string",
211
- "name": "string",
212
- "display_attribute_id": "string"
213
- },
225
+ SplitApi::DataObjects::TrafficType
214
226
  # ...
215
227
  ]
216
228
  ```
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splitapi-rb (1.0.1)
4
+ splitapi-rb (1.2.0)
5
5
  json (~> 1.8)
6
6
  rest-client (~> 2.0)
7
7
 
data/NEWS CHANGED
@@ -1,3 +1,7 @@
1
+ 1.1.0
2
+
3
+ Models now return DTOs instaed of plain hashes
4
+
1
5
  1.0.0
2
6
 
3
7
  Initial release
data/README.md CHANGED
@@ -18,7 +18,7 @@ Split has built and maintains a API wrappers for:
18
18
 
19
19
  * Java [Github](https://github.com/splitio/java-api)
20
20
  * Node [Github](https://github.com/splitio/javascript-api)
21
- * .NET [Github](https://github.com/splitio/net-api)
21
+ * .NET [Github](https://github.com/splitio/.net-api)
22
22
  * Ruby [Github](https://github.com/splitio/ruby-api)
23
23
  * PHP [Github](https://github.com/splitio/php-api)
24
24
  * Python [Github](https://github.com/splitio/python-api)
data/lib/splitapi-rb.rb CHANGED
@@ -5,6 +5,12 @@ require 'splitapi-rb/version'
5
5
  require 'splitapi-rb/client'
6
6
  require 'splitapi-rb/config'
7
7
 
8
+ require 'splitapi-rb/data_objects/base_data_object'
9
+ require 'splitapi-rb/data_objects/attribute'
10
+ require 'splitapi-rb/data_objects/environment'
11
+ require 'splitapi-rb/data_objects/identity'
12
+ require 'splitapi-rb/data_objects/traffic_type'
13
+
8
14
  require 'splitapi-rb/models/base_model'
9
15
  require 'splitapi-rb/models/attributes'
10
16
  require 'splitapi-rb/models/environments'
@@ -1,12 +1,14 @@
1
1
  module SplitApi
2
2
  class Config
3
+ DEFAULT_URI = 'https://api.split.io/internal/api/v1'.freeze
4
+
3
5
  # Base URI for the API
4
6
  attr_reader :base_uri
5
7
  # API key to authorize API requests
6
8
  attr_reader :api_key
7
9
 
8
10
  def initialize(opts)
9
- @base_uri = opts[:base_uri]
11
+ @base_uri = (opts[:base_uri] || DEFAULT_URI).chomp('/')
10
12
  @api_key = opts[:api_key]
11
13
  end
12
14
  end
@@ -0,0 +1,8 @@
1
+ module SplitApi
2
+ module DataObjects
3
+ class Attribute < BaseDataObject
4
+ PROPERTIES = %i(description display_name traffic_type_id id organization_id data_type is_searchable).freeze
5
+ attr_accessor *PROPERTIES
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module SplitApi
2
+ module DataObjects
3
+ class BaseDataObject
4
+ PROPERTIES = %i().freeze # this is redefined in the subclass
5
+
6
+ def initialize(opts = {})
7
+ opts.each do |k, v|
8
+ instance_variable_set("@#{k}", v) unless v.nil?
9
+ end
10
+ end
11
+
12
+ def ==(other_obj)
13
+ self.class::PROPERTIES.all? { |property| send(property) == other_obj.send(property) }
14
+ end
15
+
16
+ def to_h
17
+ self.class::PROPERTIES.each_with_object({}) do |property, memo|
18
+ memo.merge!(property => instance_variable_get("@#{property}"))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ module SplitApi
2
+ module DataObjects
3
+ class Environment < BaseDataObject
4
+ PROPERTIES = %i(id name).freeze
5
+ attr_accessor *PROPERTIES
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module SplitApi
2
+ module DataObjects
3
+ class Identity < BaseDataObject
4
+ PROPERTIES = %i(values key environment_id traffic_type_id organization_id timestamp).freeze
5
+ attr_accessor *PROPERTIES
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module SplitApi
2
+ module DataObjects
3
+ class TrafficType < BaseDataObject
4
+ PROPERTIES = %i(id display_attribute_id name).freeze
5
+ attr_accessor *PROPERTIES
6
+ end
7
+ end
8
+ end
@@ -14,12 +14,22 @@ module SplitApi
14
14
  RestClient.get(
15
15
  "#{@config.base_uri}/trafficTypes/#{traffic_type_id}/schema", auth_headers
16
16
  ).body
17
- )
17
+ ).map do |attribute|
18
+ DataObjects::Attribute.new(
19
+ description: attribute['description'],
20
+ display_name: attribute['displayName'],
21
+ traffic_type_id: attribute['trafficTypeId'],
22
+ id: attribute['id'],
23
+ organization_id: attribute['organizationId'],
24
+ data_type: attribute['dataType'],
25
+ is_searchable: attribute['isSearchable']
26
+ )
27
+ end
18
28
  end
19
29
 
20
30
  # PUT /trafficTypes/{traffic_type_id}/schema
21
31
  def save(attribute)
22
- JSON.parse(
32
+ attribute = JSON.parse(
23
33
  RestClient.put(
24
34
  "#{@config.base_uri}/trafficTypes/#{attribute[:traffic_type_id]}/schema",
25
35
  {
@@ -28,7 +38,18 @@ module SplitApi
28
38
  'displayName' => attribute[:display_name],
29
39
  'description' => attribute[:description],
30
40
  'dataType' => attribute[:data_type]
31
- }.to_json, auth_headers).body
41
+ }.to_json, auth_headers
42
+ ).body
43
+ )
44
+
45
+ DataObjects::Attribute.new(
46
+ description: attribute['description'],
47
+ display_name: attribute['displayName'],
48
+ traffic_type_id: attribute['trafficTypeId'],
49
+ id: attribute['id'],
50
+ organization_id: attribute['organizationId'],
51
+ data_type: attribute['dataType'],
52
+ is_searchable: attribute['isSearchable']
32
53
  )
33
54
  end
34
55
 
@@ -10,7 +10,12 @@ module SplitApi
10
10
 
11
11
  # GET /environments
12
12
  def list
13
- JSON.parse(RestClient.get("#{@config.base_uri}/environments", auth_headers).body)
13
+ JSON.parse(RestClient.get("#{@config.base_uri}/environments", auth_headers).body).map do |environment|
14
+ DataObjects::Environment.new(
15
+ id: environment['id'],
16
+ name: environment['name']
17
+ )
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -10,38 +10,72 @@ module SplitApi
10
10
 
11
11
  # PUT /trafficTypes/{traffic_type_id}/environments/{environment_id}/identities/{key}
12
12
  def save(identity)
13
- JSON.parse(RestClient.put(
13
+ identity = JSON.parse(RestClient.put(
14
14
  "#{@config.base_uri}/trafficTypes/#{identity[:traffic_type_id]}" \
15
15
  "/environments/#{identity[:environment_id]}/identities/#{identity[:key]}",
16
16
  {
17
17
  'key' => identity[:key],
18
18
  'trafficTypeId' => identity[:traffic_type_id],
19
19
  'environmentId' => identity[:environment_id],
20
+ 'organizationId' => identity[:organization_id],
20
21
  'values' => identity[:values]
21
22
  }.to_json, auth_headers).body)
23
+
24
+ DataObjects::Identity.new(
25
+ key: identity['key'],
26
+ traffic_type_id: identity['trafficTypeId'],
27
+ environment_id: identity['environmentId'],
28
+ organization_id: identity['organizationId'],
29
+ values: identity['values']
30
+ )
22
31
  end
23
32
 
24
33
  # POST /trafficTypes/{traffic_type_id}/environments/{environment_id}/identities
25
34
  def save_all(traffic_type_id, environment_id, identities)
26
- JSON.parse(RestClient.post(
35
+ result = JSON.parse(RestClient.post(
27
36
  "#{@config.base_uri}/trafficTypes/#{traffic_type_id}" \
28
37
  "/environments/#{environment_id}" \
29
38
  "/identities",
30
39
  identities.to_json, auth_headers).body
31
- )['objects']
40
+ )
41
+
42
+ objects = result['objects'].map do |identity|
43
+ DataObjects::Identity.new(
44
+ key: identity['key'],
45
+ traffic_type_id: identity['trafficTypeId'],
46
+ environment_id: identity['environmentId'],
47
+ organization_id: identity['organizationId'],
48
+ values: identity['values']
49
+ )
50
+ end
51
+
52
+ {
53
+ objects: objects,
54
+ failed: result['failed'],
55
+ metadata: result['metadata']
56
+ }
32
57
  end
33
58
 
34
59
  # PATCH /trafficTypes/{traffic_type_id}/environments/{environment_id}/identities/{key}
35
60
  def update(identity)
36
- JSON.parse(RestClient.patch(
61
+ identity = JSON.parse(RestClient.patch(
37
62
  "#{@config.base_uri}/trafficTypes/#{identity[:traffic_type_id]}" \
38
63
  "/environments/#{identity[:environment_id]}/identities/#{identity[:key]}",
39
64
  {
40
65
  'key' => identity[:key],
41
66
  'trafficTypeId' => identity[:traffic_type_id],
42
67
  'environmentId' => identity[:environment_id],
68
+ 'organizationId' => identity[:organization_id],
43
69
  'values' => identity[:values]
44
70
  }.to_json, auth_headers).body)
71
+
72
+ DataObjects::Identity.new(
73
+ key: identity['key'],
74
+ traffic_type_id: identity['trafficTypeId'],
75
+ environment_id: identity['environmentId'],
76
+ organization_id: identity['organizationId'],
77
+ values: identity['values']
78
+ )
45
79
  end
46
80
 
47
81
  # DELETE /trafficTypes/{traffic_type_id}/environments/{environment_id}/identities/{key}
@@ -10,7 +10,13 @@ module SplitApi
10
10
 
11
11
  # GET /trafficTypes
12
12
  def list
13
- JSON.parse(RestClient.get("#{@config.base_uri}/trafficTypes", auth_headers).body)
13
+ JSON.parse(RestClient.get("#{@config.base_uri}/trafficTypes", auth_headers).body).map do |traffic_type|
14
+ DataObjects::TrafficType.new(
15
+ id: traffic_type['id'],
16
+ display_attribute_id: traffic_type['displayAttributeId'],
17
+ name: traffic_type['name']
18
+ )
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -1,3 +1,3 @@
1
1
  module SplitApi
2
- VERSION = '1.0.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splitapi-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Split Software
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-29 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,6 +155,11 @@ files:
155
155
  - lib/splitapi-rb.rb
156
156
  - lib/splitapi-rb/client.rb
157
157
  - lib/splitapi-rb/config.rb
158
+ - lib/splitapi-rb/data_objects/attribute.rb
159
+ - lib/splitapi-rb/data_objects/base_data_object.rb
160
+ - lib/splitapi-rb/data_objects/environment.rb
161
+ - lib/splitapi-rb/data_objects/identity.rb
162
+ - lib/splitapi-rb/data_objects/traffic_type.rb
158
163
  - lib/splitapi-rb/exceptions/splitapi_exception.rb
159
164
  - lib/splitapi-rb/exceptions/splitapi_not_found_exception.rb
160
165
  - lib/splitapi-rb/models/attributes.rb