gitlab-customer-support-operations_gitlab 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 (35) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_gitlab/gitlab/badges.rb +229 -0
  3. data/lib/support_ops_gitlab/gitlab/base.rb +552 -0
  4. data/lib/support_ops_gitlab/gitlab/client.rb +51 -0
  5. data/lib/support_ops_gitlab/gitlab/commits.rb +198 -0
  6. data/lib/support_ops_gitlab/gitlab/configuration.rb +86 -0
  7. data/lib/support_ops_gitlab/gitlab/epics.rb +325 -0
  8. data/lib/support_ops_gitlab/gitlab/events.rb +167 -0
  9. data/lib/support_ops_gitlab/gitlab/gpg_keys.rb +64 -0
  10. data/lib/support_ops_gitlab/gitlab/group_memberships.rb +33 -0
  11. data/lib/support_ops_gitlab/gitlab/groups.rb +431 -0
  12. data/lib/support_ops_gitlab/gitlab/invitations.rb +72 -0
  13. data/lib/support_ops_gitlab/gitlab/issues.rb +606 -0
  14. data/lib/support_ops_gitlab/gitlab/jobs.rb +61 -0
  15. data/lib/support_ops_gitlab/gitlab/markdown.rb +54 -0
  16. data/lib/support_ops_gitlab/gitlab/merge_requests.rb +411 -0
  17. data/lib/support_ops_gitlab/gitlab/milestones.rb +195 -0
  18. data/lib/support_ops_gitlab/gitlab/namespaces.rb +184 -0
  19. data/lib/support_ops_gitlab/gitlab/notes.rb +182 -0
  20. data/lib/support_ops_gitlab/gitlab/pipelines.rb +258 -0
  21. data/lib/support_ops_gitlab/gitlab/project_access_tokens.rb +245 -0
  22. data/lib/support_ops_gitlab/gitlab/project_memberships.rb +33 -0
  23. data/lib/support_ops_gitlab/gitlab/project_webhook_events.rb +33 -0
  24. data/lib/support_ops_gitlab/gitlab/project_webhooks.rb +218 -0
  25. data/lib/support_ops_gitlab/gitlab/projects.rb +741 -0
  26. data/lib/support_ops_gitlab/gitlab/repository_files.rb +102 -0
  27. data/lib/support_ops_gitlab/gitlab/repository_submodules.rb +78 -0
  28. data/lib/support_ops_gitlab/gitlab/ssh_keys.rb +67 -0
  29. data/lib/support_ops_gitlab/gitlab/user_emails.rb +147 -0
  30. data/lib/support_ops_gitlab/gitlab/user_memberships.rb +21 -0
  31. data/lib/support_ops_gitlab/gitlab/user_tokens.rb +344 -0
  32. data/lib/support_ops_gitlab/gitlab/users.rb +1059 -0
  33. data/lib/support_ops_gitlab/gitlab.rb +45 -0
  34. data/lib/support_ops_gitlab.rb +28 -0
  35. metadata +251 -0
