github_api2 1.0.0
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/CHANGELOG.md +770 -0
- data/LICENSE.txt +20 -0
- data/README.md +741 -0
- data/lib/github_api2/api/actions.rb +60 -0
- data/lib/github_api2/api/arguments.rb +253 -0
- data/lib/github_api2/api/config/property.rb +30 -0
- data/lib/github_api2/api/config/property_set.rb +120 -0
- data/lib/github_api2/api/config.rb +105 -0
- data/lib/github_api2/api/factory.rb +33 -0
- data/lib/github_api2/api.rb +398 -0
- data/lib/github_api2/authorization.rb +75 -0
- data/lib/github_api2/client/activity/events.rb +233 -0
- data/lib/github_api2/client/activity/feeds.rb +50 -0
- data/lib/github_api2/client/activity/notifications.rb +181 -0
- data/lib/github_api2/client/activity/starring.rb +130 -0
- data/lib/github_api2/client/activity/watching.rb +176 -0
- data/lib/github_api2/client/activity.rb +31 -0
- data/lib/github_api2/client/authorizations/app.rb +98 -0
- data/lib/github_api2/client/authorizations.rb +142 -0
- data/lib/github_api2/client/emojis.rb +19 -0
- data/lib/github_api2/client/gists/comments.rb +100 -0
- data/lib/github_api2/client/gists.rb +289 -0
- data/lib/github_api2/client/git_data/blobs.rb +51 -0
- data/lib/github_api2/client/git_data/commits.rb +101 -0
- data/lib/github_api2/client/git_data/references.rb +150 -0
- data/lib/github_api2/client/git_data/tags.rb +95 -0
- data/lib/github_api2/client/git_data/trees.rb +113 -0
- data/lib/github_api2/client/git_data.rb +31 -0
- data/lib/github_api2/client/gitignore.rb +57 -0
- data/lib/github_api2/client/issues/assignees.rb +77 -0
- data/lib/github_api2/client/issues/comments.rb +146 -0
- data/lib/github_api2/client/issues/events.rb +50 -0
- data/lib/github_api2/client/issues/labels.rb +189 -0
- data/lib/github_api2/client/issues/milestones.rb +146 -0
- data/lib/github_api2/client/issues.rb +248 -0
- data/lib/github_api2/client/markdown.rb +62 -0
- data/lib/github_api2/client/meta.rb +19 -0
- data/lib/github_api2/client/orgs/hooks.rb +182 -0
- data/lib/github_api2/client/orgs/members.rb +142 -0
- data/lib/github_api2/client/orgs/memberships.rb +131 -0
- data/lib/github_api2/client/orgs/projects.rb +57 -0
- data/lib/github_api2/client/orgs/teams.rb +407 -0
- data/lib/github_api2/client/orgs.rb +127 -0
- data/lib/github_api2/client/projects/cards.rb +158 -0
- data/lib/github_api2/client/projects/columns.rb +146 -0
- data/lib/github_api2/client/projects.rb +83 -0
- data/lib/github_api2/client/pull_requests/comments.rb +140 -0
- data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
- data/lib/github_api2/client/pull_requests.rb +195 -0
- data/lib/github_api2/client/repos/branches/protections.rb +75 -0
- data/lib/github_api2/client/repos/branches.rb +48 -0
- data/lib/github_api2/client/repos/collaborators.rb +84 -0
- data/lib/github_api2/client/repos/comments.rb +125 -0
- data/lib/github_api2/client/repos/commits.rb +80 -0
- data/lib/github_api2/client/repos/contents.rb +263 -0
- data/lib/github_api2/client/repos/deployments.rb +138 -0
- data/lib/github_api2/client/repos/downloads.rb +62 -0
- data/lib/github_api2/client/repos/forks.rb +50 -0
- data/lib/github_api2/client/repos/hooks.rb +214 -0
- data/lib/github_api2/client/repos/invitations.rb +41 -0
- data/lib/github_api2/client/repos/keys.rb +104 -0
- data/lib/github_api2/client/repos/merging.rb +47 -0
- data/lib/github_api2/client/repos/pages.rb +48 -0
- data/lib/github_api2/client/repos/projects.rb +62 -0
- data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
- data/lib/github_api2/client/repos/releases/assets.rb +136 -0
- data/lib/github_api2/client/repos/releases/tags.rb +24 -0
- data/lib/github_api2/client/repos/releases.rb +189 -0
- data/lib/github_api2/client/repos/statistics.rb +89 -0
- data/lib/github_api2/client/repos/statuses.rb +91 -0
- data/lib/github_api2/client/repos.rb +473 -0
- data/lib/github_api2/client/say.rb +25 -0
- data/lib/github_api2/client/scopes.rb +46 -0
- data/lib/github_api2/client/search/legacy.rb +111 -0
- data/lib/github_api2/client/search.rb +133 -0
- data/lib/github_api2/client/users/emails.rb +65 -0
- data/lib/github_api2/client/users/followers.rb +115 -0
- data/lib/github_api2/client/users/keys.rb +104 -0
- data/lib/github_api2/client/users.rb +117 -0
- data/lib/github_api2/client.rb +77 -0
- data/lib/github_api2/configuration.rb +70 -0
- data/lib/github_api2/connection.rb +82 -0
- data/lib/github_api2/constants.rb +61 -0
- data/lib/github_api2/core_ext/array.rb +25 -0
- data/lib/github_api2/core_ext/hash.rb +91 -0
- data/lib/github_api2/deprecation.rb +39 -0
- data/lib/github_api2/error/client_error.rb +89 -0
- data/lib/github_api2/error/service_error.rb +223 -0
- data/lib/github_api2/error.rb +32 -0
- data/lib/github_api2/ext/faraday.rb +40 -0
- data/lib/github_api2/mash.rb +7 -0
- data/lib/github_api2/middleware.rb +37 -0
- data/lib/github_api2/mime_type.rb +33 -0
- data/lib/github_api2/normalizer.rb +23 -0
- data/lib/github_api2/null_encoder.rb +25 -0
- data/lib/github_api2/page_iterator.rb +138 -0
- data/lib/github_api2/page_links.rb +63 -0
- data/lib/github_api2/paged_request.rb +42 -0
- data/lib/github_api2/pagination.rb +115 -0
- data/lib/github_api2/parameter_filter.rb +35 -0
- data/lib/github_api2/params_hash.rb +115 -0
- data/lib/github_api2/rate_limit.rb +25 -0
- data/lib/github_api2/request/basic_auth.rb +36 -0
- data/lib/github_api2/request/jsonize.rb +54 -0
- data/lib/github_api2/request/oauth2.rb +45 -0
- data/lib/github_api2/request/verbs.rb +63 -0
- data/lib/github_api2/request.rb +84 -0
- data/lib/github_api2/response/atom_parser.rb +22 -0
- data/lib/github_api2/response/follow_redirects.rb +140 -0
- data/lib/github_api2/response/header.rb +87 -0
- data/lib/github_api2/response/jsonize.rb +28 -0
- data/lib/github_api2/response/mashify.rb +24 -0
- data/lib/github_api2/response/raise_error.rb +22 -0
- data/lib/github_api2/response/xmlize.rb +28 -0
- data/lib/github_api2/response.rb +48 -0
- data/lib/github_api2/response_wrapper.rb +161 -0
- data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api2/utils/url.rb +63 -0
- data/lib/github_api2/validations/format.rb +26 -0
- data/lib/github_api2/validations/presence.rb +32 -0
- data/lib/github_api2/validations/required.rb +21 -0
- data/lib/github_api2/validations/token.rb +41 -0
- data/lib/github_api2/validations.rb +22 -0
- data/lib/github_api2/version.rb +5 -0
- data/lib/github_api2.rb +92 -0
- metadata +363 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
require_relative 'pagination'
|
|
6
|
+
|
|
7
|
+
module Github
|
|
8
|
+
# A class responsible for proxing to faraday response
|
|
9
|
+
class ResponseWrapper
|
|
10
|
+
extend Forwardable
|
|
11
|
+
include Pagination
|
|
12
|
+
include Enumerable
|
|
13
|
+
|
|
14
|
+
attr_reader :response
|
|
15
|
+
|
|
16
|
+
attr_reader :current_api
|
|
17
|
+
|
|
18
|
+
attr_reader :env
|
|
19
|
+
|
|
20
|
+
def_delegators :body, :empty?, :size, :include?, :length, :to_a, :first, :flatten, :include?, :keys, :[]
|
|
21
|
+
|
|
22
|
+
def initialize(response, current_api)
|
|
23
|
+
@response = response
|
|
24
|
+
@current_api = current_api
|
|
25
|
+
@env = response.env
|
|
26
|
+
@body = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Overwrite methods to hash keys
|
|
30
|
+
#
|
|
31
|
+
['id', 'type', 'fork'].each do |method_name|
|
|
32
|
+
define_method(method_name) do
|
|
33
|
+
self.body.fetch(method_name.to_s)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Request url
|
|
38
|
+
#
|
|
39
|
+
def url
|
|
40
|
+
response.env[:url].to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def body=(value)
|
|
44
|
+
@body = value
|
|
45
|
+
@env[:body] = value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Response raw body
|
|
49
|
+
#
|
|
50
|
+
def body
|
|
51
|
+
@body ? @body : response.body
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Response status
|
|
55
|
+
#
|
|
56
|
+
def status
|
|
57
|
+
response.status
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def success?
|
|
61
|
+
response.success?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def redirect?
|
|
65
|
+
status.to_i >= 300 && status.to_i < 400
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def client_error?
|
|
69
|
+
status.to_i >= 400 && status.to_i < 500
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def server_error?
|
|
73
|
+
status.to_i >= 500 && status.to_i < 600
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Return response headers
|
|
77
|
+
#
|
|
78
|
+
def headers
|
|
79
|
+
Github::Response::Header.new(env)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Lookup an attribute from the body if hash, otherwise behave like array index.
|
|
83
|
+
# Convert any key to string before calling.
|
|
84
|
+
#
|
|
85
|
+
def [](key)
|
|
86
|
+
if self.body.is_a?(Array)
|
|
87
|
+
self.body[key]
|
|
88
|
+
else
|
|
89
|
+
self.body.send(:"#{key}")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Return response body as string
|
|
94
|
+
#
|
|
95
|
+
def to_s
|
|
96
|
+
body.to_s
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Convert the ResponseWrapper into a Hash
|
|
100
|
+
#
|
|
101
|
+
def to_hash
|
|
102
|
+
body.to_hash
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Convert the ResponseWrapper into an Array
|
|
106
|
+
#
|
|
107
|
+
def to_ary
|
|
108
|
+
body.to_ary
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Iterate over each resource inside the body
|
|
112
|
+
#
|
|
113
|
+
def each
|
|
114
|
+
body_parts = self.body.respond_to?(:each) ? self.body : [self.body]
|
|
115
|
+
return body_parts.to_enum unless block_given?
|
|
116
|
+
body_parts.each { |part| yield(part) }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Check if body has an attribute
|
|
120
|
+
#
|
|
121
|
+
def has_key?(key)
|
|
122
|
+
self.body.is_a?(Hash) && self.body.has_key?(key)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Coerce any method calls for body attributes
|
|
126
|
+
#
|
|
127
|
+
def method_missing(method_name, *args, &block)
|
|
128
|
+
if self.has_key?(method_name.to_s)
|
|
129
|
+
self.[](method_name, &block)
|
|
130
|
+
else
|
|
131
|
+
super
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Check if method is defined on the body
|
|
136
|
+
#
|
|
137
|
+
def respond_to?(method_name, include_all = false)
|
|
138
|
+
if self.has_key?(method_name.to_s)
|
|
139
|
+
true
|
|
140
|
+
else
|
|
141
|
+
super
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Print only response body
|
|
146
|
+
#
|
|
147
|
+
def inspect
|
|
148
|
+
"#<#{self.class.name} @body=\"#{self.body}\">"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Compare the wrapper with other wrapper for equality
|
|
152
|
+
#
|
|
153
|
+
def ==(other)
|
|
154
|
+
return false unless other.is_a?(self.class)
|
|
155
|
+
return false unless (other.respond_to?(:env) && other.respond_to?(:body))
|
|
156
|
+
self.env == other.env && self.body == other.body
|
|
157
|
+
end
|
|
158
|
+
alias eql? ==
|
|
159
|
+
|
|
160
|
+
end # ResponseWrapper
|
|
161
|
+
end # Github
|