Class: ProcessOut::WebhookEndpoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the WebhookEndpoint object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/processout/webhook_endpoint.rb', line 66

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.url = data.fetch(:url, nil)
  self.events_whitelist = data.fetch(:events_whitelist, nil)
  self.sandbox = data.fetch(:sandbox, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#events_whitelistObject

Returns the value of attribute events_whitelist.



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

def events_whitelist
  @events_whitelist
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#projectObject

Returns the value of attribute project.



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

def project
  @project
end

#project_idObject

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

#sandboxObject

Returns the value of attribute sandbox.



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

def sandbox
  @sandbox
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/processout/webhook_endpoint.rb', line 100

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? "url"
    self.url = data["url"]
  end
  if data.include? "events_whitelist"
    self.events_whitelist = data["events_whitelist"]
  end
  if data.include? "sandbox"
    self.sandbox = data["sandbox"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new WebhookEndpoint using the current client



80
81
82
# File 'lib/processout/webhook_endpoint.rb', line 80

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

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/processout/webhook_endpoint.rb', line 132

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.url = data.fetch(:url, self.url)
  self.events_whitelist = data.fetch(:events_whitelist, self.events_whitelist)
  self.sandbox = data.fetch(:sandbox, self.sandbox)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/processout/webhook_endpoint.rb', line 85

def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "project_id": self.project_id,
      "url": self.url,
      "events_whitelist": self.events_whitelist,
      "sandbox": self.sandbox,
      "created_at": self.created_at,
  }.to_json
end