oeh-client 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 387ba081ef8853fc009d375625937d086de71905
4
- data.tar.gz: 2306b95911d221c4b377c0c3547de92d2f6cba78
3
+ metadata.gz: 523096f4e6ed912ba9438ae57ee5db4c5436a107
4
+ data.tar.gz: 0acd9dd22c8d6a825ff85f337425d9862e80a0b8
5
5
  SHA512:
6
- metadata.gz: 704963a6de39b8b22fe7715aece3ad147b175329dac4bb45a079274d2c1bf32756653b9992453cfc165a652d83a0a9e058247207dcbf804deb6799166b02b231
7
- data.tar.gz: 518ae34e6924ffca0d244b79961d7566123b31e71713ec2fe6b443c6eb3617947f908f7179be236fe8149f9a2d5f9de56c29feec85a4abf73ccb5ac76e67cb02
6
+ metadata.gz: 7c095dfd4864698e800cd3caa046c0069836b44928a57e60e73e9f8cde139c85867244585681f8ae329fd5f1b3651da17246711f8769d467eb87b82eafe73594
7
+ data.tar.gz: 0226d6c29edbe1e84e3fcda936f1ccac0aae561ae1074d9c77a117ebd6a7bad28d451301bca55a487fd435be084b58b4860c60ad3d06c319d04700bb456af9f5
@@ -13,6 +13,9 @@ module OEHClient
13
13
  API_URI_PART = "/rt/api"
14
14
  API_VERSION = "/2.0"
15
15
 
16
+ POST_METHOD = "post"
17
+ PUT_METHOD = "put"
18
+
16
19
  # request_url builds the target request URL with the passed parameters, URL encoding the parameters
17
20
  # as necessary to create a valid request
18
21
  def self.format_url(url, params)
@@ -60,6 +63,23 @@ module OEHClient
60
63
 
61
64
  end # module Response
62
65
 
66
+
67
+ module Timestamp
68
+
69
+ # convert the time value from a Time, DateTime, String, or Integer to a proper ONE timestamp value
70
+ # format (UTC Milliseconds)
71
+ def self.to_one_timestamp(timevalue)
72
+
73
+ one_timestamp = timevalue if (timevalue.is_a?(Integer))
74
+ one_timestamp = timevalue.utc.strftime("%s%L").to_i if (timevalue.is_a?(Time) || timevalue.is_a?(DateTime))
75
+ one_timestamp = Time.parse(timevalue).utc.strftime("%s%L").to_i if (timevalue.is_a?(String))
76
+
77
+ one_timestamp
78
+
79
+ end
80
+
81
+ end
82
+
63
83
  end
64
84
 
65
85
  end
@@ -51,9 +51,9 @@ class OEHClient::Interaction::Interaction
51
51
  }
52
52
 
53
53
  # conditionally merge the rest of the attributes if they are passed
54
- attributes.merge!(:timestamp => timestamp) unless (timestamp.nil?)
55
- attributes.merge!(:tid => tid) if (!tid.nil? && !tid.empty?)
56
- attributes.merge!(:ck => customer_key) if (!customer_key.nil? && !customer_key.empty?)
54
+ attributes.merge!(:timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)) unless(timestamp.blank?)
55
+ attributes.merge!(:tid => tid) unless(timestamp.blank?)
56
+ attributes.merge!(:ck => customer_key) unless(customer_key.blank?)
57
57
 
58
58
 
59
59
  # create a new interaction using all attributes pass
@@ -96,13 +96,13 @@ class OEHClient::Interaction::Interaction
96
96
  # set the instance attributes is the parameter hash is created
97
97
  if (!attributes.nil? && attributes.kind_of?(Hash))
98
98
 
99
- @uri = attributes[:uri] if (attributes.has_key?(:uri))
100
- @customer_key = attributes[:ck] if (attributes.has_key?(:ck))
101
- @tid = attributes[:tid] if (attributes.has_key?(:tid))
102
- @session = attributes[:session] if (attributes.has_key?(:session))
103
- @timestamp = attributes[:timestamp] if (attributes.has_key?(:timestamp))
99
+ @uri = attributes[:uri] if (attributes.has_key?(:uri))
100
+ @customer_key = attributes[:ck] if (attributes.has_key?(:ck))
101
+ @tid = attributes[:tid] if (attributes.has_key?(:tid))
102
+ @session = attributes[:session] if (attributes.has_key?(:session))
103
+ @timestamp = OEHClient::Helper::Timestamp.to_one_timestamp(attributes[:timestamp]) if (attributes.has_key?(:timestamp))
104
104
 
105
- @space = OEHClient::Config::SpaceManager.instance.get(attributes[:sk]) if (attributes.has_key?(:sk))
105
+ @space = OEHClient::Config::SpaceManager.instance.get(attributes[:sk]) if (attributes.has_key?(:sk))
106
106
 
107
107
  end
108
108
 
@@ -115,7 +115,7 @@ class OEHClient::Interaction::Interaction
115
115
  raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
116
116
 
117
117
  # call the appropriate method based on the existance of the timestamp value
