lib/processout/event.rb in processout-0.2.1 vs lib/processout/event.rb in processout-0.3.0
- old
+ new
@@ -49,22 +49,28 @@
# Initializes the Event object
# Params:
# +client+:: +ProcessOut+ client instance
- def initialize(client)
+ # +data+:: data that can be used to fill the object
+ def initialize(client, data = {})
@client = client
- @id = ""
- @project = nil
- @name = ""
- @data = nil
- @sandbox = false
- @fired_at = ""
+ @id = data.fetch(:id, "")
+ @project = data.fetch(:project, nil)
+ @name = data.fetch(:name, "")
+ @data = data.fetch(:data, nil)
+ @sandbox = data.fetch(:sandbox, false)
+ @fired_at = data.fetch(:fired_at, "")
end
+ # Create a new Event using the current client
+ def new(data = {})
+ Event.new(@client, data)
+ end
+
# Fills the object with data coming from the API
# Params:
# +data+:: +Hash+ of data coming from the API
def fill_with_data(data)
if data.include? "id"
@@ -90,11 +96,11 @@
end
# Get all the webhooks of the event.
# Params:
# +options+:: +Hash+ of options
- def webhooks(options = nil)
+ def webhooks(options = {})
request = Request.new(@client)
path = "/events/" + CGI.escape(@id) + "/webhooks"
data = {
}
@@ -103,11 +109,11 @@
return_values = Array.new
a = Array.new
body = response.body
for v in body['webhooks']
- tmp = Webhook(@client)
+ tmp = Webhook.new(@client)
tmp.fill_with_data(v)
a.push(tmp)
end
return_values.push(a)
@@ -118,11 +124,11 @@
end
# Get all the events.
# Params:
# +options+:: +Hash+ of options
- def all(options = nil)
+ def all(options = {})
request = Request.new(@client)
path = "/events"
data = {
}
@@ -131,11 +137,11 @@
return_values = Array.new
a = Array.new
body = response.body
for v in body['events']
- tmp = Event(@client)
+ tmp = Event.new(@client)
tmp.fill_with_data(v)
a.push(tmp)
end
return_values.push(a)
@@ -147,10 +153,10 @@
# Find an event by its ID.
# Params:
# +event_id+:: ID of the event
# +options+:: +Hash+ of options
- def find(event_id, options = nil)
+ def find(event_id, options = {})
request = Request.new(@client)
path = "/events/" + CGI.escape(event_id) + ""
data = {
}