moxiworks_platform 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a2a814339155946906d80974370d8e8335aff15
4
- data.tar.gz: b6db5eb3132f59317c65c6fe68566065ff8ac80f
3
+ metadata.gz: f4d49576abd1c15d64e80f9ee278c1171da8b910
4
+ data.tar.gz: adfd70c2e4854f001666b920378e9e1893f50057
5
5
  SHA512:
6
- metadata.gz: 8d0886cc1acd4a873a14fec8cc96f129072f052fc0e86159e8416b4c7d43e1eaafedff48db1b88bfa33c0142bd0afbef9b6c25f1ae5140d28d7ac61629323bdd
7
- data.tar.gz: 22f5ee37d8b37bc527d1d3c62ab377197cc409d913467448d274ef8587389de5b8f8a4c8029d2b55af7242b45e6a6d36e16649091b743c1e4ace8495845eb759
6
+ metadata.gz: 1a6b7ae51c1e053bf30c5b99a7747de63690752688495b3ab88d857c334a4aaeeaf36c59ceb3b81705f8af26b14a503ed5925c0b3380cb069e893eec2dde8dfd
7
+ data.tar.gz: de0bba221f202a21ddd0857b10bec85c3fa99bd3fbb186b0619cf4f547def204f0b190f7d99548417ce70cbef44c5a2f4c5076015ddfecd14ae1d13cc649cea7
@@ -5,9 +5,10 @@ require 'moxiworks_platform/resource'
5
5
  require 'moxiworks_platform/credentials'
6
6
  require 'moxiworks_platform/contact'
7
7
  require 'moxiworks_platform/agent'
8
+ require 'moxiworks_platform/event'
8
9
 
9
10
 
10
11
 
11
12
  module MoxiworksPlatform
12
- # Your code goes here...
13
+
13
14
  end
@@ -425,7 +425,7 @@ module MoxiworksPlatform
425
425
 
426
426
  # Find a Contact your system has previously created in Moxi Works Platform
427
427
  # @param [Hash] opts named parameter Hash
428
- # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this contact is to be associated
428
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this contact is associated
429
429
  # @option opts [String] :partner_contact_id *REQUIRED* Your system's unique ID for this contact.
430
430
  #
431
431
  # @return [MoxiworksPlatform::Contact]
@@ -440,7 +440,7 @@ module MoxiworksPlatform
440
440
 
441
441
  # Search an Agent's Contacts in Moxi Works Platform
442
442
  # @param [Hash] opts named parameter Hash
443
- # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this contact is to be associated
443
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this contact is associated
444
444
  #
445
445
  # optional Search parameters
446
446
  #
@@ -691,7 +691,7 @@ module MoxiworksPlatform
691
691
  MoxiworksPlatform::Contact.update(self.to_hash)
692
692
  end
693
693
 
694
- # Delete an instance of MoxiWorksPlatform::Contact from Moxi Works Platform
694
+ # Delete an instance of MoxiWorksPlatform::Contact from Moxi Works Platform that your system has previously created
695
695
  #
696
696
  # @return [Boolean] -- success of the delete action
697
697
  #
@@ -704,39 +704,16 @@ module MoxiworksPlatform
704
704
  end
705
705
 
706
706
  private
707
- def method_missing(meth, *args, &block)
708
- float_attrs = [:property_baths, :search_min_baths]
709
- int_attrs = [:property_beds, :property_list_price, :search_min_year_built,
710
- :search_min_sq_ft, :search_min_price, :search_min_beds,
711
- :search_max_year_built, :search_max_sq_ft, :search_max_price,
712
- :search_max_lot_size]
713
- all_attrs = float_attrs + int_attrs
714
-
715
- name = meth.to_sym
716
- if all_attrs.include? name
717
- return numeric_value_for(name, type: :integer) if int_attrs.include? name
718
- return numeric_value_for(name, type: :float) if float_attrs.include? name
719
- end
720
- super(meth, *args, &block)
707
+
708
+ def float_attrs
709
+ [:property_baths, :search_min_baths]
721
710
  end
722
711
 
