ricardochimal-activeresource_auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/LICENSE +22 -0
- data/README +10 -0
- data/activeresource_auth.gemspec +19 -0
- data/lib/activeresource_auth.rb +31 -0
- metadata +57 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008 Ricardo Chimal, Jr.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The purpose of this gem is to provide better http auth basic support into ActiveResource. Encoding it in the url makes me gag and it should make you gag too.
|
2
|
+
|
3
|
+
Usage:
|
4
|
+
|
5
|
+
require 'activeresource_auth'
|
6
|
+
|
7
|
+
class MyResource
|
8
|
+
site = "http://remote.com"
|
9
|
+
auth_as "myuser", "mypass"
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.rubygems_version = "1.1.1"
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = "activeresource_auth"
|
5
|
+
s.description = "Improves ActiveResource HTTP Basic Auth Support"
|
6
|
+
s.summary = "ActiveResource + Better HTTP Auth"
|
7
|
+
s.authors = [ "Ricardo Chimal, Jr." ]
|
8
|
+
s.email = "ricardo@heroku.com"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
s.has_rdoc = false
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.files = [
|
13
|
+
"lib/activeresource_auth.rb",
|
14
|
+
"README",
|
15
|
+
"CHANGELOG",
|
16
|
+
"activeresource_auth.gemspec",
|
17
|
+
"LICENSE",
|
18
|
+
]
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
class ActiveResource::Connection
|
4
|
+
attr_writer :basic_auth_user, :basic_auth_password
|
5
|
+
|
6
|
+
def authorization_header
|
7
|
+
if (@basic_auth_user || @basic_auth_pass)
|
8
|
+
build_auth_header(@basic_auth_user, @basic_auth_password)
|
9
|
+
elsif (@site.user || @site.password) # remain backwards compatible
|
10
|
+
build_auth_header(@site.user, @site.password)
|
11
|
+
else
|
12
|
+
{}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_auth_header(user, password)
|
17
|
+
{ 'Authorization' => 'Basic ' + ["#{user}:#{password}"].pack('m').delete("\r\n") }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActiveResource::Base
|
22
|
+
def self.auth_as(user, password)
|
23
|
+
connection.basic_auth_user = user
|
24
|
+
connection.basic_auth_password = password
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.clear_auth
|
28
|
+
connection.basic_auth_user = nil
|
29
|
+
connection.basic_auth_password = nil
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ricardochimal-activeresource_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Chimal, Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Improves ActiveResource HTTP Basic Auth Support
|
17
|
+
email: ricardo@heroku.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/activeresource_auth.rb
|
26
|
+
- README
|
27
|
+
- CHANGELOG
|
28
|
+
- activeresource_auth.gemspec
|
29
|
+
- LICENSE
|
30
|
+
has_rdoc: false
|
31
|
+
homepage:
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: ActiveResource + Better HTTP Auth
|
56
|
+
test_files: []
|
57
|
+
|