twitter_server 0.1.0 → 0.2.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/.gitignore CHANGED
@@ -1,17 +1,21 @@
1
+ ## Move SYSTEM GENERAL .gitignore settings to system-wide area
2
+ #
3
+ # git config --global core.excludesfile ~/.gitignore
4
+ #
1
5
  ## MAC OS
2
- .DS_Store
3
-
6
+ #.DS_Store
7
+ #
4
8
  ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
9
+ #*.tmproj
10
+ #tmtags
11
+ #
12
+ ### EMACS
13
+ #*~
14
+ #\#*
15
+ #.\#*
16
+ #
13
17
  ## VIM
14
- *.swp
18
+ #*.swp
15
19
 
16
20
  ## PROJECT::GENERAL
17
21
  coverage
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -22,7 +22,9 @@ module Sinatra
22
22
  module TwitterServer
23
23
  module Helpers
24
24
  def api_options(*keys)
25
- keys.inject({}) do |memo, key|
25
+ options = {}
26
+ options[:auth] = @auth if @auth
27
+ keys.inject(options) do |memo, key|
26
28
  params.include?(key.to_s) ? memo.update(key => params[key]) : memo
27
29
  end
28
30
  end
@@ -54,6 +56,14 @@ module Sinatra
54
56
  app.helpers Sinatra::TwitterServer::Helpers
55
57
  end
56
58
 
59
+ def twitter_basic_auth
60
+ before do
61
+ base64 = env['HTTP_AUTHORIZATION'].gsub(/Basic /, '')
62
+ user, pass = Base64.decode64(base64).split(":")
63
+ @auth = yield user, pass
64
+ end
65
+ end
66
+
57
67
  # http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-home_timeline
58
68
  def twitter_statuses_home_timeline
59
69
  get "/statuses/home_timeline.:format" do
@@ -112,7 +122,8 @@ module Sinatra
112
122
  def twitter_account_verify_credentials
113
123
  get "/account/verify_credentials.:format" do
114
124
  format = params[:format]
115
- user = yield
125
+ options = api_options
126
+ user = yield options
116
127
  render_xml_user(user)
117
128
  end
118
129
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'context'
3
+ require 'base64'
3
4
 
4
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
2
+
3
+ class ApiBasicAuthTest < TwitterServer::TestCase
4
+ class BasicAuthApp < Sinatra::Base
5
+ register Sinatra::TwitterServer
6
+
7
+ twitter_basic_auth do |user, pass|
8
+ {:user => user, :pass => pass}
9
+ end
10
+
11
+ twitter_account_verify_credentials { |params| {:id => 1, :screen_name => "#{params[:auth][:user]} => #{params[:auth][:pass]}"} }
12
+ end
13
+
14
+ def app
15
+ BasicAuthApp
16
+ end
17
+
18
+ it "passes auth hash to requests" do
19
+ get '/account/verify_credentials.xml', {},
20
+ 'HTTP_AUTHORIZATION' => "Basic #{Base64.encode64("user:monkey")}".strip
21
+ assert_xml do |xml|
22
+ xml.user do
23
+ xml.id_ 1
24
+ xml.screen_name "user => monkey"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twitter_server}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["technoweenie"]
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/twitter_server.rb",
29
29
  "test/helper.rb",
30
30
  "test/sinatra/account_test.rb",
31
+ "test/sinatra/basic_auth_test.rb",
31
32
  "test/sinatra/help_test.rb",
32
33
  "test/sinatra/statuses_test.rb",
33
34
  "twitter_server.gemspec"
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
40
41
  s.test_files = [
41
42
  "test/helper.rb",
42
43
  "test/sinatra/account_test.rb",
44
+ "test/sinatra/basic_auth_test.rb",
43
45
  "test/sinatra/help_test.rb",
44
46
  "test/sinatra/statuses_test.rb"
45
47
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - technoweenie
@@ -43,6 +43,7 @@ files:
43
43
  - lib/twitter_server.rb
44
44
  - test/helper.rb
45
45
  - test/sinatra/account_test.rb
46
+ - test/sinatra/basic_auth_test.rb
46
47
  - test/sinatra/help_test.rb
47
48
  - test/sinatra/statuses_test.rb
48
49
  - twitter_server.gemspec
@@ -77,5 +78,6 @@ summary: Twitter API implementation on top of Sinatra
77
78
  test_files:
78
79
  - test/helper.rb
79
80
  - test/sinatra/account_test.rb
81
+ - test/sinatra/basic_auth_test.rb
80
82
  - test/sinatra/help_test.rb
81
83
  - test/sinatra/statuses_test.rb