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.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +741 -0
  4. data/lib/github_api.rb +93 -0
  5. data/lib/github_api/api.rb +398 -0
  6. data/lib/github_api/api/actions.rb +60 -0
  7. data/lib/github_api/api/arguments.rb +253 -0
  8. data/lib/github_api/api/config.rb +105 -0
  9. data/lib/github_api/api/config/property.rb +30 -0
  10. data/lib/github_api/api/config/property_set.rb +120 -0
  11. data/lib/github_api/api/factory.rb +33 -0
  12. data/lib/github_api/authorization.rb +75 -0
  13. data/lib/github_api/client.rb +77 -0
  14. data/lib/github_api/client/activity.rb +31 -0
  15. data/lib/github_api/client/activity/events.rb +233 -0
  16. data/lib/github_api/client/activity/feeds.rb +50 -0
  17. data/lib/github_api/client/activity/notifications.rb +181 -0
  18. data/lib/github_api/client/activity/starring.rb +130 -0
  19. data/lib/github_api/client/activity/watching.rb +176 -0
  20. data/lib/github_api/client/authorizations.rb +142 -0
  21. data/lib/github_api/client/authorizations/app.rb +98 -0
  22. data/lib/github_api/client/emojis.rb +19 -0
  23. data/lib/github_api/client/gists.rb +289 -0
  24. data/lib/github_api/client/gists/comments.rb +100 -0
  25. data/lib/github_api/client/git_data.rb +31 -0
  26. data/lib/github_api/client/git_data/blobs.rb +51 -0
  27. data/lib/github_api/client/git_data/commits.rb +101 -0
  28. data/lib/github_api/client/git_data/references.rb +150 -0
  29. data/lib/github_api/client/git_data/tags.rb +95 -0
  30. data/lib/github_api/client/git_data/trees.rb +113 -0
  31. data/lib/github_api/client/gitignore.rb +57 -0
  32. data/lib/github_api/client/issues.rb +248 -0
  33. data/lib/github_api/client/issues/assignees.rb +77 -0
  34. data/lib/github_api/client/issues/comments.rb +146 -0
  35. data/lib/github_api/client/issues/events.rb +50 -0
  36. data/lib/github_api/client/issues/labels.rb +189 -0
  37. data/lib/github_api/client/issues/milestones.rb +146 -0
  38. data/lib/github_api/client/markdown.rb +62 -0
  39. data/lib/github_api/client/meta.rb +19 -0
  40. data/lib/github_api/client/orgs.rb +127 -0
  41. data/lib/github_api/client/orgs/hooks.rb +182 -0
  42. data/lib/github_api/client/orgs/members.rb +142 -0
  43. data/lib/github_api/client/orgs/memberships.rb +131 -0
  44. data/lib/github_api/client/orgs/projects.rb +57 -0
  45. data/lib/github_api/client/orgs/teams.rb +407 -0
  46. data/lib/github_api/client/projects.rb +83 -0
  47. data/lib/github_api/client/projects/cards.rb +158 -0
  48. data/lib/github_api/client/projects/columns.rb +146 -0
  49. data/lib/github_api/client/pull_requests.rb +195 -0
  50. data/lib/github_api/client/pull_requests/comments.rb +140 -0
  51. data/lib/github_api/client/pull_requests/reviews.rb +158 -0
  52. data/lib/github_api/client/repos.rb +468 -0
  53. data/lib/github_api/client/repos/branches.rb +48 -0
  54. data/lib/github_api/client/repos/branches/protections.rb +75 -0
  55. data/lib/github_api/client/repos/collaborators.rb +84 -0
  56. data/lib/github_api/client/repos/comments.rb +125 -0
  57. data/lib/github_api/client/repos/commits.rb +80 -0
  58. data/lib/github_api/client/repos/contents.rb +246 -0
  59. data/lib/github_api/client/repos/deployments.rb +138 -0
  60. data/lib/github_api/client/repos/downloads.rb +62 -0
  61. data/lib/github_api/client/repos/forks.rb +48 -0
  62. data/lib/github_api/client/repos/hooks.rb +214 -0
  63. data/lib/github_api/client/repos/keys.rb +104 -0
  64. data/lib/github_api/client/repos/merging.rb +47 -0
  65. data/lib/github_api/client/repos/pages.rb +48 -0
  66. data/lib/github_api/client/repos/projects.rb +62 -0
  67. data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
  68. data/lib/github_api/client/repos/releases.rb +189 -0
  69. data/lib/github_api/client/repos/releases/assets.rb +136 -0
  70. data/lib/github_api/client/repos/releases/tags.rb +24 -0
  71. data/lib/github_api/client/repos/statistics.rb +89 -0
  72. data/lib/github_api/client/repos/statuses.rb +91 -0
  73. data/lib/github_api/client/say.rb +25 -0
  74. data/lib/github_api/client/scopes.rb +46 -0
  75. data/lib/github_api/client/search.rb +133 -0
  76. data/lib/github_api/client/search/legacy.rb +111 -0
  77. data/lib/github_api/client/users.rb +117 -0
  78. data/lib/github_api/client/users/emails.rb +65 -0
  79. data/lib/github_api/client/users/followers.rb +115 -0
  80. data/lib/github_api/client/users/keys.rb +104 -0
  81. data/lib/github_api/configuration.rb +70 -0
  82. data/lib/github_api/connection.rb +82 -0
  83. data/lib/github_api/constants.rb +61 -0
  84. data/lib/github_api/core_ext/array.rb +25 -0
  85. data/lib/github_api/core_ext/hash.rb +91 -0
  86. data/lib/github_api/core_ext/ordered_hash.rb +107 -0
  87. data/lib/github_api/deprecation.rb +39 -0
  88. data/lib/github_api/error.rb +32 -0
  89. data/lib/github_api/error/client_error.rb +89 -0
  90. data/lib/github_api/error/service_error.rb +223 -0
  91. data/lib/github_api/ext/faraday.rb +38 -0
  92. data/lib/github_api/mash.rb +7 -0
  93. data/lib/github_api/middleware.rb +37 -0
  94. data/lib/github_api/mime_type.rb +33 -0
  95. data/lib/github_api/normalizer.rb +23 -0
  96. data/lib/github_api/null_encoder.rb +25 -0
  97. data/lib/github_api/page_iterator.rb +138 -0
  98. data/lib/github_api/page_links.rb +63 -0
  99. data/lib/github_api/paged_request.rb +42 -0
  100. data/lib/github_api/pagination.rb +115 -0
  101. data/lib/github_api/parameter_filter.rb +35 -0
  102. data/lib/github_api/params_hash.rb +115 -0
  103. data/lib/github_api/rate_limit.rb +25 -0
  104. data/lib/github_api/request.rb +85 -0
  105. data/lib/github_api/request/basic_auth.rb +36 -0
  106. data/lib/github_api/request/jsonize.rb +54 -0
  107. data/lib/github_api/request/oauth2.rb +44 -0
  108. data/lib/github_api/request/verbs.rb +63 -0
  109. data/lib/github_api/response.rb +48 -0
  110. data/lib/github_api/response/atom_parser.rb +22 -0
  111. data/lib/github_api/response/follow_redirects.rb +140 -0
  112. data/lib/github_api/response/header.rb +87 -0
  113. data/lib/github_api/response/jsonize.rb +28 -0
  114. data/lib/github_api/response/mashify.rb +24 -0
  115. data/lib/github_api/response/raise_error.rb +22 -0
  116. data/lib/github_api/response/xmlize.rb +27 -0
  117. data/lib/github_api/response_wrapper.rb +161 -0
  118. data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api/utils/url.rb +63 -0
  120. data/lib/github_api/validations.rb +22 -0
  121. data/lib/github_api/validations/format.rb +26 -0
  122. data/lib/github_api/validations/presence.rb +32 -0
  123. data/lib/github_api/validations/required.rb +21 -0
  124. data/lib/github_api/validations/token.rb +41 -0
  125. data/lib/github_api/version.rb +5 -0
  126. metadata +338 -0
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ # Responsible for providing inspection of api methods
5
+ class API
6
+ # Returns all API public methods for a given class.
7
+ #
8
+ # @return [nil]
9
+ #
10
+ # @api public
11
+ def self.extend_with_actions(child_class)
12
+ return unless child_class.is_a?(Class)
13
+ return if child_class.name.nil? # Skip anonymous classes
14
+
15
+ child_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
16
+ def self.actions
17
+ self.new.actions
18
+ end
19
+
20
+ def actions
21
+ api_methods_in(#{child_class}) + module_methods_in(#{child_class})
22
+ end
23
+ RUBY_EVAL
24
+ end
25
+
26
+ # Finds api methods in a class
27
+ #
28
+ # @param [Class] klass
29
+ # The klass to inspect for methods.
30
+ #
31
+ # @api private
32
+ def api_methods_in(klass)
33
+ methods = klass.send(:instance_methods, false) - [:actions]
34
+ methods.sort.each_with_object([]) do |method_name, accumulator|
35
+ unless method_name.to_s.include?('with') ||
36
+ method_name.to_s.include?('without')
37
+ accumulator << method_name
38
+ end
39
+ accumulator
40
+ end
41
+ end
42
+
43
+ # Finds methods included through class modules
44
+ #
45
+ # @param [Class] klass
46
+ # The klass to inspect for methods.
47
+ #
48
+ # @api private
49
+ def module_methods_in(klass)
50
+ klass.included_modules.each_with_object([]) do |mod, accumulator|
51
+ if mod.to_s =~ /#{klass}/
52
+ mod.instance_methods(false).each do |method|
53
+ accumulator << method
54
+ end
55
+ end
56
+ accumulator
57
+ end
58
+ end
59
+ end # API
60
+ end # Github
@@ -0,0 +1,253 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../normalizer'
4
+ require_relative '../parameter_filter'
5
+ require_relative '../params_hash'
6
+ require_relative '../validations'
7
+
8
+ module Github
9
+ class API
10
+ # A class responsible for handilng request arguments
11
+ class Arguments
12
+ include Normalizer
13
+ include ParameterFilter
14
+ include Validations
15
+
16
+ AUTO_PAGINATION = 'auto_pagination'.freeze
17
+
18
+ # Parameters passed to request
19
+ attr_reader :params
20
+
21
+ # The remaining unparsed arguments
22
+ attr_reader :remaining
23
+
24
+ # The request api
25
+ attr_reader :api
26
+
27
+ # Initialize an Arguments
28
+ #
29
+ # @param [Hash] options
30
+ #
31
+ # @option options [Array[String]] :required
32
+ # arguments that must be present before request is fired
33
+ #
34
+ # @option options [Github::API] :api
35
+ # the reference to the current api
36
+ #
37
+ # @api public
38
+ def initialize(options = {}, &block)
39
+ normalize! options
40
+
41
+ @api = options.fetch('api')
42
+ @required = options.fetch('required', []).map(&:to_s)
43
+ @optional = options.fetch('optional', []).map(&:to_s)
44
+ @assigns = {}
45
+
46
+ yield_or_eval(&block)
47
+ end
48
+
49
+ # Specify required attribute(s)
50
+ #
51
+ # @api public
52
+ def require(*attrs, &block)
53
+ attrs_clone = attrs.clone
54
+ @required = Array(attrs_clone)
55
+ self
56
+ end
57
+ alias :required :require
58
+
59
+ # Specify optional attribute(s)
60
+ #
61
+ # @api public
62
+ def optional(*attrs, &block)
63
+ end
64
+
65
+ # Hash like access to request arguments
66
+ #
67
+ # @param [String, Symbol] property
68
+ # the property name
69
+ #
70
+ # @api public
71
+ def [](property)
72
+ @assigns[property.to_s]
73
+ end
74
+
75
+ def []=(property, value)
76
+ @assigns[property.to_s] = value
77
+ end
78
+
79
+ def method_missing(method_name, *args, &block)
80
+ if @assigns.key?(method_name.to_s)
81
+ self[method_name]
82
+ else
83
+ super
84
+ end
85
+ end
86
+
87
+ def respond_to_missing?(method_name, include_private = false)
88
+ @assigns.key?(method_name) || super
89
+ end
90
+
91
+ # Parse arguments to allow for flexible api calls
92
+ #
93
+ # Arguments can be part of parameters hash or be simple string arguments.
94
+ #
95
+ # @api public
96
+ def parse(*args, &block)
97
+ options = ParamsHash.new(args.extract_options!)
98
+ normalize! options
99
+
100
+ if args.size.zero? # Arguments are inside the parameters hash
101
+ parse_hash(options)
102
+ else
103
+ parse_array(*args)
104
+ end
105
+ @params = options
106
+ @remaining = args[@required.size..-1]
107
+ extract_pagination(options)
108
+
109
+ yield_or_eval(&block)
110
+ self
111
+ end
112
+
113
+ # Remove unknown keys from parameters hash.
114
+ #
115
+ # = Parameters
116
+ # :recursive - boolean that toggles whether nested filtering should be applied
117
+ #
118
+ def permit(keys, key=nil, options={})
119
+ filter! keys, (key.nil? ? params : params[key]), options if keys.any?
120
+ self
121
+ end
122
+
123
+ # Check if required keys are present inside parameters hash.
124
+ #
125
+ # @api public
126
+ def assert_required(*required)
127
+ assert_required_keys(required, params)
128
+ self
129
+ end
130
+
131
+ # Check if parameters match expected values.
132
+ #
133
+ # @api public
134
+ def assert_values(values, key=nil)
135
+ assert_valid_values values, (key.nil? ? params : params[key])
136
+ self
137
+ end
138
+
139
+ private
140
+
141
+ # Parse array arguments and assign in order to required properties
142
+ #
143
+ # @param [Array[Object]] args
144
+ #
145
+ # @raise ArgumentError
146
+ #
147
+ # @return [nil]
148
+ #
149
+ # @api public
150
+ def parse_array(*args)
151
+ assert_presence_of(*args)
152
+ @required.each_with_index do |req, indx|
153
+ @assigns[req] = args[indx]
154
+ end
155
+ check_requirement!(*args)
156
+ end
157
+
158
+ # Remove required arguments from parameters and
159
+ # validate their presence(if not nil or empty string).
160
+ #
161
+ # @param [Hash[String]] options
162
+ #
163
+ # @return [nil]
164
+ #
165
+ # @api private
166
+ def parse_hash(options)
167
+ options.each { |key, val| remove_required(options, key, val) }
168
+ hash = update_required_from_global
169
+ check_requirement!(*hash.keys)
170
+ end
171
+
172
+ # Remove required property from hash
173
+ #
174
+ # @param [Hash[String]] options
175
+ # the options to check
176
+ #
177
+ # @param [String] key
178
+ # the key to remove
179
+ #
180
+ # @param [String] val
181
+ # the value to assign
182
+ #
183
+ # @api private
184
+ def remove_required(options, key, val)
185
+ if @required.include?(key.to_s)
186
+ assert_presence_of(val)
187
+ options.delete(key)
188
+ @assigns[key.to_s] = val
189
+ end
190
+ end
191
+
192
+ # Update required property from globals if not present
193
+ #
194
+ # @return [Hash[String]]
195
+ #
196
+ # @api private
197
+ def update_required_from_global
198
+ @required.reduce({}) do |hash, property|
199
+ if @assigns.key?(property)
200
+ hash[property] = self[property]
201
+ elsif api_property?(property)
202
+ hash[property] = api.send(:"#{property}")
203
+ self[property] = hash[property]
204
+ end
205
+ hash
206
+ end
207
+ end
208
+
209
+ # Check if api has non-empty property
210
+ #
211
+ # @param [String] property
212
+ # the property to check
213
+ #
214
+ # @return [Boolean]
215
+ #
216
+ # @api private
217
+ def api_property?(property)
218
+ api.respond_to?(:"#{property}") && api.send(:"#{property}")
219
+ end
220
+
221
+ # Check if required arguments are present.
222
+ #
223
+ #
224
+ def check_requirement!(*args)
225
+ args_length = args.length
226
+ required_length = @required.length
227
+
228
+ if args_length < required_length
229
+ raise ArgumentError, "Wrong number of arguments " \
230
+ "(#{args_length} for #{required_length}). " \
231
+ "Expected `#{@required.join(', ')}` as required arguments, " \
232
+ "but got `#{args.join(", ")}`."
233
+ end
234
+ end
235
+
236
+ # Find auto_pagination parameter in options hash
237
+ #
238
+ def extract_pagination(options)
239
+ if (value = options.delete(AUTO_PAGINATION))
240
+ api.auto_pagination = value
241
+ end
242
+ end
243
+
244
+ # Evaluate a block
245
+ #
246
+ # @api privte
247
+ def yield_or_eval(&block)
248
+ return unless block
249
+ block.arity > 0 ? yield(self) : instance_eval(&block)
250
+ end
251
+ end # Arguments
252
+ end # Api
253
+ end # Github
@@ -0,0 +1,105 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'config/property'
4
+ require_relative 'config/property_set'
5
+
6
+ module Github
7
+ class API
8
+ # A base class for constructing api configuration
9
+ class Config
10
+ # Defines a property on an object's class or instance
11
+ #
12
+ # @example
13
+ # class Configuration < Api::Config
14
+ # property :adapter, default: :net_http
15
+ # property :user, required: true
16
+ # end
17
+ #
18
+ # @param [Symbol] name
19
+ # the name of a property
20
+ #
21
+ # @param [#to_hash] options
22
+ # the extra options
23
+ #
24
+ # @return [self]
25
+ #
26
+ # @api public
27
+ def self.property(name, options = {})
28
+ self.property_set << Property.new(name, options)
29
+ update_subclasses(name, options)
30
+ self
31
+ end
32
+
33
+ def self.update_subclasses(name, options)
34
+ if defined?(@subclasses) && @subclasses
35
+ @subclasses.each { |klass| klass.property(name, options) }
36
+ end
37
+ end
38
+
39
+ # Check if property is defined
40
+ #
41
+ # @param [Symbol] name
42
+ # the name to check
43
+ #
44
+ # @return [Boolean]
45
+ #
46
+ # @api public
47
+ def self.property?(name)
48
+ property_set.include?(name)
49
+ end
50
+
51
+ class << self
52
+ attr_reader :property_set
53
+ end
54
+
55
+ instance_variable_set("@property_set", PropertySet.new(self))
56
+
57
+ def self.inherited(descendant)
58
+ super
59
+ (@subclasses ||= Set.new) << descendant
60
+ descendant.instance_variable_set('@property_set',
61
+ PropertySet.new(descendant, self.property_set.properties.dup))
62
+ end
63
+
64
+ def initialize(&block)
65
+ super(&block)
66
+ end
67
+
68
+ def property_names
69
+ self.class.property_set.properties.map(&:name)
70
+ end
71
+
72
+ def self.property_names
73
+ property_set.properties.map(&:name)
74
+ end
75
+
76
+ # Fetach all the properties and their values
77
+ #
78
+ # @return [Hash[Symbol]]
79
+ #
80
+ # @api public
81
+ def fetch(value = nil)
82
+ if value
83
+ self.class.property_set[value]
84
+ else
85
+ self.class.property_set.to_hash
86
+ end
87
+ end
88
+
89
+ # Provide access to properties
90
+ #
91
+ # @example
92
+ # config.call do |config|
93
+ # config.adapter = :net_http
94
+ # end
95
+ #
96
+ # @return [self]
97
+ #
98
+ # @api private
99
+ def call(&block)
100
+ block.call(self) if block_given?
101
+ self
102
+ end
103
+ end # Config
104
+ end # Api
105
+ end # Github
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class API
5
+ class Config
6
+
7
+ # Property objects provide an interface for configuration options
8
+ class Property
9
+
10
+ attr_reader :name
11
+ attr_reader :default
12
+ attr_reader :required
13
+
14
+ def initialize(name, options)
15
+ @name = name
16
+ @default = options.fetch(:default, nil)
17
+ @required = options.fetch(:required, nil)
18
+ @options = options
19
+ end
20
+
21
+ # @api private
22
+ def define_accessor_methods(properties)
23
+ properties.define_reader_method(self, self.name, :public)
24
+ properties.define_writer_method(self, "#{self.name}=", :public)
25
+ end
26
+ end # Property
27
+
28
+ end # Config
29
+ end # Api
30
+ end # Github