forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.rb
More file actions
124 lines (98 loc) · 3.21 KB
/
configuration.rb
File metadata and controls
124 lines (98 loc) · 3.21 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# encoding: utf-8
module Github
module Configuration
VALID_OPTIONS_KEYS = [
:adapter,
:client_id,
:client_secret,
:oauth_token,
:endpoint,
:site,
:ssl,
:mime_type,
:user_agent,
:connection_options,
:repo,
:user,
:org,
:login,
:password,
:basic_auth,
:auto_pagination
].freeze
# Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
DEFAULT_ADAPTER = :net_http
# By default, don't set an application key
DEFAULT_CLIENT_ID = nil
# By default, don't set an application secret
DEFAULT_CLIENT_SECRET = nil
# By default, don't set a user oauth access token
DEFAULT_OAUTH_TOKEN = nil
# By default, don't set a user login name
DEFAULT_LOGIN = nil
# By default, don't set a user password
DEFAULT_PASSWORD = nil
# By default, don't set a user basic authentication
DEFAULT_BASIC_AUTH = nil
# The api endpoint used to connect to GitHub if none is set
DEFAULT_ENDPOINT = 'https://api.github.com'.freeze
# The web endpoint used to connect to GitHub if none is set
DEFAULT_SITE = 'https://github.com'.freeze
# The default SSL configuration
DEFAULT_SSL = {}
# The value sent in the http header for 'User-Agent' if none is set
DEFAULT_USER_AGENT = "Github Ruby Gem #{Github::VERSION::STRING}".freeze
# By default the <tt>Accept</tt> header will make a request for <tt>JSON</tt>
DEFAULT_MIME_TYPE = :json
# By default uses the Faraday connection options if none is set
DEFAULT_CONNECTION_OPTIONS = {}
# By default, don't set user name
DEFAULT_USER = nil
# By default, don't set repository name
DEFAULT_REPO = nil
# By default, don't set organization name
DEFAULT_ORG = nil
# By default, don't traverse the page links
DEFAULT_AUTO_PAGINATION = false
attr_accessor *VALID_OPTIONS_KEYS
# Convenience method to allow for global setting of configuration options
def configure
yield self
end
def self.extended(base)
base.reset!
end
class << self
def keys
VALID_OPTIONS_KEYS
end
end
def options
options = {}
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
options
end
# Reset configuration options to their defaults
#
def reset!
self.adapter = DEFAULT_ADAPTER
self.client_id = DEFAULT_CLIENT_ID
self.client_secret = DEFAULT_CLIENT_SECRET
self.oauth_token = DEFAULT_OAUTH_TOKEN
self.endpoint = DEFAULT_ENDPOINT
self.site = DEFAULT_SITE
self.ssl = DEFAULT_SSL
self.user_agent = DEFAULT_USER_AGENT
self.connection_options = DEFAULT_CONNECTION_OPTIONS
self.mime_type = DEFAULT_MIME_TYPE
self.user = DEFAULT_USER
self.repo = DEFAULT_REPO
self.org = DEFAULT_ORG
self.login = DEFAULT_LOGIN
self.password = DEFAULT_PASSWORD
self.basic_auth = DEFAULT_BASIC_AUTH
self.auto_pagination = DEFAULT_AUTO_PAGINATION
self
end
end # Configuration
end # Github