neuron-client 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/README.md +11 -8
  2. data/lib/neuron-client/api.rb +5 -0
  3. data/lib/neuron-client/model/ad.rb +142 -0
  4. data/lib/neuron-client/model/ad_calculations.rb +325 -0
  5. data/lib/neuron-client/model/ad_zone.rb +45 -0
  6. data/lib/neuron-client/model/base.rb +233 -18
  7. data/lib/neuron-client/model/blocked_referer.rb +20 -0
  8. data/lib/neuron-client/model/blocked_user_agent.rb +21 -0
  9. data/lib/neuron-client/model/geo_target.rb +36 -0
  10. data/lib/neuron-client/model/pixel.rb +22 -0
  11. data/lib/neuron-client/model/report.rb +35 -0
  12. data/lib/neuron-client/model/s3_file.rb +30 -0
  13. data/lib/neuron-client/model/zone.rb +64 -0
  14. data/lib/neuron-client/model/zone_calculations.rb +37 -0
  15. data/lib/neuron-client/schema/ad.rb +406 -0
  16. data/lib/neuron-client/schema/ad_zone.rb +49 -0
  17. data/lib/neuron-client/schema/blocked_referer.rb +52 -0
  18. data/lib/neuron-client/schema/blocked_user_agent.rb +64 -0
  19. data/lib/neuron-client/schema/common.rb +220 -0
  20. data/lib/neuron-client/schema/event.rb +17 -0
  21. data/lib/neuron-client/schema/geo_target.rb +33 -0
  22. data/lib/neuron-client/schema/pixel.rb +39 -0
  23. data/lib/neuron-client/schema/report.rb +59 -0
  24. data/lib/neuron-client/schema/s3_file.rb +87 -0
  25. data/lib/neuron-client/schema/zone.rb +214 -0
  26. data/lib/neuron-client/version.rb +1 -1
  27. data/lib/neuron-client.rb +24 -59
  28. data/neuron-client.gemspec +3 -0
  29. data/spec/lib/admin_connection_spec.rb +234 -0
  30. data/spec/lib/api_spec.rb +41 -63
  31. data/spec/lib/model/ad_calculations_spec.rb +1146 -0
  32. data/spec/lib/model/ad_spec.rb +253 -0
  33. data/spec/lib/model/ad_zone_spec.rb +15 -0
  34. data/spec/lib/model/base_spec.rb +5 -83
  35. data/spec/lib/model/blocked_referer_spec.rb +36 -0
  36. data/spec/lib/model/blocked_user_agent_spec.rb +36 -0
  37. data/spec/lib/model/geo_target_spec.rb +28 -0
  38. data/spec/lib/model/pixel_spec.rb +36 -0
  39. data/spec/lib/model/report_spec.rb +17 -0
  40. data/spec/lib/{s3_file_spec.rb → model/s3_file_spec.rb} +6 -5
  41. data/spec/lib/model/zone_calculations_spec.rb +49 -0
  42. data/spec/lib/model/zone_spec.rb +155 -0
  43. data/spec/lib/schema/ad_spec.rb +515 -0
  44. data/spec/lib/schema/ad_zone_spec.rb +149 -0
  45. data/spec/lib/schema/blocked_referer_spec.rb +136 -0
  46. data/spec/lib/schema/blocked_user_agent_spec.rb +147 -0
  47. data/spec/lib/schema/geo_target_spec.rb +92 -0
  48. data/spec/lib/schema/pixel_spec.rb +125 -0
  49. data/spec/lib/schema/report_spec.rb +129 -0
  50. data/spec/lib/schema/s3_file_spec.rb +164 -0
  51. data/spec/lib/schema/zone_spec.rb +243 -0
  52. data/spec/spec_helper.rb +2 -1
  53. metadata +141 -121
  54. data/lib/neuron-client/model/admin/ad.rb +0 -22
  55. data/lib/neuron-client/model/admin/ad_zone.rb +0 -15
  56. data/lib/neuron-client/model/admin/base.rb +0 -91
  57. data/lib/neuron-client/model/admin/blocked_referer.rb +0 -12
  58. data/lib/neuron-client/model/admin/blocked_user_agent.rb +0 -12
  59. data/lib/neuron-client/model/admin/geo_target.rb +0 -16
  60. data/lib/neuron-client/model/admin/pixel.rb +0 -12
  61. data/lib/neuron-client/model/admin/report.rb +0 -15
  62. data/lib/neuron-client/model/admin/s3_file.rb +0 -12
  63. data/lib/neuron-client/model/admin/zone.rb +0 -15
  64. data/lib/neuron-client/model/common/ad.rb +0 -42
  65. data/lib/neuron-client/model/common/ad_calculations.rb +0 -329
  66. data/lib/neuron-client/model/common/ad_zone.rb +0 -17
  67. data/lib/neuron-client/model/common/base.rb +0 -67
  68. data/lib/neuron-client/model/common/blocked_referer.rb +0 -16
  69. data/lib/neuron-client/model/common/blocked_user_agent.rb +0 -16
  70. data/lib/neuron-client/model/common/geo_target.rb +0 -16
  71. data/lib/neuron-client/model/common/pixel.rb +0 -18
  72. data/lib/neuron-client/model/common/report.rb +0 -21
  73. data/lib/neuron-client/model/common/s3_file.rb +0 -16
  74. data/lib/neuron-client/model/common/zone.rb +0 -22
  75. data/lib/neuron-client/model/common/zone_calculations.rb +0 -41
  76. data/lib/neuron-client/model/membase/ad.rb +0 -49
  77. data/lib/neuron-client/model/membase/ad_zone.rb +0 -11
  78. data/lib/neuron-client/model/membase/blocked_referer.rb +0 -20
  79. data/lib/neuron-client/model/membase/blocked_user_agent.rb +0 -20
  80. data/lib/neuron-client/model/membase/geo_target.rb +0 -11
  81. data/lib/neuron-client/model/membase/pixel.rb +0 -22
  82. data/lib/neuron-client/model/membase/report.rb +0 -11
  83. data/lib/neuron-client/model/membase/s3_file.rb +0 -11
  84. data/lib/neuron-client/model/membase/zone.rb +0 -30
  85. data/lib/neuron-client/model/models.rb +0 -15
  86. data/spec/lib/model/admin/ad_spec.rb +0 -34
  87. data/spec/lib/model/admin/ad_zone_spec.rb +0 -19
  88. data/spec/lib/model/admin/base_spec.rb +0 -11
  89. data/spec/lib/model/admin/blocked_referer_spec.rb +0 -11
  90. data/spec/lib/model/admin/blocked_user_agent_spec.rb +0 -11
  91. data/spec/lib/model/admin/geo_target_spec.rb +0 -30
  92. data/spec/lib/model/admin/report_spec.rb +0 -21
  93. data/spec/lib/model/admin/s3_spec.rb +0 -11
  94. data/spec/lib/model/admin/zone_spec.rb +0 -21
  95. data/spec/lib/model/common/ad_calculations_spec.rb +0 -1151
  96. data/spec/lib/model/common/ad_spec.rb +0 -11
  97. data/spec/lib/model/common/ad_zone_spec.rb +0 -11
  98. data/spec/lib/model/common/base_spec.rb +0 -11
  99. data/spec/lib/model/common/blocked_referer_spec.rb +0 -11
  100. data/spec/lib/model/common/blocked_user_agent_spec.rb +0 -11
  101. data/spec/lib/model/common/geo_target_spec.rb +0 -11
  102. data/spec/lib/model/common/report_spec.rb +0 -11
  103. data/spec/lib/model/common/s3_spec.rb +0 -11
  104. data/spec/lib/model/common/zone_calculations_spec.rb +0 -54
  105. data/spec/lib/model/common/zone_spec.rb +0 -11
  106. data/spec/lib/model/membase/ad_spec.rb +0 -54
  107. data/spec/lib/model/membase/ad_zone_spec.rb +0 -11
  108. data/spec/lib/model/membase/base_spec.rb +0 -11
  109. data/spec/lib/model/membase/blocked_referer_spec.rb +0 -34
  110. data/spec/lib/model/membase/blocked_user_agent_spec.rb +0 -34
  111. data/spec/lib/model/membase/geo_target_spec.rb +0 -11
  112. data/spec/lib/model/membase/pixel_spec.rb +0 -34
  113. data/spec/lib/model/membase/report_spec.rb +0 -11
  114. data/spec/lib/model/membase/s3_spec.rb +0 -11
  115. data/spec/lib/model/membase/zone_spec.rb +0 -32
  116. data/spec/lib/old_spec.rb +0 -437
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe Ad do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe AdZone do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe Base do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe BlockedReferer do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe BlockedUserAgent do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe GeoTarget do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe Report do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe S3File do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,54 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- class FakeZone
6
- include ZoneCalculations
7
- def initialize(ads, ad_links)
8
- @ads = ads
9
- @ad_links = ad_links
10
- end
11
- attr_reader :ad_links
12
- def find_ad(ad_id)
13
- @ads[ad_id]
14
- end
15
- end
16
-
17
- class ZoneCalculationSpecAd
18
- def initialize(active, pressure)
19
- @active = active
20
- @pressure = pressure
21
- end
22
- attr_reader :pressure, :active
23
- alias_method :active?, :active
24
- end
25
-
26
- describe ZoneCalculations do
27
- describe ".calculate_ads_by_priority" do
28
- it "should generate the expected result" do
29
- ads = {
30
- "0" => ZoneCalculationSpecAd.new(false, 42.0),
31
- "1" => ZoneCalculationSpecAd.new(true, 11.1),
32
- "2" => ZoneCalculationSpecAd.new(true, 11.1),
33
- "3" => ZoneCalculationSpecAd.new(true, 22.2),
34
- "4" => ZoneCalculationSpecAd.new(true, 1000),
35
- "5" => ZoneCalculationSpecAd.new(true, 828282)
36
- }
37
- ad_links = {
38
- "0" => {"priority" => 1, "weight" => 50},
39
- "1" => {"priority" => 1, "weight" => 4},
40
- "2" => {"priority" => 1, "weight" => 2},
41
- "3" => {"priority" => 1, "weight" => 2},
42
- "4" => {"priority" => 2, "weight" => 99.9}
43
- }
44
- zone = FakeZone.new(ads, ad_links)
45
-
46
- zone.calculate_ads_by_priority.should == [[["1", 44.4], ["2", 22.2], ["3", 44.4]], [["4", 99900.0]]]
47
- end
48
- end
49
- end
50
-
51
- end
52
- end
53
- end
54
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Common
5
- describe Zone do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,54 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe Ad do
6
- describe "total_impressed" do
7
- it "should call the expected methods and return the expected value" do
8
- a = Ad.allocate
9
- a.should_receive(:id).and_return(7)
10
- Ad.stub_chain(:connection, :get).with('count_delivery_ad_7',1).and_return('999.999')
11
-
12
- a.total_impressed.should == 999.999
13
- end
14
- end
15
-
16
- describe "today_impressed" do
17
- it "should call the expected methods and return the expected value" do
18
- a = Ad.allocate
19
- a.should_receive(:time_zone).and_return('time_zone_value')
20
- Time.stub_chain(:now, :in_time_zone).with('time_zone_value').and_return(Time.parse("2011-05-06 07:08"))
21
- a.should_receive(:id).and_return(7)
22
- Ad.stub_chain(:connection, :get).with('count_delivery_20110506_ad_7',1).and_return('99.99')
23
-
24
- a.today_impressed.should == 99.99
25
- end
26
- end
27
-
28
- describe "Ad.find(id)" do
29
- context "when the connection returns a value" do
30
- it "should call the expected methods and return the expected value" do
31
- connection = MembaseConnection.new("example.com:11211")
32
- Ad.stub(:connection).and_return(connection)
33
- connection.stub(:get).with('Ad:7').and_return('{"ad":{"attr":"value","attr2":"value2"}}')
34
- a = stub(:ad)
35
- Ad.should_receive(:new).with({'attr' => 'value', 'attr2' => 'value2'}).and_return(a)
36
-
37
- Ad.find(7).should == a
38
- end
39
- end
40
- context "when the connection returns nil" do
41
- it "should call the expected methods and return nil" do
42
- connection = MembaseConnection.new("example.com:11211")
43
- Ad.stub(:connection).and_return(connection)
44
- connection.stub(:get).with('Ad:7').and_return(nil)
45
-
46
- Ad.find(7).should be_nil
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe AdZone do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe Base do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,34 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe BlockedReferer do
6
- describe "BlockedReferer.all" do
7
- context "when connection returns a value" do
8
- it "should call the expected methods and return the expected value" do
9
- conn = MembaseConnection.new("example.com:11211")
10
- BlockedReferer.stub(:connection).and_return(conn)
11
- conn.stub(:get).with('blocked_referers').and_return('[{"blocked_referer":{"attr":"value"}},{"blocked_referer":{"attr2":"value2"}}]')
12
- br = stub(:blocked_referer)
13
- br2 = stub(:blocked_referer2)
14
- BlockedReferer.should_receive(:new).with({'attr' => 'value'}).and_return(br)
15
- BlockedReferer.should_receive(:new).with({'attr2' => 'value2'}).and_return(br2)
16
-
17
- BlockedReferer.all.should == [br, br2]
18
- end
19
- end
20
- context "when connection returns nil" do
21
- it "should call the expected methods and return the expected value" do
22
- conn = MembaseConnection.new("example.com:11211")
23
- BlockedReferer.stub(:connection).and_return(conn)
24
- conn.stub(:get).with('blocked_referers').and_return(nil)
25
-
26
- BlockedReferer.all.should == []
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,34 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe BlockedUserAgent do
6
- describe "BlockedUserAgent.all" do
7
- context "when connection returns a value" do
8
- it "should call the expected methods and return the expected value" do
9
- conn = MembaseConnection.new("example.com:11211")
10
- BlockedUserAgent.stub(:connection).and_return(conn)
11
- conn.stub(:get).with('blocked_user_agents').and_return('[{"blocked_user_agent":{"attr":"value"}},{"blocked_user_agent":{"attr2":"value2"}}]')
12
- bua = stub(:blocked_user_agent)
13
- bua2 = stub(:blocked_user_agent2)
14
- BlockedUserAgent.should_receive(:new).with({'attr' => 'value'}).and_return(bua)
15
- BlockedUserAgent.should_receive(:new).with({'attr2' => 'value2'}).and_return(bua2)
16
-
17
- BlockedUserAgent.all.should == [bua, bua2]
18
- end
19
- end
20
- context "when connection returns nil" do
21
- it "should call the expected methods and return the expected value" do
22
- conn = MembaseConnection.new("example.com:11211")
23
- BlockedUserAgent.stub(:connection).and_return(conn)
24
- conn.stub(:get).with('blocked_user_agents').and_return(nil)
25
-
26
- BlockedUserAgent.all.should == []
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe GeoTarget do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,34 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe Pixel do
6
- describe "Pixel.find(id)" do
7
- context "when the connection returns a value" do
8
- it "should call the expected methods and return the expected value" do
9
- c = stub(:connection)
10
- Pixel.should_receive(:connection).exactly(2).times.and_return(c)
11
- p = stub(:pixel)
12
- c.stub_chain(:local_cache, :fetch).with('Neuron::Client::Model::Pixel:7').and_yield.and_return(p)
13
- c.should_receive(:get).with('Pixel:7').and_return('{"pixel":{"attr":"value","attr2":"value2"}}')
14
- Pixel.should_receive(:new).with({'attr' => 'value', 'attr2' => 'value2'}).and_return(p)
15
-
16
- Pixel.find(7).should == p
17
- end
18
- end
19
- context "when the connection returns nil" do
20
- it "should call the expected methods and return nil" do
21
- c = stub(:connection)
22
- Pixel.should_receive(:connection).exactly(2).times.and_return(c)
23
- c.stub_chain(:local_cache, :fetch).with('Neuron::Client::Model::Pixel:7').and_yield.and_return(nil)
24
- c.should_receive(:get).with('Pixel:7').and_return(nil)
25
-
26
- Pixel.find(7).should be_nil
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe Report do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe S3File do
6
-
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,32 +0,0 @@
1
- module Neuron
2
- module Client
3
- module Model
4
- module Membase
5
- describe Zone do
6
- describe "Zone.all" do
7
- context "when connection.get returns a value" do
8
- it "should call the expected methods and return the expected result" do
9
- conn = MembaseConnection.new("example.com:11211")
10
- Zone.stub(:connection).and_return(conn)
11
- conn.stub(:get).with('Zone:7').and_return('{"zone":{"attr":"value","attr2":"value2"}}')
12
- z = stub(:zone)
13
- Zone.should_receive(:new).with({'attr' => 'value', 'attr2' => 'value2'}).and_return(z)
14
-
15
- Zone.find(7).should == z
16
- end
17
- end
18
- context "when connection.get returns nil" do
19
- it "should call the expected methods and return nil" do
20
- conn = MembaseConnection.new("example.com:11211")
21
- Zone.stub(:connection).and_return(conn)
22
- conn.stub(:get).with('Zone:7').and_return(nil)
23
-
24
- Zone.find(7).should be_nil
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end