moxiworks_platform 0.5.0 → 0.6.0

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: 072579124ac364093cd09aa3d4f38f51c9e989f3
4
- data.tar.gz: df8c6f749772c71cea209cfb680e383f816541fa
3
+ metadata.gz: 3d70046f5068c47a6d9178766c79098202ace1c2
4
+ data.tar.gz: a1415726e2d739f552748550414726b00e4c4fd3
5
5
  SHA512:
6
- metadata.gz: 92e57d0bb040aaf014780ec238c2ab823276151d01cf8f178eef3af957e0b6e80df4062a0b2955ad0ab49d8c28bf02b105a20498415ee8b5c72f3378f9ce3d5a
7
- data.tar.gz: ccb695f90ae5533724c320871a6803eb9f81040e234ec9287d039c6220924a0fa9ca6911d2b919f47b721c3d14c07969d942604eb13010e69db0b9d4dc18bc3d
6
+ metadata.gz: fb909fa1c8e6bf010df56b355778ca45075ab1b55efb1593163a0843a154b9798ba45b09b10a2063f5211d4c866466156166eb3acb1792a231ec1909d0c4fca0
7
+ data.tar.gz: 2c5196daa5c8dee9fec32fd2a271c71d9ed7e9069c13cf2c4a86077d9c4078b5120b64acb8ddad3af63f0ffdca2ee576768c910e1b3f6e298b3d965ac6872c59
@@ -8,6 +8,7 @@ require 'moxiworks_platform/agent'
8
8
  require 'moxiworks_platform/event'
9
9
  require 'moxiworks_platform/group'
10
10
  require 'moxiworks_platform/action_log'
11
+ require 'moxiworks_platform/task'
11
12
 
12
13
 
13
14
 
@@ -20,13 +20,13 @@ module MoxiworksPlatform
20
20
  # @!attribute title
21
21
  # the title to be displayed for this ActionLog Entry
22
22
  #
23
- # @return [String] -- Default ''
23
+ # @return [String]
24
24
  attr_accessor :title
25
25
 
26
26
  # @!attribute body
27
27
  # the body of the log entry to be displayed for this ActionLog Entry
28
28
  #
29
- # @return [String] -- Default ''
29
+ # @return [String]
30
30
  attr_accessor :body
31
31
 
32
32
  # Creates a new ActionLog entry in Moxi Works Platform
@@ -73,7 +73,7 @@ module MoxiworksPlatform
73
73
  required_opts = [:moxi_works_agent_id, :partner_contact_id]
74
74
  required_opts.each do |opt|
75
75
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
76
- opts[opt].nil? or opts[opt].empty?
76
+ opts[opt].nil? or opts[opt].to_s.empty?
77
77
  end
78
78
  results = []
