faraday 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{faraday}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rick"]
@@ -4,6 +4,11 @@ module Faraday
4
4
  class << self
5
5
  attr_accessor :default_adapter
6
6
  attr_writer :default_connection
7
+
8
+ private
9
+ def method_missing(name, *args, &block)
10
+ default_connection.send(name, *args, &block)
11
+ end
7
12
  end
8
13
 
9
14
  self.default_adapter = :net_http
@@ -12,51 +17,6 @@ module Faraday
12
17
  @default_connection ||= Connection.new
13
18
  end
14
19
 
15
- # use the method signature from Faraday::Connection
16
- def self.build(options = {}, &block)
17
- default_connection.build(options, &block)
18
- end
19
-
20
- def self.get(url = nil, headers = nil, &block)
21
- default_connection.get(url, headers, &block)
22
- end
23
-
24
- def self.post(url = nil, body = nil, headers = nil, &block)
25
- default_connection.post(url, body, headers, &block)
26
- end
27
-
28
- def self.put(url = nil, body = nil, headers = nil, &block)
29
- default_connection.put(url, body, headers, &block)
30
- end
31
-
32
- def self.head(url = nil, headers = nil, &block)
33
- default_connection.head(url, headers, &block)
34
- end
35
-
36
- def self.delete(url = nil, headers = nil, &block)
37
- default_connection.delete(url, headers, &block)
38
- end
39
-
40
- def self.in_parallel?
41
- default_connection.in_parallel?
42
- end
43
-
44
- def self.in_parallel(manager)
45
- default_connection.in_parallel(manager)
46
- end
47
-
48
- def self.proxy(arg = nil)
49
- default_connection.proxy(arg)
50
- end
51
-
52
- def self.url_prefix=(url)
53
- default_connection.url_prefix = url
54
- end
55
-
56
- def self.path_prefix=(value)
57
- default_connection.path_prefix = value
58
- end
59
-
60
20
  module AutoloadHelper
61
21
  def register_lookup_modules(mods)
62
22
  (@lookup_module_index ||= {}).update(mods)
@@ -1,5 +1,6 @@
1
1
  require 'addressable/uri'
2
2
  require 'set'
3
+ require 'base64'
3
4
 
4
5
  module Faraday
5
6
  class Connection
@@ -68,6 +69,20 @@ module Faraday
68
69
  run_request :delete, url, nil, headers, &block
69
70
  end
70
71
 
72
+ def basic_auth(login, pass)
73
+ @headers['authorization'] = "Basic #{Base64.encode64("#{login}:#{pass}").strip}"
74
+ end
75
+
76
+ def token_auth(token, options = {})
77
+ values = ["token=#{token.to_s.inspect}"]
78
+ options.each do |key, value|
79
+ values << "#{key}=#{value.to_s.inspect}"
80
+ end
81
+ # 21 = "Authorization: Token ".size
82
+ comma = ",\n#{' ' * 21}"
83
+ @headers['authorization'] = "Token #{values * comma}"
84
+ end
85
+
71
86
  def in_parallel?
72
87
  !!@parallel_manager
73
88
  end
@@ -52,6 +52,25 @@ class TestConnection < Faraday::TestCase
52
52
  assert_equal '1', conn.headers['A']
53
53
  end
54
54
 
55
+ def test_basic_auth_sets_authorization_header
56
+ conn = Faraday::Connection.new
57
+ conn.basic_auth 'Aladdin', 'open sesame'
58
+ assert_equal 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', conn.headers['Authorization']
59
+ end
60
+
61
+ def test_token_auth_sets_authorization_header
62
+ conn = Faraday::Connection.new
63
+ conn.token_auth 'abcdef'
64
+ assert_equal 'Token token="abcdef"', conn.headers['Authorization']
65
+ end
66
+
67
+ def test_token_auth_with_options_sets_authorization_header
68
+ conn = Faraday::Connection.new
69
+ conn.token_auth 'abcdef', :nonce => 'abc'
70
+ assert_equal 'Token token="abcdef",
71
+ nonce="abc"', conn.headers['Authorization']
72
+ end
73
+
55
74
  def test_build_url_uses_connection_host_as_default_uri_host
56
75
  conn = Faraday::Connection.new
57
76
  conn.host = 'sushi.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - rick