cloudenv 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: 941ebef72e3bf3307d1428abe2fd9513863cc319
4
+ data.tar.gz: b703af2cc226d4467dbbc2d8079d5126359dadcf
5
+ SHA512:
6
+ metadata.gz: 1f9eb71bf4749022a063c851b954a2d8669dc23c80e20c57e9ae5420b20c5408cb5075b1f6a1a06c2c02681e0bac5472b69a2ba88868c378ec4d64bdeb55d8d9
7
+ data.tar.gz: 99a1a37cc7e1bb58908c5040527cf8ce50eff30c93c2fcbed8eddc94523c8059a896ceb5c0679161ca23ae78034e72d2e7cd77e83aebb0ef0b524f2416f87759
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 cloudenv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jakub Svehla
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,29 @@
1
+ # Cloudenv
2
+
3
+ Ruby client for Cloudenv
4
+
5
+ ## Usage
6
+
7
+ Add the `cloudenv` gem to your application's `Gemfile`
8
+
9
+ gem 'cloudenv'
10
+
11
+ Install the gem
12
+
13
+ $ bundle install
14
+
15
+ Configure the Cloudenv module with your API key
16
+
17
+ $ bin/rails generate cloudenv YOUR_API_KEY
18
+
19
+ Create the Cloudenv app
20
+
21
+ $ bin/rake cloudenv:apps:create
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/cloudenv/cloudenv-ruby/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/cloudenv.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloudenv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloudenv"
8
+ spec.version = Cloudenv::VERSION
9
+ spec.authors = ["Jakub Svehla"]
10
+ spec.email = ["jakub.svehla@gmail.com"]
11
+ spec.summary = %q{Ruby client for Cloudenv}
12
+ spec.homepage = "http://cloudenv.io"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "faraday"
21
+ spec.add_runtime_dependency "faraday_middleware"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
data/lib/cloudenv.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "cloudenv/version"
2
+ require "cloudenv/configuration"
3
+ require "cloudenv/environment"
4
+ require "cloudenv/error"
5
+ require "cloudenv/client"
6
+ require "cloudenv/railtie" if defined?(Rails)
7
+
8
+ module Cloudenv
9
+ def self.config
10
+ @config ||= Configuration.new
11
+ end
12
+
13
+ def self.configure(&block)
14
+ config.configure(&block)
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Cloudenv
5
+ class Client
6
+
7
+ def create_app(attrs)
8
+ request :post, "apps", { app: attrs }
9
+ end
10
+
11
+ def get_app_variables(id)
12
+ response = request :get, "apps/#{id}/variables"
13
+ Environment.new(response)
14
+ end
15
+
16
+ protected
17
+
18
+ def request(method, path, params = {})
19
+ response = connection.send method, path, params
20
+ case response.status
21
+ when 200, 201
22
+ response.body
23
+ when 401
24
+ raise Cloudenv::Error::Unauthorized.new
25
+ when 422
26
+ raise Cloudenv::Error::UnprocessableEntity.new
27
+ else
28
+ raise Cloudenv::Error.new
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def connection
35
+ @connection ||= Faraday.new Cloudenv.config.endpoint do |faraday|
36
+ faraday.request :json
37
+ faraday.response :json, content_type: /\bjson$/
38
+
39
+ faraday.params[:access_token] = Cloudenv.config.api_key
40
+
41
+ faraday.adapter Faraday.default_adapter
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ module Cloudenv
2
+ class Configuration
3
+ DEFAULT_ENDPOINT = 'https://cloudenv.herokuapp.com/api'
4
+
5
+ attr_accessor :api_key
6
+ attr_accessor :endpoint
7
+
8
+ def initialize
9
+ self.api_key = ENV['CLOUDENV_API_KEY']
10
+ self.endpoint = DEFAULT_ENDPOINT
11
+ end
12
+
13
+ def configure
14
+ yield self
15
+ self
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Cloudenv
2
+ class Environment < Hash
3
+ def initialize(variables)
4
+ load(variables)
5
+ end
6
+
7
+ def load(variables)
8
+ variables.each do |variable|
9
+ self[variable['key']] = variable['value']
10
+ end
11
+ end
12
+
13
+ def apply
14
+ each { |k, v| ENV[k] ||= v }
15
+ end
16
+
17
+ def apply!
18
+ each { |k, v| ENV[k] = v }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Cloudenv
2
+ class Error < StandardError
3
+
4
+ # Raised when Cloudenv returns a 4xx HTTP status code
5
+ ClientError = Class.new(self)
6
+
7
+ # Raised when Cloudenv returns the HTTP status code 401
8
+ Unauthorized = Class.new(ClientError)
9
+
10
+ # Raised when Cloudenv returns the HTTP status code 422
11
+ UnprocessableEntity = Class.new(ClientError)
12
+
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'cloudenv'
2
+
3
+ module Cloudenv
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'cloudenv/tasks/cloudenv.rake'
7
+ end
8
+
9
+ config.after_initialize do
10
+ if Rails.env.production?
11
+ name = Rails.application.class.parent_name.underscore.dasherize
12
+
13
+ client = Cloudenv::Client.new
14
+ environment = client.get_app_variables(name)
15
+
16
+ environment.apply
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'cloudenv'
2
+
3
+ namespace :cloudenv do
4
+ namespace :apps do
5
+ task :create => :environment do
6
+ name = Rails.application.class.parent_name.underscore.dasherize
7
+
8
+ client = Cloudenv::Client.new
9
+ client.create_app name: name
10
+
11
+ puts "You can add/edit your environment variables at http://cloudenv.io/apps/#{name}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Cloudenv
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+
3
+ class CloudenvGenerator < Rails::Generators::Base
4
+ argument :api_key, required: true, desc: 'required'
5
+
6
+ gem 'cloudenv'
7
+
8
+ def create_initializer_file
9
+ unless /^[a-f0-9]{32}$/ =~ api_key
10
+ raise Thor::Error, "Invalid Cloudenv API key #{api_key.inspect}\nYou can find the API key in the dashboard of http://cloudenv.io"
11
+ end
12
+
13
+ initializer 'cloudenv.rb' do
14
+ <<-EOF
15
+ Cloudenv.configure do |config|
16
+ config.api_key = #{api_key.inspect}
17
+ end
18
+ EOF
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Svehla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - jakub.svehla@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - cloudenv.gemspec
82
+ - lib/cloudenv.rb
83
+ - lib/cloudenv/client.rb
84
+ - lib/cloudenv/configuration.rb
85
+ - lib/cloudenv/environment.rb
86
+ - lib/cloudenv/error.rb
87
+ - lib/cloudenv/railtie.rb
88
+ - lib/cloudenv/tasks/cloudenv.rake
89
+ - lib/cloudenv/version.rb
90
+ - lib/generators/cloudenv/cloudenv_generator.rb
91
+ homepage: http://cloudenv.io
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.0
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Ruby client for Cloudenv
115
+ test_files: []