Class: ProcessOut::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ Webhook

Initializes the Webhook object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/processout/webhook.rb', line 112

def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.project = data.fetch(:project, nil)
  self.project_id = data.fetch(:project_id, nil)
  self.event = data.fetch(:event, nil)
  self.event_id = data.fetch(:event_id, nil)
  self.request_url = data.fetch(:request_url, nil)
  self.request_method = data.fetch(:request_method, nil)
  self.response_body = data.fetch(:response_body, nil)
  self.response_code = data.fetch(:response_code, nil)
  self.response_headers = data.fetch(:response_headers, nil)
  self.response_time_ms = data.fetch(:response_time_ms, nil)
  self.status = data.fetch(:status, nil)
  self.created_at = data.fetch(:created_at, nil)
  self.release_at = data.fetch(:release_at, nil)
  
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



23
24
25
# File 'lib/processout/webhook.rb', line 23

def created_at
  @created_at
end

#eventObject

Returns the value of attribute event.



14
15
16
# File 'lib/processout/webhook.rb', line 14

def event
  @event
end

#event_idObject

Returns the value of attribute event_id.



15
16
17
# File 'lib/processout/webhook.rb', line 15

def event_id
  @event_id
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/processout/webhook.rb', line 11

def id
  @id
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/processout/webhook.rb', line 12

def project
  @project
end

#project_idObject

Returns the value of attribute project_id.



13
14
15
# File 'lib/processout/webhook.rb', line 13

def project_id
  @project_id
end

#release_atObject

Returns the value of attribute release_at.



24
25
26
# File 'lib/processout/webhook.rb', line 24

def release_at
  @release_at
end

#request_methodObject

Returns the value of attribute request_method.



17
18
19
# File 'lib/processout/webhook.rb', line 17

def request_method
  @request_method
end

#request_urlObject

Returns the value of attribute request_url.



16
17
18
# File 'lib/processout/webhook.rb', line 16

def request_url
  @request_url
end

#response_bodyObject

Returns the value of attribute response_body.



18
19
20
# File 'lib/processout/webhook.rb', line 18

def response_body
  @response_body
end

#response_codeObject

Returns the value of attribute response_code.



19
20
21
# File 'lib/processout/webhook.rb', line 19

def response_code
  @response_code
end

#response_headersObject

Returns the value of attribute response_headers.



20
21
22
# File 'lib/processout/webhook.rb', line 20

def response_headers
  @response_headers
end

#response_time_msObject

Returns the value of attribute response_time_ms.



21
22
23
# File 'lib/processout/webhook.rb', line 21

def response_time_ms
  @response_time_ms
end

#statusObject

Returns the value of attribute status.



22
23
24
# File 'lib/processout/webhook.rb', line 22

def status
  @status
end

Instance Method Details

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/processout/webhook.rb', line 160

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "project"
    self.project = data["project"]
  end
  if data.include? "project_id"
    self.project_id = data["project_id"]
  end
  if data.include? "event"
    self.event = data["event"]
  end
  if data.include? "event_id"
    self.event_id = data["event_id"]
  end
  if data.include? "request_url"
    self.request_url = data["request_url"]
  end
  if data.include? "request_method"
    self.request_method = data["request_method"]
  end
  if data.include? "response_body"
    self.response_body = data["response_body"]
  end
  if data.include? "response_code"
    self.response_code = data["response_code"]
  end
  if data.include? "response_headers"
    self.response_headers = data["response_headers"]
  end
  if data.include? "response_time_ms"
    self.response_time_ms = data["response_time_ms"]
  end
  if data.include? "status"
    self.status = data["status"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  if data.include? "release_at"
    self.release_at = data["release_at"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new Webhook using the current client



133
134
135
# File 'lib/processout/webhook.rb', line 133

def new(data = {})
  Webhook.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/processout/webhook.rb', line 213

def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.project = data.fetch(:project, self.project)
  self.project_id = data.fetch(:project_id, self.project_id)
  self.event = data.fetch(:event, self.event)
  self.event_id = data.fetch(:event_id, self.event_id)
  self.request_url = data.fetch(:request_url, self.request_url)
  self.request_method = data.fetch(:request_method, self.request_method)
  self.response_body = data.fetch(:response_body, self.response_body)
  self.response_code = data.fetch(:response_code, self.response_code)
  self.response_headers = data.fetch(:response_headers, self.response_headers)
  self.response_time_ms = data.fetch(:response_time_ms, self.response_time_ms)
  self.status = data.fetch(:status, self.status)
  self.created_at = data.fetch(:created_at, self.created_at)
  self.release_at = data.fetch(:release_at, self.release_at)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/processout/webhook.rb', line 138

def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "project_id": self.project_id,
      "event": self.event,
      "event_id": self.event_id,
      "request_url": self.request_url,
      "request_method": self.request_method,
      "response_body": self.response_body,
      "response_code": self.response_code,
      "response_headers": self.response_headers,
      "response_time_ms": self.response_time_ms,
      "status": self.status,
      "created_at": self.created_at,
      "release_at": self.release_at,
  }.to_json
end