@@ -0,0 +1,245 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class ProjectAccessTokens within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Integer] access_level Role for the token; possible values: 10 (Guest), 15 (Planner), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)
13
+ # @attr [Boolean] active If the token is active or not
14
+ # @attr [String] created_at The timestamp the token was created at
15
+ # @attr [String] description The description of the token
16
+ # @attr [String] expires_at Expiration date of the token in ISO format (YYYY-MM-DD).
17
+ # @attr [Integer] id The ID of the token
18
+ # @attr [String] last_used_at The timestamp the token was last used
19
+ # @attr [String] name The name of the token
20
+ # @attr [Integer] project_id The ID of the project the token is attached to
21
+ # @attr [String] revoked If the token is revoked or not
22
+ # @attr [Array] scopes The scopes of the token
23
+ # @attr [String] token The token itself (only shows on create and rotate)
24
+ # @attr [Integer] user_id The user who created the token
25
+ # @todo Get details on a project access token => https://docs.gitlab.com/api/project_access_tokens/#get-details-on-a-project-access-token
26
+ class ProjectAccessTokens < SupportOps::GitLab::Base
27
+ # @!parse
28
+ # # Create a project access token
29
+ # #
30
+ # # @author Jason Colyer
31
+ # # @since 1.0.0
32
+ # # @return [Object] Instance of {SupportOps::GitLab::ProjectAccessTokens}
33
+ # # @note This is inherited from {SupportOps::GitLab::Base#save!}
34
+ # # @see
35
+ # # https://docs.gitlab.com/api/project_access_tokens/#create-a-project-access-token
36
+ # # GitLab API > Projects > Access tokens > Create a project access token
37
+ # # @example
38
+ # # require 'support_ops_gitlab'
39
+ # #
40
+ # # SupportOps::GitLab::Configuration.configure do |config|
41
+ # # config.token = ENV.fetch('GL_TOKEN')
42
+ # # config.url = 'https://gitlab.com/api/v4'
43
+ # # end
44
+ # #
45
+ # # new_project_access_token = SupportOps::GitLab::ProjectAccessTokens.new
46
+ # # new_project_access_token.name = 'Jason Test'
47
+ # # new_project_access_token.expires_at = '2025-05-28'
48
+ # # new_project_access_token.description = 'Jason Test Desc'
49
+ # # new_project_access_token.scopes = ['api']
50
+ # # new_project_access_token.project_id = 123456
51
+ # #
52
+ # # new_project_access_token.save!
53
+ # #
54
+ # # pp new_project_access_token.token
55
+ # # # => "glpat-abc123"
56
+ # def save!; end
57
+ # @!parse
58
+ # # Rotates a project access token
59
+ # #
60
+ # # @author Jason Colyer
61
+ # # @since 1.0.0
62
+ # # @return [Object] Instance of {SupportOps::GitLab::ProjectAccessTokens}
63
+ # # @note This is inherited from {SupportOps::GitLab::Base#rotate!}
64
+ # # @see
65
+ # # https://docs.gitlab.com/api/project_access_tokens/#rotate-a-project-access-token
66
+ # # GitLab API > Projects > Access tokens > Rotate a project access token
67
+ # # @example
68
+ # # require 'support_ops_gitlab'
69
+ # #
70
+ # # SupportOps::GitLab::Configuration.configure do |config|
71
+ # # config.token = ENV.fetch('GL_TOKEN')
72
+ # # config.url = 'https://gitlab.com/api/v4'
73
+ # # end
74
+ # #
75
+ # # tokens = SupportOps::GitLab::ProjectAccessTokens.list(project_id: 123456)
76
+ # # new_token = tokens.last.rotate!
77
+ # # pp new_token.token
78
+ # # # => "glpat-def456"
79
+ # def rotate!; end
80
+ # @!parse
81
+ # # Revokes a project access token
82
+ # #
83
+ # # @author Jason Colyer
84
+ # # @since 1.0.0
85
+ # # @return [Object] Instance of {SupportOps::GitLab::ProjectAccessTokens}
86
+ # # @note This is inherited from {SupportOps::GitLab::Base#revoke!}
87
+ # # @see
88
+ # # https://docs.gitlab.com/api/project_access_tokens/#revoke-a-project-access-token
89
+ # # GitLab API > Projects > Access tokens > Revoke a project access token
90
+ # # @example
91
+ # # require 'support_ops_gitlab'
92
+ # #
93
+ # # SupportOps::GitLab::Configuration.configure do |config|
94
+ # # config.token = ENV.fetch('GL_TOKEN')
95
+ # # config.url = 'https://gitlab.com/api/v4'
96
+ # # end
97
+ # #
98
+ # # tokens = SupportOps::GitLab::ProjectAccessTokens.list(project_id: 123456)
99
+ # # tokens.last.revoke!
100
+ # def revoke!; end
101
+ define_attributes :access_level, :active, :created_at, :description,
102
+ :expires_at, :id, :last_used_at, :name, :project_id,
103
+ :revoked, :scopes, :token, :user_id
104
+ readonly_attributes :active, :created_at, :id, :last_used_at, :project_id,
105
+ :revoked, :token, :user_id
106
+
107
+ ##
108
+ # List all project access tokens
109
+ #
110
+ # @author Jason Colyer
111
+ # @since 1.0.0
112
+ # overload list(key: value)
113
+ # @param created_after [String optional] If defined, returns tokens
114
+ # created after the specified time
115
+ # @param created_before [String optional] If defined, returns tokens
116
+ # created before the specified time
117
+ # @param expires_after [String optional] If defined, returns tokens that
118
+ # expire after the specified time
119
+ # @param expires_before [String optional] If defined, returns tokens
120
+ # that expire before the specified time
121
+ # @param last_used_after [String optional] If defined, returns tokens
122
+ # last used after the specified time
123
+ # @param last_used_before [String optional] If defined, returns tokens
124
+ # last used before the specified time
125
+ # @param project_id [Integer required] The ID of the project to use
126
+ # @param revoked [Boolean optional] If true, only returns revoked tokens
127
+ # @param search [String optional] If defined, returns tokens that
128
+ # include the specified value in the name
129
+ # @param sort [String optional] If defined, sorts the results by the
130
+ # specified value; possible values: created_asc, created_desc,
131
+ # expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc,
132
+ # name_desc
133
+ # @param state [String optional] If defined, returns tokens with the
134
+ # specified state; possible values: active and inactive
135
+ # @param limit [Integer optional] The limit to the number of users
136
+ # returned. Default to 0 (i.e. no limit)
137
+ # @return [Array]
138
+ # #see
139
+ # https://docs.gitlab.com/api/project_access_tokens/#list-all-project-access-tokens
140
+ # GitLab API > Projects > Access tokens > List all project access tokens
141
+ # @example
142
+ # require 'support_ops_gitlab'
143
+ #
144
+ # SupportOps::GitLab::Configuration.configure do |config|
145
+ # config.url = 'https://gitlab.example.com/api/v4'
146
+ # config.token = 'abc123'
147
+ # end
148
+ #
149
+ # tokens = SupportOps::GitLab::ProjectAccessTokens.list(project_id: 5, limit: 10)
150
+ # pp tokens.count
151
+ # # => 10
152
+ # pp tokens.last.revoked
153
+ # # => false
154
+ def self.list(**args)
155
+ raise 'You have to provide a project_id' unless args[:project_id]
156
+
157
+ args[:created_after] = nil unless args[:created_after]
158
+ args[:created_before] = nil unless args[:created_before]
159
+ args[:expires_after] = nil unless args[:expires_after]
160
+ args[:expires_before] = nil unless args[:expires_before]
161
+ args[:last_used_after] = nil unless args[:last_used_after]
162
+ args[:last_used_before] = nil unless args[:last_used_before]
163
+ args[:revoked] = nil unless args[:revoked]
164
+ args[:search] = nil unless args[:search]
165
+ args[:sort] = nil unless args[:sort]
166
+ args[:state] = nil unless args[:state]
167
+ args[:limit] = 0 unless args[:limit]
168
+ params = ''
169
+ params += "created_after=#{args[:created_after]}&" unless args[:created_after].nil?
170
+ params += "created_before=#{args[:created_before]}&" unless args[:created_before].nil?
171
+ params += "expires_after=#{args[:expires_after]}&" unless args[:expires_after].nil?
172
+ params += "expires_before=#{args[:expires_before]}&" unless args[:expires_before].nil?
173
+ params += "last_used_after=#{args[:last_used_after]}&" unless args[:last_used_after].nil?
174
+ params += "last_used_before=#{args[:last_used_before]}&" unless args[:last_used_before].nil?
175
+ params += "revoked=#{args[:revoked]}&" unless args[:revoked].nil?
176
+ params += "search=#{args[:search]}&" unless args[:search].nil?
177
+ params += "sort=#{args[:sort]}&" unless args[:sort].nil?
178
+ params += "state=#{args[:state]}&" unless args[:state].nil?
179
+ array = []
180
+ page = 1
181
+ loop do
182
+ response = client.connection.get("projects/#{args[:project_id]}/access_tokens?#{params}&page=#{page}&per_page=100")
183
+ body = Oj.load(response.body)
184
+ array += body.map { |p| Projects.new(p) }
185
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
186
+ break if body.count < 100
187
+
188
+ page += 1
189
+ end
190
+ return array if args[:limit].to_i.zero?
191
+
192
+ array.first(args[:limit].to_i)
193
+ end
194
+
195
+ private
196
+
197
+ ##
198
+ # @private
199
+ def create_record
200
+ url = "projects/#{self.project_id}/access_tokens"
201
+ response = self.client.connection.post(url, attributes_for_save.to_json)
202
+ body = Oj.load(response.body)
203
+ raise "Error creating project access token => #{body}" unless response.status == 201
204
+ body
205
+ end
206
+
207
+ ##
208
+ # @private
209
+ def update_record
210
+ raise 'You cannot update a token, you must create a new one'
211
+ end
212
+
213
+ ##
214
+ # @private
215
+ def delete_record
216
+ raise 'You cannot delete a token, you must revoke it'
217
+ end
218
+
219
+ ##
220
+ # @private
221
+ def rotate_record
222
+ data = { expires_at: self.expires_at }.to_json
223
+ response = self.client.connection.post("projects/#{self.project_id}/access_tokens/#{self.id}/rotate", data)
224
+ body = Oj.load(response.body)
225
+ raise "Failed to rotate project access tokentoken #{self.id} => #{body}" unless response.status == 200
226
+ body.each do |key, value|
227
+ self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
228
+ end
229
+ body
230
+ end
231
+
232
+ ##
233
+ # @private
234
+ def revoke_record
235
+ url = "projects/#{self.project_id}/access_tokens/#{self.id}"
236
+ response = self.client.connection.delete(url)
237
+ body = Oj.load(response.body)
238
+ raise "Error revoking project access token token => #{self.body}" unless response.status == 204
239
+ self.instance_variable_set("@active", false)
240
+ self.instance_variable_set("@revoked", true)
241
+ true
242
+ end
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class ProjectMemberships within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Integer] access_level The membership level
13
+ # @attr [String] avatar_url URL of the user's avatar
14
+ # @attr [String] created_at The time the membership was created at
15
+ # @attr [Hash] created_by A hash containing information on who created the membership
16
+ # @attr [String] email The email of the user
17
+ # @attr [String] expires_at The timestamp when the membership expires
18
+ # @attr [Hash] group_saml_identity A hash containing the group's SAML information tied to the membership
19
+ # @attr [Integer] id The user's ID
20
+ # @attr [String] name The name of the user
21
+ # @attr [String] state The state of the membership, can be awaiting or active
22
+ # @attr [String] username The username of the user
23
+ # @attr [String] web_url The web URL of theuser
24
+ class ProjectMemberships < SupportOps::GitLab::Base
25
+ define_attributes :access_level, :avatar_url, :created_at, :created_by,
26
+ :email, :expires_at, :group_saml_identity, :id, :name,
27
+ :state, :username, :web_url
28
+ readonly_attributes :access_level, :avatar_url, :created_at, :created_by,
29
+ :email, :expires_at, :group_saml_identity, :id, :name,
30
+ :state, :username, :web_url
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class ProjectWebhookEvents within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Float] execution_duration
13
+ # @attr [Integer] id
14
+ # @attr [Hash] request_data
15
+ # @attr [Hash] request_headers
16
+ # @attr [Hash] response_body
17
+ # @attr [Hash] response_headers
18
+ # @attr [String] response_status
19
+ # @attr [String] trigger
20
+ # @attr [String] url
21
+ # @todo Document attribute meaning
22
+ class ProjectWebhookEvents < SupportOps::GitLab::Base
23
+ define_attributes :execution_duration, :id, :request_data,
24
+ :request_headers, :response_body, :response_headers,
25
+ :response_status, :trigger, :url
26
+ readonly_attributes :execution_duration, :id, :request_data,
27
+ :request_headers, :response_body, :response_headers,
28
+ :response_status, :trigger, :url
29
+
30
+ private
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class ProjectWebhooks within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] alert_status
13
+ # @attr [String] branch_filter_strategy Filter push events by branch; possible values are wildcard (default), regex, and all_branches
14
+ # @attr [Boolean] confidential_issues_events
15
+ # @attr [Boolean] confidential_note_events
16
+ # @attr [String] created_at
17
+ # @attr [Array] custom_headers
18
+ # @attr [String] custom_webhook_template
19
+ # @attr [Boolean] deployment_events
20
+ # @attr [String] description
21
+ # @attr [String] disabled_until
22
+ # @attr [Boolean] enable_ssl_verification
23
+ # @attr [Boolean] feature_flag_events
24
+ # @attr [Integer] id
25
+ # @attr [Boolean] issues_events
26
+ # @attr [Boolean] job_events
27
+ # @attr [Boolean] merge_requests_events
28
+ # @attr [String] name
29
+ # @attr [Boolean] note_events
30
+ # @attr [Boolean] pipeline_events
31
+ # @attr [Integer] project_id
32
+ # @attr [Boolean] push_events
33
+ # @attr [String] push_events_branch_filter
34
+ # @attr [Boolean] releases_events
35
+ # @attr [Boolean] repository_update_events
36
+ # @attr [Boolean] resource_access_token_events
37
+ # @attr [Boolean] tag_push_events
38
+ # @attr [String] token Secret token to validate received payloads; the token isn’t returned in the response (creates/updates only)
39
+ # @attr [String] url
40
+ # @attr [Array] url_variables
41
+ # @attr [Boolean] wiki_page_events
42
+ # @todo Anything list at https://docs.gitlab.com/api/project_webhooks
43
+ # @todo Document save!
44
+ # @todo Document delete!
45
+ # @todo Document events
46
+ class ProjectWebhooks < SupportOps::GitLab::Base
47
+ define_attributes :alert_status, :branch_filter_strategy,
48
+ :confidential_issues_events, :confidential_note_events,
49
+ :created_at, :custom_headers, :custom_webhook_template,
50
+ :deployment_events, :description, :disabled_until,
51
+ :enable_ssl_verification, :feature_flag_events, :id,
52
+ :issues_events, :job_events, :merge_requests_events,
53
+ :name, :note_events, :pipeline_events, :project_id,
54
+ :push_events, :push_events_branch_filter,
55
+ :releases_events, :repository_update_events,
56
+ :resource_access_token_events, :tag_push_events,
57
+ :token, :url, :url_variables, :wiki_page_events
58
+ readonly_attributes :alert_status, :created_at, :disabled_until, :id,
59
+ :project_id
60
+
61
+ ##
62
+ # List webhooks for a project
63
+ #
64
+ # @author Jason Colyer
65
+ # @since 1.0.0
66
+ # @overload list(key: value)
67
+ # @param project_id [Integer required] The project ID to look in
68
+ # @return [Array]
69
+ # @see
70
+ # https://docs.gitlab.com/api/project_webhooks/#list-webhooks-for-a-project
71
+ # GitLab API > Projects > Webhooks > List webhooks for a project
72
+ # @see SupportOps::GitLab::Configuration Setting up a client
73
+ # @example
74
+ # require 'support_ops_gitlab'
75
+ #
76
+ # SupportOps::GitLab::Configuration.configure do |config|
77
+ # config.url = 'https://gitlab.example.com/api/v4'
78
+ # config.token = 'abc123'
79
+ # end
80
+ #
81
+ # webhooks = SupportOps::GitLab::ProjectWebhooks.list(project_id: 123)
82
+ # pp webhooks.count
83
+ # # => 11
84
+ # pp webhooks.last.name
85
+ # # => "Aweomse Project Webhook"
86
+ def self.list(**args)
87
+ args[:project_id] = nil unless args[:project_id]
88
+ raise 'You have to provide a project_id' if args[:project_id].nil?
89
+ array = []
90
+ page = 1
91
+ loop do
92
+ response = client.connection.get("projects/#{args[:args[:project_id]]}/hooks?per_page=100&page=#{page}")
93
+ body = Oj.load(response.body)
94
+ array += body.map { |w| ProjectWebhooks(w) }
95
+ break if body.count < 100
96
+
97
+ page += 1
98
+ end
99
+ array
100
+ end
101
+
102
+ ##
103
+ # Get a project webhook
104
+ #
105
+ # @author Jason Colyer
106
+ # @since 1.0.0
107
+ # @see
108
+ # https://docs.gitlab.com/api/project_webhooks/#get-a-project-webhook
109
+ # GitLab API > Projects > Webhooks > Get a project webhook
110
+ # @see SupportOps::GitLab::Configuration Setting up a client
111
+ # @example
112
+ # require 'support_ops_gitlab'
113
+ #
114
+ # SupportOps::GitLab::Configuration.configure do |config|
115
+ # config.url = 'https://gitlab.com/api/v4'
116
+ # config.token = 'abc123'
117
+ # end
118
+ #
119
+ # webhook = SupportOps::GitLab::ProjectWebhooks.get(id: 123, project_id: 456)
120
+ # pp webhook.name
121
+ # # => "Awesome project webhook"
122
+ def self.get(object)
123
+ if object.is_a? ProjectWebhooks
124
+ ProjectWebhooks.new(id: id, project_id: project_id).find
125
+ elsif object.is_a? Hash
126
+ ProjectWebhooks.new({ id: object[:id], project_id: object[:project_id] }).find
127
+ else
128
+ raise 'You need an id and a project_id attribute'
129
+ end
130
+ end
131
+
132
+ ##
133
+ # Get a project webhook
134
+ #
135
+ # @author Jason Colyer
136
+ # @since 1.0.0
137
+ # @see
138
+ # https://docs.gitlab.com/api/project_webhooks/#get-a-project-webhook
139
+ # GitLab API > Projects > Webhooks > Get a project webhook
140
+ # @see SupportOps::GitLab::Configuration Setting up a client
141
+ # @example
142
+ # require 'support_ops_gitlab'
143
+ #
144
+ # SupportOps::GitLab::Configuration.configure do |config|
145
+ # config.url = 'https://gitlab.com/api/v4'
146
+ # config.token = 'abc123'
147
+ # end
148
+ #
149
+ # webhook = SupportOps::GitLab::ProjectWebhooks.get!(id: 123, project_id: 456)
150
+ # pp webhook.name
151
+ # # => "Awesome project webhook"
152
+ def self.get!(object)
153
+ if object.is_a? ProjectWebhooks
154
+ ProjectWebhooks.new(id: id, project_id: project_id).find!
155
+ elsif object.is_a? Hash
156
+ ProjectWebhooks.new({ id: object[:id], project_id: object[:project_id] }).find!
157
+ else
158
+ raise 'You need an id and a project_id attribute'
159
+ end
160
+ end
161
+
162
+ private
163
+
164
+ ##
165
+ # @private
166
+ def get_record
167
+ response = client.connection.get("projects/#{self.project_id}/hooks/#{self.id}")
168
+ return nil if response.status != 200
169
+
170
+ Oj.load(response.body)
171
+ end
172
+
173
+ ##
174
+ # @private
175
+ def create_record
176
+ response = self.client.connection.post("projects/#{self.project_id}/hooks", attributes_for_save.to_json)
177
+ body = Oj.load(response.body)
178
+ raise "Failed to create project webhook => #{body}" if response.status != 201
179
+ body
180
+ end
181
+
182
+ ##
183
+ # @private
184
+ def update_record
185
+ raise "Failed to update project webhook => You didn't change anything in the object" if attributes_for_save.keys == [:id]
186
+ response = self.client.connection.put("projects/#{self.project_id}/hooks/#{self.id}", attributes_for_save.to_json)
187
+ body = Oj.load(response.body)
188
+ raise "Failed to update project webhook #{self.id} => #{body}" if response.status != 200
189
+ body
190
+ end
191
+
192
+ ##
193
+ # @private
194
+ def delete_record
195
+ response = self.client.connection.delete("projects/#{self.project_id}/hooks/#{self.id}")
196
+ body = Oj.load(response.body)
197
+ raise "Failed to delete issue #{self.id} => #{body}" unless response.status == 204
198
+ true
199
+ end
200
+
201
+ ##
202
+ # @private
203
+ def events_record
204
+ array = []
205
+ page = 1
206
+ loop do
207
+ response = self.client.conneciton.get("projects/#{self.project_id}/hoosk/#{self.id}/events?per_page=100&page=#{page}")
208
+ body = Oj.load(Response.body)
209
+ array += body.map { |e| ProjectWebhookEvents.new(e) }
210
+ break if body.count < 100
211
+
212
+ page += 1
213
+ end
214
+ array
215
+ end
216
+ end
217
+ end
218
+ end