oauth2-core 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,8 @@ module OAuth2
31
31
  return
32
32
  end
33
33
 
34
- if value = @attributes[:#{handle}]
34
+ if @attributes.key?(:#{handle})
35
+ value = @attributes[:#{handle}]
35
36
  value.is_a?(Proc) ? value.call : value
36
37
  else
37
38
  raise "No attribute or callback for '#{handle}' defined"
@@ -1,4 +1,5 @@
1
1
  require 'oauth2/attributes'
2
+ require 'active_support/ordered_hash'
2
3
 
3
4
  module OAuth2
4
5
 
@@ -44,10 +45,19 @@ module OAuth2
44
45
  end
45
46
 
46
47
  def attributes
47
- Attributes.inject(Hash.new) do |hash, attribute|
48
+ hash = ActiveSupport::OrderedHash.new
49
+ Attributes.each do |attribute|
48
50
  hash[attribute] = instance_variable_get("@#{attribute}")
49
- hash
50
51
  end
52
+ hash
53
+ end
54
+
55
+ def to_s
56
+ attrs = attributes.collect do |key, value|
57
+ %{#{key}="#{value}"} if value
58
+ end.compact
59
+
60
+ "Token " + attrs.join(",\n ")
51
61
  end
52
62
 
53
63
  class << self
@@ -55,18 +65,21 @@ module OAuth2
55
65
  # This method does what it is named after. Give it a String and it
56
66
  # returns a Hash. The header specification can be found on:
57
67
  # http://tools.ietf.org/html/draft-hammer-oauth2-00#section-5.1
58
- # TODO: Use OrderedHash and verify that token is the first parameter
59
- def parse(string, attributes = {})
60
- header = new(attributes)
68
+ # TODO: Verify that token is the first attribute.
69
+ def parse(string)
70
+ header = new
61
71
 
62
72
  string.strip!
63
73
 
64
74
  type, tuples = string[0..4], string[5..-1].split("\n")
65
75
 
66
- header.errors << :format_invalid unless type == "Token"
76
+ unless type == "Token"
77
+ header.errors << :format_invalid
78
+ return header
79
+ end
67
80
 
68
81
  tuples.map! { |tuple| tuple.strip! }
69
-
82
+
70
83
  tuples.each do |tuple|
71
84
  unless tuple =~ /\s*(.+)="(.+)"/
72
85
  header.errors << :format_invalid
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Flatter
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-07 00:00:00 +02:00
17
+ date: 2010-05-08 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency