lib/oehclient/interaction/interaction.rb in oeh-client-0.1.0 vs lib/oehclient/interaction/interaction.rb in oeh-client-0.1.1
- old
+ new
@@ -20,11 +20,11 @@
ONE_RESPONSE_TRACKERS = "trackers"
ONE_RESPONSE_CAPTURES = "captures"
attr_accessor :uri, # The full touchpoint/interaction URI used to post the interaction
- :space, # The configured OEHClient::Config::Space object that represents the
+ :space, # The configured OEHClient::Config::Space object that represents the OEH workspace
:timestamp, # A millisecond value representing a Time value of the interaction
:customer_key, # The customer to which this interaction is related
:tid, # The Thunderhead ID (TID) to which this interaction is related
:session, # The session id to which this interaction is related
@@ -49,11 +49,11 @@
:sk => site_key,
:uri => uri
}
# conditionally merge the rest of the attributes if they are passed
- attributes.merge!(:timestamp => timestamp) if (!timestamp.nil? && !timestamp.empty?)
+ attributes.merge!(:timestamp => timestamp) unless (timestamp.nil?)
attributes.merge!(:tid => tid) if (!tid.nil? && !tid.empty?)
attributes.merge!(:ck => customer_key) if (!customer_key.nil? && !customer_key.empty?)
# create a new interaction using all attributes pass
@@ -109,22 +109,25 @@
end
# send() will post a new interaction using either the realtime (current timestamp) or the offline (historic)
# API interface based on the existence of a timestamp value
def send(parameters={})
+ # raise the MissingParameterException when one (or more) of the miminal parameters are missing
+ raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
# call the appropriate method based on the existance of the timestamp value
- ((minimal_parameters? && !@timestamp.nil? && @timestamp > 0) ? send_offline(@space.token) : send_realtime(@space.token, parameters))
+ ((!@timestamp.nil? && @timestamp > 0) ? send_offline(@space.token) : send_realtime(@space.token, parameters))
# return the current instance interacton
self
-
end
# send_new posts a new interaction using the existing instance data, but for a different touchpoint
# URI. The method returns a new instance of the OEHClient::Interaction::Interaction class
def send_new(uri, timestamp=nil, parameters={})
+ # raise the MissingParameterException when one (or more) of the miminal parameters are missing
+ raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
# protect against NIL by creating a new Hash object if the parameters, for any reason is
# NIL
parameters ||= Hash.new
@@ -140,16 +143,17 @@
:timestamp => timestamp
})
# Send the interaction for processing and return the current instance
new_interaction.send(parameters)
-
end
# send_update allows the system to update the capture and tracking properties that are defined as
# part of the existing interaction
def send_update(properties={})
+ # raise the MissingParameterException when one (or more) of the miminal parameters are missing
+ raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
# force the properties object to be an empty Hash if, for any reason, it is NIL
properties ||= Hash.new
# Call the PUT method to update the
@@ -157,11 +161,10 @@
OEHClient::Helper::Request.format_url(realtime_url, {:sk => @space.site_key}),
nil,
request_data(properties))) unless properties.empty?
# return the current object
self
-
end
private
@@ -226,10 +229,23 @@
# minimal_parameters? determines if the minimal number of request parameters (uri & site_key) are
# present in the current instance of the interaction class. This is a helper method that is used
# before making any request
def minimal_parameters?()
- !@uri.nil? && !@site_key.nil?
+ ((!@uri.nil? && !@uri.empty?) && !@space.nil?)
+ end
+
+ # missing_minimal_parameters returns an array of the minimal attributes that are missing from the current
+ # instance of OEHClient::Interaction::Interaction class
+ def missing_minimal_parameters
+
+ missing_parameters = []
+
+ missing_parameters << "site_key" if (!minimal_parameters? && @site_key.nil?)
+ missing_parameters << "uri" if (!minimal_parameters? && @uri.nil?)
+
+ missing_parameters
+
end
# request_url returns the base of the request URL used to make either a realtime or offline request
# through published API
def request_url()
\ No newline at end of file