Skip to content

Commit

Permalink
feat: PPT-642 Add Place API support (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis authored Aug 30, 2024
1 parent 72bbe61 commit ebdd7e4
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 11 deletions.
43 changes: 33 additions & 10 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
# This configuration file was generated by `ameba --gen-config`
# on 2020-03-10 06:52:09 UTC using Ameba version 0.10.1.
# The point is for the user to remove these configuration records
# one by one as the reported problems are removed from the code base.

# Problems found: 83
# Run `ameba --only Style/VariableNames` for details
Style/VariableNames:
Description: Enforces variable names to be in underscored case
Enabled: true
Lint/NotNil:
Description: Identifies usage of `not_nil!` calls
Enabled: false
Severity: Warning

Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions
Enabled: false
Severity: Warning

Naming/AccessorMethodName:
Description: Makes sure that accessor methods are named properly
Enabled: false
Severity: Convention

Naming/QueryBoolMethods:
Description: Reports boolean properties without the `?` suffix
Enabled: false
Severity: Convention

Metrics/CyclomaticComplexity:
Description: Disallows methods with a cyclomatic complexity higher than `MaxComplexity`
Enabled: false
Severity: Warning

Naming/BlockParameterName:
Description: Disallows non-descriptive block parameter names
Enabled: false
Severity: Convention

Naming/PredicateName:
Description: Disallows tautological predicate names
Enabled: false
Severity: Convention
80 changes: 80 additions & 0 deletions spec/places/places_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require "../spec_helper"

describe Office365::Places do
describe "list_places" do
it "list_places works for rooms" do
SpecHelper.mock_client_auth
SpecHelper.mock_list_room

client = Office365::Client.new(**SpecHelper.mock_credentials)

rooms = client.list_rooms

rooms.value.size.should eq(2)
rooms.value.first.is_a?(Office365::Room).should be_true

list = client.list_places

list.value.size.should eq(2)
list.value.first.is_a?(Office365::Room).should be_true
end

it "list_places works for roomList" do
SpecHelper.mock_client_auth
SpecHelper.mock_list_room_list

client = Office365::Client.new(**SpecHelper.mock_credentials)

room_list = client.list_room_list

room_list.value.size.should eq(2)
room_list.value.first.is_a?(Office365::RoomList).should be_true

list = client.list_places(type: Office365::PlaceType::RoomList)

list.value.size.should eq(2)
list.value.first.is_a?(Office365::RoomList).should be_true
end
end

describe "#get_place" do
it "get room when room id is provided" do
SpecHelper.mock_client_auth
SpecHelper.mock_get_room

client = Office365::Client.new(**SpecHelper.mock_credentials)
id = "979e9793-3e91-40eb-b18c-0ea937893956"

room = client.get_room(id)
room.is_a?(Office365::Room).should be_true
room.id.should eq(id)
end

it "get RoomList when room list email provided" do
SpecHelper.mock_client_auth
SpecHelper.mock_get_room_list

client = Office365::Client.new(**SpecHelper.mock_credentials)
email = "Building2Rooms@contoso.com"

room = client.get_room_list(email)
room.is_a?(Office365::RoomList).should be_true
room.email_address.should eq(email)
end
end

describe "#list_room_in_room_list" do
it "list rooms in room list" do
SpecHelper.mock_client_auth
SpecHelper.mock_get_room_in_room_list

client = Office365::Client.new(**SpecHelper.mock_credentials)
email = "Building2Rooms@contoso.com"

rooms = client.list_rooms_in_room_list(email)
rooms.is_a?(Office365::RoomLists).should be_true
rooms.value.size.should eq(3)
rooms.value.first.is_a?(Office365::RoomList).should be_true
end
end
end
232 changes: 231 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,25 @@ module SpecHelper
Office365::User.from_json(%({"id":"1234","mail":"foo@bar.com","displayName":"Foo Bar","userPrincipalName":"foo@bar.com","businessPhones":[]}))
end

def mock_user2_data
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"id": "0faa49e2-0602-41c2-8a7b-1438333c0af1",
"businessPhones": [] of String,
"displayName": "Adele Vance",
"givenName": nil,
"jobTitle": nil,
"mail": nil,
"mobilePhone": nil,
"officeLocation": nil,
"preferredLanguage": nil,
"surname": nil,
"userPrincipalName": "adelevancetest@testing.onmicrosoft.com",
}
end

def mock_user2
Office365::User.from_json(%({"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity","id":"0faa49e2-0602-41c2-8a7b-1438333c0af1","businessPhones":[],"displayName":"Adele Vance","givenName":null,"jobTitle":null,"mail":null,"mobilePhone":null,"officeLocation":null,"preferredLanguage":null,"surname":null,"userPrincipalName":"adelevancetest@testing.onmicrosoft.com"}))
Office365::User.from_json(mock_user2_data.to_json)
end

def mock_invitation
Expand Down Expand Up @@ -418,6 +435,219 @@ module SpecHelper
],
}
end

def mock_list_room
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/microsoft.graph.room")
.to_return(body: mock_list_rooms_data.to_json)
end