723
- def numeric_value_for(attr_name, opts={})
724
- val = self.instance_variable_get("@#{attr_name}")
725
- return val.to_i if val.is_a? Numeric and opts[:type] == :integer
726
- return val if val.is_a? Numeric
727
- val.gsub!(/[^[:digit:]|\.]/, '') if val.is_a? String
728
- case opts[:type]
729
- when :integer
730
- instance_variable_set("@#{attr_name}", (val.nil? or val.empty?) ? nil : val.to_i)
731
- when :float
732
- instance_variable_set("@#{attr_name}", (val.nil? or val.empty?) ? nil : val.to_f)
733
- else
734
- instance_variable_set("@#{attr_name}", nil)
735
- end
736
- self.instance_variable_get("@#{attr_name}")
737
- rescue => e
738
- puts "problem with auto conversion: #{e.message} #{e.backtrace}"
739
- nil
712
+ def int_attrs
713
+ [:property_beds, :property_list_price, :search_min_year_built,
714
+ :search_min_sq_ft, :search_min_price, :search_min_beds,
715
+ :search_max_year_built, :search_max_sq_ft, :search_max_price,
716
+ :search_max_lot_size]
740
717
  end
741
718
 
742
719
  end
@@ -0,0 +1,334 @@
1
+ module MoxiworksPlatform
2
+ # = Moxi Works Platform Event
3
+ class Event < MoxiworksPlatform::Resource
4
+ # @!attribute moxi_works_agent_id
5
+ # moxi_works_agent_id is the Moxi Works Platform ID of the agent which a event is
6
+ # or is to be associated with.
7
+ #
8
+ # this must be set for any Moxi Works Platform transaction
9
+ #
10
+ # @return [String] the Moxi Works Platform ID of the agent
11
+ attr_accessor :moxi_works_agent_id
12
+
13
+ # @!attribute partner_event_id
14
+ # your system's event ID for the event
15
+ #
16
+ # @return [String] representing the ID of the event in your system
17
+ attr_accessor :partner_event_id
18
+
19
+ # @!attribute event_subject
20
+ # a short description of the event
21
+ #
22
+ # @return [String]
23
+ attr_accessor :event_subject
24
+
25
+ # @!attribute location
26
+ # a short description of the location of the event
27
+ #
28
+ # @return [String]
29
+ attr_accessor :event_location
30
+
31
+ # @!attribute note
32
+ # a more detailed description of the event
33
+ #
34
+ # @return [String]
35
+ attr_accessor :note
36
+
37
+ # @!attribute send_reminder
38
+ # whether a reminder should be sent to the agent
39
+ #
40
+ # @return [Boolean]
41
+ attr_accessor :send_reminder
42
+
43
+ # @!attribute remind_minutes_before
44
+ # how many minutes before the event a reminder should be sent (if send_reminder is true)
45
+ #
46
+ # @return [Integer]
47
+ attr_writer :remind_minutes_before
48
+
49
+ # @!attribute is_meeting
50
+ # whether this event is a meeting
51
+ #
52
+ # @return [Boolean]
53
+ attr_accessor :is_meeting
54
+
55
+ # @!attribute event_start
56
+ # a unix timestamp representing the start time of the event
57
+ #
58
+ # @return [Integer]
59
+ attr_writer :event_start
60
+
61
+ # @!attribute event_end
62
+ # a unix timestamp representing the end time of the event
63
+ #
64
+ # @return [Integer]
65
+ attr_writer :event_end
66
+
67
+ # @!attribute recurring
68
+ # whether the event is recurring
69
+ #
70
+ # @return [Boolean]
71
+ attr_accessor :recurring
72
+
73
+ # @!attribute all_day
74
+ # whether the event is an all day event
75
+ #
76
+ # @return [Boolean]
77
+ attr_accessor :all_day
78
+
79
+
80
+ # Creates a new Event in Moxi Works Platform
81
+ # @param [Hash] opts named parameter Hash
82
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this event is to be associated
83
+ # @option opts [String] :partner_event_id *REQUIRED* Your system's unique ID for this event.
84
+ #
85
+ # optional Event parameters
86
+ #
87
+ # @option opts [String] :event_subject a brief human-readable description of the event
88
+ # @option opts [String] :event_location human-readable description of the event's location
89
+ # @option opts [String] :note human-readable details regarding the event
90
+ # @option opts [Boolean] :send_reminder whether a reminder should be sent beforehand
91
+ # @option opts [Integer] :remind_minutes_before how many minutes before the event the reminder should be sent (if send_reminder is true)
92
+ # @option opts [Boolean] :is_meeting whether the event is a meeting
93
+ # @option opts [Integer] :event_start Unix timestamp representing the start time of the event
94
+ # @option opts [Integer] :event_end Unix timestamp representing the end time of the event
95
+ # @option opts [Boolean] :recurring whether the event is a recurring event
96
+ # @option opts [Boolean] :all_day whether the event is an all day event
97
+ #
98
+ # @return [MoxiworksPlatform::Event]
99
+ #
100
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
101
+ # named parameters aren't included
102
+ #
103
+ # @example
104
+ # MoxiworksPlatform::Event.create(
105
+ # partner_event_id: 'mySystemsUniqueEventID',
106
+ # event_subject: 'foo deeaz',
107
+ # event_location: '1234 there ave',
108
+ # note: 'yo, whatup?',
109
+ # send_reminder: true,
110
+ # remind_minutes_before: 10,
111
+ # is_meeting: true,
112
+ # event_start: Time.now.to_i,
113
+ # event_end: Time.now.to_i + 86400,
114
+ # recurring: false,
115
+ # all_day: false
116
+ # )
117
+ #
118
+ def self.create(opts={})
119
+ self.send_request(:post, opts)
120
+ end
121
+
122
+ # Find an Event 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 event is associated
125
+ # @option opts [String] :partner_event_id *REQUIRED* Your system's unique ID for this event.
126
+ #
127
+ # @return [MoxiworksPlatform::Event]
128
+ #
129
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
130
+ # named parameters aren't included
131
+ #
132
+ def self.find(opts={})
133
+ url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
134
+ self.send_request(:get, opts, url)
135
+ end
136
+
137
+
138
+ # Search an Agent's Events in Moxi Works Platform
139
+ # @param [Hash] opts named parameter Hash
140
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this event is associated
141
+ # @option opts [Integer] :date_start *REQUIRED* The Unix timestamp representing the date after which to search
142
+ # @option opts [Integer] :date_end *REQUIRED* The Unix timestamp representing the date before which to search
143
+ #
144
+ # @return [Array] containing Hash objects formatted as follows:
145
+ # { "date" => "MM/DD/YY",
146
+ # "events" => [ MoxiworkPlatform::Event, MoxiworkPlatform::Event ]
147
+ # }
148
+ #
149
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
150
+ # named parameters aren't included
151
+ #
152
+ # @example
153
+ # results = MoxiworksPlatform::Contact.search(
154
+ # moxi_works_agent_id: '123abc',
155
+ # date_start: Time.now - 60 * 60 * 24 * 7, # 1 week
156
+ # date_end: Time.now
157
+ # )
158
+ #
159
+ def self.search(opts={})
160
+ url ||= "#{MoxiworksPlatform::Config.url}/api/events"
161
+ required_opts = [:moxi_works_agent_id, :date_start, :date_end]
162
+ required_opts.each do |opt|
163
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
164
+ opts[opt].nil? or opts[opt].empty?
165
+ end
166
+ results = []
167
+ RestClient::Request.execute(method: :get,
168
+ url: url,
169
+ payload: opts, headers: self.headers) do |response|
170
+ puts response if MoxiworksPlatform::Config.debug
171
+ self.check_for_error_in_response(response)
172
+ json = JSON.parse(response)
173
+ json.each do |events_for_date|
174
+ events = []
175
+ events_for_date.each do |date, event_array|
176
+ event_array.each do |r|
177
+ events << MoxiworksPlatform::Event.new(r) unless r.nil? or r.empty?
178
+ end
179
+ results << {date: date, events: events}
180
+ end
181
+ end
182
+ end
183
+ results
184
+ end
185
+
186
+ # Updates a new Event in Moxi Works Platform
187
+ # @param [Hash] opts named parameter Hash
188
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this event is to be associated
189
+ # @option opts [String] :partner_event_id *REQUIRED* Your system's unique ID for this event.
190
+ #
191
+ # optional Event parameters
192
+ #
193
+ # @option opts [String] :event_subject a brief human-readable description of the event
194
+ # @option opts [String] :event_location human-readable description of the event's location
195
+ # @option opts [String] :note human-readable details regarding the event
196
+ # @option opts [Boolean] :send_reminder whether a reminder should be sent beforehand
197
+ # @option opts [Integer] :remind_minutes_before how many minutes before the event the reminder should be sent (if send_reminder is true)
198
+ # @option opts [Boolean] :is_meeting whether the event is a meeting
199
+ # @option opts [Integer] :event_start Unix timestamp representing the start time of the event
200
+ # @option opts [Integer] :event_end Unix timestamp representing the end time of the event
201
+ # @option opts [Boolean] :recurring whether the event is a recurring event
202
+ # @option opts [Boolean] :all_day whether the event is an all day event
203
+ #
204
+ # @return [MoxiworksPlatform::Event]
205
+ #
206
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
207
+ # named parameters aren't included
208
+ #
209
+ # @example
210
+ # MoxiworksPlatform::Event.update(
211
+ # partner_event_id: 'mySystemsUniqueEventID',
212
+ # event_subject: 'foo deeaz',
213
+ # event_location: '1234 there ave',
214
+ # note: 'yo, whatup?',
215
+ # send_reminder: true,
216
+ # remind_minutes_before: 10,
217
+ # is_meeting: true,
218
+ # event_start: Time.now.to_i,
219
+ # event_end: Time.now.to_i + 86400,
220
+ # recurring: false,
221
+ # all_day: false
222
+ # )
223
+ #
224
+ def self.update(opts={})
225
+ opts[:event_id] = opts[:partner_event_id]
226
+ url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
227
+ self.send_request(:put, opts, url)
228
+ end
229
+
230
+ # Delete an Event your system has previously created in Moxi Works Platform
231
+ # @param [Hash] opts named parameter Hash
232
+ #
233
+ # required parameters
234
+ #
235
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this event is associated
236
+ # @option opts [String] :partner_event_id *REQUIRED* Your system's unique ID for this event.
237
+ #
238
+ # @return [Boolean] -- success of the delete action
239
+ #
240
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
241
+ # named parameters aren't included
242
+ #
243
+ # @example
244
+ # success = MoxiWorksPlatform::Event.delete(moxi_works_agent_id: '123abcd', partner_event_id: 'myUniqueEventId' )
245
+ #
246
+ def self.delete(opts={})
247
+ url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
248
+ required_opts = [:moxi_works_agent_id, :partner_event_id]
249
+ required_opts.each do |opt|
250
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
251
+ opts[opt].nil? or opts[opt].empty?
252
+ end
253
+ RestClient::Request.execute(method: :delete,
254
+ url: url,
255
+ payload: opts, headers: self.headers) do |response|
256
+ puts response if MoxiworksPlatform::Config.debug
257
+ json = JSON.parse(response)
258
+ raise ::MoxiworksPlatform::Exception::RemoteRequestFailure,
259
+ 'unable to delete' if json['status'] == 'error'
260
+ json['status'] == 'success'
261
+ end
262
+ end
263
+
264
+ # Send our remote request to the Moxi Works Platform
265
+ #
266
+ # @param [String] method The HTTP method to be used when connecting; ex: :put, :post, :get
267
+ # @param [Hash] opts
268
+ # @option opts [String] :moxi_works_agent_id *REQUIRED* The Moxi Works Agent ID for the agent to which this event is associated
269
+ # @option opts [String] :partner_event_id *REQUIRED* Your system's unique ID for this event.
270
+ #
271
+ # optional Event parameters
272
+ #
273
+ # @option opts [String] :event_subject a brief human-readable description of the event
274
+ # @option opts [String] :event_location human-readable description of the event's location
275
+ # @option opts [String] :note human-readable details regarding the event
276
+ # @option opts [Boolean] :send_reminder whether a reminder should be sent beforehand
277
+ # @option opts [Integer] :remind_minutes_before how many minutes before the event the reminder should be sent (if send_reminder is true)
278
+ # @option opts [Boolean] :is_meeting whether the event is a meeting
279
+ # @option opts [Integer] :event_start Unix timestamp representing the start time of the event
280
+ # @option opts [Integer] :event_end Unix timestamp representing the end time of the event
281
+ # @option opts [Boolean] :recurring whether the event is a recurring event
282
+ # @option opts [Boolean] :all_day whether the event is an all day event
283
+ #
284
+ # @return [MoxiworksPlatform::Event]
285
+ #
286
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
287
+ # named parameters aren't included
288
+ #
289
+ def self.send_request(method, opts={}, url=nil)
290
+ url ||= "#{MoxiworksPlatform::Config.url}/api/events"
291
+ required_opts = [:moxi_works_agent_id, :partner_event_id]
292
+ required_opts.each do |opt|
293
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
294
+ opts[opt].nil? or opts[opt].empty?
295
+ end
296
+ opts[:event_id] = opts[:partner_event_id]
297
+ super(method, opts, url)
298
+ end
299
+
300
+ # Save an instance of MoxiWorksPlatform::Event to Moxi Works Platform
301
+ #
302
+ # @return [MoxiWorksPlatform:Event]
303
+ #
304
+ # @example
305
+ # event = MoxiWorksPlatform::Event.new()
306
+ # event.moxi_works_agent_id = '123abcd'
307
+ # event.partner_event_id = 'myUniqueEventdentifier'
308
+ # event.event_start = Time.now.to_i
309
+ # event.save
310
+ def save
311
+ MoxiworksPlatform::Event.update(self.to_hash)
312
+ end
313
+
314
+ # Delete an instance of MoxiWorksPlatform::Event from Moxi Works Platform that your system has previously created
315
+ #
316
+ # @return [Boolean] -- success of the delete action
317
+ #
318
+ # @example
319
+ # event = MoxiWorksPlatform::Event.find(moxi_works_agent_id: '123abcd', partner_event_id: 'myUniqueEventtId' )
320
+ # success = event.delete
321
+ #
322
+ def delete
323
+ MoxiworksPlatform::Event.delete(self.to_hash)
324
+ end
325
+
326
+ private
327
+
328
+ def int_attrs
329
+ [:remind_minutes_before, :event_start, :event_end]
330
+ end
331
+
332
+
333
+ end
334
+ end
@@ -83,6 +83,15 @@ module MoxiworksPlatform
83
83
  end