79
79
  RestClient::Request.execute(method: :get,
@@ -109,7 +109,7 @@ module MoxiworksPlatform
109
109
  required_opts = [:moxi_works_agent_id, :partner_contact_id, :title, :body]
110
110
  required_opts.each do |opt|
111
111
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
112
- opts[opt].nil? or opts[opt].empty?
112
+ opts[opt].nil? or opts[opt].to_s.empty?
113
113
  end
114
114
  super(method, opts, url)
115
115
  end
@@ -170,7 +170,7 @@ module MoxiworksPlatform
170
170
  required_opts = [:moxi_works_agent_id]
171
171
  required_opts.each do |opt|
172
172
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
173
- opts[opt].nil? or opts[opt].empty?
173
+ opts[opt].nil? or opts[opt].to_s.empty?
174
174
  end
175
175
  super(method, opts, url)
176
176
  end
@@ -471,7 +471,7 @@ module MoxiworksPlatform
471
471
  required_opts = [:moxi_works_agent_id]
472
472
  required_opts.each do |opt|
473
473
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
474
- opts[opt].nil? or opts[opt].empty?
474
+ opts[opt].nil? or opts[opt].to_s.empty?
475
475
  end
476
476
  results = []
477
477
  RestClient::Request.execute(method: :get,
@@ -596,7 +596,7 @@ module MoxiworksPlatform
596
596
  required_opts = [:moxi_works_agent_id, :partner_contact_id]
597
597
  required_opts.each do |opt|
598
598
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
599
- opts[opt].nil? or opts[opt].empty?
599
+ opts[opt].nil? or opts[opt].to_s.empty?
600
600
  end
601
601
  RestClient::Request.execute(method: :delete,
602
602
  url: url,
@@ -674,7 +674,7 @@ module MoxiworksPlatform
674
674
  required_opts = [:moxi_works_agent_id, :partner_contact_id]
675
675
  required_opts.each do |opt|
676
676
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
677
- opts[opt].nil? or opts[opt].empty?
677
+ opts[opt].nil? or opts[opt].to_s.empty?
678
678
  end
679
679
  opts[:contact_id] = opts[:partner_contact_id]
680
680
  super(method, opts, url)
@@ -158,7 +158,7 @@ module MoxiworksPlatform
158
158
  required_opts = [:moxi_works_agent_id, :date_start, :date_end]
159
159
  required_opts.each do |opt|
160
160
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
161
- opts[opt].nil? or opts[opt].empty?
161
+ opts[opt].nil? or opts[opt].to_s.empty?
162
162
  end
163
163
  results = []
164
164
  RestClient::Request.execute(method: :get,
@@ -243,7 +243,7 @@ module MoxiworksPlatform
243
243
  required_opts = [:moxi_works_agent_id, :partner_event_id]
244
244
  required_opts.each do |opt|
245
245
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
246
- opts[opt].nil? or opts[opt].empty?
246
+ opts[opt].nil? or opts[opt].to_s.empty?
247
247
  end
248
248
  RestClient::Request.execute(method: :delete,
249
249
  url: url,
@@ -287,7 +287,7 @@ module MoxiworksPlatform
287
287
  required_opts = [:moxi_works_agent_id, :partner_event_id]
288
288
  required_opts.each do |opt|
289
289
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
290
- opts[opt].nil? or opts[opt].empty?
290
+ opts[opt].nil? or opts[opt].to_s.empty?
291
291
  end
292
292
  opts[:event_id] = opts[:partner_event_id]
293
293
  super(method, opts, url)
@@ -73,7 +73,7 @@ module MoxiworksPlatform
73
73
  required_opts = [:moxi_works_agent_id]
74
74
  required_opts.each do |opt|
75
75
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
76
- opts[opt].nil? or opts[opt].empty?
76
+ opts[opt].nil? or opts[opt].to_s.empty?
77
77
  end
78
78
  results = []
79
79
  RestClient::Request.execute(method: :get,
@@ -107,7 +107,7 @@ module MoxiworksPlatform
107
107
  required_opts = [:moxi_works_agent_id]
108
108
  required_opts.each do |opt|
109
109
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
110
- opts[opt].nil? or opts[opt].empty?
110
+ opts[opt].nil? or opts[opt].to_s.empty?
111
111
  end
112
112
  super(method, opts, url)
113
113
  end
@@ -96,7 +96,7 @@ module MoxiworksPlatform
96
96
  #
97
97
  # @return [Array][String] all defined accessors of this class
98
98
  def attributes
99
- self.class.attributes
99
+ self.class.attributes + numeric_attrs
100
100
  end
101
101
 
102
102
  # convert this class into a Hash structure where attributes are Hash key names and attribute values are Hash values
@@ -0,0 +1,299 @@
1
+ module MoxiworksPlatform
2
+ class Task < MoxiworksPlatform::Resource
3
+ # @!attribute moxi_works_agent_id
4
+ # moxi_works_agent_id is the Moxi Works Platform ID of the agent which a Task is
5
+ # or is to be associated with.
6
+ #
7
+ # this must be set for any Moxi Works Platform transaction
8
+ #
9
+ # @return [String] the Moxi Works Platform ID of the agent
10
+ attr_accessor :moxi_works_agent_id
11
+
12
+ # @!attribute partner_contact_id
13
+ # *your system's* unique ID for the Contact
14
+ #
15
+ # this must be set for any Moxi Works Platform transaction
16
+ #
17
+ # @return [String] your system's unique ID for the contact
18
+ attr_accessor :partner_contact_id
19
+
20
+ # @!attribute partner_task_id
21
+ #
22
+ # @return [String] your system's unique identifier for the Task
23
+ attr_accessor :partner_task_id
24
+
25
+ # @!attribute name
26
+ # the title to be displayed to the agent for this Task
27
+ #
28
+ # @return [String]
29
+ attr_accessor :name
30
+
31
+ # @!attribute description
32
+ # a detailed description to be displayed to the agent for this Task
33
+ #
34
+ # @return [String]
35
+ attr_accessor :description
36
+
37
+ # @!attribute due_at
38
+ # the Unix timestamp representing the due date of this Task
39
+ #
40
+ # @return [Integer]
41
+ attr_writer :due_at
42
+
43
+ # @!attribute duration
44
+ # the length (in minutes) estimated to complete this Task
45
+ #
46
+ # @return [Integer]
47
+ attr_writer :duration
48
+
49
+ # @!attribute status
50
+ # an enumerated string representing the state of this Task
51
+ #
52
+ # allowed values:
53
+ # active
54
+ # completed
55
+ # [nil]
56
+ #
57
+ # When creating a new task, the assumed state is 'active;' this attribute does
58
+ # not need to be populated when creating or updating a Task unless the
59
+ # status is 'completed.'
60
+ #
61
+ #
62
+ # @return [String, enumerated] -- Default: 'active'
63
+ attr_accessor :status
64
+
65
+ # @!attribute created_at
66
+ # the Unix timestamp representing the Date/Time this Task was created
67
+ #
68
+ # Read Only Attribute
69
+ #
70
+ # @return [Integer]
71
+ attr_writer :created_at
72
+
73
+ # @!attribute completed_at
74
+ # the Unix timestamp representing the Date/Time this task was completed.
75
+ #
76
+ # When the task is not in a 'completed' state, this attribute will be nil.
77
+ #
78
+ # When updating the *completed_at* attribute, the *status* attribute must
79
+ # be set to 'completed'
80
+ #
81
+ # @return [Integer|nil] -- Default nil
82
+ attr_writer :completed_at
83
+
84
+ # Creates a new Task in Moxi Works Platform
85
+ # @param [Hash] opts named parameter Hash
86
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this task is to be associated
87
+ # @option opts [String] :partner_task_id *REQUIRED* Your system's unique ID for this task.
88
+ # @option opts [String] :partner_contact_id *REQUIRED* Your system's unique ID for the Contact for whom this Task is to be associated.
89
+ #
90
+ # optional Task parameters
91
+ #
92
+ # @option opts [String] :name short description of the task
93
+ # @option opts [String] :description longer description of the task
94
+ # @option opts [Integer] :due_at Unix timestamp representing the due date
95
+ # @option opts [Integer] :duration Length of time in minutes that the task should take
96
+ #
97
+ # @return [MoxiworksPlatform::Task]
98
+ #
99
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
100
+ # named parameters aren't included
101
+ #
102
+ # @example
103
+ # MoxiworksPlatform::Task.create(
104
+ # moxi_works_agent_id: '123abc',
105
+ # partner_contact_id: '1234',
106
+ # partner_task_id: 'mySystemsUniqueTaskID',
107
+ # name: 'pick up client keys',
108
+ # description: 'pick up client keys from1234 there ave',
109
+ # due_at: Time.now.to_i + 86400,
110
+ # duration: 30
111
+ # )
112
+ #
113
+ def self.create(opts={})
114
+ required_opts = [:moxi_works_agent_id, :partner_task_id, :partner_contact_id]
115
+ required_opts.each do |opt|
116
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
117
+ opts[opt].nil? or opts[opt].to_s.empty?
118
+ end
119
+ self.send_request(:post, opts)
120
+ end
121
+
122
+ # Find an Task your system has previously created in Moxi Works Platform
123
+ # @param [Hash] opts named parameter Hash
124
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this task is associated
125
+ # @option opts [String] :partner_task_id *REQUIRED* Your system's unique ID for this task.
126
+ #
127
+ # @return [MoxiworksPlatform::Task]
128
+ #
129
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
130
+ # named parameters aren't included
131
+ #
132
+ def self.find(opts={})
133
+ required_opts = [:moxi_works_agent_id, :partner_task_id]
134
+ required_opts.each do |opt|
135
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
136
+ opts[opt].nil? or opts[opt].to_s.empty?
137
+ end
138
+ url = "#{MoxiworksPlatform::Config.url}/api/tasks/#{opts[:partner_task_id]}"
139
+ self.send_request(:get, opts, url)
140
+ end
141
+
142
+
143
+ # Search Agent's Tasks in Moxi Works Platform
144
+ # @param [Hash] opts named parameter Hash
145
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this contact is associated
146
+ # @option opts [Integer] :due_date_start *REQUIRED* Tasks due after specified date
147
+ # @options opts [Integer] :due_date_end *REQUIRED* tasks due before specified date
148
+ #
149
+ #
150
+ # optional Search parameters
151
+ #
152
+ # @option opts [String] :partner_contact_id The partner's ID for the contact whose tasks they are looking for
153
+ # @option opts [Integer] :page_number the page of results to return
154
+ #
155
+ # @return [Hash] with the format:
156
+ # {
157
+ # page_number: [Integer],
158
+ # total_pages: [Integer],
159
+ # tasks: [Array] containing MoxiworkPlatform::Task objects
160
+ # }
161
+ #
162
+ #
163
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
164
+ # named parameters aren't included
165
+ #
166
+ # @example
167
+ # results = MoxiworksPlatform::Contact.search(
168
+ # moxi_works_agent_id: '123abc',
169
+ # due_date_start: Time.now.to_i - 1296000,
170
+ # due_date_end: Time.now.to_i,
171
+ # page_number: 2
172
+ # )
173
+ #
174
+ def self.search(opts={})
175
+ url ||= "#{MoxiworksPlatform::Config.url}/api/tasks"
176
+ required_opts = [:moxi_works_agent_id, :due_date_start, :due_date_end]
177
+ required_opts.each do |opt|
178
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
179
+ opts[opt].nil? or opts[opt].to_s.empty?
180
+ end
181
+ results = []
182
+ json = { 'page_number': 1, 'total_pages': 0, 'tasks':[]}
183
+ RestClient::Request.execute(method: :get,
184
+ url: url,
185
+ payload: opts, headers: self.headers) do |response|
186
+ puts response if MoxiworksPlatform::Config.debug
187
+ self.check_for_error_in_response(response)
188
+ json = JSON.parse(response)
189
+ json['tasks'].each do |r|
190
+ results << MoxiworksPlatform::Task.new(r) unless r.nil? or r.empty?
191
+ end
192
+ json['tasks'] = results
193
+ end
194
+ json
195
+ end
196
+
197
+ # Updates an existing Task in Moxi Works Platform
198
+ # @param [Hash] opts named parameter Hash
199
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this task is to be associated
200
+ # @option opts [String] :partner_task_id *REQUIRED* Your system's unique ID for this task.
201
+ # @option opts [String] :partner_contact_id *REQUIRED* Your system's unique ID for the Contact for whom this Task is to be associated.
202
+ #
203
+ # optional Task parameters
204
+ #
205
+ # @option opts [String] :name short description of the task
206
+ # @option opts [String] :description longer description of the task
207
+ # @option opts [Integer] :due_at Unix timestamp representing the due date
208
+ # @option opts [Integer] :duration Length of time in minutes that the task should take
209
+ # @option opts [Integer] :completed_at Unix timestamp representing the date the task was completed
210
+ # @option opts [String] :status enumerated string representing task status
211
+ #
212
+ # @return [MoxiworksPlatform::Task]
213
+ #
214
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
215
+ # named parameters aren't included
216
+ #
217
+ # @example
218
+ # MoxiworksPlatform::Task.create(
219
+ # moxi_works_agent_id: '123abc',
220
+ # partner_contact_id: '1234',
221
+ # partner_task_id: 'mySystemsUniqueTaskID',
222
+ # name: 'pick up client keys',
223
+ # description: 'pick up client keys from1234 there ave',
224
+ # due_at: Time.now.to_i + 86400,
225
+ # duration: 30,
226
+ # status: 'completed',
227
+ # completed_at: Time.now.to_i,
228
+ # )
229
+ #
230
+ def self.update(opts={})
231
+ required_opts = [:moxi_works_agent_id, :partner_task_id, :partner_contact_id]
232
+ required_opts.each do |opt|
233
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
234
+ opts[opt].nil? or opts[opt].to_s.empty?
235
+ end
236
+ url = "#{MoxiworksPlatform::Config.url}/api/tasks/#{opts[:partner_task_id]}"
237
+ self.send_request(:put, opts, url)
238
+ end
239
+
240
+
241
+ # Send our remote request to the Moxi Works Platform
242
+ #
243
+ # @param [Hash] opts named parameter Hash
244
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this task is to be associated
245
+ # @option opts [String] :partner_task_id *REQUIRED* Your system's unique ID for this task.
246
+ # @option opts [String] :partner_contact_id *REQUIRED* Your system's unique ID for the Contact for whom this Task is to be associated.
247
+ #
248
+ # optional Task parameters
249
+ #
250
+ # @option opts [String] :name short description of the task
251
+ # @option opts [String] :description longer description of the task
252
+ # @option opts [Integer] :due_at Unix timestamp representing the due date
253
+ # @option opts [Integer] :duration Length of time in minutes that the task should take
254
+ # @option opts [Integer] :completed_at Unix timestamp representing the date the task was completed
255
+ # @option opts [String] :status enumerated string representing task status
256
+ #
257
+ # @return [MoxiworksPlatform::Task]
258
+ #
259
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
260
+ # named parameters aren't included
261
+ #
262
+ def self.send_request(method, opts={}, url=nil)
263
+ url ||= "#{MoxiworksPlatform::Config.url}/api/tasks"
264
+ required_opts = [:moxi_works_agent_id, :partner_task_id]
265
+ required_opts.each do |opt|
266
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
267
+ opts[opt].nil? or opts[opt].to_s.empty?
268
+ end
269
+ super(method, opts, url)
270
+ end
271
+
272
+ # Save an instance of MoxiWorksPlatform::Task to Moxi Works Platform
273
+ #
274
+ # @return [MoxiWorksPlatform:Task]
275
+ #
276
+ # @example
277
+ # task = MoxiWorksPlatform::Task.new()
278
+ # task.moxi_works_agent_id = '123abcd'
279
+ # task.partner_task_id = 'myUniqueTaskdentifier'
280
+ # task.status = 'completed'
281
+ # task.completed_at = Time.now.to_i
282
+ # task.save
283
+ def save
284
+ MoxiworksPlatform::Task.update(self.to_hash)
285
+ end
286
+
287
+ def created_at=(w)
288
+ raise ::MoxiworksPlatform::Exception::ArgumentError, 'created_at is a read-only attribute'
289
+ end
290
+
291
+ private
292
+
293
+ def int_attrs
294
+ [:due_at, :duration, :completed_at, :created_at]
295
+ end
296
+
297
+
298
+ end
299
+ end
@@ -1,3 +1,3 @@
1
1
  module MoxiworksPlatform
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxiworks_platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tres Wong-Godfrey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ files:
92
92
  - lib/moxiworks_platform/exception.rb
93
93
  - lib/moxiworks_platform/group.rb
94
94
  - lib/moxiworks_platform/resource.rb
95
+ - lib/moxiworks_platform/task.rb
95
96
  - lib/moxiworks_platform/version.rb
96
97
  - moxiworks_platform.gemspec
97
98
  homepage: https://github.com/moxiworks-platform/moxiworks-ruby