optimizely 1.1.3 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa83fb3b2bb1b65e4e2150afe12519dd2d3dd9e5
4
- data.tar.gz: 7ea18ff8e4b38015ded6a68952215df458b3624f
3
+ metadata.gz: 8b66e79d51fa50c9646d90e3dfdce45969256c33
4
+ data.tar.gz: 7fa873506a686f2e4e691cb280ee35ac44c6c250
5
5
  SHA512:
6
- metadata.gz: 5c63338bb7ab215c8a6cf64b3eb2541fabe1e894d5041ae62b1165916278b5bef82514c5b1598ec99da8baa6a73e8cf102da32b67d5526182b20c93c1323cf3e
7
- data.tar.gz: f20b8372833a57a54c0dc6f0b9510dfccd6665ad87c4da32129e058ff41638113dd02399f24dbfaaefefb68834d88c43bbef5411049ac9d8447524d5f8ab5a92
6
+ metadata.gz: f48dd35107452634ae87980421b0ca0a9bf645230fe8755f82e379a5738bb57fdd8f6cc37a3b3ecd3335dc41f71c3d770d5ee9009561ef4ed547e8a0bc33f80b
7
+ data.tar.gz: 8d484df17bffcd2adf824aa9840db07ef7e867d7f75329d39ea66c60d1890aabecd626038465c65b410cffd698dc124023a0b138d389f06134b6a525669a0ee1
data/README.md CHANGED
@@ -68,6 +68,13 @@ The fields that are available for an audience: id, name, project_id and descript
68
68
 
69
69
  ### Changelog
70
70
 
71
+ #### 1.2.0
72
+ * Provide users with a method to delete audiences, experiments, variations and projects.
73
+
74
+ #### 1.1.3
75
+ * Add methods for put, post and delete requests.
76
+ * Refactor the way we check response codes to make it available to the put, post and delete methods.
77
+
71
78
  #### 1.1.2
72
79
  * Write tests to check what happens if data is not available.
73
80
 
@@ -3,7 +3,7 @@ module Optimizely
3
3
 
4
4
  BASE_URL = "https://www.optimizelyapis.com/experiment/v1/"
5
5
 
6
- attr_accessor :id, :method
6
+ attr_accessor :url
7
7
 
8
8
  # Initialize Optimizely using an API token.
9
9
  #
@@ -44,10 +44,11 @@ module Optimizely
44
44
  # project = optimizely.project(12345) # Look up the project.
45
45
  #
46
46
  def project(id)
47
+ @url = "projects/#{id}"
47
48
  raise OptimizelyError::NoProjectID, "A Project ID is required to retrieve the project." if id.nil?
48
49
 
49
50
  if @project.nil?
50
- response = self.get("projects/#{id}")
51
+ response = self.get(@url)
51
52
  @project = Project.new(response)
52
53
  end
53
54
  @project
@@ -76,10 +77,11 @@ module Optimizely
76
77
  # experiment = optimizely.experiment(12345) # Look up the experiment.
77
78
  #
78
79
  def experiment(id)
80
+ @url = "experiments/#{id}"
79
81
  raise OptimizelyError::NoExperimentID, "An Experiment ID is required to retrieve the experiment." if id.nil?
80
82
 
81
83
  if @experiment.nil?
82
- response = self.get("experiments/#{id}")
84
+ response = self.get(@url)
83
85
  @experiment = Experiment.new(response)
84
86
  end
85
87
  @experiment
@@ -108,10 +110,11 @@ module Optimizely
108
110
  # variation = optimizely.variation(12345) # Look up the variation.
109
111
  #
110
112
  def variation(id)
113
+ @url = "variations/#{id}"
111
114
  raise OptimizelyError::NoVariationID, "A Variation ID is required to retrieve the variation." if id.nil?
112
115
 
113
116
  if @variation.nil?
114
- response = self.get("variations/#{id}")
117
+ response = self.get(@url)
115
118
  @variation = Variation.new(response)
116
119
  end
117
120
  @variation
@@ -140,10 +143,11 @@ module Optimizely
140
143
  # audience = optimizely.audience(12345) # Look up the audience.
141
144
  #
142
145
  def audience(id)
146
+ @url = "audiences/#{id}"
143
147
  raise OptimizelyError::NoAudienceID, "An Audience ID is required to retrieve the audience." if id.nil?
144
148
 
145
149
  if @audience.nil?
146
- response = self.get("audiences/#{id}")
150
+ response = self.get(@url)
147
151
  @audience = Audience.new(response)
148
152
  end
149
153
  @audience
@@ -161,13 +165,13 @@ module Optimizely
161
165
 
162
166
  # Response code error checking
163
167
  if response.code != '200'
164
- check_response(response.code)
168
+ check_response(response.code, response.body)
165
169
  else
166
170
  parse_json(response.body)
167
171
  end
168
172
  end
169
173
 
170
- def post()
174
+ def post
171
175
  uri = URI.parse("#{BASE_URL}#{url}/")
172
176
  https = Net::HTTP.new(uri.host, uri.port)
173
177
  https.read_timeout = @options[:timeout] if @options[:timeout]
@@ -177,10 +181,10 @@ module Optimizely
177
181
  response = https.request(request)
178
182
 
179
183
  # Response code error checking
180
- check_response(response.code) if response.code != '201'
184
+ check_response(response.code, response.body) if response.code != '201'
181
185
  end
182
186
 
183
- def put()
187
+ def put
184
188
  uri = URI.parse("#{BASE_URL}#{url}/")
185
189
  https = Net::HTTP.new(uri.host, uri.port)
186
190
  https.read_timeout = @options[:timeout] if @options[:timeout]
@@ -190,11 +194,11 @@ module Optimizely
190
194
  response = https.request(request)
191
195
 
192
196
  # Response code error checking
193
- check_response(response.code) if response.code != '202'
197
+ check_response(response.code, response.body) if response.code != '202'
194
198
  end
195
199
 
196
- def delete()
197
- uri = URI.parse("#{BASE_URL}#{url}/")
200
+ def delete
201
+ uri = URI.parse("#{BASE_URL}#{@url}")
198
202
  https = Net::HTTP.new(uri.host, uri.port)
199
203
  https.read_timeout = @options[:timeout] if @options[:timeout]
200
204
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -203,7 +207,7 @@ module Optimizely
203
207
  response = https.request(request)
204
208
 
205
209
  # Response code error checking
206
- check_response(response.code, response.body) if response.code != '203'
210
+ check_response(response.code, response.body) if response.code != '204'
207
211
  end
208
212
 
209
213
  def check_response(code, body)
@@ -217,7 +221,7 @@ module Optimizely
217
221
  when '404'
218
222
  raise OptimizelyError::NotFound, body + "The id used in the request was inaccurate or you didn't have permission to view/edit it (status code: #{code})."
219
223
  else
220
- raise OptimizelyError::UnknownError, body + "(status code: #{code})."
224
+ raise OptimizelyError::UnknownError, body + " (status code: #{code})."
221
225
  end
222
226
  end
223
227
 
@@ -1,3 +1,3 @@
1
1
  module Optimizely
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimizely
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martijn Scheijbeler
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubyforge_project:
70
- rubygems_version: 2.0.14
70
+ rubygems_version: 2.0.3
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: The Optimizely Experiment API lets you create and manage Optimizely projects