Permalink
Browse files

Added functionality to get user availability

  • Loading branch information...
1 parent a62831f commit debd23963feb1ad433cdc40e165e4b5141add3f1 Artis Abolts committed May 29, 2012
View
@@ -1,5 +1,6 @@
coverage
spec/config.yml
+spec/fixtures/get_user_availability.yml
pkg
.yardoc
doc
View
@@ -29,6 +29,7 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
rubyntlm (0.1.1)
+ tzinfo (0.3.33)
yard (0.6.4)
PLATFORMS
@@ -41,4 +42,5 @@ DEPENDENCIES
rake
rcov
rspec (~> 2.6.0)
+ tzinfo
yard
View
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rcov"
s.add_development_dependency "yard"
s.add_development_dependency "BlueCloth" # required by yard
+ s.add_development_dependency "tzinfo"
s.files = Dir.glob("{lib,spec}/**/*") + %w(README.md LICENSE)
s.require_paths = ["lib"]
View
@@ -1,6 +1,8 @@
require "singleton"
require "delegate"
require "base64"
+require 'kconv' # Need for rubyntlm on Ruby 1.9
+require 'tzinfo'
require "active_support/core_ext"
require "nokogiri"
@@ -47,6 +49,8 @@
require "exchanger/elements/meeting_cancellation"
require "exchanger/elements/task"
require "exchanger/elements/distribution_list"
+require "exchanger/elements/calendar_event_details"
+require "exchanger/elements/calendar_event"
# Operations
require "exchanger/operation"
@@ -59,6 +63,7 @@
require "exchanger/operations/delete_item"
require "exchanger/operations/resolve_names"
require "exchanger/operations/expand_dl"
+require "exchanger/operations/get_user_availability"
module Exchanger
NS = {
@@ -0,0 +1,11 @@
+module Exchanger
+ # The CalendarEvent element represents a unique calendar item occurrence.
+ #
+ # http://msdn.microsoft.com/en-us/library/aa564053(v=exchg.140)
+ class CalendarEvent < Item
+ element :start_time, :type => Time
+ element :end_time, :type => Time
+ element :busy_type
+ element :calendar_event_details, :type => CalendarEventDetails
+ end
+end
@@ -0,0 +1,8 @@
+module Exchanger
+ # The CalendarEventDetails element provides additional information about a calendar event
+ #
+ # http://msdn.microsoft.com/en-us/library/aa579732(v=exchg.140)
+ class CalendarEventDetails < Item
+ element :id, :type => Identifier
+ end
+end
@@ -0,0 +1,92 @@
+module Exchanger
+ # Getting User Availability
+ #
+ # http://msdn.microsoft.com/en-us/library/aa494212(v=exchg.80)
+ class GetUserAvailability < Operation
+ class Request < Operation::Request
+ attr_accessor :time_zone, :email_address, :start_time, :end_time
+
+ # Reset request options to defaults.
+ def reset
+ @time_zone = 'Europe/London'
+ @email_address = 'test.test@test.com'
+ @start_time = Date.today.to_time + 1
+ @end_time = (Date.today + 1).to_time - 1
+ end
+
+ def time_zone_period
+ begin
+ current_tz = TZInfo::Timezone.get(time_zone).current_period
+ rescue => e
+ raise Exchanger::Operation::ResponseError.new(e, 500)
+ end
+ end
+
+ def to_xml
+ current_tz = time_zone_period
+ minutes_of_utc_offset = current_tz.utc_offset/60 # Get the base offset of the timezone from UTC in minutes
+ minutes_of_std_offset = current_tz.std_offset/60 # Get the daylight savings offset from standard time in minutes
+
+ start_date_time = start_time.strftime("%Y-%m-%dT%H:%M:%S")
+ end_date_time = end_time.strftime("%Y-%m-%dT%H:%M:%S")
+
+ Nokogiri::XML::Builder.new do |xml|
+ xml.send("soap:Envelope", "xmlns:xsi" => NS["xsi"], "xmlns:xsd" => NS["xsd"], "xmlns:soap" => NS["soap"], "xmlns:t" => NS["t"], "xmlns:m" => NS["m"]) do
+ xml.send("soap:Body") do
+ xml.send("m:GetUserAvailabilityRequest") do
+ xml.send("t:TimeZone") do
+ xml.send("t:Bias", (minutes_of_utc_offset * -1))
+ # if daylight savings time is active for current time zone
+ # How to find correct standard time and daylight saving time configuration
+ if current_tz.dst?
+ xml.send("t:StandardTime") do
+ xml.send("t:Bias", 0)
+ xml.send("t:Time", "04:00:00")
+ xml.send("t:DayOrder", 5)
+ xml.send("t:Month", 10)
+ xml.send("t:DayOfWeek", "Sunday")
+ end
+ xml.send("t:DaylightTime") do
+ xml.send("t:Bias", (minutes_of_std_offset * -1))
+ xml.send("t:Time", "03:00:00")
+ xml.send("t:DayOrder", 5)
+ xml.send("t:Month", 3)
+ xml.send("t:DayOfWeek", "Sunday")
+ end
+ end
+ end
+ xml.send("m:MailboxDataArray") do
+ xml.send("t:MailboxData") do
+ xml.send("t:Email") do
+ xml.send("t:Address", email_address)
+ end
+ xml.send("t:AttendeeType", "Required")
+ xml.send("t:ExcludeConflicts", "false")
+ end
+ end
+ xml.send("t:FreeBusyViewOptions") do
+ xml.send("t:TimeWindow") do
+ xml.send("t:StartTime", start_date_time)
+ xml.send("t:EndTime", end_date_time)
+ end
+ xml.send("t:MergedFreeBusyIntervalInMinutes", 60)
+ xml.send("t:RequestedView", "DetailedMerged")
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ class Response < Operation::Response
+ def items
+ to_xml.xpath(".//t:CalendarEventArray", NS).children.map do |node|
+ item_klass = Exchanger.const_get(node.name)
+ item_klass.new_from_xml(node)
+ end
+ end
+ end
+ end
+
+end
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::CalendarFolder do
before do
View
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::Client do
before do
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::Contact do
before do
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::Element do
end
View
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::Field do
describe "String (default type)" do
@@ -0,0 +1,4 @@
+email_address: test.test@test.com
+time_zone: EET
+start_time: '2012-05-31 00:00:01'
+end_time: '2012-05-31 23:59:59'
View
@@ -1,4 +1,4 @@
-require "spec_helper"
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Exchanger::Folder do
describe "Root" do
@@ -0,0 +1,44 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Exchanger::GetUserAvailability do
+ describe "Get user availability" do
+ before(:all) do
+ @valid_attributes = YAML.load_file("#{File.dirname(__FILE__)}/fixtures/get_user_availability.yml")
+ @valid_attributes["start_time"] = Time.parse(@valid_attributes["start_time"])
+ @valid_attributes["end_time"] = Time.parse(@valid_attributes["end_time"])
+ end
+
+ before do
+ @response = Exchanger::GetUserAvailability.run(@valid_attributes)
+ @items = @response.items
+ end
+
+ it "should be sucessfull with default values" do
+ Exchanger::GetUserAvailability.run().status.should == 200
+ end
+
+ it "should be sucessfull with valid data" do
+ @response.status.should == 200
+ end
+
+ it "should response have calendar event items" do
+ @items.all?{ |i| i.class.name == "Exchanger::CalendarEvent" }.should be_true
+ end
+
+ it "should calendar event item have valid attributes" do
+ ["start_time", "end_time", "busy_type", "calendar_event_details"].each do |k|
+ @items[0].attributes.keys.include?(k).should be_true
+ end
+ end
+
+ it "should calendar event items have calendar event details" do
+ @items.all?{ |i| i.calendar_event_details.class.name == "Exchanger::CalendarEventDetails" }.should be_true
+ end
+
+ it "should calendar event details item have valid attributes" do
+ ["id","subject","location", "is_meeting", "is_recurring", "is_exception", "is_reminder_set", "is_private"].each do |k|
+ @items[0].calendar_event_details.attributes.keys.include?(k).should be_true
+ end
+ end
+ end
+end

0 comments on commit debd239

Please sign in to comment.