octodoggy 4.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +714 -0
  6. data/Rakefile +22 -0
  7. data/lib/ext/sawyer/relation.rb +10 -0
  8. data/lib/octokit.rb +59 -0
  9. data/lib/octokit/arguments.rb +14 -0
  10. data/lib/octokit/authentication.rb +82 -0
  11. data/lib/octokit/client.rb +238 -0
  12. data/lib/octokit/client/authorizations.rb +244 -0
  13. data/lib/octokit/client/commit_comments.rb +95 -0
  14. data/lib/octokit/client/commits.rb +239 -0
  15. data/lib/octokit/client/contents.rb +162 -0
  16. data/lib/octokit/client/deployments.rb +62 -0
  17. data/lib/octokit/client/downloads.rb +50 -0
  18. data/lib/octokit/client/emojis.rb +18 -0
  19. data/lib/octokit/client/events.rb +151 -0
  20. data/lib/octokit/client/feeds.rb +33 -0
  21. data/lib/octokit/client/gists.rb +233 -0
  22. data/lib/octokit/client/gitignore.rb +43 -0
  23. data/lib/octokit/client/hooks.rb +297 -0
  24. data/lib/octokit/client/integrations.rb +77 -0
  25. data/lib/octokit/client/issues.rb +321 -0
  26. data/lib/octokit/client/labels.rb +156 -0
  27. data/lib/octokit/client/legacy_search.rb +42 -0
  28. data/lib/octokit/client/licenses.rb +45 -0
  29. data/lib/octokit/client/markdown.rb +27 -0
  30. data/lib/octokit/client/meta.rb +21 -0
  31. data/lib/octokit/client/milestones.rb +87 -0
  32. data/lib/octokit/client/notifications.rb +171 -0
  33. data/lib/octokit/client/objects.rb +141 -0
  34. data/lib/octokit/client/organizations.rb +768 -0
  35. data/lib/octokit/client/pages.rb +63 -0
  36. data/lib/octokit/client/projects.rb +314 -0
  37. data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
  38. data/lib/octokit/client/pull_requests.rb +301 -0
  39. data/lib/octokit/client/rate_limit.rb +54 -0
  40. data/lib/octokit/client/reactions.rb +158 -0
  41. data/lib/octokit/client/refs.rb +118 -0
  42. data/lib/octokit/client/releases.rb +163 -0
  43. data/lib/octokit/client/repositories.rb +654 -0
  44. data/lib/octokit/client/repository_invitations.rb +103 -0
  45. data/lib/octokit/client/reviews.rb +174 -0
  46. data/lib/octokit/client/say.rb +19 -0
  47. data/lib/octokit/client/search.rb +76 -0
  48. data/lib/octokit/client/service_status.rb +38 -0
  49. data/lib/octokit/client/source_import.rb +161 -0
  50. data/lib/octokit/client/stats.rb +105 -0
  51. data/lib/octokit/client/statuses.rb +47 -0
  52. data/lib/octokit/client/traffic.rb +69 -0
  53. data/lib/octokit/client/users.rb +354 -0
  54. data/lib/octokit/configurable.rb +147 -0
  55. data/lib/octokit/connection.rb +199 -0
  56. data/lib/octokit/default.rb +166 -0
  57. data/lib/octokit/enterprise_admin_client.rb +40 -0
  58. data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
  59. data/lib/octokit/enterprise_admin_client/license.rb +18 -0
  60. data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
  61. data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
  62. data/lib/octokit/enterprise_admin_client/users.rb +128 -0
  63. data/lib/octokit/enterprise_management_console_client.rb +50 -0
  64. data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
  65. data/lib/octokit/error.rb +286 -0
  66. data/lib/octokit/gist.rb +36 -0
  67. data/lib/octokit/middleware/follow_redirects.rb +131 -0
  68. data/lib/octokit/organization.rb +17 -0
  69. data/lib/octokit/preview.rb +38 -0
  70. data/lib/octokit/rate_limit.rb +33 -0
  71. data/lib/octokit/repo_arguments.rb +19 -0
  72. data/lib/octokit/repository.rb +93 -0
  73. data/lib/octokit/response/feed_parser.rb +21 -0
  74. data/lib/octokit/response/raise_error.rb +21 -0
  75. data/lib/octokit/user.rb +19 -0
  76. data/lib/octokit/version.rb +17 -0
  77. data/lib/octokit/warnable.rb +17 -0
  78. data/octokit.gemspec +22 -0
  79. metadata +160 -0
