gh 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gh.rb CHANGED
@@ -19,6 +19,7 @@ module GH
19
19
  autoload :Response, 'gh/response'
20
20
  autoload :ResponseWrapper, 'gh/response_wrapper'
21
21
  autoload :Stack, 'gh/stack'
22
+ autoload :TokenCheck, 'gh/token_check'
22
23
  autoload :Wrapper, 'gh/wrapper'
23
24
 
24
25
  def self.with(backend)
@@ -58,6 +59,7 @@ module GH
58
59
  DefaultStack = Stack.new do
59
60
  use Instrumentation
60
61
  use Parallel
62
+ use TokenCheck
61
63
  use Pagination
62
64
  use LinkFollower
63
65
  use MergeCommit
@@ -10,7 +10,7 @@ module GH
10
10
  @info = info.merge(:error => error, :payload => payload)
11
11
 
12
12
  if error
13
- set_backtrace error.backtrace
13
+ set_backtrace error.backtrace if error.respond_to? :backtrace
14
14
  if error.respond_to? :response and error.response
15
15
  case response = error.response
16
16
  when Hash
@@ -49,4 +49,7 @@ module GH
49
49
  (key.to_s + ": ").ljust(12) + value
50
50
  end
51
51
  end
52
+
53
+ class TokenInvalid < Error
54
+ end
52
55
  end
@@ -27,8 +27,8 @@ module GH
27
27
  @api_host = Addressable::URI.parse(api_host)
28
28
  @headers = options[:headers].try(:dup) || {
29
29
  "User-Agent" => options[:user_agent] || "GH/#{GH::VERSION}",
30
- "Accept" => "application/vnd.github.v3.full+json," \
31
- "application/vnd.github.beta.full+json;q=0.5," \
30
+ "Accept" => "application/vnd.github.v3+json," \
31
+ "application/vnd.github.beta+json;q=0.5," \
32
32
  "application/json;q=0.1",
33
33
  "Accept-Charset" => "utf-8",
34
34
  }
@@ -0,0 +1,27 @@
1
+ require 'gh/error'
2
+
3
+ module GH
4
+ class TokenCheck < Wrapper
5
+ attr_accessor :client_id, :token
6
+
7
+ def setup(backend, options)
8
+ @client_id = options[:client_id]
9
+ @token = options[:token]
10
+ @check_token = true
11
+ super
12
+ end
13
+
14
+ def check_token
15
+ return unless @check_token and client_id and token
16
+ http :head, "/applications/#{client_id}/tokens/#{token}"
17
+ @check_token = false
18
+ rescue GH::Error
19
+ raise GH::TokenInvalid
20
+ end
21
+
22
+ def fetch_resource(*)
23
+ check_token
24
+ super
25
+ end
26
+ end
27
+ end
@@ -1,4 +1,4 @@
1
1
  module GH
2
2
  # Public: Library version.
3
- VERSION = "0.9.2"
3
+ VERSION = "0.10.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -170,6 +170,7 @@ files:
170
170
  - lib/gh/response.rb
171
171
  - lib/gh/response_wrapper.rb
172
172
  - lib/gh/stack.rb
173
+ - lib/gh/token_check.rb
173
174
  - lib/gh/version.rb
174
175
  - lib/gh/wrapper.rb
175
176
  - spec/cache_spec.rb