def mock_list_room_list
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/microsoft.graph.roomList")
.to_return(body: mock_list_room_list_data.to_json)
end

def mock_list_rooms_data
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/microsoft.graph.room",
"value": [
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78989EB1",
"emailAddress": "cf100@contoso.com",
"displayName": "Conf Room 100",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA",
},
"geoCoordinates": {
"latitude": 47.640568390488626,
"longitude": -122.1293731033803,
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "100",
"capacity": 50,
"building": "1",
"floorNumber": 1,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"bean bags",
],
"audioDeviceName": nil,
"videoDeviceName": nil,
"displayDevice": "surface hub",
},
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78970B97",
"emailAddress": "cf200@contoso.com",
"displayName": "Conf Room 200",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA",
},
"geoCoordinates": {
"latitude": 47.640568390488625,
"longitude": -122.1293731033802,
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "200",
"capacity": 40,
"building": "2",
"floorNumber": 2,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"benches",
"nice view",
],
"audioDeviceName": nil,
"videoDeviceName": nil,
"displayDevice": "surface hub",
},
],
}
end

def mock_list_room_list_data
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/microsoft.graph.roomList",
"value": [
{
"id": "DC404124-302A-92AA-F98D-7B4DEB0C1705",
"displayName": "Building 1",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA",
},
"geocoordinates": nil,
"phone": nil,
"emailAddress": "bldg1@contoso.com",
},
{
"id": "DC404124-302A-92AA-F98D-7B4DEB0C1706",
"displayName": "Building 2",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA",
},
"geocoordinates": nil,
"phone": nil,
"emailAddress": "bldg2@contoso.com",
},
],
}
end

def mock_get_room
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/979e9793-3e91-40eb-b18c-0ea937893956")
.to_return(body: mock_get_room_data.to_json)
end

def mock_get_room_list
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/Building2Rooms%40contoso.com")
.to_return(body: mock_get_room_data.to_json)
end

def mock_get_room_data
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/$entity",
"@odata.type": "#microsoft.graph.roomList",
"id": "979e9793-3e91-40eb-b18c-0ea937893956",
"displayName": "Building 2 Rooms",
"address": nil,
"geoCoordinates": nil,
"phone": "",
"emailAddress": "Building2Rooms@contoso.com",
}
end

def mock_get_room_in_room_list
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/Building2Rooms%40contoso.com/microsoft.graph.roomlist/rooms")
.to_return(body: mock_get_room_in_room_list_data.to_json)
end

def mock_get_room_in_room_list_data
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#places('Building2Rooms%40contoso.com')/microsoft.graph.roomList/rooms",
"value": [
{
"id": "f4119db7-9a33-4bfe-a387-4444b9e7fd54",
"displayName": "Conf Room Rainier",
"address": nil,
"geoCoordinates": nil,
"phone": "",
"nickname": "Conf Room Rainier",
"emailAddress": "Rainier@contoso.com",
"building": nil,
"floorNumber": nil,
"floorLabel": nil,
"label": nil,
"capacity": nil,
"bookingType": "standard",
"audioDeviceName": nil,
"videoDeviceName": nil,
"displayDeviceName": nil,
"isWheelChairAccessible": false,
"tags": ["some_tag"],
},
{
"id": "42385a28-1a16-4043-8d84-07615656c4e3",
"displayName": "Conf Room Hood",
"address": nil,
"geoCoordinates": nil,
"phone": "",
"nickname": "Conf Room Hood",
"emailAddress": "Hood@contoso.com",
"building": nil,
"floorNumber": nil,
"floorLabel": nil,
"label": nil,
"capacity": nil,
"bookingType": "standard",
"audioDeviceName": nil,
"videoDeviceName": nil,
"displayDeviceName": nil,
"isWheelChairAccessible": false,
"tags": ["some_tag"],
},
{
"id": "850ee91e-a154-4d87-928e-da04c788fd90",
"displayName": "Conf Room Baker",
"address": nil,
"geoCoordinates": nil,
"phone": "",
"nickname": "Conf Room Baker",
"emailAddress": "Baker@contoso.com",
"building": nil,
"floorNumber": nil,
"floorLabel": nil,
"label": nil,
"capacity": nil,
"bookingType": "standard",
"audioDeviceName": nil,
"videoDeviceName": nil,
"displayDeviceName": nil,
"isWheelChairAccessible": false,
"tags": ["some_tag"],
},
],
}
end
end

Spec.before_each do
Expand Down
3 changes: 3 additions & 0 deletions src/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ require "./batch_request"
require "./subscriptions"
require "./odata"
require "./password_credentials"
require "./places"

module Office365
USERS_BASE = "/v1.0/users"
INVITATIONS_BASE = "/v1.0/invitations"
PLACES_BASE = "/v1.0/places"

class Client
include Office365::Mail
Expand All @@ -24,6 +26,7 @@ module Office365
include Office365::Subscriptions
include Office365::OData
include Office365::PasswordCredentials
include Office365::Places

LOGIN_URI = URI.parse("https://login.microsoftonline.com")
GRAPH_URI = URI.parse("https://graph.microsoft.com/")
Expand Down
Loading

0 comments on commit ebdd7e4

Please sign in to comment.