neuron-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/lib/neuron-client/ad.rb +2 -2
- data/lib/neuron-client/connected.rb +27 -9
- data/lib/neuron-client/connection.rb +4 -0
- data/lib/neuron-client/version.rb +1 -1
- data/spec/lib/old_spec.rb +146 -0
- metadata +94 -83
data/Gemfile
CHANGED
data/lib/neuron-client/ad.rb
CHANGED
@@ -11,7 +11,7 @@ module Neuron
|
|
11
11
|
:redirect_url,
|
12
12
|
# video
|
13
13
|
:video_api_url, :video_setup_xml, :video_flv_url,
|
14
|
-
:video_clickthru_url, :video_companion_ad_html,
|
14
|
+
:video_clickthru_url, :video_companion_ad_html, :social_links,
|
15
15
|
# caps
|
16
16
|
:frequency_cap_limit, :frequency_cap_window, :overall_cap,
|
17
17
|
:daily_cap, :day_partitions, :ideal_impressions_per_hour,
|
@@ -37,4 +37,4 @@ module Neuron
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -8,7 +8,7 @@ module Neuron
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def attributes
|
11
|
-
self.class.attributes
|
11
|
+
self.class.attributes || []
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_hash
|
@@ -24,19 +24,29 @@ module Neuron
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def save
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
@errors = catch :errors do
|
28
|
+
if new_record?
|
29
|
+
response = self.class.connection.post("#{self.class.resources_name}", {self.class.resource_name => self.to_hash})
|
30
|
+
self.id = response[self.class.resource_name]['id']
|
31
|
+
else
|
32
|
+
response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => self.to_hash})
|
33
|
+
end
|
34
|
+
[]
|
32
35
|
end
|
36
|
+
|
37
|
+
@errors.empty?
|
33
38
|
end
|
34
39
|
|
35
40
|
def update_attributes(attrs={})
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
@errors = catch :errors do
|
42
|
+
response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => attrs})
|
43
|
+
attrs.each do |key, value|
|
44
|
+
self.send("#{key}=", value) if self.respond_to?("#{key}=")
|
45
|
+
end
|
46
|
+
[]
|
39
47
|
end
|
48
|
+
|
49
|
+
@errors.empty?
|
40
50
|
end
|
41
51
|
|
42
52
|
def destroy
|
@@ -45,6 +55,7 @@ module Neuron
|
|
45
55
|
|
46
56
|
def self.included(base)
|
47
57
|
base.send(:attr_accessor, :id)
|
58
|
+
base.send(:attr_accessor, :errors)
|
48
59
|
base.extend(ClassMethods)
|
49
60
|
end
|
50
61
|
|
@@ -97,6 +108,13 @@ module Neuron
|
|
97
108
|
end
|
98
109
|
|
99
110
|
def create(attrs={})
|
111
|
+
@errors = catch (:errors) do
|
112
|
+
return create!(attrs)
|
113
|
+
end
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def create!(attrs={})
|
100
118
|
response = self.connection.post("#{self.resources_name}", {self.resource_name => attrs})
|
101
119
|
self.new(response[self.resource_name])
|
102
120
|
end
|
@@ -43,6 +43,8 @@ module Neuron
|
|
43
43
|
case response.code
|
44
44
|
when 201
|
45
45
|
return (format == :json ? Yajl.load(response.to_str) : response.to_str)
|
46
|
+
when 422
|
47
|
+
throw :errors, Yajl.load(response.to_str)
|
46
48
|
else
|
47
49
|
raise "Error : #{response.code} - #{response.to_str}"
|
48
50
|
end
|
@@ -57,6 +59,8 @@ module Neuron
|
|
57
59
|
case response.code
|
58
60
|
when 200
|
59
61
|
return (format == :json ? Yajl.load(response.to_str) : response.to_str)
|
62
|
+
when 422
|
63
|
+
throw :errors, Yajl.load(response.to_str)
|
60
64
|
else
|
61
65
|
raise "Error : #{response.code} - #{response.to_str}"
|
62
66
|
end
|
data/spec/lib/old_spec.rb
CHANGED
@@ -168,6 +168,132 @@ module Neuron
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
describe Connected do
|
172
|
+
class ConnectedTest
|
173
|
+
include Connected
|
174
|
+
resource_name 'connection'
|
175
|
+
resources_name 'connection'
|
176
|
+
end
|
177
|
+
|
178
|
+
before(:each) do
|
179
|
+
@connection = stub(:connection)
|
180
|
+
API.stub(:connection).and_return(@connection)
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "update_attributes" do
|
184
|
+
it "should return false when errors occur for updated objects" do
|
185
|
+
@connection.should_receive(:put).with("connection/1", {'connection' => {}}) do
|
186
|
+
throw :errors, {:error => "is required"}
|
187
|
+
end
|
188
|
+
|
189
|
+
ConnectedTest.new(:id => 1).update_attributes({}).should be_false
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should provide access to errors when validation fails" do
|
193
|
+
@connection.should_receive(:put).with("connection/1", {'connection' => {}}) do
|
194
|
+
throw :errors, {:error => "is required"}
|
195
|
+
end
|
196
|
+
|
197
|
+
c = ConnectedTest.new(:id => 1)
|
198
|
+
c.update_attributes({}).should be_false
|
199
|
+
c.errors.should == {:error => "is required"}
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should return true when errors do not occure for updated objects" do
|
203
|
+
@connection.should_receive(:put).with("connection/1", {'connection' => {}})
|
204
|
+
|
205
|
+
ConnectedTest.new(:id => 1).update_attributes({}).should be_true
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "save" do
|
210
|
+
it "should return false when errors occur for new objects" do
|
211
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}) do
|
212
|
+
throw :errors, {:error => "is required"}
|
213
|
+
end
|
214
|
+
|
215
|
+
ConnectedTest.new.save.should be_false
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should provide access to errors when validation fails" do
|
219
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}) do
|
220
|
+
throw :errors, {:error => "is required"}
|
221
|
+
end
|
222
|
+
|
223
|
+
c = ConnectedTest.new
|
224
|
+
c.save.should be_false
|
225
|
+
c.errors.should == {:error => "is required"}
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should return true when errors do not occur for new objects" do
|
229
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}).and_return({'connection' => {:id => 1}})
|
230
|
+
|
231
|
+
ConnectedTest.new.save.should be_true
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should return false when errors occur for existing objects" do
|
235
|
+
@connection.should_receive(:put).with('connection/1', {'connection' => {}}) do
|
236
|
+
throw :errors, {:error => "is required"}
|
237
|
+
end
|
238
|
+
|
239
|
+
ConnectedTest.new(:id => 1).save.should be_false
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should provide access to errors when validation fails" do
|
243
|
+
@connection.should_receive(:put).with("connection/1", {'connection' => {}}) do
|
244
|
+
throw :errors, {:error => "is required"}
|
245
|
+
end
|
246
|
+
|
247
|
+
c = ConnectedTest.new(:id => 1)
|
248
|
+
c.save.should be_false
|
249
|
+
c.errors.should == {:error => "is required"}
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should return true when errors do not occur for existing objects" do
|
253
|
+
@connection.should_receive(:put).with("connection/1", {'connection' => {}})
|
254
|
+
|
255
|
+
ConnectedTest.new(:id => 1).save.should be_true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "create" do
|
260
|
+
it "should return nil when errors occur" do
|
261
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}) do
|
262
|
+
throw :errors, {:error => "is_required"}
|
263
|
+
end
|
264
|
+
|
265
|
+
ConnectedTest.create({}).should be_nil
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should return the created object when no errors occur" do
|
269
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}).and_return({'connection' => {:id => 1}})
|
270
|
+
|
271
|
+
ConnectedTest.create({}).should be_a ConnectedTest
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe "create!" do
|
276
|
+
it "should return nil when errors occur" do
|
277
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}) do
|
278
|
+
throw :errors, {:error => "is_required"}
|
279
|
+
end
|
280
|
+
|
281
|
+
errors = catch(:errors) do
|
282
|
+
ConnectedTest.create!({})
|
283
|
+
nil
|
284
|
+
end
|
285
|
+
errors.should_not be_nil
|
286
|
+
errors.should == {:error => 'is_required'}
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should return the created object when no errors occur" do
|
290
|
+
@connection.should_receive(:post).with("connection", {'connection' => {}}).and_return({'connection' => {:id => 1}})
|
291
|
+
|
292
|
+
ConnectedTest.create!({}).should be_a ConnectedTest
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
171
297
|
describe Connection do
|
172
298
|
before(:each) do
|
173
299
|
@connection = Connection.new('http://neuron.admin', "my_api_key")
|
@@ -209,6 +335,16 @@ module Neuron
|
|
209
335
|
@connection.post("test", {:data => 1})
|
210
336
|
end.should raise_error
|
211
337
|
end
|
338
|
+
|
339
|
+
it "should throw :errors if validation fails" do
|
340
|
+
FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => Yajl.dump({:my_field => 'is_required'}), :status => ["422", "Errors"])
|
341
|
+
errors = catch(:errors) do
|
342
|
+
value = @connection.post("test", {:data => 1})
|
343
|
+
nil
|
344
|
+
end
|
345
|
+
errors.should_not be_nil
|
346
|
+
errors.should == {'my_field' => 'is_required'}
|
347
|
+
end
|
212
348
|
end
|
213
349
|
|
214
350
|
describe "put" do
|
@@ -225,6 +361,16 @@ module Neuron
|
|
225
361
|
@connection.put("test", {:data => 1})
|
226
362
|
end.should raise_error
|
227
363
|
end
|
364
|
+
|
365
|
+
it "should throw :errors if validation fails" do
|
366
|
+
FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => Yajl.dump({:my_field => 'is_required'}), :status => ["422", "Errors"])
|
367
|
+
errors = catch(:errors) do
|
368
|
+
value = @connection.put("test", {:data => 1})
|
369
|
+
nil
|
370
|
+
end
|
371
|
+
errors.should_not be_nil
|
372
|
+
errors.should == {'my_field' => 'is_required'}
|
373
|
+
end
|
228
374
|
end
|
229
375
|
|
230
376
|
describe "delete" do
|
metadata
CHANGED
@@ -1,135 +1,138 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: neuron-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Mark Simoneau
|
9
9
|
- Chris Johnson
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
|
14
|
+
date: 2011-08-03 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
18
|
-
requirement: &
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
23
|
version: 1.6.3
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
28
|
name: yajl-ruby
|
29
|
-
requirement: &
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
34
|
version: 0.8.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
45
|
version: 2.6.0
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
50
|
name: simplecov
|
51
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
56
|
version: 0.4.2
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
60
|
-
- !ruby/object:Gem::Dependency
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
61
|
name: rb-fsevent
|
62
|
-
requirement: &
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
67
|
version: 0.4.1
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
71
|
-
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
72
|
name: guard
|
73
|
-
requirement: &
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
78
|
version: 0.5.1
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
82
|
-
- !ruby/object:Gem::Dependency
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
83
|
name: guard-bundler
|
84
|
-
requirement: &
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
89
|
version: 0.1.3
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
93
|
-
- !ruby/object:Gem::Dependency
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
94
|
name: guard-rspec
|
95
|
-
requirement: &
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
100
|
version: 0.4.0
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
104
|
-
- !ruby/object:Gem::Dependency
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
105
|
name: fakeweb
|
106
|
-
requirement: &
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
111
|
version: 1.3.0
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
|
-
version_requirements: *
|
115
|
-
- !ruby/object:Gem::Dependency
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
116
|
name: vcr
|
117
|
-
requirement: &
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
|
-
requirements:
|
120
|
-
- -
|
121
|
-
- !ruby/object:Gem::Version
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
122
|
version: 1.10.2
|
123
123
|
type: :development
|
124
124
|
prerelease: false
|
125
|
-
version_requirements: *
|
125
|
+
version_requirements: *id010
|
126
126
|
description: Neuron Admin Client Gem
|
127
|
-
email:
|
127
|
+
email:
|
128
128
|
- devteam@rmmonline.com
|
129
129
|
executables: []
|
130
|
+
|
130
131
|
extensions: []
|
132
|
+
|
131
133
|
extra_rdoc_files: []
|
132
|
-
|
134
|
+
|
135
|
+
files:
|
133
136
|
- .gitignore
|
134
137
|
- .rvmrc
|
135
138
|
- Gemfile
|
@@ -154,32 +157,40 @@ files:
|
|
154
157
|
- spec/lib/old_spec.rb
|
155
158
|
- spec/lib/s3_file_spec.rb
|
156
159
|
- spec/spec_helper.rb
|
157
|
-
has_rdoc: true
|
158
160
|
homepage: http://github.com/rmm/neuron-client
|
159
161
|
licenses: []
|
162
|
+
|
160
163
|
post_install_message:
|
161
164
|
rdoc_options: []
|
162
|
-
|
165
|
+
|
166
|
+
require_paths:
|
163
167
|
- lib
|
164
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
169
|
none: false
|
166
|
-
requirements:
|
167
|
-
- -
|
168
|
-
- !ruby/object:Gem::Version
|
169
|
-
|
170
|
-
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
hash: 3235199418878311580
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
version: "0"
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
178
|
none: false
|
172
|
-
requirements:
|
173
|
-
- -
|
174
|
-
- !ruby/object:Gem::Version
|
175
|
-
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
hash: 3235199418878311580
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
version: "0"
|
176
186
|
requirements: []
|
187
|
+
|
177
188
|
rubyforge_project: neuron-client
|
178
|
-
rubygems_version: 1.
|
189
|
+
rubygems_version: 1.8.4
|
179
190
|
signing_key:
|
180
191
|
specification_version: 3
|
181
192
|
summary: Neuron Admin Client Gem
|
182
|
-
test_files:
|
193
|
+
test_files:
|
183
194
|
- spec/fixtures/vcr_cassettes/s3_file.yml
|
184
195
|
- spec/lib/old_spec.rb
|
185
196
|
- spec/lib/s3_file_spec.rb
|