chairman 0.0.2 → 0.0.3.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/chairman.rb CHANGED
@@ -1,38 +1,50 @@
1
1
  require 'sinatra/base'
2
- require 'github_api'
2
+ require 'faraday/http_cache'
3
+ require 'http_cache/response'
4
+ require 'octokit'
5
+ require 'logger'
3
6
 
4
7
  module Chairman
5
8
  class << self
6
9
  attr_reader :session, :client_id, :client_secret, :scope
7
10
 
8
11
  def config(client_id, client_secret, scope)
12
+ memcache_host = ENV['MEMCACHIER_SERVERS'] || 'localhost:11211'
13
+
14
+ stack = Faraday::Builder.new do |builder|
15
+ builder.use Faraday::HttpCache, logger: Logger.new(STDOUT), store: :mem_cache_store, store_options: [memcache_host]
16
+ builder.adapter Faraday.default_adapter
17
+ end
18
+ Octokit.middleware = stack
19
+
9
20
  @client_id = client_id
10
21
  @client_secret = client_secret
11
22
  @scope = scope
12
23
  end
13
24
 
14
25
  def session(auth_token = '')
15
- @session = Github.new do |config|
16
- config.client_id = @client_id
17
- config.client_secret = @client_secret
18
- config.oauth_token = auth_token
19
- end
26
+ @session = Octokit::Client.new :access_token => auth_token,
27
+ :client_id => @client_id,
28
+ :client_secret => @client_secret
20
29
  end
21
30
  end
22
31
 
23
32
  class Routes < Sinatra::Base
24
33
  get '/authorize' do
25
- redirect to Chairman.session.authorize_url :scope => Chairman.scope
34
+ redirect to Chairman.session.authorize_url(Chairman.client_id, '', :scope => Chairman.scope.join(','))
26
35
  end
27
36
 
28
37
  get '/authorize/return' do
29
38
  halt if params[:error] == 'access_denied'
30
39
 
31
- token = Chairman.session.get_token(params[:code])
40
+ token = Chairman.session.exchange_code_for_token(params[:code], Chairman.client_id, Chairman.client_secret, {:accept => 'application/json'})
41
+
42
+ # TODO: Verify that returned scope is the same as we requested
43
+ # See: http://developer.github.com/changes/2013-10-04-oauth-changes-coming/
32
44
 
33
- @user = Chairman.session(token.token).users.get
45
+ @user = Chairman.session(token.access_token).user
34
46
 
35
- session[:github_token] = token.token
47
+ session[:github_token] = token.access_token
36
48
  session[:github_id] = @user.login
37
49
  session[:gravatar_id] = @user.gravatar_id
38
50
  end
@@ -0,0 +1,15 @@
1
+ module Faraday
2
+ class HttpCache < Faraday::Middleware
3
+ # Internal: a class to represent a response from a Faraday request.
4
+ # It decorates the response hash into a smarter object that queries
5
+ # the response headers and status informations about how the caching
6
+ # middleware should handle this specific response.
7
+ class Response
8
+ def cacheable?
9
+ return false if cache_control.no_store?
10
+
11
+ cacheable_status_code? && (validateable? || fresh?)
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chairman
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3.alpha.1"
3
3
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chairman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3.alpha.1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jed Foster
@@ -28,13 +28,13 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.4.3
30
30
  - !ruby/object:Gem::Dependency
31
- name: github_api
31
+ name: octokit
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.10.2
37
+ version: '2.0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,55 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.10.2
45
+ version: '2.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday-http-cache
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.3.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: dalli
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.6.4
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: memcachier
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.0.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.2
46
94
  description: GitHub authentication routes and tools for Sinatra apps
47
95
  email: jed@jedfoster.com
48
96
  executables: []
@@ -52,6 +100,7 @@ files:
52
100
  - README.md
53
101
  - LICENSE
54
102
  - lib/chairman.rb
103
+ - lib/http_cache/response.rb
55
104
  - lib/version.rb
56
105
  homepage: https://github.com/jedfoster/Chairman
57
106
  licenses: []
@@ -68,9 +117,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
117
  required_rubygems_version: !ruby/object:Gem::Requirement
69
118
  none: false
70
119
  requirements:
71
- - - ! '>='
120
+ - - ! '>'
72
121
  - !ruby/object:Gem::Version
73
- version: '0'
122
+ version: 1.3.1
74
123
  requirements: []
75
124
  rubyforge_project:
76
125
  rubygems_version: 1.8.23