lingfennan-github_api 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +741 -0
- data/lib/github_api.rb +93 -0
- data/lib/github_api/api.rb +398 -0
- data/lib/github_api/api/actions.rb +60 -0
- data/lib/github_api/api/arguments.rb +253 -0
- data/lib/github_api/api/config.rb +105 -0
- data/lib/github_api/api/config/property.rb +30 -0
- data/lib/github_api/api/config/property_set.rb +120 -0
- data/lib/github_api/api/factory.rb +33 -0
- data/lib/github_api/authorization.rb +75 -0
- data/lib/github_api/client.rb +77 -0
- data/lib/github_api/client/activity.rb +31 -0
- data/lib/github_api/client/activity/events.rb +233 -0
- data/lib/github_api/client/activity/feeds.rb +50 -0
- data/lib/github_api/client/activity/notifications.rb +181 -0
- data/lib/github_api/client/activity/starring.rb +130 -0
- data/lib/github_api/client/activity/watching.rb +176 -0
- data/lib/github_api/client/authorizations.rb +142 -0
- data/lib/github_api/client/authorizations/app.rb +98 -0
- data/lib/github_api/client/emojis.rb +19 -0
- data/lib/github_api/client/gists.rb +289 -0
- data/lib/github_api/client/gists/comments.rb +100 -0
- data/lib/github_api/client/git_data.rb +31 -0
- data/lib/github_api/client/git_data/blobs.rb +51 -0
- data/lib/github_api/client/git_data/commits.rb +101 -0
- data/lib/github_api/client/git_data/references.rb +150 -0
- data/lib/github_api/client/git_data/tags.rb +95 -0
- data/lib/github_api/client/git_data/trees.rb +113 -0
- data/lib/github_api/client/gitignore.rb +57 -0
- data/lib/github_api/client/issues.rb +248 -0
- data/lib/github_api/client/issues/assignees.rb +77 -0
- data/lib/github_api/client/issues/comments.rb +146 -0
- data/lib/github_api/client/issues/events.rb +50 -0
- data/lib/github_api/client/issues/labels.rb +189 -0
- data/lib/github_api/client/issues/milestones.rb +146 -0
- data/lib/github_api/client/markdown.rb +62 -0
- data/lib/github_api/client/meta.rb +19 -0
- data/lib/github_api/client/orgs.rb +127 -0
- data/lib/github_api/client/orgs/hooks.rb +182 -0
- data/lib/github_api/client/orgs/members.rb +142 -0
- data/lib/github_api/client/orgs/memberships.rb +131 -0
- data/lib/github_api/client/orgs/projects.rb +57 -0
- data/lib/github_api/client/orgs/teams.rb +407 -0
- data/lib/github_api/client/projects.rb +83 -0
- data/lib/github_api/client/projects/cards.rb +158 -0
- data/lib/github_api/client/projects/columns.rb +146 -0
- data/lib/github_api/client/pull_requests.rb +195 -0
- data/lib/github_api/client/pull_requests/comments.rb +140 -0
- data/lib/github_api/client/pull_requests/reviews.rb +158 -0
- data/lib/github_api/client/repos.rb +468 -0
- data/lib/github_api/client/repos/branches.rb +48 -0
- data/lib/github_api/client/repos/branches/protections.rb +75 -0
- data/lib/github_api/client/repos/collaborators.rb +84 -0
- data/lib/github_api/client/repos/comments.rb +125 -0
- data/lib/github_api/client/repos/commits.rb +80 -0
- data/lib/github_api/client/repos/contents.rb +246 -0
- data/lib/github_api/client/repos/deployments.rb +138 -0
- data/lib/github_api/client/repos/downloads.rb +62 -0
- data/lib/github_api/client/repos/forks.rb +48 -0
- data/lib/github_api/client/repos/hooks.rb +214 -0
- data/lib/github_api/client/repos/keys.rb +104 -0
- data/lib/github_api/client/repos/merging.rb +47 -0
- data/lib/github_api/client/repos/pages.rb +48 -0
- data/lib/github_api/client/repos/projects.rb +62 -0
- data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
- data/lib/github_api/client/repos/releases.rb +189 -0
- data/lib/github_api/client/repos/releases/assets.rb +136 -0
- data/lib/github_api/client/repos/releases/tags.rb +24 -0
- data/lib/github_api/client/repos/statistics.rb +89 -0
- data/lib/github_api/client/repos/statuses.rb +91 -0
- data/lib/github_api/client/say.rb +25 -0
- data/lib/github_api/client/scopes.rb +46 -0
- data/lib/github_api/client/search.rb +133 -0
- data/lib/github_api/client/search/legacy.rb +111 -0
- data/lib/github_api/client/users.rb +117 -0
- data/lib/github_api/client/users/emails.rb +65 -0
- data/lib/github_api/client/users/followers.rb +115 -0
- data/lib/github_api/client/users/keys.rb +104 -0
- data/lib/github_api/configuration.rb +70 -0
- data/lib/github_api/connection.rb +82 -0
- data/lib/github_api/constants.rb +61 -0
- data/lib/github_api/core_ext/array.rb +25 -0
- data/lib/github_api/core_ext/hash.rb +91 -0
- data/lib/github_api/core_ext/ordered_hash.rb +107 -0
- data/lib/github_api/deprecation.rb +39 -0
- data/lib/github_api/error.rb +32 -0
- data/lib/github_api/error/client_error.rb +89 -0
- data/lib/github_api/error/service_error.rb +223 -0
- data/lib/github_api/ext/faraday.rb +38 -0
- data/lib/github_api/mash.rb +7 -0
- data/lib/github_api/middleware.rb +37 -0
- data/lib/github_api/mime_type.rb +33 -0
- data/lib/github_api/normalizer.rb +23 -0
- data/lib/github_api/null_encoder.rb +25 -0
- data/lib/github_api/page_iterator.rb +138 -0
- data/lib/github_api/page_links.rb +63 -0
- data/lib/github_api/paged_request.rb +42 -0
- data/lib/github_api/pagination.rb +115 -0
- data/lib/github_api/parameter_filter.rb +35 -0
- data/lib/github_api/params_hash.rb +115 -0
- data/lib/github_api/rate_limit.rb +25 -0
- data/lib/github_api/request.rb +85 -0
- data/lib/github_api/request/basic_auth.rb +36 -0
- data/lib/github_api/request/jsonize.rb +54 -0
- data/lib/github_api/request/oauth2.rb +44 -0
- data/lib/github_api/request/verbs.rb +63 -0
- data/lib/github_api/response.rb +48 -0
- data/lib/github_api/response/atom_parser.rb +22 -0
- data/lib/github_api/response/follow_redirects.rb +140 -0
- data/lib/github_api/response/header.rb +87 -0
- data/lib/github_api/response/jsonize.rb +28 -0
- data/lib/github_api/response/mashify.rb +24 -0
- data/lib/github_api/response/raise_error.rb +22 -0
- data/lib/github_api/response/xmlize.rb +27 -0
- data/lib/github_api/response_wrapper.rb +161 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/utils/url.rb +63 -0
- data/lib/github_api/validations.rb +22 -0
- data/lib/github_api/validations/format.rb +26 -0
- data/lib/github_api/validations/presence.rb +32 -0
- data/lib/github_api/validations/required.rb +21 -0
- data/lib/github_api/validations/token.rb +41 -0
- data/lib/github_api/version.rb +5 -0
- metadata +338 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'delegate'
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
require_relative 'normalizer'
|
|
7
|
+
require_relative 'mime_type'
|
|
8
|
+
|
|
9
|
+
module Github
|
|
10
|
+
# Class responsible for holding request parameters
|
|
11
|
+
class ParamsHash < DelegateClass(Hash)
|
|
12
|
+
include Normalizer
|
|
13
|
+
include MimeType
|
|
14
|
+
|
|
15
|
+
REQUEST_PARAMS = [:accept, :media, :data, :raw, :headers]
|
|
16
|
+
|
|
17
|
+
def initialize(hash)
|
|
18
|
+
super(normalize!(Hash[hash]))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create empty hash
|
|
22
|
+
#
|
|
23
|
+
# @api public
|
|
24
|
+
def self.empty
|
|
25
|
+
new({})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Extract and parse media type param
|
|
29
|
+
#
|
|
30
|
+
# [.version].param[+json]
|
|
31
|
+
#
|
|
32
|
+
# @api public
|
|
33
|
+
def media
|
|
34
|
+
parse(delete('media'))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Get accept header
|
|
38
|
+
#
|
|
39
|
+
# @api public
|
|
40
|
+
def accept
|
|
41
|
+
if key?('accept') then self['accept']
|
|
42
|
+
elsif key?('media') then media
|
|
43
|
+
else nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Extract request data from parameters
|
|
48
|
+
#
|
|
49
|
+
# @api public
|
|
50
|
+
def data
|
|
51
|
+
if key?('data') && !self['data'].nil?
|
|
52
|
+
self['data']
|
|
53
|
+
else
|
|
54
|
+
request_params
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def encoder
|
|
59
|
+
if key?('encoder') && self['encoder']
|
|
60
|
+
self['encoder']
|
|
61
|
+
else
|
|
62
|
+
{}
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Configuration options from request
|
|
67
|
+
#
|
|
68
|
+
# @return [Hash]
|
|
69
|
+
#
|
|
70
|
+
# @api public
|
|
71
|
+
def options
|
|
72
|
+
opts = fetch('options', {})
|
|
73
|
+
headers = fetch('headers', {})
|
|
74
|
+
if value = accept
|
|
75
|
+
headers[:accept] = value
|
|
76
|
+
end
|
|
77
|
+
opts[:raw] = key?('raw') ? self['raw'] : false
|
|
78
|
+
opts[:headers] = headers unless headers.empty?
|
|
79
|
+
opts
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Update hash with default parameters for non existing keys
|
|
83
|
+
#
|
|
84
|
+
def merge_default(defaults)
|
|
85
|
+
if defaults && !defaults.empty?
|
|
86
|
+
defaults.each do |key, value|
|
|
87
|
+
self[key] = value unless self.key?(key)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
self
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Base64 encode string removing newline characters
|
|
94
|
+
#
|
|
95
|
+
# @api public
|
|
96
|
+
def strict_encode64(key)
|
|
97
|
+
value = self[key]
|
|
98
|
+
encoded = if Base64.respond_to?(:strict_encode64)
|
|
99
|
+
Base64.strict_encode64(value)
|
|
100
|
+
else
|
|
101
|
+
[value].pack('m0')
|
|
102
|
+
end
|
|
103
|
+
self[key] = encoded.delete("\n\r")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Filter out request params
|
|
107
|
+
#
|
|
108
|
+
# @api public
|
|
109
|
+
def request_params
|
|
110
|
+
to_hash.select do |key, value|
|
|
111
|
+
!REQUEST_PARAMS.include?(key.to_sym)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end # ParamsHash
|
|
115
|
+
end # Github
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Github
|
|
4
|
+
module RateLimit
|
|
5
|
+
|
|
6
|
+
def ratelimit(*args)
|
|
7
|
+
arguments(args)
|
|
8
|
+
|
|
9
|
+
get_request("/rate_limit", arguments.params).rate.limit
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ratelimit_remaining(*args)
|
|
13
|
+
arguments(args)
|
|
14
|
+
|
|
15
|
+
get_request("/rate_limit", arguments.params).rate.remaining
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ratelimit_reset(*args)
|
|
19
|
+
arguments(args)
|
|
20
|
+
|
|
21
|
+
get_request("/rate_limit", arguments.params).rate.reset
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end # RateLimit
|
|
25
|
+
end # Github
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative 'connection'
|
|
4
|
+
require_relative 'response_wrapper'
|
|
5
|
+
require_relative 'request/oauth2'
|
|
6
|
+
require_relative 'request/basic_auth'
|
|
7
|
+
require_relative 'request/jsonize'
|
|
8
|
+
|
|
9
|
+
module Github
|
|
10
|
+
# A class responsible for dispatching http requests
|
|
11
|
+
class Request
|
|
12
|
+
include Connection
|
|
13
|
+
|
|
14
|
+
HTTP_METHODS = [:get, :head, :post, :put, :delete, :patch]
|
|
15
|
+
|
|
16
|
+
METHODS_WITH_BODIES = [:post, :put, :patch]
|
|
17
|
+
|
|
18
|
+
# Return http verb
|
|
19
|
+
#
|
|
20
|
+
# @return [Symbol]
|
|
21
|
+
attr_reader :action
|
|
22
|
+
|
|
23
|
+
# Return url
|
|
24
|
+
#
|
|
25
|
+
# @return [String]
|
|
26
|
+
attr_accessor :path
|
|
27
|
+
|
|
28
|
+
# Return api this request is associated with
|
|
29
|
+
#
|
|
30
|
+
# @return [Github::API]
|
|
31
|
+
attr_reader :api
|
|
32
|
+
|
|
33
|
+
# Create a new Request
|
|
34
|
+
#
|
|
35
|
+
# @return [Github::Request]
|
|
36
|
+
#
|
|
37
|
+
# @api public
|
|
38
|
+
def initialize(action, path, api)
|
|
39
|
+
@action = action
|
|
40
|
+
@path = path
|
|
41
|
+
@api = api
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Performs a request
|
|
45
|
+
#
|
|
46
|
+
# @param [Symbol] method - The Symbol the HTTP verb
|
|
47
|
+
# @param [String] path - String relative URL to access
|
|
48
|
+
# @param [ParamsHash] params - ParamsHash to configure the request API
|
|
49
|
+
#
|
|
50
|
+
# @return [Github::ResponseWrapper]
|
|
51
|
+
#
|
|
52
|
+
# @api private
|
|
53
|
+
def call(current_options, params)
|
|
54
|
+
unless HTTP_METHODS.include?(action)
|
|
55
|
+
raise ArgumentError, "unknown http method: #{method}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
puts "EXECUTED: #{action} - #{path} with PARAMS: #{params.request_params}" if ENV['DEBUG']
|
|
59
|
+
|
|
60
|
+
request_options = params.options
|
|
61
|
+
connection_options = current_options.merge(request_options)
|
|
62
|
+
conn = connection(api, connection_options)
|
|
63
|
+
|
|
64
|
+
self.path = Utils::Url.normalize(self.path)
|
|
65
|
+
if conn.path_prefix != '/' && self.path.index(conn.path_prefix) != 0
|
|
66
|
+
self.path = (conn.path_prefix + self.path).gsub(/\/(\/)*/, '/')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
response = conn.send(action) do |request|
|
|
70
|
+
case action.to_sym
|
|
71
|
+
when *(HTTP_METHODS - METHODS_WITH_BODIES)
|
|
72
|
+
request.body = params.data if params.key?('data')
|
|
73
|
+
if params.key?('encoder')
|
|
74
|
+
request.params.params_encoder(params.encoder)
|
|
75
|
+
end
|
|
76
|
+
request.url(self.path, params.request_params)
|
|
77
|
+
when *METHODS_WITH_BODIES
|
|
78
|
+
request.url(self.path, connection_options[:query] || {})
|
|
79
|
+
request.body = params.data unless params.empty?
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
ResponseWrapper.new(response, api)
|
|
83
|
+
end
|
|
84
|
+
end # Request
|
|
85
|
+
end # Github
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
module Github
|
|
7
|
+
class Request
|
|
8
|
+
class BasicAuth < Faraday::Middleware
|
|
9
|
+
dependency 'base64'
|
|
10
|
+
|
|
11
|
+
# @api private
|
|
12
|
+
def initialize(app, *args)
|
|
13
|
+
@app = app
|
|
14
|
+
@auth = nil
|
|
15
|
+
options = args.extract_options!
|
|
16
|
+
|
|
17
|
+
if options.key?(:login) && !options[:login].nil?
|
|
18
|
+
credentials = "#{options[:login]}:#{options[:password]}"
|
|
19
|
+
@auth = Base64.encode64(credentials)
|
|
20
|
+
@auth.gsub!("\n", "")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Update request headers
|
|
25
|
+
#
|
|
26
|
+
# @api private
|
|
27
|
+
def call(env)
|
|
28
|
+
if @auth
|
|
29
|
+
env[:request_headers].merge!('Authorization' => "Basic #{@auth}")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
@app.call(env)
|
|
33
|
+
end
|
|
34
|
+
end # BasicAuth
|
|
35
|
+
end # Request
|
|
36
|
+
end # Github
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Github
|
|
6
|
+
class Request::Jsonize < Faraday::Middleware
|
|
7
|
+
|
|
8
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
|
9
|
+
MIME_TYPE = 'application/json'.freeze
|
|
10
|
+
|
|
11
|
+
dependency 'multi_json'
|
|
12
|
+
|
|
13
|
+
def call(env)
|
|
14
|
+
if request_with_body?(env)
|
|
15
|
+
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
|
16
|
+
env[:body] = encode_body env[:body] unless env[:body].respond_to?(:to_str)
|
|
17
|
+
elsif safe_to_modify?(env)
|
|
18
|
+
# Ensure valid body for put and post requests
|
|
19
|
+
if [:put, :patch, :post].include?(env[:method])
|
|
20
|
+
env[:body] = encode_body({})
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
@app.call env
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def encode_body(value)
|
|
27
|
+
if MultiJson.respond_to?(:dump)
|
|
28
|
+
MultiJson.dump(value)
|
|
29
|
+
else
|
|
30
|
+
MultiJson.encode(value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def request_with_body?(env)
|
|
35
|
+
has_body?(env) and safe_to_modify?(env)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def safe_to_modify?(env)
|
|
39
|
+
type = request_type(env)
|
|
40
|
+
type.empty? or type == MIME_TYPE
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Don't encode bodies in string form
|
|
44
|
+
def has_body?(env)
|
|
45
|
+
body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def request_type(env)
|
|
49
|
+
type = env[:request_headers][CONTENT_TYPE].to_s
|
|
50
|
+
type = type.split(';', 2).first if type.index(';')
|
|
51
|
+
type
|
|
52
|
+
end
|
|
53
|
+
end # Request::Jsonize
|
|
54
|
+
end # Github
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
require_relative '../utils/url'
|
|
6
|
+
|
|
7
|
+
module Github
|
|
8
|
+
class Request
|
|
9
|
+
class OAuth2 < Faraday::Middleware
|
|
10
|
+
include Github::Utils::Url
|
|
11
|
+
|
|
12
|
+
ACCESS_TOKEN = 'access_token'.freeze
|
|
13
|
+
AUTH_HEADER = 'Authorization'.freeze
|
|
14
|
+
|
|
15
|
+
dependency 'oauth2'
|
|
16
|
+
|
|
17
|
+
def call(env)
|
|
18
|
+
# Extract parameters from the query
|
|
19
|
+
params = { ACCESS_TOKEN => @token }.update query_params(env[:url])
|
|
20
|
+
|
|
21
|
+
if token = params[ACCESS_TOKEN] and !token.empty?
|
|
22
|
+
env[:url].query = build_query params
|
|
23
|
+
env[:request_headers].merge!(AUTH_HEADER => "token #{token}")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@app.call env
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def initialize(app, *args)
|
|
30
|
+
super app
|
|
31
|
+
@app = app
|
|
32
|
+
@token = args.shift
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def query_params(url)
|
|
36
|
+
if url.query.nil? or url.query.empty?
|
|
37
|
+
{}
|
|
38
|
+
else
|
|
39
|
+
parse_query url.query
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end # OAuth2
|
|
43
|
+
end # Request
|
|
44
|
+
end # Github
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../request'
|
|
4
|
+
require_relative '../params_hash'
|
|
5
|
+
|
|
6
|
+
module Github
|
|
7
|
+
# A class responsible for dispatching http requests
|
|
8
|
+
class Request
|
|
9
|
+
|
|
10
|
+
# Defines HTTP verbs
|
|
11
|
+
module Verbs
|
|
12
|
+
# Make a head request
|
|
13
|
+
#
|
|
14
|
+
# @api public
|
|
15
|
+
def head_request(path, params = ParamsHash.empty)
|
|
16
|
+
Request.new(:head, path, self).call(current_options, params)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Make a get request
|
|
20
|
+
#
|
|
21
|
+
# @api public
|
|
22
|
+
def get_request(path, params = ParamsHash.empty)
|
|
23
|
+
request = Request.new(:get, path, self).call(current_options, params)
|
|
24
|
+
request.auto_paginate
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Make a patch request
|
|
28
|
+
#
|
|
29
|
+
# @api public
|
|
30
|
+
def patch_request(path, params = ParamsHash.empty)
|
|
31
|
+
Request.new(:patch, path, self).call(current_options, params)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Make a post request
|
|
35
|
+
#
|
|
36
|
+
# @api public
|
|
37
|
+
def post_request(path, params = ParamsHash.empty)
|
|
38
|
+
Request.new(:post, path, self).call(current_options, params)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Make a put request
|
|
42
|
+
#
|
|
43
|
+
# @api public
|
|
44
|
+
def put_request(path, params = ParamsHash.empty)
|
|
45
|
+
Request.new(:put, path, self).call(current_options, params)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Make a delete request
|
|
49
|
+
#
|
|
50
|
+
# @api public
|
|
51
|
+
def delete_request(path, params = ParamsHash.empty)
|
|
52
|
+
Request.new(:delete, path, self).call(current_options, params)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Make a options request
|
|
56
|
+
#
|
|
57
|
+
# @api public
|
|
58
|
+
def options_request(path, params = ParamsHash.empty)
|
|
59
|
+
Request.new(:options, path, self).call(current_options, params)
|
|
60
|
+
end
|
|
61
|
+
end # Verbs
|
|
62
|
+
end # Request
|
|
63
|
+
end # Github
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Github
|
|
6
|
+
# Contains methods and attributes that act on the response returned from the
|
|
7
|
+
# request
|
|
8
|
+
class Response < Faraday::Response::Middleware
|
|
9
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
attr_accessor :parser
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.define_parser(&block)
|
|
16
|
+
@parser = block
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize(app, options = {})
|
|
20
|
+
super(app)
|
|
21
|
+
@content_types = Array(options[:content_type])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def process_body(env)
|
|
25
|
+
env[:body] = parse(env[:body])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def parse_body?(env)
|
|
29
|
+
parse_response_type?(response_type(env)) and parse_response?(env)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def response_type(env)
|
|
33
|
+
type = env[:response_headers][CONTENT_TYPE].to_s
|
|
34
|
+
type = type.split(';', 2).first if type.index(';')
|
|
35
|
+
type
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def parse_response_type?(type)
|
|
39
|
+
@content_types.empty? || @content_types.any? { |pattern|
|
|
40
|
+
pattern.is_a?(Regexp) ? type =~ pattern : type == pattern
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def parse_response?(env)
|
|
45
|
+
env[:body].respond_to?(:to_str)
|
|
46
|
+
end
|
|
47
|
+
end # Response
|
|
48
|
+
end # Github
|