118
- ((!@timestamp.nil?) ? send_offline(@space.token) : send_realtime(@space.token, parameters))
118
+ ((!@timestamp.nil?) ? send_offline(@space.token, parameters) : send_realtime(@space.token, parameters))
119
119
 
120
120
  # return the current instance interacton
121
121
  self
@@ -140,7 +140,7 @@ class OEHClient::Interaction::Interaction
140
140
  :tid => @tid,
141
141
  :session => @session,
142
142
  :sk => @space.site_key,
143
- :timestamp => timestamp
143
+ :timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)
144
144
  })
145
145
 
146
146
  # Send the interaction for processing and return the current instance
@@ -157,10 +157,13 @@ class OEHClient::Interaction::Interaction
157
157
  properties ||= Hash.new
158
158
 
159
159
  # Call the PUT method to update the
160
- OEHClient::Helper::Response.handle(OEHClient.put(@space.token(),
161
- OEHClient::Helper::Request.format_url(realtime_url, {:sk => @space.site_key}),
162
- nil,
163
- request_data(properties))) unless properties.empty?
160
+ #OEHClient::Helper::Response.handle(OEHClient.put(@space.token(),
161
+ # OEHClient::Helper::Request.format_url(realtime_url, {:sk => @space.site_key}),
162
+ # nil,
163
+ # request_data(properties))) unless properties.empty?
164
+
165
+ send_request(OEHClient::Helper::Request::PUT_METHOD, @space.token(), realtime_url, properties) unless properties.empty?
166
+
164
167
  # return the current object
165
168
  self
166
169
  end
@@ -171,28 +174,33 @@ class OEHClient::Interaction::Interaction
171
174
 
172
175
  # send_realtime posts a new interaction occuring at the moment (in realtime). The response attributes
173
176
  # are mapped to the current instance attributes for all valid requests
174
- def send_realtime(token, parameters={})
175
-
176
- response = OEHClient::Helper::Response.handle(OEHClient.post(token,
177
- OEHClient::Helper::Request.format_url(realtime_url, {:sk => @space.site_key}),
178
- nil,
179
- request_data(parameters))
180
- )
181
-
177
+ def send_realtime(token, properties={})
178
+ # POST the realtime interaction method
179
+ response = send_request(OEHClient::Helper::Request::POST_METHOD, token, realtime_url, properties)
180
+ # map the response message to the current instance attributes
182
181
  map_response(response)
183
-
184
-
185
182
  end
186
183
 
187
184
  # send_offline posts a historic interaction, using a specified timestamp
188
- def send_offline(token)
189
-
190
- response = OEHClient::Helper::Response.handle(OEHClient.put(token,
191
- OEHClient::Helper::Request.format_url(offline_url, {:sk => @space.site_key}),
192
- nil,
193
- request_data))
185
+ def send_offline(token, properties={})
186
+ # PUT the offline interaction method
187
+ response = send_request(OEHClient::Helper::Request::PUT_METHOD, token, offline_url, properties)
188
+ # map the response message to the current instance attributes
194
189
  map_response(response)
190
+ end
195
191
 
192
+ # send_request acts as the wrapper to send all client requests to the ONE server in a unified manner
193
+ def send_request(method, token, url, properties={})
194
+ # set the URL parameters for the site_key and the tid, of the value exists
195
+ url_parameters = {:sk => @space.site_key}
196
+ url_parameters.merge!({:tid => @tid}) unless (@tid.blank?)
197
+ # send the POST or PUT methond along with the arguments to the OEHClient class
198
+ OEHClient::Helper::Response.handle(OEHClient.send(method.downcase.to_sym,
199
+ token,
200
+ OEHClient::Helper::Request.format_url(url, url_parameters),
201
+ nil,
202
+ request_data(properties)
203
+ ))
196
204
 
197
205
  end
198
206
 
@@ -278,7 +286,6 @@ class OEHClient::Interaction::Interaction
278
286
  parameters.merge!({ONE_PARAM_URI => @uri}) if (!@uri.nil? && @uri.length > 0)
279
287
 
280
288
  parameters.merge!({ONE_PARAM_CK => @customer_key}) if (!@customer_key.nil? && @customer_key.length > 0)
281
- parameters.merge!({ONE_PARAM_TID => @tid}) if (!@tid.nil? && @tid.length > 0)
282
289
 
283
290
  parameters.merge!({ONE_PARAM_SESSION => @session}) if (!@session.nil? && @session.length > 0)
284
291
  parameters.merge!({ONE_PARAM_TS => @timestamp}) if (!@timestamp.nil?)
@@ -1,3 +1,3 @@
1
1
  module OEHClient
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oeh-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Balliet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,6 @@ files:
155
155
  - lib/oehclient/interaction/interaction.rb
156
156
  - lib/oehclient/interaction/optimization.rb
157
157
  - lib/oehclient/version.rb
158
- - oeh-client-0.1.0.gem
159
158
  - oeh-client.gemspec
160
159
  homepage: https://rubygems.org/gems/oeh-client
161
160
  licenses:
data/oeh-client-0.1.0.gem DELETED
Binary file