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
|
module Ievkit
# Configuration options for {Client}, defaulting to values
# in {Default}
module Configurable
attr_accessor :access_token, :auto_paginate, :client_id,
:client_secret, :default_media_type, :connection_options,
:middleware, :netrc, :netrc_file,
:per_page, :proxy, :user_agent
attr_writer :password, :web_endpoint, :api_endpoint, :login
class << self
# List of configurable keys for {Octokit::Client}
# @return [Array] of option keys
def keys
@keys ||= [
:access_token,
:api_endpoint,
:auto_paginate,
:client_id,
:client_secret,
:connection_options,
:default_media_type,
:login,
:middleware,
:netrc,
:netrc_file,
:per_page,
:password,
:proxy,
:user_agent,
:web_endpoint
]
end
end
# Set configuration options using a block
def configure
yield self
end
# Reset configuration options to default values
def reset!
Ievkit::Configurable.keys.each do |key|
instance_variable_set(:"@#{key}", Ievkit::Default.options[key])
end
self
end
alias setup reset!
def api_endpoint
File.join(@api_endpoint, "")
end
# Base URL for generated web URLs
#
# @return [String] Default: https://github.com/
def web_endpoint
File.join(@web_endpoint, "")
end
def login
@login ||= begin
user.login if token_authenticated?
end
end
def netrc?
!!@netrc
end
private
def options
Hash[Ievkit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
end
def fetch_client_id_and_secret(overrides = {})
opts = options.merge(overrides)
opts.values_at :client_id, :client_secret
end
end
end
|