84
84
  end
85
85
 
86
+ def method_missing(meth, *args, &block)
87
+ name = meth.to_sym
88
+ if numeric_attrs.include? name
89
+ return numeric_value_for(name, type: :integer) if int_attrs.include? name
90
+ return numeric_value_for(name, type: :float) if float_attrs.include? name
91
+ end
92
+ super(meth, *args, &block)
93
+ end
94
+
86
95
  # all available accessors defined in this class
87
96
  #
88
97
  # @return [Array][String] all defined accessors of this class
@@ -111,6 +120,42 @@ module MoxiworksPlatform
111
120
  end
112
121
  end
113
122
 
123
+ def numeric_value_for(attr_name, opts={})
124
+ val = self.instance_variable_get("@#{attr_name}")
125
+ return val.to_i if val.is_a? Numeric and opts[:type] == :integer
126
+ return val if val.is_a? Numeric
127
+ val.gsub!(/[^[:digit:]|\.]/, '') if val.is_a? String
128
+ case opts[:type]
129
+ when :integer
130
+ instance_variable_set("@#{attr_name}", (val.nil? or val.empty?) ? nil : val.to_i)
131
+ when :float
132
+ instance_variable_set("@#{attr_name}", (val.nil? or val.empty?) ? nil : val.to_f)
133
+ else
134
+ instance_variable_set("@#{attr_name}", nil)
135
+ end
136
+ self.instance_variable_get("@#{attr_name}")
137
+ rescue => e
138
+ puts "problem with auto conversion: #{e.message} #{e.backtrace}"
139
+ nil
140
+ end
141
+
142
+ # used by method_missing to ensure that a number is the type we expect it to be
143
+ def numeric_attrs
144
+ int_attrs + float_attrs
145
+ end
146
+
147
+ # used by method_missing to ensure that a number is the type we expect it to be
148
+ # this should be overridden if we have any int values we want to return as ints
149
+ def int_attrs
150
+ []
151
+ end
152
+
153
+ # used by method_missing to ensure that a number is the type we expect it to be
154
+ # this should be overridden if we have any float values we want to return as floats
155
+ def float_attrs
156
+ []
157
+ end
158
+
114
159
  end
115
160
 
116
161
  end
@@ -1,3 +1,3 @@
1
1
  module MoxiworksPlatform
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.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.2.2
4
+ version: 0.3.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-05-01 00:00:00.000000000 Z
11
+ date: 2016-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - lib/moxiworks_platform/config.rb
88
88
  - lib/moxiworks_platform/contact.rb
89
89
  - lib/moxiworks_platform/credentials.rb
90
+ - lib/moxiworks_platform/event.rb
90
91
  - lib/moxiworks_platform/exception.rb
91
92
  - lib/moxiworks_platform/resource.rb
92
93
  - lib/moxiworks_platform/version.rb