unveil-ruby 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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unveil-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jonathan Clem
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Unveil::Ruby
2
+
3
+ A Rubygem for connecting to the Unveil service.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'unveil-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install unveil-ruby
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/unveil/app.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Unveil
2
+ class App
3
+ def attributes(reload = false)
4
+ @attributes = nil if reload
5
+ @attributes ||= JSON.parse(Unveil.get("").body)
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ if attributes.has_key?(method.to_s)
10
+ attributes(*args)[method.to_s]
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ module Unveil
2
+ class Feature
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ def enabled(user_id)
8
+ Unveil.get "features/#{@name}/enabled/#{user_id}"
9
+ end
10
+
11
+ def deactivate_all
12
+ Unveil.post 'features/deactivate_all', feature: @name
13
+ end
14
+
15
+ def activate_group(group)
16
+ group = group.is_a?(Unveil::Group) ? group.name : group
17
+ Unveil.post 'features/activate_group', feature: @name, group: group
18
+ end
19
+
20
+ def deactivate_group(group)
21
+ group = group.is_a?(Unveil::Group) ? group.name : group
22
+ Unveil.post 'features/deactivate_group', feature: @name, group: group
23
+ end
24
+
25
+ def activate_user(user_id)
26
+ Unveil.post 'features/activate_user', feature: @name, user_id: user_id
27
+ end
28
+
29
+ def deactivate_user(user_id)
30
+ Unveil.post 'features/deactivate_user', feature: @name, user_id: user_id
31
+ end
32
+
33
+ def activate_percentage(percentage)
34
+ Unveil.post 'features/activate_percentage', feature: @name, percentage: percentage
35
+ end
36
+
37
+ def deactivate_percentage
38
+ Unveil.post 'features/deactivate_percentage', feature: @name
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ module Unveil
2
+ class Group
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ def save
8
+ Unveil.post 'groups', name: @name
9
+ end
10
+
11
+ def destroy
12
+ Unveil.delete 'groups', name: @name
13
+ end
14
+
15
+ def add_user(user_id)
16
+ Unveil.post 'groups/add_user', group: @name, user_id: user_id
17
+ end
18
+
19
+ def remove_user(user_id)
20
+ Unveil.post 'groups/remove_user', group: @name, user_id: user_id
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Unveil
2
+ class User
3
+ def initialize(user_id)
4
+ @user_id = user_id
5
+ end
6
+
7
+ def attributes(reload = false)
8
+ @attributes = nil if reload
9
+ @attributes ||= JSON.parse(Unveil.get("users/#{@user_id}").body)
10
+ end
11
+
12
+ def method_missing(method, *args, &block)
13
+ if attributes.has_key?(method.to_s)
14
+ attributes(*args)[method.to_s]
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Unveil
2
+ VERSION = "0.0.1"
3
+ end
data/lib/unveil.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'unveil/version'
2
+ require 'net/https'
3
+
4
+ module Unveil
5
+ class << self
6
+ def configure
7
+ yield self
8
+ end
9
+
10
+ def public_key=(public_key)
11
+ @@public_key = public_key
12
+ end
13
+
14
+ def private_key=(private_key)
15
+ @@private_key = private_key
16
+ end
17
+
18
+ def get(path)
19
+ build_request :get, path
20
+ end
21
+
22
+ def post(path, body)
23
+ build_request :post, path, body
24
+ end
25
+
26
+ def delete(path, body)
27
+ build_request :delete, path, body
28
+ end
29
+
30
+ private
31
+
32
+ def root
33
+ 'https://unveil.herokuapp.com'
34
+ end
35
+
36
+ def build_request(method, path, body = nil)
37
+ uri = URI.parse("#{root}/#{path}")
38
+ http = Net::HTTP.new(uri.host, uri.port)
39
+ http.use_ssl = true
40
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
+
42
+ case method
43
+ when :post
44
+ request = Net::HTTP::Post.new(uri.request_uri)
45
+ when :get
46
+ request = Net::HTTP::Get.new(uri.request_uri)
47
+ when :delete
48
+ request = Net::HTTP::Delete.new(uri.request_uri)
49
+ end
50
+
51
+ timestamp = Time.now.utc.iso8601.gsub(/\W/, '')
52
+
53
+ request.set_form_data(body) if body
54
+ request.add_field('TIMESTAMP', timestamp)
55
+ request.add_field('PUBLIC_KEY', @@public_key)
56
+ request.add_field('SIGNATURE', signature(timestamp, uri.path))
57
+
58
+ http.request(request)
59
+ end
60
+
61
+ def signature(timestamp, path)
62
+ digest = Digest::SHA2.new
63
+ digest << @@public_key
64
+ digest << @@private_key
65
+ digest << timestamp
66
+ digest << path
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ Dir['lib/unveil/**/*'].each { |f| require f }
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "unveil-ruby"
8
+ gem.version = Unveil::VERSION
9
+ gem.authors = ["Jonathan Clem"]
10
+ gem.email = ["jonathan@jclem.net"]
11
+ gem.description = %q{A Rubygem for connecting to the Unveil service.}
12
+ gem.summary = %q{}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.require_paths = ["lib"]
18
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unveil-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Clem
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Rubygem for connecting to the Unveil service.
15
+ email:
16
+ - jonathan@jclem.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/unveil.rb
27
+ - lib/unveil/app.rb
28
+ - lib/unveil/feature.rb
29
+ - lib/unveil/group.rb
30
+ - lib/unveil/user.rb
31
+ - lib/unveil/version.rb
32
+ - unveil-ruby.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: ''
57
+ test_files: []