forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.rb
More file actions
30 lines (27 loc) · 975 Bytes
/
middleware.rb
File metadata and controls
30 lines (27 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# encoding: utf-8
require 'github_api/response'
require 'github_api/response/mashify'
require 'github_api/response/jsonize'
require 'github_api/response/raise_error'
require 'github_api/response/header'
module Github
class Middleware
def self.default(options = {})
api = options[:api]
proc do |builder|
builder.use Github::Request::Jsonize
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Github::Request::OAuth2, api.oauth_token if api.oauth_token?
builder.use Github::Request::BasicAuth, api.authentication if api.basic_authed?
builder.use Faraday::Response::Logger if ENV['DEBUG']
unless options[:raw]
builder.use Github::Response::Mashify
builder.use Github::Response::Jsonize
end
builder.use Github::Response::RaiseError
builder.adapter options[:adapter]
end
end
end # Middleware
end # Github