uri_config 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTA1OWY5MzFkN2I5NDE0N2MxMmZiOTViMDk0NWE4NzJhMWViMzg0OA==
5
+ data.tar.gz: !binary |-
6
+ NzU1ODlkYWRlODI3ZDAyYTY4MzViYmY3MmZlNzY1MmE3MGU3NWNiZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTIwNTgzOWYzNjE5MzZlNDAzZWJmZGZmZGVmOTNkNGMwNzUxMjQ5OTNlNmUy
10
+ YTdjZmM5MzM2MDhlZThkY2U5MmJiMDlkMGMwMDUyZjFmZTlmMmNiYjkyNjVh
11
+ YmQ5ODYxNWY3ODIzMmZlNTRlMmQ4NWE0YzUxYmEwMzk3MDAxYWU=
12
+ data.tar.gz: !binary |-
13
+ ODNjYzEzMDViYjM3ODI4ZjEwOWY2N2RlZmYwNGFjZTQ4Y2U4Njc1NzBkMzEy
14
+ MWY5YTE1MmJkMGMzYzhjMGQyY2U4MWU2OTE2YTgyN2IzODU3NDg1MjU3NDMw
15
+ YmVhMzViZDRkOWYwMTY5NzhlODAxNGQ0NDczOTZjMGQ3M2RjZTc=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/RegexpLiteral:
8
+ MaxSlashes: 0
9
+
10
+ Style/StringLiterals:
11
+ Enabled: false
12
+
13
+ Style/TrailingComma:
14
+ EnforcedStyleForMultiline: comma
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uri_config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jonathon M. Abbott
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,64 @@
1
+ # UriConfig
2
+
3
+ [![Build Status](https://travis-ci.org/JonathonMA/uri_config.svg?branch=master)](https://travis-ci.org/JonathonMA/uri_config)
4
+
5
+ Configure services via URI.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'uri_config'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install uri_config
22
+
23
+ ## Usage
24
+
25
+ Extract credentials from generic URIs:
26
+
27
+ ```ruby
28
+ config = URIConfig::Config.new("https://my_user:my_pass@s3.amazonaws.com/a_path")
29
+
30
+ config.username # => "my_user"
31
+ config.password # => "my_password"
32
+ config.path # => "/bucket_name"
33
+ ```
34
+
35
+ Build wrapper classes for more specific configuration hashes:
36
+
37
+ ```ruby
38
+ class S3Config < Config
39
+ alias_method :access_key_id, :username
40
+ alias_method :secret_access_key, :password
41
+
42
+ def bucket
43
+ path[1..-1]
44
+ end
45
+
46
+ config :access_key_id, :secret_access_key, :bucket
47
+ end
48
+
49
+ config = S3Config.new("https://AKIAJUSERNAME:abcd12345678@s3.amazonaws.com/bucket_name")
50
+
51
+ config.access_key_id # => "AKIAJUSERNAME"
52
+ config.secret_access_key # => "abcd12345678"
53
+ config.bucket # => "bucket_name"
54
+
55
+ config.config # => {access_key_id: "AKIAJUSERNAME, secret_access_key: "abcd12345678", bucket: "bucket_name" }
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/JonathonMA/uri_config/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: [
9
+ :spec,
10
+ :rubocop,
11
+ ]
@@ -0,0 +1,47 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+
4
+ module URIConfig
5
+ class Config
6
+ def initialize(url)
7
+ @url = url
8
+ end
9
+
10
+ def username
11
+ CGI.unescape uri.user
12
+ end
13
+
14
+ def password
15
+ CGI.unescape uri.password
16
+ end
17
+
18
+ def path
19
+ uri.path
20
+ end
21
+
22
+ def base_uri
23
+ uri.dup.tap do |uri|
24
+ uri.user = nil
25
+ uri.password = nil
26
+ end.to_s
27
+ end
28
+
29
+ def self.config(*keys)
30
+ define_method :config do
31
+ keys.each_with_object({}) do |key, hash|
32
+ hash[key] = send(key)
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def query
40
+ CGI.parse(uri.query || '')
41
+ end
42
+
43
+ def uri
44
+ @uri ||= URI.parse @url
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module URIConfig
2
+ VERSION = "0.0.1"
3
+ end
data/lib/uri_config.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "uri_config/version"
2
+
3
+ module UriConfig
4
+ end
5
+
6
+ require "uri_config/config"
@@ -0,0 +1,35 @@
1
+ require 'uri_config'
2
+
3
+ module URIConfig
4
+ describe Config do
5
+ subject { described_class.new(url) }
6
+
7
+ {
8
+ "https://TESTMERCHANT1:abcd1234abcd@secure.ap.tnspayments.com" => {
9
+ username: 'TESTMERCHANT1',
10
+ password: 'abcd1234abcd',
11
+ base_uri: 'https://secure.ap.tnspayments.com',
12
+ },
13
+ "https://foo:bar@us-west-2.amazonaws.com/namespace" => {
14
+ username: "foo",
15
+ password: "bar",
16
+ path: "/namespace",
17
+ },
18
+ "https://AKIAJBPUOK67MOQ3VVXQ:7d123FASD123sljnfdsaSADFasdfhsdf12ddFDH4@s3.amazonaws.com/bucket_name" => {
19
+ username: "AKIAJBPUOK67MOQ3VVXQ",
20
+ password: "7d123FASD123sljnfdsaSADFasdfhsdf12ddFDH4",
21
+ path: "/bucket_name",
22
+ },
23
+ }.each do |url, components|
24
+ context "with a URL of #{url}" do
25
+ let(:url) { url }
26
+
27
+ components.each do |key, value|
28
+ it "has a #{key} of #{value}" do
29
+ expect(subject.send(key)).to eq value
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ module URIConfig
2
+ class S3Config < Config
3
+ alias_method :access_key_id, :username
4
+ alias_method :secret_access_key, :password
5
+
6
+ def bucket
7
+ path[1..-1]
8
+ end
9
+
10
+ config :access_key_id, :secret_access_key, :bucket
11
+ end
12
+
13
+ describe S3Config do
14
+ subject { described_class.new(url) }
15
+
16
+ {
17
+ "https://AKIAJBPUOK67MOQ3VVXQ:7d123FASD123sljnfdsaSADFasdfhsdf12ddFDH4@s3.amazonaws.com/bucket_name" => {
18
+ access_key_id: "AKIAJBPUOK67MOQ3VVXQ",
19
+ secret_access_key: "7d123FASD123sljnfdsaSADFasdfhsdf12ddFDH4",
20
+ bucket: "bucket_name",
21
+ },
22
+ }.each do |url, components|
23
+ context "with a URL of #{url}" do
24
+ let(:url) { url }
25
+
26
+ components.each do |key, value|
27
+ it "has a #{key} of #{value}" do
28
+ expect(subject.send(key)).to eq value
29
+ end
30
+ end
31
+
32
+ it "has a config hash" do
33
+ expect(subject.config).to eq components
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -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 'uri_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uri_config"
8
+ spec.version = URIConfig::VERSION
9
+ spec.authors = ["Jonathon M. Abbott"]
10
+ spec.email = ["jonathona@everydayhero.com.au"]
11
+ spec.summary = "extract configuration from URIs"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/JonathonMA/uri_config"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ spec.add_development_dependency "rubocop", "~> 0.27.0"
25
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uri_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathon M. Abbott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.27.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.27.0
69
+ description: extract configuration from URIs
70
+ email:
71
+ - jonathona@everydayhero.com.au
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .rubocop.yml
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/uri_config.rb
85
+ - lib/uri_config/config.rb
86
+ - lib/uri_config/version.rb
87
+ - spec/config_spec.rb
88
+ - spec/s3_config_spec.rb
89
+ - uri_config.gemspec
90
+ homepage: https://github.com/JonathonMA/uri_config
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: extract configuration from URIs
114
+ test_files:
115
+ - spec/config_spec.rb
116
+ - spec/s3_config_spec.rb