neuron-client 0.2.1 → 0.2.2
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.
- data/lib/neuron-client/api.rb +2 -2
- data/lib/neuron-client/membase_connection.rb +2 -2
- data/lib/neuron-client/model/membase/ad.rb +9 -7
- data/lib/neuron-client/model/membase/blocked_referer.rb +6 -4
- data/lib/neuron-client/model/membase/blocked_user_agent.rb +6 -4
- data/lib/neuron-client/model/membase/zone.rb +7 -5
- data/lib/neuron-client/version.rb +1 -1
- data/spec/lib/model/membase/ad_spec.rb +8 -4
- data/spec/lib/model/membase/blocked_referer_spec.rb +6 -2
- data/spec/lib/model/membase/blocked_user_agent_spec.rb +6 -2
- data/spec/lib/model/membase/zone_spec.rb +6 -2
- metadata +3 -3
data/lib/neuron-client/api.rb
CHANGED
@@ -50,8 +50,8 @@ module Neuron
|
|
50
50
|
def configure_membase_connection
|
51
51
|
required(@config, :membase_servers)
|
52
52
|
self.connection = MembaseConnection.new(config.membase_servers,
|
53
|
-
:local_cache_size => config
|
54
|
-
:local_cache_expires => config
|
53
|
+
:local_cache_size => config.local_cache_size,
|
54
|
+
:local_cache_expires => config.local_cache_expires
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
@@ -5,7 +5,7 @@ module Neuron
|
|
5
5
|
module Client
|
6
6
|
class MembaseConnection
|
7
7
|
|
8
|
-
attr_reader :client
|
8
|
+
attr_reader :client, :local_cache
|
9
9
|
|
10
10
|
def initialize(servers, opts={})
|
11
11
|
@client = Dalli::Client.new(servers)
|
@@ -22,7 +22,7 @@ module Neuron
|
|
22
22
|
|
23
23
|
def fetch(key, ttl=nil, options=nil, &callback)
|
24
24
|
@local_cache.fetch(key, local_ttl(ttl)) do
|
25
|
-
@client.fetch(key, options, &callback)
|
25
|
+
@client.fetch(key, ttl, options, &callback)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -9,14 +9,14 @@ module Neuron
|
|
9
9
|
|
10
10
|
def total_impressed
|
11
11
|
key = "count_delivery_ad_#{self.id}"
|
12
|
-
self.class.connection.get(key).to_f
|
12
|
+
self.class.connection.get(key,1).to_f
|
13
13
|
end
|
14
14
|
|
15
15
|
def today_impressed
|
16
16
|
now_adjusted_for_ad_time_zone = Time.now.in_time_zone(self.time_zone)
|
17
17
|
formatted_date = now_adjusted_for_ad_time_zone.strftime('%Y%m%d') # format to YYYYMMDD
|
18
18
|
key = "count_delivery_#{formatted_date}_ad_#{self.id}"
|
19
|
-
self.class.connection.get(key).to_f
|
19
|
+
self.class.connection.get(key,1).to_f
|
20
20
|
end
|
21
21
|
|
22
22
|
def active?
|
@@ -33,11 +33,13 @@ module Neuron
|
|
33
33
|
|
34
34
|
class << self
|
35
35
|
def find(id)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
self.connection.local_cache.fetch("Neuron::Client::Model::Ad:#{id}") do
|
37
|
+
ad = nil
|
38
|
+
membase_key = "Ad:#{id}"
|
39
|
+
cached_json = self.connection.get(membase_key)
|
40
|
+
ad = self.new(Yajl.load(cached_json)[superclass.resource_name]) if cached_json.present?
|
41
|
+
ad
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -5,10 +5,12 @@ module Neuron
|
|
5
5
|
class BlockedReferer < Common::BlockedReferer
|
6
6
|
class << self
|
7
7
|
def all
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
self.connection.local_cache.fetch("Neuron::Client::Model::BlockedReferer:all") do
|
9
|
+
blocked_referers = []
|
10
|
+
cached_json = self.connection.get('blocked_referers')
|
11
|
+
blocked_referers = Yajl.load(cached_json).collect{|item| self.new(item[superclass.resource_name])} if cached_json.present?
|
12
|
+
blocked_referers
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -5,10 +5,12 @@ module Neuron
|
|
5
5
|
class BlockedUserAgent < Common::BlockedUserAgent
|
6
6
|
class << self
|
7
7
|
def all
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
self.connection.local_cache.fetch("Neuron::Client::Model::BlockedUserAgent:all") do
|
9
|
+
blocked_user_agents = []
|
10
|
+
cached_json = self.connection.get('blocked_user_agents')
|
11
|
+
blocked_user_agents = Yajl.load(cached_json).collect{|item| self.new(item[superclass.resource_name])} if cached_json.present?
|
12
|
+
blocked_user_agents
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -14,11 +14,13 @@ module Neuron
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
def find(id)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
self.connection.local_cache.fetch("Neuron::Client::Model::Zone:#{id}") do
|
18
|
+
zone = nil
|
19
|
+
membase_key = "Zone:#{id}"
|
20
|
+
cached_json = self.connection.get(membase_key)
|
21
|
+
zone = self.new(Yajl.load(cached_json)[superclass.resource_name]) if cached_json.present?
|
22
|
+
zone
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -7,7 +7,7 @@ module Neuron
|
|
7
7
|
it "should call the expected methods and return the expected value" do
|
8
8
|
a = Ad.allocate
|
9
9
|
a.should_receive(:id).and_return(7)
|
10
|
-
Ad.stub_chain(:connection, :get).with('count_delivery_ad_7').and_return('999.999')
|
10
|
+
Ad.stub_chain(:connection, :get).with('count_delivery_ad_7',1).and_return('999.999')
|
11
11
|
|
12
12
|
a.total_impressed.should == 999.999
|
13
13
|
end
|
@@ -19,7 +19,7 @@ module Neuron
|
|
19
19
|
a.should_receive(:time_zone).and_return('time_zone_value')
|
20
20
|
Time.stub_chain(:now, :in_time_zone).with('time_zone_value').and_return(Time.parse("2011-05-06 07:08"))
|
21
21
|
a.should_receive(:id).and_return(7)
|
22
|
-
Ad.stub_chain(:connection, :get).with('count_delivery_20110506_ad_7').and_return('99.99')
|
22
|
+
Ad.stub_chain(:connection, :get).with('count_delivery_20110506_ad_7',1).and_return('99.99')
|
23
23
|
|
24
24
|
a.today_impressed.should == 99.99
|
25
25
|
end
|
@@ -28,7 +28,9 @@ module Neuron
|
|
28
28
|
describe "Ad.find(id)" do
|
29
29
|
context "when the connection returns a value" do
|
30
30
|
it "should call the expected methods and return the expected value" do
|
31
|
-
|
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"}}')
|
32
34
|
a = stub(:ad)
|
33
35
|
Ad.should_receive(:new).with({'attr' => 'value', 'attr2' => 'value2'}).and_return(a)
|
34
36
|
|
@@ -37,7 +39,9 @@ module Neuron
|
|
37
39
|
end
|
38
40
|
context "when the connection returns nil" do
|
39
41
|
it "should call the expected methods and return nil" do
|
40
|
-
|
42
|
+
connection = MembaseConnection.new("example.com:11211")
|
43
|
+
Ad.stub(:connection).and_return(connection)
|
44
|
+
connection.stub(:get).with('Ad:7').and_return(nil)
|
41
45
|
|
42
46
|
Ad.find(7).should be_nil
|
43
47
|
end
|
@@ -6,7 +6,9 @@ module Neuron
|
|
6
6
|
describe "BlockedReferer.all" do
|
7
7
|
context "when connection returns a value" do
|
8
8
|
it "should call the expected methods and return the expected value" do
|
9
|
-
|
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"}}]')
|
10
12
|
br = stub(:blocked_referer)
|
11
13
|
br2 = stub(:blocked_referer2)
|
12
14
|
BlockedReferer.should_receive(:new).with({'attr' => 'value'}).and_return(br)
|
@@ -17,7 +19,9 @@ module Neuron
|
|
17
19
|
end
|
18
20
|
context "when connection returns nil" do
|
19
21
|
it "should call the expected methods and return the expected value" do
|
20
|
-
|
22
|
+
conn = MembaseConnection.new("example.com:11211")
|
23
|
+
BlockedReferer.stub(:connection).and_return(conn)
|
24
|
+
conn.stub(:get).with('blocked_referers').and_return(nil)
|
21
25
|
|
22
26
|
BlockedReferer.all.should == []
|
23
27
|
end
|
@@ -6,7 +6,9 @@ module Neuron
|
|
6
6
|
describe "BlockedUserAgent.all" do
|
7
7
|
context "when connection returns a value" do
|
8
8
|
it "should call the expected methods and return the expected value" do
|
9
|
-
|
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"}}]')
|
10
12
|
bua = stub(:blocked_user_agent)
|
11
13
|
bua2 = stub(:blocked_user_agent2)
|
12
14
|
BlockedUserAgent.should_receive(:new).with({'attr' => 'value'}).and_return(bua)
|
@@ -17,7 +19,9 @@ module Neuron
|
|
17
19
|
end
|
18
20
|
context "when connection returns nil" do
|
19
21
|
it "should call the expected methods and return the expected value" do
|
20
|
-
|
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)
|
21
25
|
|
22
26
|
BlockedUserAgent.all.should == []
|
23
27
|
end
|
@@ -6,7 +6,9 @@ module Neuron
|
|
6
6
|
describe "Zone.all" do
|
7
7
|
context "when connection.get returns a value" do
|
8
8
|
it "should call the expected methods and return the expected result" do
|
9
|
-
|
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"}}')
|
10
12
|
z = stub(:zone)
|
11
13
|
Zone.should_receive(:new).with({'attr' => 'value', 'attr2' => 'value2'}).and_return(z)
|
12
14
|
|
@@ -15,7 +17,9 @@ module Neuron
|
|
15
17
|
end
|
16
18
|
context "when connection.get returns nil" do
|
17
19
|
it "should call the expected methods and return nil" do
|
18
|
-
|
20
|
+
conn = MembaseConnection.new("example.com:11211")
|
21
|
+
Zone.stub(:connection).and_return(conn)
|
22
|
+
conn.stub(:get).with('Zone:7').and_return(nil)
|
19
23
|
|
20
24
|
Zone.find(7).should be_nil
|
21
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neuron-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- RMM Online
|