neuron-client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -8
- data/lib/neuron-client.rb +61 -12
- data/lib/neuron-client/{connection.rb → admin_connection.rb} +7 -7
- data/lib/neuron-client/api.rb +48 -31
- data/lib/neuron-client/membase_connection.rb +18 -0
- data/lib/neuron-client/model/admin/ad.rb +22 -0
- data/lib/neuron-client/model/admin/ad_zone.rb +15 -0
- data/lib/neuron-client/model/admin/base.rb +91 -0
- data/lib/neuron-client/model/admin/blocked_referer.rb +12 -0
- data/lib/neuron-client/model/admin/blocked_user_agent.rb +12 -0
- data/lib/neuron-client/model/admin/geo_target.rb +16 -0
- data/lib/neuron-client/model/admin/report.rb +15 -0
- data/lib/neuron-client/model/admin/s3_file.rb +12 -0
- data/lib/neuron-client/model/admin/zone.rb +15 -0
- data/lib/neuron-client/model/base.rb +38 -0
- data/lib/neuron-client/model/common/ad.rb +40 -0
- data/lib/neuron-client/model/common/ad_calculations.rb +329 -0
- data/lib/neuron-client/model/common/ad_zone.rb +17 -0
- data/lib/neuron-client/model/common/base.rb +67 -0
- data/lib/neuron-client/model/common/blocked_referer.rb +16 -0
- data/lib/neuron-client/model/common/blocked_user_agent.rb +16 -0
- data/lib/neuron-client/model/common/geo_target.rb +16 -0
- data/lib/neuron-client/model/common/report.rb +21 -0
- data/lib/neuron-client/model/common/s3_file.rb +16 -0
- data/lib/neuron-client/model/common/zone.rb +22 -0
- data/lib/neuron-client/model/common/zone_calculations.rb +41 -0
- data/lib/neuron-client/model/membase/ad.rb +31 -0
- data/lib/neuron-client/model/membase/ad_zone.rb +11 -0
- data/lib/neuron-client/model/membase/blocked_referer.rb +18 -0
- data/lib/neuron-client/model/membase/blocked_user_agent.rb +18 -0
- data/lib/neuron-client/model/membase/geo_target.rb +11 -0
- data/lib/neuron-client/model/membase/report.rb +11 -0
- data/lib/neuron-client/model/membase/s3_file.rb +11 -0
- data/lib/neuron-client/model/membase/zone.rb +19 -0
- data/lib/neuron-client/model/models.rb +14 -0
- data/lib/neuron-client/version.rb +1 -1
- data/neuron-client.gemspec +18 -11
- data/spec/fixtures/vcr_cassettes/s3_file.yml +186 -4
- data/spec/lib/admin_connection_spec.rb +82 -0
- data/spec/lib/api_spec.rb +80 -0
- data/spec/lib/membase_connection_spec.rb +27 -0
- data/spec/lib/model/admin/ad_spec.rb +34 -0
- data/spec/lib/model/admin/ad_zone_spec.rb +19 -0
- data/spec/lib/model/admin/base_spec.rb +11 -0
- data/spec/lib/model/admin/blocked_referer_spec.rb +11 -0
- data/spec/lib/model/admin/blocked_user_agent_spec.rb +11 -0
- data/spec/lib/model/admin/geo_target_spec.rb +30 -0
- data/spec/lib/model/admin/report_spec.rb +21 -0
- data/spec/lib/model/admin/s3_spec.rb +11 -0
- data/spec/lib/model/admin/zone_spec.rb +21 -0
- data/spec/lib/model/base_spec.rb +89 -0
- data/spec/lib/model/common/ad_calculations_spec.rb +1148 -0
- data/spec/lib/model/common/ad_spec.rb +11 -0
- data/spec/lib/model/common/ad_zone_spec.rb +11 -0
- data/spec/lib/model/common/base_spec.rb +11 -0
- data/spec/lib/model/common/blocked_referer_spec.rb +11 -0
- data/spec/lib/model/common/blocked_user_agent_spec.rb +11 -0
- data/spec/lib/model/common/geo_target_spec.rb +11 -0
- data/spec/lib/model/common/report_spec.rb +11 -0
- data/spec/lib/model/common/s3_spec.rb +11 -0
- data/spec/lib/model/common/zone_calculations_spec.rb +54 -0
- data/spec/lib/model/common/zone_spec.rb +11 -0
- data/spec/lib/model/membase/ad_spec.rb +50 -0
- data/spec/lib/model/membase/ad_zone_spec.rb +11 -0
- data/spec/lib/model/membase/base_spec.rb +11 -0
- data/spec/lib/model/membase/blocked_referer_spec.rb +30 -0
- data/spec/lib/model/membase/blocked_user_agent_spec.rb +30 -0
- data/spec/lib/model/membase/geo_target_spec.rb +11 -0
- data/spec/lib/model/membase/report_spec.rb +11 -0
- data/spec/lib/model/membase/s3_spec.rb +11 -0
- data/spec/lib/model/membase/zone_spec.rb +28 -0
- data/spec/lib/old_spec.rb +192 -149
- data/spec/lib/s3_file_spec.rb +45 -42
- data/spec/spec_helper.rb +2 -1
- metadata +296 -57
- data/lib/neuron-client/ad.rb +0 -39
- data/lib/neuron-client/ad_zone.rb +0 -16
- data/lib/neuron-client/blocked_referer.rb +0 -12
- data/lib/neuron-client/blocked_user_agent.rb +0 -12
- data/lib/neuron-client/connected.rb +0 -138
- data/lib/neuron-client/geo_target.rb +0 -16
- data/lib/neuron-client/real_time_stats.rb +0 -0
- data/lib/neuron-client/report.rb +0 -20
- data/lib/neuron-client/s3_file.rb +0 -10
- data/lib/neuron-client/zone.rb +0 -16
data/lib/neuron-client/ad.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
class Ad
|
4
|
-
include Connected
|
5
|
-
resource_name("ad")
|
6
|
-
resources_name("ads")
|
7
|
-
|
8
|
-
attr_accessor :name, :approved, :response_type, :parameters, :geo_target_ids,
|
9
|
-
# redirect
|
10
|
-
:redirect_url,
|
11
|
-
# video
|
12
|
-
:video_api_url, :video_setup_xml, :video_flv_url,
|
13
|
-
:video_clickthru_url, :video_companion_ad_html, :social_links, :social_links_attributes,
|
14
|
-
# caps
|
15
|
-
:frequency_cap_limit, :frequency_cap_window, :overall_cap,
|
16
|
-
:daily_cap, :day_partitions, :ideal_impressions_per_hour,
|
17
|
-
# range
|
18
|
-
:start_datetime, :end_datetime, :time_zone,
|
19
|
-
# timestamps
|
20
|
-
:created_at, :updated_at
|
21
|
-
|
22
|
-
def self.stringify_day_partitions(days)
|
23
|
-
result = ""
|
24
|
-
168.times do |i|
|
25
|
-
result << (days[i.to_s] || "F")
|
26
|
-
end
|
27
|
-
result
|
28
|
-
end
|
29
|
-
|
30
|
-
def recent(statistic, parameters)
|
31
|
-
self.class.connection.get("ads/#{id}/recent/#{statistic}", parameters)
|
32
|
-
end
|
33
|
-
|
34
|
-
def unlink(ad_id)
|
35
|
-
self.class.connection.delete("ads/#{id}/zones/#{ad_id}")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
class AdZone
|
4
|
-
include Connected
|
5
|
-
resource_name("ad_zone")
|
6
|
-
resources_name("ad_zones")
|
7
|
-
|
8
|
-
attr_accessor :ad_id, :zone_id, :priority, :weight,
|
9
|
-
:created_at, :updated_at
|
10
|
-
|
11
|
-
def self.unlink(ad_id, zone_id)
|
12
|
-
self.connection.delete("zones/#{zone_id}/ads/#{ad_id}")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
module Connected
|
4
|
-
def initialize(attrs=nil)
|
5
|
-
(attrs || {}).each do |k,v|
|
6
|
-
next if k.to_s == 'id' && self.class.remote_id != 'id'
|
7
|
-
k = 'id' if k.to_s == self.class.remote_id
|
8
|
-
self.send("#{k}=", v) if self.respond_to?("#{k}=")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def attributes
|
13
|
-
self.class.attributes || []
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_hash(*except)
|
17
|
-
hash = {}
|
18
|
-
attributes.reject{|a| except.collect(&:to_sym).include?(a.to_sym)}.each do |attribute|
|
19
|
-
value = send(attribute)
|
20
|
-
hash[attribute] = value unless value.nil?
|
21
|
-
end
|
22
|
-
hash
|
23
|
-
end
|
24
|
-
|
25
|
-
def new_record?
|
26
|
-
id.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
def save
|
30
|
-
@errors = catch :errors do
|
31
|
-
if new_record?
|
32
|
-
response = self.class.connection.post("#{self.class.resources_name}", {self.class.resource_name => self.to_hash(:errors, :updated_at, :created_at)})
|
33
|
-
self.id = response[self.class.resource_name][self.class.remote_id]
|
34
|
-
else
|
35
|
-
response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => self.to_hash(:errors, :updated_at, :created_at)})
|
36
|
-
end
|
37
|
-
[]
|
38
|
-
end
|
39
|
-
|
40
|
-
@errors.empty?
|
41
|
-
end
|
42
|
-
|
43
|
-
def update_attributes(attrs={})
|
44
|
-
@errors = catch :errors do
|
45
|
-
response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => attrs})
|
46
|
-
attrs.each do |key, value|
|
47
|
-
self.send("#{key}=", value) if self.respond_to?("#{key}=")
|
48
|
-
end
|
49
|
-
[]
|
50
|
-
end
|
51
|
-
|
52
|
-
@errors.empty?
|
53
|
-
end
|
54
|
-
|
55
|
-
def valid?
|
56
|
-
@errors.empty?
|
57
|
-
end
|
58
|
-
|
59
|
-
def destroy
|
60
|
-
self.class.connection.delete("#{self.class.resources_name}/#{id}")
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.included(base)
|
64
|
-
base.send(:attr_accessor, :id)
|
65
|
-
base.send(:attr_accessor, :errors)
|
66
|
-
base.extend(ClassMethods)
|
67
|
-
end
|
68
|
-
|
69
|
-
module ClassMethods
|
70
|
-
def attr_accessor(*vars)
|
71
|
-
@attributes ||= []
|
72
|
-
@attributes += vars
|
73
|
-
super(*vars)
|
74
|
-
end
|
75
|
-
|
76
|
-
def attributes
|
77
|
-
@attributes
|
78
|
-
end
|
79
|
-
|
80
|
-
attr_accessor :connection
|
81
|
-
|
82
|
-
def connected?
|
83
|
-
!connected.nil?
|
84
|
-
end
|
85
|
-
|
86
|
-
def connection
|
87
|
-
API.connection
|
88
|
-
end
|
89
|
-
|
90
|
-
def resource_name(res=nil)
|
91
|
-
if res
|
92
|
-
@resource_name = res.to_s
|
93
|
-
end
|
94
|
-
@resource_name
|
95
|
-
end
|
96
|
-
|
97
|
-
def resources_name(res=nil)
|
98
|
-
if res
|
99
|
-
@resources_name = res.to_s.downcase
|
100
|
-
end
|
101
|
-
if @resources_name.nil? && !@resource_name.nil?
|
102
|
-
@resources_name = "#{@resource_name}s"
|
103
|
-
end
|
104
|
-
@resources_name
|
105
|
-
end
|
106
|
-
|
107
|
-
def remote_id(remote_id=nil)
|
108
|
-
if remote_id
|
109
|
-
@remote_id = remote_id.to_s
|
110
|
-
end
|
111
|
-
@remote_id || 'id'
|
112
|
-
end
|
113
|
-
|
114
|
-
def find(id)
|
115
|
-
response = self.connection.get("#{self.resources_name}/#{id}")
|
116
|
-
self.new(response[self.resource_name])
|
117
|
-
end
|
118
|
-
|
119
|
-
def all
|
120
|
-
response = self.connection.get("#{self.resources_name}")
|
121
|
-
response.map{|hash| self.new(hash[self.resource_name])}
|
122
|
-
end
|
123
|
-
|
124
|
-
def create(attrs={})
|
125
|
-
@errors = catch (:errors) do
|
126
|
-
return create!(attrs)
|
127
|
-
end
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
|
131
|
-
def create!(attrs={})
|
132
|
-
response = self.connection.post("#{self.resources_name}", {self.resource_name => attrs})
|
133
|
-
self.new(response[self.resource_name])
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
class GeoTarget
|
4
|
-
include Connected
|
5
|
-
resource_name("geo_target")
|
6
|
-
resources_name("geo_targets")
|
7
|
-
|
8
|
-
attr_accessor :geo_type, :full_name, :name, :abbreviation, :updated_at
|
9
|
-
|
10
|
-
def self.query(parameters)
|
11
|
-
response = self.connection.get("geo_targets", parameters)
|
12
|
-
response.map{|hash| self.new(hash[self.resource_name])}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
File without changes
|
data/lib/neuron-client/report.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
class Report
|
4
|
-
include Connected
|
5
|
-
resource_name("report")
|
6
|
-
resources_name("reports")
|
7
|
-
|
8
|
-
attr_accessor :errors
|
9
|
-
attr_accessor :template, :parameters, :state
|
10
|
-
|
11
|
-
def status
|
12
|
-
@state
|
13
|
-
end
|
14
|
-
|
15
|
-
def result
|
16
|
-
self.class.connection.get("reports/#{id}/result", :format => "")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/neuron-client/zone.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Neuron
|
2
|
-
module Client
|
3
|
-
class Zone
|
4
|
-
include Connected
|
5
|
-
resource_name("zone")
|
6
|
-
resources_name("zones")
|
7
|
-
|
8
|
-
attr_accessor :slug, :response_type, :template_slug, :parameters,
|
9
|
-
:created_at, :updated_at
|
10
|
-
|
11
|
-
def unlink(ad_id)
|
12
|
-
self.class.connection.delete("zones/#{id}/ads/#{ad_id}")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|