weary 1.0.0.rc1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,11 @@ gemspec
4
4
 
5
5
  gem "rake", "~> 0.9.2"
6
6
 
7
+ group :test do
8
+ gem "rspec", "~> 2.9.0"
9
+ gem "webmock", "~> 1.8.5"
10
+ end
11
+
7
12
  group :doc do
8
13
  gem "yard", "~> 0.7.5"
9
14
  gem "yard-tomdoc", "~> 0.4.0"
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weary (1.0.0.rc1)
5
- addressable (~> 2.2.6)
4
+ weary (1.0.0)
5
+ addressable (~> 2.2.7)
6
6
  multi_json (~> 1.1.0)
7
7
  promise (~> 0.3.0)
8
8
  rack (~> 1.4.0)
@@ -11,25 +11,25 @@ PATH
11
11
  GEM
12
12
  remote: http://rubygems.org/
13
13
  specs:
14
- addressable (2.2.6)
14
+ addressable (2.2.7)
15
15
  crack (0.3.1)
16
16
  diff-lcs (1.1.3)
17
17
  multi_json (1.1.0)
18
18
  promise (0.3.0)
19
19
  rack (1.4.1)
20
20
  rake (0.9.2.2)
21
- rspec (2.8.0)
22
- rspec-core (~> 2.8.0)
23
- rspec-expectations (~> 2.8.0)
24
- rspec-mocks (~> 2.8.0)
25
- rspec-core (2.8.0)
26
- rspec-expectations (2.8.0)
27
- diff-lcs (~> 1.1.2)
28
- rspec-mocks (2.8.0)
21
+ rspec (2.9.0)
22
+ rspec-core (~> 2.9.0)
23
+ rspec-expectations (~> 2.9.0)
24
+ rspec-mocks (~> 2.9.0)
25
+ rspec-core (2.9.0)
26
+ rspec-expectations (2.9.0)
27
+ diff-lcs (~> 1.1.3)
28
+ rspec-mocks (2.9.0)
29
29
  simple_oauth (0.1.5)
30
30
  tomparse (0.2.0)
31
- webmock (1.7.10)
32
- addressable (~> 2.2, > 2.2.5)
31
+ webmock (1.8.5)
32
+ addressable (>= 2.2.7)
33
33
  crack (>= 0.1.7)
34
34
  yard (0.7.5)
35
35
  yard-tomdoc (0.4.0)
@@ -42,8 +42,8 @@ PLATFORMS
42
42
  DEPENDENCIES
43
43
  jruby-openssl
44
44
  rake (~> 0.9.2)
45
- rspec (~> 2.8.0)
45
+ rspec (~> 2.9.0)
46
46
  weary!
47
- webmock (~> 1.7.10)
47
+ webmock (~> 1.8.5)
48
48
  yard (~> 0.7.5)
49
49
  yard-tomdoc (~> 0.4.0)
