neuron-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2@neuron-client
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in neuron-client.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ guard 'rspec', :cli => '-c --format documentation -r ./spec/spec_helper.rb',
10
+ :version => 2 do
11
+ watch(%r{^spec/.+_spec\.rb})
12
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Neuron Client Gem
2
+ =================
3
+
4
+
5
+ Setup
6
+ =====
7
+
8
+ Neuron::Client::API.configure do |config|
9
+ config.admin_url = "https://example.com"
10
+ config.admin_key = "secret"
11
+ end
12
+
13
+
14
+ Zones
15
+ =====
16
+
17
+ Create a zone:
18
+
19
+ zone = Neuron::Client::Zone.new(:slug => 'test', :response_type => 'Redirect')
20
+ zone.save
21
+
22
+ ... or simply:
23
+
24
+ Neuron::Client::Zone.create(:slug => 'test', :response_type => 'Redirect')
25
+
26
+ List all zones:
27
+
28
+ Neuron::Client::Zone.all # => Array of Zone objects (with limited attributes)
29
+
30
+ Find a zone by ID:
31
+
32
+ Neuron::Client::Zone.find(zone_id)
33
+
34
+ Update a zone:
35
+
36
+ zone.update_attributes(:parameters => {'foo' => 'bar'})
37
+
38
+ TODO: Finish and finalize the API
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run all specs"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = [
7
+ '-c',
8
+ '--format documentation',
9
+ '-r ./spec/spec_helper.rb'
10
+ ]
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ desc "open coverage report"
15
+ task :coverage do
16
+ system 'rake spec'
17
+ system 'open coverage/index.html'
18
+ end
19
+
20
+ desc "Open development console"
21
+ task :console do
22
+ puts "Loading development console..."
23
+ system "irb -I #{File.join('.', 'lib')} -r #{File.join('.', 'lib', 'neuron-client')}"
24
+ end
25
+
26
+ task :force_release do
27
+ gem_helper = Bundler::GemHelper.new(Dir.pwd)
28
+ built_gem_path = gem_helper.build_gem
29
+ gem_helper.send(:rubygem_push, built_gem_path)
30
+ end
@@ -0,0 +1,59 @@
1
+ module Neuron
2
+ module Client
3
+ class Ad
4
+ include Connected
5
+ resource_name("ad")
6
+ resources_name("ads")
7
+
8
+ attr_accessor :errors
9
+ attr_accessor :name, :approved, :response_type, :parameters,
10
+ # redirect
11
+ :redirect_url,
12
+ # video
13
+ :video_api_url, :video_setup_xml, :video_flv_url,
14
+ :video_clickthru_url, :video_companion_ad_html,
15
+ # caps
16
+ :frequency_cap_limit, :frequency_cap_window, :overall_cap,
17
+ :daily_cap, :day_partitions, :ideal_impressions_per_hour,
18
+ # range
19
+ :start_datetime, :end_datetime, :time_zone,
20
+ # timestamps
21
+ :created_at, :updated_at
22
+
23
+ def valid?
24
+ validate
25
+ @errors.empty?
26
+ end
27
+
28
+ def self.stringify_day_partitions(days)
29
+ result = ""
30
+ 168.times do |i|
31
+ result << (days[i.to_s] || "F")
32
+ end
33
+ result
34
+ end
35
+
36
+ def validate
37
+ @errors = []
38
+ @errors << [:approved, "is not 'Yes' or 'No'"] if ["Yes", "No"].include?(@approved)
39
+ @errors << [:response_type, "is not 'Redirect' or 'Video'"] if ["Redirect", "Video"].include?(@response_type)
40
+ @errors << [:start_datetime, "is required"] if @start_datetime.blank?
41
+ @errors << [:end_datetime, "is required"] if @end_datetime.blank?
42
+ @errors << [:time_zone, "is required"] if @time_zone.blank?
43
+
44
+ if @response_type == "Video"
45
+ @errors << [:video_api_url, "is required"] if @video_api_url.blank?
46
+ @errors << [:video_setup_xml, "is required"] if @video_setup_xml.blank?
47
+ elsif @response_type == "Redirect"
48
+ @errors << [:redirect_url, "is required"] if @redirect_url.blank?
49
+ end
50
+
51
+ @errors << [:day_partitions, "Must be exactly 168 TF characters"] if !@day_partitions.blank? && @day_partitions.length != 168 && !(@day_partitions.match(/[TF]+/).try(:to_a).try(:first) == @day_partitions)
52
+ end
53
+
54
+ def unlink(ad_id)
55
+ self.class.connection.delete("ads/#{id}/zones/#{ad_id}")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,45 @@
1
+ module Neuron
2
+ module Client
3
+
4
+ # Neuron::Client::API.configure do |config|
5
+ # config.admin_url = "https://example.com"
6
+ # config.admin_key = "secret"
7
+ # end
8
+ #
9
+ # Neuron::Client::API.connection
10
+ class API
11
+ autoload :OpenStruct, "ostruct"
12
+ class << self
13
+ attr_accessor :connection
14
+
15
+ def reset!
16
+ self.connection = nil
17
+ @config = nil
18
+ end
19
+
20
+ def configure
21
+ @config ||= OpenStruct.new
22
+ yield @config
23
+ required(@config, :admin_url)
24
+ required(@config, :admin_key)
25
+ begin
26
+ URI.parse(@config.admin_url)
27
+ rescue
28
+ raise "Invalid admin_url: #{@config.admin_url}"
29
+ end
30
+ self.connection = Connection.new(@config.admin_url, @config.key)
31
+ true
32
+ end
33
+
34
+ private
35
+
36
+ def required(obj, attrib)
37
+ val = obj.send(attrib)
38
+ if val.nil? || (val.respond_to?(:empty?) && val.empty?)
39
+ raise "Missing: #{attrib}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
File without changes
File without changes
@@ -0,0 +1,106 @@
1
+ module Neuron
2
+ module Client
3
+ module Connected
4
+ def initialize(attrs=nil)
5
+ (attrs || {}).each do |k,v|
6
+ self.send("#{k}=", v) if self.respond_to?("#{k}=")
7
+ end
8
+ end
9
+
10
+ def attributes
11
+ self.class.attributes
12
+ end
13
+
14
+ def to_hash
15
+ hash = {}
16
+ attributes.each do |attribute|
17
+ hash[attribute] = send(attribute)
18
+ end
19
+ hash
20
+ end
21
+
22
+ def new_record?
23
+ id.nil?
24
+ end
25
+
26
+ def save
27
+ if new_record?
28
+ response = self.class.connection.post("#{self.class.resources_name}", {self.class.resource_name => self.to_hash})
29
+ else
30
+ response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => self.to_hash})
31
+ self.id = response[self.resource_name]['id']
32
+ end
33
+ end
34
+
35
+ def update_attributes(attrs={})
36
+ response = self.class.connection.put("#{self.class.resources_name}/#{id}", {self.class.resource_name => attrs})
37
+ attrs.each do |key, value|
38
+ self.send("#{key}=", value) if self.respond_to?("#{key}=")
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ self.class.connection.delete("#{self.class.resources_name}/#{id}")
44
+ end
45
+
46
+ def self.included(base)
47
+ base.send(:attr_accessor, :id)
48
+ base.extend(ClassMethods)
49
+ end
50
+
51
+ module ClassMethods
52
+ def attr_accessor(*vars)
53
+ @attributes ||= []
54
+ @attributes += vars
55
+ super(*vars)
56
+ end
57
+
58
+ def attributes
59
+ @attributes
60
+ end
61
+
62
+ attr_accessor :connection
63
+
64
+ def connected?
65
+ !connected.nil?
66
+ end
67
+
68
+ def connection
69
+ API.connection
70
+ end
71
+
72
+ def resource_name(res=nil)
73
+ if res
74
+ @resource_name = res.to_s
75
+ end
76
+ @resource_name
77
+ end
78
+
79
+ def resources_name(res=nil)
80
+ if res
81
+ @resources_name = res.to_s.downcase
82
+ end
83
+ if @resources_name.nil? && !@resource_name.nil?
84
+ @resources_name = "#{@resource_name}s"
85
+ end
86
+ @resources_name
87
+ end
88
+
89
+ def find(id)
90
+ response = self.connection.get("#{self.resources_name}/#{id}")
91
+ self.new(response[self.resource_name])
92
+ end
93
+
94
+ def all
95
+ response = self.connection.get("#{self.resources_name}")
96
+ response.map{|hash| self.new(hash[self.resource_name])}
97
+ end
98
+
99
+ def create(attrs={})
100
+ response = self.connection.post("#{self.resources_name}", {self.resource_name => attrs})
101
+ self.new(response[self.resource_name])
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,65 @@
1
+ require 'rest_client'
2
+ require 'yajl'
3
+
4
+ module Neuron
5
+ module Client
6
+ class Connection
7
+ def initialize(url, key)
8
+ @url = url
9
+ @key = key
10
+ end
11
+
12
+ def query_string(attrs={})
13
+ q = []
14
+ {:api_key => @key}.merge(attrs).each do |key, value|
15
+ q << "#{key}=#{value.nil? ? '' : CGI::escape(value)}"
16
+ end
17
+ q.join("&")
18
+ end
19
+
20
+ def get(path="", attrs={})
21
+ RestClient.get("#{@url}/#{path}.json?#{query_string(attrs)}", :content_type => :json, :accept => :json) do |response, request, result, &block|
22
+ case response.code
23
+ when 200
24
+ return Yajl.load(response.to_str)
25
+ else
26
+ raise "Error : #{response.code} - #{response.to_str}"
27
+ end
28
+ end
29
+ end
30
+
31
+ def post(path="", form={}, attrs={})
32
+ RestClient.post("#{@url}/#{path}.json?#{query_string(attrs)}", Yajl.dump(form), :content_type => :json, :accept => :json) do |response, request, result, &block|
33
+ case response.code
34
+ when 201
35
+ return Yajl.load(response.to_str)
36
+ else
37
+ raise "Error : #{response.code} - #{response.to_str}"
38
+ end
39
+ end
40
+ end
41
+
42
+ def put(path="", form={}, attrs={})
43
+ RestClient.put("#{@url}/#{path}.json?#{query_string}", Yajl.dump(form), :content_type => :json, :accept => :json) do |response, request, result, &block|
44
+ case response.code
45
+ when 200
46
+ return Yajl.load(response.to_str)
47
+ else
48
+ raise "Error : #{response.code} - #{response.to_str}"
49
+ end
50
+ end
51
+ end
52
+
53
+ def delete(path="", attrs={})
54
+ RestClient.delete("#{@url}/#{path}.json?#{query_string(attrs)}", :content_type => :json, :accept => :json) do |response, request, result, &block|
55
+ case response.code
56
+ when 200
57
+ return Yajl.load(response.to_str)
58
+ else
59
+ raise "Error : #{response.code} - #{response.to_str}"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ module Neuron
2
+ module Client
3
+ class S3File
4
+ include Connected
5
+ resource_name("s3_file")
6
+ resources_name("s3_files")
7
+ attr_accessor :bucket, :filename, :purpose, :created_at, :updated_at
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Neuron
2
+ module Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,12 @@
1
+ require "neuron-client/version"
2
+ require "neuron-client/api"
3
+ require "neuron-client/connection"
4
+ require "neuron-client/connected"
5
+ require "neuron-client/ad"
6
+ require "neuron-client/ad_zone"
7
+ require "neuron-client/blocked_referer"
8
+ require "neuron-client/blocked_user_agent"
9
+ require "neuron-client/real_time_stats"
10
+ require "neuron-client/report"
11
+ require "neuron-client/s3_file"
12
+ require "neuron-client/zone"
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "neuron-client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "neuron-client"
7
+ s.version = Neuron::Client::VERSION
8
+ s.authors = ["Mark Simoneau", "Chris Johnson"]
9
+ s.email = ["devteam@rmmonline.com"]
10
+ s.homepage = "http://github.com/rmm/neuron-client"
11
+ s.summary = "Neuron Admin Client Gem"
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "neuron-client"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.add_dependency "rest-client", ">= 1.6.3"
21
+ s.add_dependency "yajl-ruby", ">= 0.8.2"
22
+ s.add_development_dependency "rspec", ">= 2.6.0"
23
+ s.add_development_dependency "simplecov", ">= 0.4.2"
24
+ s.add_development_dependency("rb-fsevent", ">= 0.4.1") if RUBY_PLATFORM =~ /darwin/i
25
+ s.add_development_dependency "guard", ">= 0.5.1"
26
+ s.add_development_dependency "guard-bundler", ">= 0.1.3"
27
+ s.add_development_dependency "guard-rspec", ">= 0.4.0"
28
+ s.add_development_dependency "fakeweb", ">= 1.3.0"
29
+ s.add_development_dependency "vcr", ">= 1.10.2"
30
+ end
@@ -0,0 +1,221 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://127.0.0.1:3000/s3_files.json?api_key=
6
+ body: !!null
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ accept-encoding:
11
+ - gzip, deflate
12
+ content-type:
13
+ - application/json
14
+ content-length:
15
+ - '77'
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ location:
22
+ - http://127.0.0.1:3000/s3_files/14
23
+ content-type:
24
+ - application/json; charset=utf-8
25
+ cache-control:
26
+ - no-cache
27
+ x-ua-compatible:
28
+ - IE=Edge
29
+ x-runtime:
30
+ - '0.067139'
31
+ server:
32
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
33
+ date:
34
+ - Wed, 20 Jul 2011 22:09:23 GMT
35
+ content-length:
36
+ - '157'
37
+ set-cookie:
38
+ - _neuron-admin_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlOWNjYmY1YTMxZjE1ZTg2YmI4OWIxZmY1ZmJkOTNmMzM%3D--d8721ac8475f99f21ce1726337ce3dc6570ee361;
39
+ path=/; HttpOnly
40
+ body: ! '{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:09:23Z","filename":"filename","id":14,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:09:23Z"}}'
41
+ http_version: '1.1'
42
+ - !ruby/struct:VCR::HTTPInteraction
43
+ request: !ruby/struct:VCR::Request
44
+ method: :get
45
+ uri: http://127.0.0.1:3000/s3_files.json?api_key=
46
+ body: !!null
47
+ headers:
48
+ accept:
49
+ - application/json
50
+ accept-encoding:
51
+ - gzip, deflate
52
+ content-type:
53
+ - application/json
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ content-type:
60
+ - application/json; charset=utf-8
61
+ etag:
62
+ - ! '"fa7070e53112e61619a0f53d917d99e7"'
63
+ cache-control:
64
+ - max-age=0, private, must-revalidate
65
+ x-ua-compatible:
66
+ - IE=Edge
67
+ x-runtime:
68
+ - '0.104567'
69
+ server:
70
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
71
+ date:
72
+ - Wed, 20 Jul 2011 22:09:23 GMT
73
+ content-length:
74
+ - '725'
75
+ body: ! '[{"s3_file":{"bucket":"legal","created_at":"2011-07-20T20:53:18Z","filename":"legal","id":11,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T20:53:18Z"}},{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:01:01Z","filename":"file5kqqlaqs12p84sr5b4nqfcc66oiddl9ob6k8wwi0izn1vl3aye","id":12,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:01:01Z"}},{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:07:57Z","filename":"file47s8gkz0i4jt8efk47bz22ceggn2yfdcue1droev1imjyoppkv_2","id":13,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:07:57Z"}},{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:09:23Z","filename":"filename","id":14,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:09:23Z"}}]'
76
+ http_version: '1.1'
77
+ - !ruby/struct:VCR::HTTPInteraction
78
+ request: !ruby/struct:VCR::Request
79
+ method: :get
80
+ uri: http://127.0.0.1:3000/s3_files/14.json?api_key=
81
+ body: !!null
82
+ headers:
83
+ accept:
84
+ - application/json
85
+ accept-encoding:
86
+ - gzip, deflate
87
+ content-type:
88
+ - application/json
89
+ response: !ruby/struct:VCR::Response
90
+ status: !ruby/struct:VCR::ResponseStatus
91
+ code: 200
92
+ message: OK
93
+ headers:
94
+ content-type:
95
+ - application/json; charset=utf-8
96
+ etag:
97
+ - ! '"82de26d0323cc7f9ae7ca9834a9cdad6"'
98
+ cache-control:
99
+ - max-age=0, private, must-revalidate
100
+ x-ua-compatible:
101
+ - IE=Edge
102
+ x-runtime:
103
+ - '0.060063'
104
+ server:
105
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
106
+ date:
107
+ - Wed, 20 Jul 2011 22:09:24 GMT
108
+ content-length:
109
+ - '157'
110
+ body: ! '{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:09:23Z","filename":"filename","id":14,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:09:23Z"}}'
111
+ http_version: '1.1'
112
+ - !ruby/struct:VCR::HTTPInteraction
113
+ request: !ruby/struct:VCR::Request
114
+ method: :get
115
+ uri: http://127.0.0.1:3000/s3_files/14.json?api_key=
116
+ body: !!null
117
+ headers:
118
+ accept:
119
+ - application/json
120
+ accept-encoding:
121
+ - gzip, deflate
122
+ content-type:
123
+ - application/json
124
+ response: !ruby/struct:VCR::Response
125
+ status: !ruby/struct:VCR::ResponseStatus
126
+ code: 200
127
+ message: OK
128
+ headers:
129
+ content-type:
130
+ - application/json; charset=utf-8
131
+ etag:
132
+ - ! '"82de26d0323cc7f9ae7ca9834a9cdad6"'
133
+ cache-control:
134
+ - max-age=0, private, must-revalidate
135
+ x-ua-compatible:
136
+ - IE=Edge
137
+ x-runtime:
138
+ - '0.059891'
139
+ server:
140
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
141
+ date:
142
+ - Wed, 20 Jul 2011 22:09:24 GMT
143
+ content-length:
144
+ - '157'
145
+ body: ! '{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:09:23Z","filename":"filename","id":14,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:09:23Z"}}'
146
+ http_version: '1.1'
147
+ - !ruby/struct:VCR::HTTPInteraction
148
+ request: !ruby/struct:VCR::Request
149
+ method: :put
150
+ uri: http://127.0.0.1:3000/s3_files/14.json?api_key=
151
+ body: !!null
152
+ headers:
153
+ accept:
154
+ - application/json
155
+ accept-encoding:
156
+ - gzip, deflate
157
+ content-type:
158
+ - application/json
159
+ content-length:
160
+ - '37'
161
+ response: !ruby/struct:VCR::Response
162
+ status: !ruby/struct:VCR::ResponseStatus
163
+ code: 200
164
+ message: OK
165
+ headers:
166
+ content-type:
167
+ - application/json; charset=utf-8
168
+ etag:
169
+ - ! '"99914b932bd37a50b983c5e7c90ae93b"'
170
+ cache-control:
171
+ - max-age=0, private, must-revalidate
172
+ x-ua-compatible:
173
+ - IE=Edge
174
+ x-runtime:
175
+ - '0.109019'
176
+ server:
177
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
178
+ date:
179
+ - Wed, 20 Jul 2011 22:09:24 GMT
180
+ content-length:
181
+ - '2'
182
+ set-cookie:
183
+ - _neuron-admin_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTM4NmUyZTg3NjMyZmEyODVlYTYzOWMzMDY2ZGVjN2Y%3D--aa8493cea97d5cd46b28e8e4ed590a78c43f527f;
184
+ path=/; HttpOnly
185
+ body: ! '{}'
186
+ http_version: '1.1'
187
+ - !ruby/struct:VCR::HTTPInteraction
188
+ request: !ruby/struct:VCR::Request
189
+ method: :get
190
+ uri: http://127.0.0.1:3000/s3_files/14.json?api_key=
191
+ body: !!null
192
+ headers:
193
+ accept:
194
+ - application/json
195
+ accept-encoding:
196
+ - gzip, deflate
197
+ content-type:
198
+ - application/json
199
+ response: !ruby/struct:VCR::Response
200
+ status: !ruby/struct:VCR::ResponseStatus
201
+ code: 200
202
+ message: OK
203
+ headers:
204
+ content-type:
205
+ - application/json; charset=utf-8
206
+ etag:
207
+ - ! '"469eafd0f989f48861aed220036e8b54"'
208
+ cache-control:
209
+ - max-age=0, private, must-revalidate
210
+ x-ua-compatible:
211
+ - IE=Edge
212
+ x-runtime:
213
+ - '0.058650'
214
+ server:
215
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
216
+ date:
217
+ - Wed, 20 Jul 2011 22:09:24 GMT
218
+ content-length:
219
+ - '159'
220
+ body: ! '{"s3_file":{"bucket":"test","created_at":"2011-07-20T22:09:23Z","filename":"filename_2","id":14,"purpose":"RAW_EVENT_LOG","updated_at":"2011-07-20T22:09:24Z"}}'
221
+ http_version: '1.1'
@@ -0,0 +1,248 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'yajl'
3
+
4
+ module Neuron
5
+ module Client
6
+
7
+ describe API do
8
+ describe "configure" do
9
+ it "creates a valid Connection object" do
10
+ API.reset!
11
+ API.connection.should be_nil
12
+ API.configure do |config|
13
+ config.admin_url = "https://example.com"
14
+ config.admin_key = "secret"
15
+ end
16
+ API.connection.should be_a(Connection)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe AdZone do
22
+ before(:each) do
23
+ @connection = stub(:connection)
24
+ API.stub(:connection).and_return(@connection)
25
+ end
26
+ describe "create" do
27
+ it "makes a post call"
28
+ end
29
+ end
30
+
31
+ describe Ad do
32
+ before(:each) do
33
+ @connection = stub(:connection)
34
+ API.stub(:connection).and_return(@connection)
35
+ end
36
+
37
+ describe "all" do
38
+ before(:each) do
39
+ @response = [{}]
40
+ end
41
+ it "returns a list of Ads" do
42
+ @connection.stub(:get).and_return(@response)
43
+ ads = Ad.all
44
+ ads.should be_a(Array)
45
+ ads.length.should be > 0
46
+ ads.first.should be_a(Ad)
47
+ end
48
+
49
+ it "makes a get call" do
50
+ @connection.should_receive(:get).with("ads").once.and_return(@response)
51
+ Ad.all
52
+ end
53
+ end
54
+
55
+ describe "find" do
56
+ before(:each) do
57
+ @response = {:ad => {:id => 1, :name => "Ad 1"}}
58
+ end
59
+
60
+ it "returns a Ad" do
61
+ @connection.stub(:get).and_return(@response)
62
+ ad = Ad.find(1)
63
+ ad.should be_a(Ad)
64
+ end
65
+
66
+ it "makes a get call" do
67
+ @connection.should_receive(:get).with("ads/1").once.and_return(@response)
68
+ Ad.find(1)
69
+ end
70
+ end
71
+
72
+ describe "create" do
73
+ before(:each) do
74
+ @attrs = {:name => "Ad 1"}
75
+ @response = {'ad' => @attrs.merge({:id => 1})}
76
+ end
77
+
78
+ it "posts json" do
79
+ @connection.should_receive(:post).with("ads", {'ad' => @attrs}).once.and_return(@response)
80
+ Ad.create(@attrs)
81
+ end
82
+
83
+ it "returns the created Ad" do
84
+ @connection.should_receive(:post).and_return(@response)
85
+ ad = Ad.create(@attrs)
86
+ ad.id.should == 1
87
+ ad.name.should == "Ad 1"
88
+ end
89
+ end
90
+
91
+ describe "update_attributes" do
92
+ it "makes a put call" do
93
+ attrs = {:id => 1, :name => "Ad 1"}
94
+ ad = Ad.new(attrs)
95
+ @connection.should_receive(:put).with("ads/1", {'ad' => {:name => "Ad 2"}})
96
+ ad.update_attributes(:name => "Ad 2")
97
+ end
98
+ end
99
+ end
100
+
101
+ describe Zone do
102
+ before(:each) do
103
+ @connection = stub(:connection)
104
+ API.stub(:connection).and_return(@connection)
105
+ end
106
+ describe "all" do
107
+ before(:each) do
108
+ @response = [{}]
109
+ end
110
+
111
+ it "returns a list of Zones" do
112
+ @connection.stub(:get).and_return(@response)
113
+ zones = Zone.all
114
+ zones.should be_a(Array)
115
+ zones.length.should be > 0
116
+ zones.first.should be_a(Zone)
117
+ end
118
+
119
+ it "makes a get call" do
120
+ @connection.should_receive(:get).with("zones").once.and_return(@response)
121
+ Zone.all
122
+ end
123
+ end
124
+
125
+ describe "find" do
126
+ before(:each) do
127
+ @response = {:zone => {:id => 1, :slug => "zone1"}}
128
+ end
129
+
130
+ it "returns a Zone" do
131
+ @connection.stub(:get).and_return(@response)
132
+ zone = Zone.find(1)
133
+ zone.should be_a(Zone)
134
+ end
135
+
136
+ it "makes a get call" do
137
+ @connection.should_receive(:get).with("zones/1").once.and_return(@response)
138
+ Zone.find(1)
139
+ end
140
+ end
141
+
142
+ describe "create" do
143
+ before(:each) do
144
+ @attrs = {:slug => "zone1"}
145
+ @response = {'zone' => @attrs.merge({:id => 1})}
146
+ end
147
+
148
+ it "posts json" do
149
+ @connection.should_receive(:post).with("zones", {'zone' => @attrs}).once.and_return(@response)
150
+ Zone.create(@attrs)
151
+ end
152
+
153
+ it "returns the created Ad" do
154
+ @connection.should_receive(:post).and_return(@response)
155
+ zone = Zone.create(@attrs)
156
+ zone.id.should == 1
157
+ zone.slug.should == "zone1"
158
+ end
159
+ end
160
+
161
+ describe "update_attributes" do
162
+ it "makes a put call" do
163
+ attrs = {:id => 1, :slug => "zone1"}
164
+ zone = Zone.new(attrs)
165
+ @connection.should_receive(:put).with("zones/1", {'zone' => {:slug => "zone2"}})
166
+ zone.update_attributes(:slug => "zone2")
167
+ end
168
+ end
169
+ end
170
+
171
+ describe Connection do
172
+ before(:each) do
173
+ @connection = Connection.new('http://neuron.admin', "my_api_key")
174
+ end
175
+
176
+ it "should escape the passed api_key" do
177
+ connection = Connection.new("http://neuron.admin", "an unescaped string")
178
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=an+unescaped+string", :body => Yajl.dump({"escaped" => true}))
179
+ connection.get("test").should == {"escaped" => true}
180
+ end
181
+
182
+ describe "get" do
183
+ it "should make a GET request to the specified url passing an API key" do
184
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
185
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
186
+ @connection.get("test").should == {}
187
+ end
188
+
189
+ it "should GET an error if the wrong api_key is passed" do
190
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
191
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
192
+ lambda do
193
+ @connection.get("test")
194
+ end.should raise_error
195
+ end
196
+ end
197
+
198
+ describe "post" do
199
+ it "should make a POST request to the specified url passing an API key" do
200
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
201
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}", :status => ["201", "Created"])
202
+ @connection.post("test", {:data => 1}).should == {}
203
+ end
204
+
205
+ it "should POST an error if the wrong api_key is passed" do
206
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}", :status => ["201", "Created"])
207
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
208
+ lambda do
209
+ @connection.post("test", {:data => 1})
210
+ end.should raise_error
211
+ end
212
+ end
213
+
214
+ describe "put" do
215
+ it "should make a PUT request to the specified url passing an API key" do
216
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
217
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
218
+ @connection.put("test", {:data => 1}).should == {}
219
+ end
220
+
221
+ it "should PUT an error if the wrong api_key is passed" do
222
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
223
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
224
+ lambda do
225
+ @connection.put("test", {:data => 1})
226
+ end.should raise_error
227
+ end
228
+ end
229
+
230
+ describe "delete" do
231
+ it "should make a DELETE request to the specified url passing an API key" do
232
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
233
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
234
+ @connection.delete("test").should == {}
235
+ end
236
+
237
+ it "should DELETE an error if the wrong api_key is passed" do
238
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
239
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
240
+ lambda do
241
+ @connection.delete("test")
242
+ end.should raise_error
243
+ end
244
+ end
245
+ end
246
+
247
+ end
248
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'yajl'
3
+
4
+ module Neuron
5
+ module Client
6
+ describe S3File do
7
+ before(:all) do
8
+ API.configure do |config|
9
+ config.admin_url = "http://127.0.0.1:3000"
10
+ config.admin_key = "secret"
11
+ end
12
+
13
+ VCR.insert_cassette('s3_file', :record => :new_episodes)
14
+ end
15
+
16
+ after(:all) do
17
+ VCR.eject_cassette
18
+ end
19
+
20
+ describe "create" do
21
+ it "returns the created S3File" do
22
+ attrs = {:bucket => 'test',
23
+ :filename => "filename",
24
+ :purpose => 'RAW_EVENT_LOG'}
25
+ s3file = S3File.create(attrs)
26
+ s3file.id.should_not be_nil
27
+ @@created_id = s3file.id
28
+ s3file.bucket.should == attrs[:bucket]
29
+ s3file.filename.should == attrs[:filename]
30
+ s3file.purpose.should == attrs[:purpose]
31
+ end
32
+ end
33
+
34
+ describe "all" do
35
+ it "returns a list of S3Files" do
36
+ s3files = S3File.all
37
+ s3files.should be_a(Array)
38
+ s3files.length.should be > 0
39
+ s3files.first.should be_a(S3File)
40
+ end
41
+ end
42
+
43
+ describe "find" do
44
+ it "returns a S3File" do
45
+ s3file = S3File.find(@@created_id)
46
+ s3file.should be_a(S3File)
47
+ end
48
+ end
49
+
50
+ describe "update_attributes" do
51
+ it "updates the S3File on the server" do
52
+ s3file = S3File.find(@@created_id)
53
+ filename = s3file.filename
54
+ s3file.update_attributes(:filename => "#{filename}_2")
55
+ s3file = S3File.find(@@created_id)
56
+ s3file.filename.should_not == filename
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ add_group "Models", "lib"
5
+ end
6
+
7
+ require 'rubygems'
8
+ require 'bundler'
9
+
10
+ Bundler.require(:default, :test, :development)
11
+
12
+
13
+ Neuron::Client::API.configure do |c|
14
+ c.admin_url = "http://127.0.0.1:3000"
15
+ c.admin_key = "secret"
16
+ end
17
+
18
+ VCR.config do |c|
19
+ c.cassette_library_dir = File.join(File.dirname(__FILE__),'fixtures','vcr_cassettes')
20
+ c.stub_with :fakeweb
21
+ c.default_cassette_options = {:record => :new_episodes}
22
+ c.ignore_localhost = false
23
+ c.allow_http_connections_when_no_cassette = false
24
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neuron-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Simoneau
9
+ - Chris Johnson
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-07-21 00:00:00.000000000 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rest-client
18
+ requirement: &2153592420 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *2153592420
27
+ - !ruby/object:Gem::Dependency
28
+ name: yajl-ruby
29
+ requirement: &2153591920 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *2153591920
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &2153591460 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *2153591460
49
+ - !ruby/object:Gem::Dependency
50
+ name: simplecov
51
+ requirement: &2153591000 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *2153591000
60
+ - !ruby/object:Gem::Dependency
61
+ name: rb-fsevent
62
+ requirement: &2153590500 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.4.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *2153590500
71
+ - !ruby/object:Gem::Dependency
72
+ name: guard
73
+ requirement: &2153622280 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.5.1
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *2153622280
82
+ - !ruby/object:Gem::Dependency
83
+ name: guard-bundler
84
+ requirement: &2153621820 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *2153621820
93
+ - !ruby/object:Gem::Dependency
94
+ name: guard-rspec
95
+ requirement: &2153621360 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: 0.4.0
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *2153621360
104
+ - !ruby/object:Gem::Dependency
105
+ name: fakeweb
106
+ requirement: &2153620900 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.0
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *2153620900
115
+ - !ruby/object:Gem::Dependency
116
+ name: vcr
117
+ requirement: &2153620440 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: 1.10.2
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *2153620440
126
+ description: Neuron Admin Client Gem
127
+ email:
128
+ - devteam@rmmonline.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rvmrc
135
+ - Gemfile
136
+ - Guardfile
137
+ - README.md
138
+ - Rakefile
139
+ - lib/neuron-client.rb
140
+ - lib/neuron-client/ad.rb
141
+ - lib/neuron-client/ad_zone.rb
142
+ - lib/neuron-client/api.rb
143
+ - lib/neuron-client/blocked_referer.rb
144
+ - lib/neuron-client/blocked_user_agent.rb
145
+ - lib/neuron-client/connected.rb
146
+ - lib/neuron-client/connection.rb
147
+ - lib/neuron-client/real_time_stats.rb
148
+ - lib/neuron-client/report.rb
149
+ - lib/neuron-client/s3_file.rb
150
+ - lib/neuron-client/version.rb
151
+ - lib/neuron-client/zone.rb
152
+ - neuron-client.gemspec
153
+ - spec/fixtures/vcr_cassettes/s3_file.yml
154
+ - spec/lib/old_spec.rb
155
+ - spec/lib/s3_file_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: true
158
+ homepage: http://github.com/rmm/neuron-client
159
+ licenses: []
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project: neuron-client
178
+ rubygems_version: 1.6.2
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Neuron Admin Client Gem
182
+ test_files:
183
+ - spec/fixtures/vcr_cassettes/s3_file.yml
184
+ - spec/lib/old_spec.rb
185
+ - spec/lib/s3_file_spec.rb
186
+ - spec/spec_helper.rb