@@ -0,0 +1,147 @@
1
+ module Octokit
2
+
3
+ # Configuration options for {Client}, defaulting to values
4
+ # in {Default}
5
+ module Configurable
6
+ # @!attribute [w] access_token
7
+ # @see https://developer.github.com/v3/oauth/
8
+ # @return [String] OAuth2 access token for authentication
9
+ # @!attribute api_endpoint
10
+ # @return [String] Base URL for API requests. default: https://api.github.com/
11
+ # @!attribute auto_paginate
12
+ # @return [Boolean] Auto fetch next page of results until rate limit reached
13
+ # @!attribute [w] bearer_token
14
+ # @see https://developer.github.com/early-access/integrations/authentication/#as-an-integration
15
+ # @return [String] JWT bearer token for authentication
16
+ # @!attribute client_id
17
+ # @see https://developer.github.com/v3/oauth/
18
+ # @return [String] Configure OAuth app key
19
+ # @!attribute [w] client_secret
20
+ # @see https://developer.github.com/v3/oauth/
21
+ # @return [String] Configure OAuth app secret
22
+ # @!attribute default_media_type
23
+ # @see https://developer.github.com/v3/media/
24
+ # @return [String] Configure preferred media type (for API versioning, for example)
25
+ # @!attribute connection_options
26
+ # @see https://github.com/lostisland/faraday
27
+ # @return [Hash] Configure connection options for Faraday
28
+ # @!attribute login
29
+ # @return [String] GitHub username for Basic Authentication
30
+ # @!attribute management_console_password
31
+ # @return [String] An admin password set up for your GitHub Enterprise management console
32
+ # @!attribute management_console_endpoint
33
+ # @return [String] Base URL for API requests to the GitHub Enterprise management console
34
+ # @!attribute middleware
35
+ # @see https://github.com/lostisland/faraday
36
+ # @return [Faraday::Builder or Faraday::RackBuilder] Configure middleware for Faraday
37
+ # @!attribute netrc
38
+ # @return [Boolean] Instruct Octokit to get credentials from .netrc file
39
+ # @!attribute netrc_file
40
+ # @return [String] Path to .netrc file. default: ~/.netrc
41
+ # @!attribute [w] password
42
+ # @return [String] GitHub password for Basic Authentication
43
+ # @!attribute per_page
44
+ # @return [String] Configure page size for paginated results. API default: 30
45
+ # @!attribute proxy
46
+ # @see https://github.com/lostisland/faraday
47
+ # @return [String] URI for proxy server
48
+ # @!attribute user_agent
49
+ # @return [String] Configure User-Agent header for requests.
50
+ # @!attribute web_endpoint
51
+ # @return [String] Base URL for web URLs. default: https://github.com/
52
+
53
+ attr_accessor :access_token, :auto_paginate, :bearer_token, :client_id,
54
+ :client_secret, :default_media_type, :connection_options,
55
+ :middleware, :netrc, :netrc_file,
56
+ :per_page, :proxy, :user_agent
57
+ attr_writer :password, :web_endpoint, :api_endpoint, :login,
58
+ :management_console_endpoint, :management_console_password
59
+
60
+ class << self
61
+
62
+ # List of configurable keys for {Octokit::Client}
63
+ # @return [Array] of option keys
64
+ def keys
65
+ @keys ||= [
66
+ :access_token,
67
+ :api_endpoint,
68
+ :auto_paginate,
69
+ :bearer_token,
70
+ :client_id,
71
+ :client_secret,
72
+ :connection_options,
73
+ :default_media_type,
74
+ :login,
75
+ :management_console_endpoint,
76
+ :management_console_password,
77
+ :middleware,
78
+ :netrc,
79
+ :netrc_file,
80
+ :per_page,
81
+ :password,
82
+ :proxy,
83
+ :user_agent,
84
+ :web_endpoint
85
+ ]
86
+ end
87
+ end
88
+
89
+ # Set configuration options using a block
90
+ def configure
91
+ yield self
92
+ end
93
+
94
+ # Reset configuration options to default values
95
+ def reset!
96
+ Octokit::Configurable.keys.each do |key|
97
+ instance_variable_set(:"@#{key}", Octokit::Default.options[key])
98
+ end
99
+ self
100
+ end
101
+ alias setup reset!
102
+
103
+ # Compares client options to a Hash of requested options
104
+ #
105
+ # @param opts [Hash] Options to compare with current client options
106
+ # @return [Boolean]
107
+ def same_options?(opts)
108
+ opts.hash == options.hash
109
+ end
110
+
111
+ def api_endpoint
112
+ File.join(@api_endpoint, "")
113
+ end
114
+
115
+ def management_console_endpoint
116
+ File.join(@management_console_endpoint, "")
117
+ end
118
+
119
+ # Base URL for generated web URLs
120
+ #
121
+ # @return [String] Default: https://github.com/
122
+ def web_endpoint
123
+ File.join(@web_endpoint, "")
124
+ end
125
+
126
+ def login
127
+ @login ||= begin
128
+ user.login if token_authenticated?
129
+ end
130
+ end
131
+
132
+ def netrc?
133
+ !!@netrc
134
+ end
135
+
136
+ private
137
+
138
+ def options
139
+ Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
140
+ end
141
+
142
+ def fetch_client_id_and_secret(overrides = {})
143
+ opts = options.merge(overrides)
144
+ opts.values_at :client_id, :client_secret
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,199 @@
1
+ require 'sawyer'
2
+ require 'octokit/authentication'
3
+ module Octokit
4
+
5
+ # Network layer for API clients.
6
+ module Connection
7
+
8
+ include Octokit::Authentication
9
+
10
+ # Header keys that can be passed in options hash to {#get},{#head}
11
+ CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
12
+
13
+ # Make a HTTP GET request
14
+ #
15
+ # @param url [String] The path, relative to {#api_endpoint}
16
+ # @param options [Hash] Query and header params for request
17
+ # @return [Sawyer::Resource]
18
+ def get(url, options = {})
19
+ request :get, url, parse_query_and_convenience_headers(options)
20
+ end
21
+
22
+ # Make a HTTP POST request
23
+ #
24
+ # @param url [String] The path, relative to {#api_endpoint}
25
+ # @param options [Hash] Body and header params for request
26
+ # @return [Sawyer::Resource]
27
+ def post(url, options = {})
28
+ request :post, url, options
29
+ end
30
+
31
+ # Make a HTTP PUT request
32
+ #
33
+ # @param url [String] The path, relative to {#api_endpoint}
34
+ # @param options [Hash] Body and header params for request
35
+ # @return [Sawyer::Resource]
36
+ def put(url, options = {})
37
+ request :put, url, options
38
+ end
39
+
40
+ # Make a HTTP PATCH request
41
+ #
42
+ # @param url [String] The path, relative to {#api_endpoint}
43
+ # @param options [Hash] Body and header params for request
44
+ # @return [Sawyer::Resource]
45
+ def patch(url, options = {})
46
+ request :patch, url, options
47
+ end
48
+
49
+ # Make a HTTP DELETE request
50
+ #
51
+ # @param url [String] The path, relative to {#api_endpoint}
52
+ # @param options [Hash] Query and header params for request
53
+ # @return [Sawyer::Resource]
54
+ def delete(url, options = {})
55
+ request :delete, url, options
56
+ end
57
+
58
+ # Make a HTTP HEAD request
59
+ #
60
+ # @param url [String] The path, relative to {#api_endpoint}
61
+ # @param options [Hash] Query and header params for request
62
+ # @return [Sawyer::Resource]
63
+ def head(url, options = {})
64
+ request :head, url, parse_query_and_convenience_headers(options)
65
+ end
66
+
67
+ # Make one or more HTTP GET requests, optionally fetching
68
+ # the next page of results from URL in Link response header based
69
+ # on value in {#auto_paginate}.
70
+ #
71
+ # @param url [String] The path, relative to {#api_endpoint}
72
+ # @param options [Hash] Query and header params for request
73
+ # @param block [Block] Block to perform the data concatination of the
74
+ # multiple requests. The block is called with two parameters, the first
75
+ # contains the contents of the requests so far and the second parameter
76
+ # contains the latest response.
77
+ # @return [Sawyer::Resource]
78
+ def paginate(url, options = {}, &block)
79
+ opts = parse_query_and_convenience_headers(options)
80
+ if @auto_paginate || @per_page
81
+ opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil)
82
+ end
83
+
84
+ data = request(:get, url, opts.dup)
85
+
86
+ if @auto_paginate
87
+ while @last_response.rels[:next] && rate_limit.remaining > 0
88
+ @last_response = @last_response.rels[:next].get(:headers => opts[:headers])
89
+ if block_given?
90
+ yield(data, @last_response)
91
+ else
92
+ data.concat(@last_response.data) if @last_response.data.is_a?(Array)
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ data
99
+ end
100
+
101
+ # Hypermedia agent for the GitHub API
102
+ #
103
+ # @return [Sawyer::Agent]
104
+ def agent
105
+ @agent ||= Sawyer::Agent.new(endpoint, sawyer_options) do |http|
106
+ http.headers[:accept] = default_media_type
107
+ http.headers[:content_type] = "application/json"
108
+ http.headers[:user_agent] = user_agent
109
+ if basic_authenticated?
110
+ http.basic_auth(@login, @password)
111
+ elsif token_authenticated?
112
+ http.authorization 'token', @access_token
113
+ elsif bearer_authenticated?
114
+ http.authorization 'Bearer', @bearer_token
115
+ elsif application_authenticated?
116
+ http.params = http.params.merge application_authentication
117
+ end
118
+ end
119
+ end
120
+
121
+ # Fetch the root resource for the API
122
+ #
123
+ # @return [Sawyer::Resource]
124
+ def root
125
+ get "/"
126
+ end
127
+
128
+ # Response for last HTTP request
129
+ #
130
+ # @return [Sawyer::Response]
131
+ def last_response
132
+ @last_response if defined? @last_response
133
+ end
134
+
135
+ protected
136
+
137
+ def endpoint
138
+ api_endpoint
139
+ end
140
+
141
+ private
142
+
143
+ def reset_agent
144
+ @agent = nil
145
+ end
146
+
147
+ def request(method, path, data, options = {})
148
+ if data.is_a?(Hash)
149
+ options[:query] = data.delete(:query) || {}
150
+ options[:headers] = data.delete(:headers) || {}
151
+ if accept = data.delete(:accept)
152
+ options[:headers][:accept] = accept
153
+ end
154
+ end
155
+
156
+ @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
157
+ response.data
158
+ end
159
+
160
+ # Executes the request, checking if it was successful
161
+ #
162
+ # @return [Boolean] True on success, false otherwise
163
+ def boolean_from_response(method, path, options = {})
164
+ request(method, path, options)
165
+ @last_response.status == 204
166
+ rescue Octokit::NotFound
167
+ false
168
+ end
169
+
170
+
171
+ def sawyer_options
172
+ opts = {
173
+ :links_parser => Sawyer::LinkParsers::Simple.new
174
+ }
175
+ conn_opts = @connection_options
176
+ conn_opts[:builder] = @middleware if @middleware
177
+ conn_opts[:proxy] = @proxy if @proxy
178
+ opts[:faraday] = Faraday.new(conn_opts)
179
+
180
+ opts
181
+ end
182
+
183
+ def parse_query_and_convenience_headers(options)
184
+ options = options.dup
185
+ headers = options.delete(:headers) { Hash.new }
186
+ CONVENIENCE_HEADERS.each do |h|
187
+ if header = options.delete(h)
188
+ headers[h] = header
189
+ end
190
+ end
191
+ query = options.delete(:query)
192
+ opts = {:query => options}
193
+ opts[:query].merge!(query) if query && query.is_a?(Hash)
194
+ opts[:headers] = headers unless headers.empty?
195
+
196
+ opts
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,166 @@
1
+ require 'octokit/middleware/follow_redirects'
2
+ require 'octokit/response/raise_error'
3
+ require 'octokit/response/feed_parser'
4
+ require 'octokit/version'
5
+
6
+ module Octokit
7
+
8
+ # Default configuration options for {Client}
9
+ module Default
10
+
11
+ # Default API endpoint
12
+ API_ENDPOINT = "https://api.github.com".freeze
13
+
14
+ # Default User Agent header string
15
+ USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}".freeze
16
+
17
+ # Default media type
18
+ MEDIA_TYPE = "application/vnd.github.v3+json".freeze
19
+
20
+ # Default WEB endpoint
21
+ WEB_ENDPOINT = "https://github.com".freeze
22
+
23
+ # In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder
24
+ RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
25
+
26
+ # Default Faraday middleware stack
27
+ MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder|
28
+ builder.use Octokit::Middleware::FollowRedirects
29
+ builder.use Octokit::Response::RaiseError
30
+ builder.use Octokit::Response::FeedParser
31
+ builder.adapter Faraday.default_adapter
32
+ end
33
+
34
+ class << self
35
+
36
+ # Configuration options
37
+ # @return [Hash]
38
+ def options
39
+ Hash[Octokit::Configurable.keys.map{|key| [key, send(key)]}]
40
+ end
41
+
42
+ # Default access token from ENV
43
+ # @return [String]
44
+ def access_token
45
+ ENV['OCTOKIT_ACCESS_TOKEN']
46
+ end
47
+
48
+ # Default API endpoint from ENV or {API_ENDPOINT}
49
+ # @return [String]
50
+ def api_endpoint
51
+ ENV['OCTOKIT_API_ENDPOINT'] || API_ENDPOINT
52
+ end
53
+
54
+ # Default pagination preference from ENV
55
+ # @return [String]
56
+ def auto_paginate
57
+ ENV['OCTOKIT_AUTO_PAGINATE']
58
+ end
59
+
60
+ # Default bearer token from ENV
61
+ # @return [String]
62
+ def bearer_token
63
+ ENV['OCTOKIT_BEARER_TOKEN']
64
+ end
65
+
66
+ # Default OAuth app key from ENV
67
+ # @return [String]
68
+ def client_id
69
+ ENV['OCTOKIT_CLIENT_ID']
70
+ end
71
+
72
+ # Default OAuth app secret from ENV
73
+ # @return [String]
74
+ def client_secret
75
+ ENV['OCTOKIT_SECRET']
76
+ end
77
+
78
+ # Default management console password from ENV
79
+ # @return [String]
80
+ def management_console_password
81
+ ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD']
82
+ end
83
+
84
+ # Default management console endpoint from ENV
85
+ # @return [String]
86
+ def management_console_endpoint
87
+ ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT']
88
+ end
89
+
90
+ # Default options for Faraday::Connection
91
+ # @return [Hash]
92
+ def connection_options
93
+ {
94
+ :headers => {
95
+ :accept => default_media_type,
96
+ :user_agent => user_agent
97
+ }
98
+ }
99
+ end
100
+
101
+ # Default media type from ENV or {MEDIA_TYPE}
102
+ # @return [String]
103
+ def default_media_type
104
+ ENV['OCTOKIT_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
105
+ end
106
+
107
+ # Default GitHub username for Basic Auth from ENV
108
+ # @return [String]
109
+ def login
110
+ ENV['OCTOKIT_LOGIN']
111
+ end
112
+
113
+ # Default middleware stack for Faraday::Connection
114
+ # from {MIDDLEWARE}
115
+ # @return [Faraday::RackBuilder or Faraday::Builder]
116
+ def middleware
117
+ MIDDLEWARE
118
+ end
119
+
120
+ # Default GitHub password for Basic Auth from ENV
121
+ # @return [String]
122
+ def password
123
+ ENV['OCTOKIT_PASSWORD']
124
+ end
125
+
126
+ # Default pagination page size from ENV
127
+ # @return [Integer] Page size
128
+ def per_page
129
+ page_size = ENV['OCTOKIT_PER_PAGE']
130
+
131
+ page_size.to_i if page_size
132
+ end
133
+
134
+ # Default proxy server URI for Faraday connection from ENV
135
+ # @return [String]
136
+ def proxy
137
+ ENV['OCTOKIT_PROXY']
138
+ end
139
+
140
+ # Default User-Agent header string from ENV or {USER_AGENT}
141
+ # @return [String]
142
+ def user_agent
143
+ ENV['OCTOKIT_USER_AGENT'] || USER_AGENT
144
+ end
145
+
146
+ # Default web endpoint from ENV or {WEB_ENDPOINT}
147
+ # @return [String]
148
+ def web_endpoint
149
+ ENV['OCTOKIT_WEB_ENDPOINT'] || WEB_ENDPOINT
150
+ end
151
+
152
+ # Default behavior for reading .netrc file
153
+ # @return [Boolean]
154
+ def netrc
155
+ ENV['OCTOKIT_NETRC'] || false
156
+ end
157
+
158
+ # Default path for .netrc file
159
+ # @return [String]
160
+ def netrc_file
161
+ ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc')
162
+ end
163
+
164
+ end
165
+ end
166
+ end