data/README.md CHANGED
@@ -131,7 +131,7 @@ Authentication, by default is done by either `Weary::Middleware::BasicAuth` or `
131
131
 
132
132
  The point is, **it's just Rack**.
133
133
 
134
- ## Release Candidate
134
+ ## Weary needs your help.
135
135
 
136
136
  At this point, I need _your_ help to further Weary along. I'd love to see more examples that utilize the Rackness of Weary: using Devise, Warden, or mounted in a Rails application.
137
137
 
@@ -1,17 +1,16 @@
1
1
  require 'weary/middleware'
2
2
  require 'simple_oauth'
3
3
 
4
+ SimpleOAuth::Header::ATTRIBUTE_KEYS << :verifier
5
+
4
6
  module Weary
5
7
  module Middleware
6
8
  class OAuth
7
9
  AUTH_HEADER = "HTTP_AUTHORIZATION"
8
10
 
9
- def initialize(app, consumer_key, access_token)
11
+ def initialize(app, oauth_options)
10
12
  @app = app
11
- @oauth = {
12
- :consumer_key => consumer_key,
13
- :token => access_token
14
- }
13
+ @oauth = oauth_options
15
14
  end
16
15
 
17
16
  def call(env)
@@ -5,10 +5,9 @@ require 'rack'
5
5
  require 'weary/env'
6
6
  require 'weary/adapter'
7
7
 
8
- autoload :Middleware, 'weary/middleware'
9
- autoload :MultiJson, 'multi_json'
10
-
11
8
  module Weary
9
+ autoload :Middleware, 'weary/middleware'
10
+ autoload :MultiJson, 'multi_json'
12
11
  # A Request is an interface to an http request. It doesn't actually make the
13
12
  # request. Instead, it builds itself up into a Rack environment. A Request
14
13
  # object is technically a Rack middleware, with a call method. The Request
@@ -112,10 +111,14 @@ module Weary
112
111
  @basic_auth
113
112
  end
114
113
 
115
- def oauth(consumer_key=nil, access_token=nil)
116
- if !consumer_key.nil? && !access_token.nil?
114
+ def oauth(consumer_key=nil, access_token=nil, token_secret=nil, consumer_secret=nil)
115
+ if !consumer_key.nil?
117
116
  @oauth = true
118
- use Weary::Middleware::OAuth, [consumer_key, access_token]
117
+ options = {:consumer_key => consumer_key}
118
+ options[:token] = access_token unless access_token.nil? || access_token.empty?
119
+ options[:token_secret] = token_secret unless token_secret.nil? || token_secret.empty?
120
+ options[:consumer_secret] = consumer_secret unless consumer_secret.nil? || consumer_secret.empty?
121
+ use Weary::Middleware::OAuth, [options]
119
122
  end
120
123
  @oauth
121
124
  end
@@ -131,7 +134,7 @@ module Weary
131
134
  end
132
135
 
133
136
  def use(middleware, *args, &block)
134
- @middlewares << [middleware, args, block]
137
+ @middlewares << [middleware, args.compact, block]
135
138
  end
136
139
 
137
140
  private
@@ -59,7 +59,7 @@ module Weary
59
59
  # Rack-friendly).
60
60
  def use(middleware, *args, &block)
61
61
  @middlewares ||= []
62
- @middlewares << [middleware, args, block]
62
+ @middlewares << [middleware, args.compact, block]
63
63
  end
64
64
 
65
65
  # Convenience method to set a User Agent Header
@@ -84,9 +84,9 @@ module Weary
84
84
  # :consumer_key)
85
85
  # token - The parameter in which to expect the user access token (defaults
86
86
  # to :token)
87
- def oauth!(key = :consumer_key, token = :token)
87
+ def oauth!(key = :consumer_key, token = :token, secret = :token_secret, consumer_secret = :consumer_secret)
88
88
  @authenticates = :oauth
89
- @credentials = [key, token]
89
+ @credentials = [key, token, secret, consumer_secret]
90
90
  end
91
91
 
92
92
  # Does the Resource anticipate some sort of authentication parameters?
@@ -130,13 +130,13 @@ module Weary
130
130
  mapping = url.keys.map {|k| [k, params.delete(k) || params.delete(k.to_sym)] }
131
131
  request = Weary::Request.new url.expand(Hash[mapping]), @method do |r|
132
132
  r.headers headers
133
+ if !@middlewares.nil? && !@middlewares.empty?
134
+ @middlewares.each {|middleware| r.use *middleware }
135
+ end
133
136
  if !expected_params.empty?
134
137
  r.params params.reject {|k,v| !expects? k }
135
138
  end
136
139
  r.send @authenticates, *credentials if authenticates?
137
- if !@middlewares.nil? && !@middlewares.empty?
138
- @middlewares.each {|middleware| r.use *middleware }
139
- end
140
140
  end
141
141
  yield request if block_given?
142
142
  request
@@ -1,3 +1,3 @@
1
1
  module Weary
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -10,12 +10,12 @@ describe Weary::Middleware::OAuth do
10
10
  end
11
11
 
12
12
  it_behaves_like "a Rack application" do
13
- subject { described_class.new(@request, "consumer_key", "access_token") }
13
+ subject { described_class.new(@request, :consumer_key => "consumer_key", :token => "access_token") }
14
14
  let(:env) { @request.env }
15
15
  end
16
16
 
17
17
  it "prepares the Authorization header for the request" do
18
- middleware = described_class.new(@request, "consumer_key", "access_token")
18
+ middleware = described_class.new(@request, :consumer_key => "consumer_key", :token => "access_token")
19
19
  middleware.call(@request.env)
20
20
  signed_header = middleware.sign(@request.env)
21
21
  a_request(:get, @url).
@@ -183,7 +183,8 @@ describe Weary::Request do
183
183
  it "adds a Middleware to the stack to sign the request" do
184
184
  req = described_class.new "https://api.github.com/gists", "POST"
185
185
  cred = ["consumer_key", "access_token"]
186
- req.should_receive(:use).with(Weary::Middleware::OAuth, cred)
186
+ expected = {:consumer_key => cred.first, :token => cred.last}
187
+ req.should_receive(:use).with(Weary::Middleware::OAuth, [expected])
187
188
  req.oauth *cred
188
189
  end
189
190
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Mark Wunsch"]
9
9
  s.email = %q{mark@markwunsch.com}
10
10
  s.summary = %q{A framework and DSL for the consumption of RESTful web services.}
11
- s.description = %q{A framework and DSL to Ruby clients to RESTful web services. }
11
+ s.description = %q{A framework and DSL to construct Ruby clients to RESTful web services. }
12
12
  s.homepage = %q{http://github.com/mwunsch/weary}
13
13
  s.rubyforge_project = %q{weary}
14
14
 
@@ -18,10 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ['lib']
19
19
 
20
20
  s.add_runtime_dependency "rack", "~> 1.4.0"
21
- s.add_runtime_dependency "addressable", "~> 2.2.6"
21
+ s.add_runtime_dependency "addressable", "~> 2.2.7"
22
22
  s.add_runtime_dependency "promise", "~> 0.3.0"
23
23
  s.add_runtime_dependency "simple_oauth", "~> 0.1.5"
24
24
  s.add_runtime_dependency "multi_json", "~> 1.1.0"
25
- s.add_development_dependency "rspec", "~> 2.8.0"
26
- s.add_development_dependency "webmock", "~> 1.7.10"
27
25
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
5
- prerelease: 6
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Wunsch
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-12 00:00:00.000000000 Z
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70096837531960 !ruby/object:Gem::Requirement
16
+ requirement: &70118788987500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 1.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70096837531960
24
+ version_requirements: *70118788987500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: addressable
27
- requirement: &70096837531380 !ruby/object:Gem::Requirement
27
+ requirement: &70118788986800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 2.2.6
32
+ version: 2.2.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70096837531380
35
+ version_requirements: *70118788986800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: promise
38
- requirement: &70096837530880 !ruby/object:Gem::Requirement
38
+ requirement: &70118788985960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.3.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70096837530880
46
+ version_requirements: *70118788985960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simple_oauth
49
- requirement: &70096837530400 !ruby/object:Gem::Requirement
49
+ requirement: &70118788985280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.1.5
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70096837530400
57
+ version_requirements: *70118788985280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70096837529860 !ruby/object:Gem::Requirement
60
+ requirement: &70118788984680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,30 +65,8 @@ dependencies:
65
65
  version: 1.1.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70096837529860
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: &70096837529320 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ~>
75
- - !ruby/object:Gem::Version
76
- version: 2.8.0
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70096837529320
80
- - !ruby/object:Gem::Dependency
81
- name: webmock
82
- requirement: &70096837528800 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ~>
86
- - !ruby/object:Gem::Version
87
- version: 1.7.10
88
- type: :development
89
- prerelease: false
90
- version_requirements: *70096837528800
91
- description: ! 'A framework and DSL to Ruby clients to RESTful web services. '
68
+ version_requirements: *70118788984680
69
+ description: ! 'A framework and DSL to construct Ruby clients to RESTful web services. '
92
70
  email: mark@markwunsch.com
93
71
  executables: []
94
72
  extensions: []
@@ -149,13 +127,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
127
  version: '0'
150
128
  segments:
151
129
  - 0
152
- hash: 3096398000685977380
130
+ hash: -931495693225517600
153
131
  required_rubygems_version: !ruby/object:Gem::Requirement
154
132
  none: false
155
133
  requirements:
156
- - - ! '>'
134
+ - - ! '>='
157
135
  - !ruby/object:Gem::Version
158
- version: 1.3.1
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: -931495693225517600
159
140
  requirements: []
160
141
  rubyforge_project: weary
161
142
  rubygems_version: 1.8.11