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.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +770 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +741 -0
  5. data/lib/github_api2/api/actions.rb +60 -0
  6. data/lib/github_api2/api/arguments.rb +253 -0
  7. data/lib/github_api2/api/config/property.rb +30 -0
  8. data/lib/github_api2/api/config/property_set.rb +120 -0
  9. data/lib/github_api2/api/config.rb +105 -0
  10. data/lib/github_api2/api/factory.rb +33 -0
  11. data/lib/github_api2/api.rb +398 -0
  12. data/lib/github_api2/authorization.rb +75 -0
  13. data/lib/github_api2/client/activity/events.rb +233 -0
  14. data/lib/github_api2/client/activity/feeds.rb +50 -0
  15. data/lib/github_api2/client/activity/notifications.rb +181 -0
  16. data/lib/github_api2/client/activity/starring.rb +130 -0
  17. data/lib/github_api2/client/activity/watching.rb +176 -0
  18. data/lib/github_api2/client/activity.rb +31 -0
  19. data/lib/github_api2/client/authorizations/app.rb +98 -0
  20. data/lib/github_api2/client/authorizations.rb +142 -0
  21. data/lib/github_api2/client/emojis.rb +19 -0
  22. data/lib/github_api2/client/gists/comments.rb +100 -0
  23. data/lib/github_api2/client/gists.rb +289 -0
  24. data/lib/github_api2/client/git_data/blobs.rb +51 -0
  25. data/lib/github_api2/client/git_data/commits.rb +101 -0
  26. data/lib/github_api2/client/git_data/references.rb +150 -0
  27. data/lib/github_api2/client/git_data/tags.rb +95 -0
  28. data/lib/github_api2/client/git_data/trees.rb +113 -0
  29. data/lib/github_api2/client/git_data.rb +31 -0
  30. data/lib/github_api2/client/gitignore.rb +57 -0
  31. data/lib/github_api2/client/issues/assignees.rb +77 -0
  32. data/lib/github_api2/client/issues/comments.rb +146 -0
  33. data/lib/github_api2/client/issues/events.rb +50 -0
  34. data/lib/github_api2/client/issues/labels.rb +189 -0
  35. data/lib/github_api2/client/issues/milestones.rb +146 -0
  36. data/lib/github_api2/client/issues.rb +248 -0
  37. data/lib/github_api2/client/markdown.rb +62 -0
  38. data/lib/github_api2/client/meta.rb +19 -0
  39. data/lib/github_api2/client/orgs/hooks.rb +182 -0
  40. data/lib/github_api2/client/orgs/members.rb +142 -0
  41. data/lib/github_api2/client/orgs/memberships.rb +131 -0
  42. data/lib/github_api2/client/orgs/projects.rb +57 -0
  43. data/lib/github_api2/client/orgs/teams.rb +407 -0
  44. data/lib/github_api2/client/orgs.rb +127 -0
  45. data/lib/github_api2/client/projects/cards.rb +158 -0
  46. data/lib/github_api2/client/projects/columns.rb +146 -0
  47. data/lib/github_api2/client/projects.rb +83 -0
  48. data/lib/github_api2/client/pull_requests/comments.rb +140 -0
  49. data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
  50. data/lib/github_api2/client/pull_requests.rb +195 -0
  51. data/lib/github_api2/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api2/client/repos/branches.rb +48 -0
  53. data/lib/github_api2/client/repos/collaborators.rb +84 -0
  54. data/lib/github_api2/client/repos/comments.rb +125 -0
  55. data/lib/github_api2/client/repos/commits.rb +80 -0
  56. data/lib/github_api2/client/repos/contents.rb +263 -0
  57. data/lib/github_api2/client/repos/deployments.rb +138 -0
  58. data/lib/github_api2/client/repos/downloads.rb +62 -0
  59. data/lib/github_api2/client/repos/forks.rb +50 -0
  60. data/lib/github_api2/client/repos/hooks.rb +214 -0
  61. data/lib/github_api2/client/repos/invitations.rb +41 -0
  62. data/lib/github_api2/client/repos/keys.rb +104 -0
  63. data/lib/github_api2/client/repos/merging.rb +47 -0
  64. data/lib/github_api2/client/repos/pages.rb +48 -0
  65. data/lib/github_api2/client/repos/projects.rb +62 -0
  66. data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
  67. data/lib/github_api2/client/repos/releases/assets.rb +136 -0
  68. data/lib/github_api2/client/repos/releases/tags.rb +24 -0
  69. data/lib/github_api2/client/repos/releases.rb +189 -0
  70. data/lib/github_api2/client/repos/statistics.rb +89 -0
  71. data/lib/github_api2/client/repos/statuses.rb +91 -0
  72. data/lib/github_api2/client/repos.rb +473 -0
  73. data/lib/github_api2/client/say.rb +25 -0
  74. data/lib/github_api2/client/scopes.rb +46 -0
  75. data/lib/github_api2/client/search/legacy.rb +111 -0
  76. data/lib/github_api2/client/search.rb +133 -0
  77. data/lib/github_api2/client/users/emails.rb +65 -0
  78. data/lib/github_api2/client/users/followers.rb +115 -0
  79. data/lib/github_api2/client/users/keys.rb +104 -0
  80. data/lib/github_api2/client/users.rb +117 -0
  81. data/lib/github_api2/client.rb +77 -0
  82. data/lib/github_api2/configuration.rb +70 -0
  83. data/lib/github_api2/connection.rb +82 -0
  84. data/lib/github_api2/constants.rb +61 -0
  85. data/lib/github_api2/core_ext/array.rb +25 -0
  86. data/lib/github_api2/core_ext/hash.rb +91 -0
  87. data/lib/github_api2/deprecation.rb +39 -0
  88. data/lib/github_api2/error/client_error.rb +89 -0
  89. data/lib/github_api2/error/service_error.rb +223 -0
  90. data/lib/github_api2/error.rb +32 -0
  91. data/lib/github_api2/ext/faraday.rb +40 -0
  92. data/lib/github_api2/mash.rb +7 -0
  93. data/lib/github_api2/middleware.rb +37 -0
  94. data/lib/github_api2/mime_type.rb +33 -0
  95. data/lib/github_api2/normalizer.rb +23 -0
  96. data/lib/github_api2/null_encoder.rb +25 -0
  97. data/lib/github_api2/page_iterator.rb +138 -0
  98. data/lib/github_api2/page_links.rb +63 -0
  99. data/lib/github_api2/paged_request.rb +42 -0
  100. data/lib/github_api2/pagination.rb +115 -0
  101. data/lib/github_api2/parameter_filter.rb +35 -0
  102. data/lib/github_api2/params_hash.rb +115 -0
  103. data/lib/github_api2/rate_limit.rb +25 -0
  104. data/lib/github_api2/request/basic_auth.rb +36 -0
  105. data/lib/github_api2/request/jsonize.rb +54 -0
  106. data/lib/github_api2/request/oauth2.rb +45 -0
  107. data/lib/github_api2/request/verbs.rb +63 -0
  108. data/lib/github_api2/request.rb +84 -0
  109. data/lib/github_api2/response/atom_parser.rb +22 -0
  110. data/lib/github_api2/response/follow_redirects.rb +140 -0
  111. data/lib/github_api2/response/header.rb +87 -0
  112. data/lib/github_api2/response/jsonize.rb +28 -0
  113. data/lib/github_api2/response/mashify.rb +24 -0
  114. data/lib/github_api2/response/raise_error.rb +22 -0
  115. data/lib/github_api2/response/xmlize.rb +28 -0
  116. data/lib/github_api2/response.rb +48 -0
  117. data/lib/github_api2/response_wrapper.rb +161 -0
  118. data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api2/utils/url.rb +63 -0
  120. data/lib/github_api2/validations/format.rb +26 -0
  121. data/lib/github_api2/validations/presence.rb +32 -0
  122. data/lib/github_api2/validations/required.rb +21 -0
  123. data/lib/github_api2/validations/token.rb +41 -0
  124. data/lib/github_api2/validations.rb +22 -0
  125. data/lib/github_api2/version.rb +5 -0
  126. data/lib/github_api2.rb +92 -0
  127. 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