rack-remote-configuration 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4318e585789e110f4f25d46a19ab95e92ca52df
4
+ data.tar.gz: c23f225cab80543587c311cd5b2b217a0f30b691
5
+ SHA512:
6
+ metadata.gz: 09876f15758b99bd01cdec0276274bd86955567e2c6d511bbb1e0ae75eb5f8ad2368a847f1c264e2bbcbcaec23983d00891a9c37e8f26adb0ec5ecc7cc526d80
7
+ data.tar.gz: 30807ba3f96c1d1c383961fd26f435988fe00ec3755f0276c2877201625b50c65a7363ca554ea63500f1904d42c4ccb70b02055f45a4ba5ac6b60344281bb31e
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-remote-configuration (0.0.1)
5
+ json (~> 1.8)
6
+ plist (~> 3.1)
7
+ rack (~> 1.4)
8
+ sinatra (~> 1.3)
9
+ sinatra-contrib (~> 1.4)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ backports (3.3.3)
15
+ diff-lcs (1.2.4)
16
+ eventmachine (1.0.3)
17
+ json (1.8.0)
18
+ plist (3.1.0)
19
+ rack (1.5.2)
20
+ rack-protection (1.5.0)
21
+ rack
22
+ rack-test (0.6.2)
23
+ rack (>= 1.0)
24
+ rake (10.0.4)
25
+ rspec (2.13.0)
26
+ rspec-core (~> 2.13.0)
27
+ rspec-expectations (~> 2.13.0)
28
+ rspec-mocks (~> 2.13.0)
29
+ rspec-core (2.13.1)
30
+ rspec-expectations (2.13.0)
31
+ diff-lcs (>= 1.1.3, < 2.0)
32
+ rspec-mocks (2.13.1)
33
+ sinatra (1.4.3)
34
+ rack (~> 1.4)
35
+ rack-protection (~> 1.4)
36
+ tilt (~> 1.3, >= 1.3.4)
37
+ sinatra-contrib (1.4.0)
38
+ backports (>= 2.0)
39
+ eventmachine
40
+ rack-protection
41
+ rack-test
42
+ sinatra (~> 1.4.2)
43
+ tilt (~> 1.3)
44
+ tilt (1.4.1)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ rack-remote-configuration!
51
+ rake
52
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ Rack::RemoteConfiguration
2
+ =========================
3
+ **Serve property list or JSON configuration files**
4
+
5
+ Although mobile and rich web clients consume resources from a server, there may be some application details that you'd like to coordinate outside of the resource structure of an API.
6
+
7
+ **Remote Configuration** is a great way to break out client-specific details into a single, orthogonal endpoint, such as [feature flags](http://code.flickr.com/blog/2009/12/02/flipping-out/), impromptu [A/B tests](http://en.wikipedia.org/wiki/A/B_testing), or a simple ["message of the day"](http://en.wikipedia.org/wiki/Motd_%28Unix%29)
8
+
9
+ ## Usage
10
+
11
+ ### config.ru
12
+
13
+ ```ruby
14
+ run Rack::RemoteConfiguration.new configuration: {
15
+ 'Greeting' => "Hello, World",
16
+ 'Price' => 4.20,
17
+ 'FeatureXIsLaunched' => true
18
+ }
19
+ ```
20
+
21
+ ### Parameters
22
+
23
+ - `configuration`: a `Hash`, or `File` or a `.json` or `.plist` file path with the specified configuration.
24
+ - `path`: the endpoint to serve the configuration, relative to the mount root of the application. _(defaults to `/configuration`)_
25
+
26
+ ## iOS Client Integration
27
+
28
+ > [GroundControl](https://github.com/mattt/GroundControl) gives you a dead-simple way to remotely configure your app's [User Defaults](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/).
29
+
30
+ ```objective-c
31
+ NSURL *URL = [NSURL URLWithString:@"http://example.com/defaults.plist"];
32
+ [[NSUserDefaults standardUserDefaults] registerDefaultsWithURL:URL];
33
+ ```
34
+
35
+ See the [GroundControl README](https://github.com/mattt/GroundControl/blob/master/README.md) for further guidance on installation & usage.
36
+
37
+ ## Deployment
38
+
39
+ `Rack::RemoteConfiguration` can be deployed to Heroku with the following commands:
40
+
41
+ ```
42
+ $ heroku create
43
+ $ git push heroku master
44
+ ```
45
+
46
+ ## Contact
47
+
48
+ Mattt Thompson
49
+
50
+ - http://github.com/mattt
51
+ - http://twitter.com/mattt
52
+ - m@mattt.me
53
+
54
+ ## License
55
+
56
+ Rack::RemoteConfiguration is available under the MIT license. See the LICENSE file for more info.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ gemspec = eval(File.read("rack-remote-configuration.gemspec"))
5
+
6
+ task :build => "#{gemspec.full_name}.gem"
7
+
8
+ file "#{gemspec.full_name}.gem" => gemspec.files + ["rack-remote-configuration.gemspec"] do
9
+ system "gem build rack-remote-configuration.gemspec"
10
+ end
@@ -0,0 +1,51 @@
1
+ require 'rack'
2
+ require 'sinatra/base'
3
+ require 'sinatra/respond_with'
4
+
5
+ require 'json'
6
+ require 'plist'
7
+
8
+ module Rack
9
+ class RemoteConfiguration
10
+ def initialize(options = {})
11
+ raise ArgumentError, "Missing required :configuration option" unless options[:configuration]
12
+
13
+ path = options[:path] || "/configuration"
14
+ configuration = case options[:configuration]
15
+ when Hash
16
+ options[:configuration]
17
+ when File
18
+ return new((Plist::parse_xml(configuration.path) || JSON.parse(configuration.read) rescue nil))
19
+ when String
20
+ return new(File.open(configuration)) if File.exist?(configuration)
21
+ end
22
+
23
+ raise ArgumentError, "Invalid configuration (expected Hash or either .json or .plist File or file path)" if configuration.nil?
24
+
25
+ begin
26
+ [:to_json, :to_plist].each do |serialization|
27
+ configuration.send(serialization)
28
+ end
29
+ rescue NoMethodError => error
30
+ raise ArgumentError, "Serialization Error: #{error}"
31
+ end
32
+
33
+ @app = Class.new(Sinatra::Base) do
34
+ register Sinatra::RespondWith
35
+
36
+ disable :raise_errors, :show_exceptions
37
+
38
+ get path, provides: ['application/json', 'application/x-plist'] do
39
+ respond_to do |f|
40
+ f.on('application/json') { configuration.to_json }
41
+ f.on('application/x-plist') { configuration.to_plist }
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def call(env)
48
+ @app.call(env)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rack-remote-configuration"
6
+ s.authors = ["Mattt Thompson"]
7
+ s.email = "m@mattt.me"
8
+ s.homepage = "http://mattt.me"
9
+ s.version = "0.0.1"
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = "Rack::RemoteConfiguration"
12
+ s.description = "Serve property list or JSON configuration files."
13
+
14
+ s.add_dependency "rack", "~> 1.4"
15
+ s.add_dependency "sinatra", "~> 1.3"
16
+ s.add_dependency "sinatra-contrib", "~> 1.4"
17
+ s.add_dependency "json", "~> 1.8"
18
+ s.add_dependency "plist", "~> 3.1"
19
+
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "rake"
22
+
23
+ s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|example|log|pkg|script|spec|test|vendor)/ }
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-remote-configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mattt Thompson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra-contrib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: plist
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Serve property list or JSON configuration files.
112
+ email: m@mattt.me
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ./Gemfile
118
+ - ./Gemfile.lock
119
+ - ./lib/rack/remote-configuration.rb
120
+ - ./LICENSE
121
+ - ./rack-remote-configuration.gemspec
122
+ - ./Rakefile
123
+ - ./README.md
124
+ homepage: http://mattt.me
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.3
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Rack::RemoteConfiguration
147
+ test_files: []