rollout_rest_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "sinatra"
7
+ gem "yajl-ruby"
8
+ gem "rollout"
9
+ gem "redis"
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "rspec", "~> 2.8.0"
15
+ gem "bundler", "~> 1.0.0"
16
+ gem "jeweler", "~> 1.6.4"
17
+ gem "rack-test"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rack (1.4.1)
11
+ rack-protection (1.2.0)
12
+ rack
13
+ rack-test (0.6.1)
14
+ rack (>= 1.0)
15
+ rake (0.9.2.2)
16
+ redis (2.2.2)
17
+ rollout (1.1.0)
18
+ rspec (2.8.0)
19
+ rspec-core (~> 2.8.0)
20
+ rspec-expectations (~> 2.8.0)
21
+ rspec-mocks (~> 2.8.0)
22
+ rspec-core (2.8.0)
23
+ rspec-expectations (2.8.0)
24
+ diff-lcs (~> 1.1.2)
25
+ rspec-mocks (2.8.0)
26
+ sinatra (1.3.2)
27
+ rack (>= 1.3.6, ~> 1.3)
28
+ rack-protection (~> 1.2)
29
+ tilt (>= 1.3.3, ~> 1.3)
30
+ tilt (1.3.3)
31
+ yajl-ruby (0.8.3)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.0.0)
38
+ jeweler (~> 1.6.4)
39
+ rack-test
40
+ redis
41
+ rollout
42
+ rspec (~> 2.8.0)
43
+ sinatra
44
+ yajl-ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 James Golick
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = rollout_rest_api
2
+
3
+ A sinatra app that exposes a REST API for rollout.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2012 James Golick. See LICENSE.txt for
8
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rollout_rest_api"
18
+ gem.homepage = "http://github.com/jamesgolick/rollout_rest_api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{}
21
+ gem.description = %Q{}
22
+ gem.email = "jamesgolick@gmail.com"
23
+ gem.authors = ["James Golick"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rollout_rest_api #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,47 @@
1
+ require "sinatra"
2
+
3
+ class RolloutRestAPI < Sinatra::Base
4
+ class FakeUser < Struct.new(:id); end
5
+
6
+ class << self
7
+ attr_accessor :rollout
8
+ end
9
+
10
+ get "/:feature.json" do
11
+ Yajl::Encoder.encode(rollout.info(params[:feature]))
12
+ end
13
+
14
+ put "/:feature/groups" do
15
+ rollout.activate_group(params[:feature], params[:group])
16
+ "ok"
17
+ end
18
+
19
+ delete "/:feature/groups" do
20
+ rollout.deactivate_group(params[:feature], params[:group])
21
+ "ok"
22
+ end
23
+
24
+ put "/:feature/users" do
25
+ rollout.activate_user(params[:feature], FakeUser.new(params[:user]))
26
+ "ok"
27
+ end
28
+
29
+ delete "/:feature/users" do
30
+ rollout.deactivate_user(params[:feature], FakeUser.new(params[:user]))
31
+ "ok"
32
+ end
33
+
34
+ put "/:feature/percentage" do
35
+ rollout.activate_percentage(params[:feature], params[:percentage])
36
+ end
37
+
38
+ delete "/:feature" do
39
+ rollout.deactivate_all(params[:feature])
40
+ "ok"
41
+ end
42
+
43
+ private
44
+ def rollout
45
+ self.class.rollout
46
+ end
47
+ end
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rollout_rest_api"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["James Golick"]
12
+ s.date = "2012-02-20"
13
+ s.description = ""
14
+ s.email = "jamesgolick@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rollout_rest_api.rb",
29
+ "rollout_rest_api.gemspec",
30
+ "spec/rollout_rest_api_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = "http://github.com/jamesgolick/rollout_rest_api"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.10"
37
+ s.summary = ""
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
44
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rollout>, [">= 0"])
46
+ s.add_runtime_dependency(%q<redis>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<sinatra>, [">= 0"])
53
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
54
+ s.add_dependency(%q<rollout>, [">= 0"])
55
+ s.add_dependency(%q<redis>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rack-test>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<sinatra>, [">= 0"])
63
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
64
+ s.add_dependency(%q<rollout>, [">= 0"])
65
+ s.add_dependency(%q<redis>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
69
+ s.add_dependency(%q<rack-test>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require "redis"
3
+ require "rollout"
4
+ require "yajl"
5
+
6
+ describe "RolloutRestApi" do
7
+ class FakeUser < Struct.new(:id); end
8
+
9
+ def app
10
+ RolloutRestAPI
11
+ end
12
+
13
+ before do
14
+ @redis = Redis.new
15
+ @redis.flushdb
16
+ @rollout = Rollout.new(@redis)
17
+ RolloutRestAPI.rollout = @rollout
18
+ end
19
+
20
+ it "gets /:feature.json" do
21
+ get "/chat.json"
22
+
23
+ last_response.should be_ok
24
+ last_response.body.should == Yajl::Encoder.encode(@rollout.info(:chat))
25
+ end
26
+
27
+ it "adds a group" do
28
+ put "/chat/groups", :group => "caretakers"
29
+ last_response.should be_ok
30
+ @rollout.info(:chat)[:groups].should include(:caretakers)
31
+ end
32
+
33
+ it "removes a group" do
34
+ @rollout.activate_group(:chat, :caretakers)
35
+ @rollout.activate_group(:chat, :greeters)
36
+
37
+ delete "/chat/groups", :group => "caretakers"
38
+ last_response.should be_ok
39
+ @rollout.info(:chat)[:groups].should == [:greeters]
40
+ end
41
+
42
+ it "adds a user" do
43
+ put "/chat/users", :user => 129315
44
+ last_response.should be_ok
45
+ @rollout.info(:chat)[:users].should include(129315)
46
+ end
47
+
48
+ it "removes a user" do
49
+ @rollout.activate_user(:chat, FakeUser.new(1))
50
+ @rollout.activate_user(:chat, FakeUser.new(129315))
51
+
52
+ delete "/chat/users", :user => 129315
53
+ last_response.should be_ok
54
+ @rollout.info(:chat)[:users].should == [1]
55
+ end
56
+
57
+ it "sets the percentage" do
58
+ put "/chat/percentage", :percentage => 22
59
+ last_response.should be_ok
60
+ @rollout.info(:chat)[:percentage].should == 22
61
+ end
62
+
63
+ it "deactivate_alls" do
64
+ @rollout.activate_percentage(:chat, 100)
65
+ @rollout.activate_group(:chat, :caretakers)
66
+ @rollout.activate_user(:chat, FakeUser.new(129315))
67
+
68
+ delete "/chat"
69
+ last_response.should be_ok
70
+ @rollout.info(:chat).should == {:groups => [], :users => [], :percentage => 0}
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rollout_rest_api'
5
+ require 'rack/test'
6
+
7
+ set :environment, :test
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.include Rack::Test::Methods
15
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rollout_rest_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Golick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &70320390852300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70320390852300
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &70320390850660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70320390850660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rollout
38
+ requirement: &70320390848900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70320390848900
47
+ - !ruby/object:Gem::Dependency
48
+ name: redis
49
+ requirement: &70320390864060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70320390864060
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70320390862840 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.8.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70320390862840
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70320390862080 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70320390862080
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70320390859820 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70320390859820
91
+ - !ruby/object:Gem::Dependency
92
+ name: rack-test
93
+ requirement: &70320390858660 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70320390858660
102
+ description: ''
103
+ email: jamesgolick@gmail.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files:
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ files:
110
+ - .document
111
+ - .rspec
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
115
+ - README.rdoc
116
+ - Rakefile
117
+ - VERSION
118
+ - lib/rollout_rest_api.rb
119
+ - rollout_rest_api.gemspec
120
+ - spec/rollout_rest_api_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: http://github.com/jamesgolick/rollout_rest_api
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
136
+ - 0
137
+ hash: -3075717740029724387
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.10
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: ''
150
+ test_files: []