cronofy 0.15.0 → 0.16.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: fef21eafed29818348df191003678a502f85b40e
4
- data.tar.gz: 006fff16ea068da743be34eb380bbd701523b341
3
+ metadata.gz: 12dca20c7955f97eac5e93f6f793e38a0363e0f1
4
+ data.tar.gz: a9017b0ee2708bb4cbb792507959658fd9f9a138
5
5
  SHA512:
6
- metadata.gz: ad2e31f0eea49062cd7f8f60691ee05773ca184a774d0e958f31cd6f68eae5f207917a6a265872f632ed24407926495b1b2dd14c3d6f49a7beb425357c60a54f
7
- data.tar.gz: e528c5a16588eb904c01bf01ce0890694efca321eba9e31976a8ad76a16fcc439f38236d0dcccaac6d27922dc89ad13041dd21b4676c47a58fc99b1c001a2c08
6
+ metadata.gz: c627b9fc733638bd60bf6248919a6fa6ccbfc27f3c0836d487ca9712867cb328b0d0dd5f80c7c1f97f001b1304646f0791cda7a632583da7132e034549b81690
7
+ data.tar.gz: 804e5ac5f5353050105435fda63a03bbbe2577b4e214464dd8c221782719c4c2f96530bbc45f081d38650d2e6dee6eb99510f80f961781e1e38f60461eeb5dbc
@@ -649,8 +649,83 @@ module Cronofy
649
649
  parse_collection(Resource, "resources", response)
650
650
  end
651
651
 
652
+ # Public: Performs an availability query.
653
+ #
654
+ # options - The Hash options used to refine the selection (default: {}):
655
+ # :participants - An Array of participant groups (or required
656
+ # particpants for the simple case).
657
+ # :required_duration - An Integer representing the minimum number
658
+ # of minutes of availability required.
659
+ # :available_periods - An Array of available time periods Hashes,
660
+ # each must specify a start and end Time.
661
+ #
662
+ # Returns an Array of AvailablePeriods.
663
+ #
664
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
665
+ # Raises Cronofy::AuthenticationFailureError if the access token is no
666
+ # longer valid.
667
+ # Raises Cronofy::AuthorizationFailureError if the access token does not
668
+ # include the required scope.
669
+ # Raises Cronofy::InvalidRequestError if the request contains invalid
670
+ # parameters.
671
+ # Raises Cronofy::TooManyRequestsError if the request exceeds the rate
672
+ # limits for the application.
673
+ def availability(options = {})
674
+ options[:participants] = map_availability_participants(options[:participants])
675
+ options[:required_duration] = map_availability_required_duration(options[:required_duration])
676
+
677
+ options[:available_periods].each do |params|
678
+ AVAILABLE_PERIODS_TIME_PARAMS.select { |tp| params.key?(tp) }.each do |tp|
679
+ params[tp] = to_iso8601(params[tp])
680
+ end
681
+ end
682
+
683
+ response = post("/v1/availability", options)
684
+ parse_collection(AvailablePeriod, "available_periods", response)
685
+ end
686
+
652
687
  private
653
688
 
689
+ def map_availability_participants(participants)
690
+ case participants
691
+ when Hash
692
+ participants[:members].map! do |member|
693
+ map_availability_member(member)
694
+ end
695
+
696
+ unless participants.key?(:required)
697
+ participants[:required] = :all
698
+ end
699
+
700
+ [participants]
701
+ else
702
+ participants
703
+ end
704
+ end
705
+
706
+ def map_availability_member(member)
707
+ case member
708
+ when String
709
+ { sub: member }
710
+ else
711
+ member
712
+ end
713
+ end
714
+
715
+ def map_availability_required_duration(required_duration)
716
+ case required_duration
717
+ when Fixnum
718
+ { minutes: required_duration }
719
+ else
720
+ required_duration
721
+ end
722
+ end
723
+
724
+ AVAILABLE_PERIODS_TIME_PARAMS = %i{
725
+ start
726
+ end
727
+ }.freeze
728
+
654
729
  FREE_BUSY_DEFAULT_PARAMS = { tzid: "Etc/UTC" }.freeze
655
730
  FREE_BUSY_TIME_PARAMS = %i{
656
731
  from
@@ -278,4 +278,22 @@ module Cronofy
278
278
 
279
279
  class PermissionsResponse < Hashie::Mash
280
280
  end
281
+
282
+ class Participant < Hashie::Mash
283
+ end
284
+
285
+ module ParticipantEnumerable
286
+ def self.coerce(values)
287
+ values.map { |v| Participant.new(v) }
288
+ end
289
+ end
290
+
291
+ class AvailablePeriod < Hashie::Mash
292
+ include Hashie::Extensions::Coercion
293
+
294
+ coerce_key :start, EventTime
295
+ coerce_key :end, EventTime
296
+
297
+ coerce_key :participants, ParticipantEnumerable
298
+ end
281
299
  end
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.15.0".freeze
2
+ VERSION = "0.16.0".freeze
3
3
  end
@@ -749,14 +749,14 @@ describe Cronofy::Client do
749
749
  end
750
750
 
751
751
  let(:correct_mapped_result) do
752
- Cronofy::PermissionsResponse.new(correct_response_body[:permissions_request])
752
+ Cronofy::PermissionsResponse.new(correct_response_body['permissions_request'])
753
753
  end
754
754
 
755
755
  describe "with uri supplied" do
756
756
  let(:correct_response_body) do
757
757
  {
758
- permissions_request: {
759
- url: "http://app.cronofy.com/permissions/"
758
+ "permissions_request" => {
759
+ "url" => "http://app.cronofy.com/permissions/"
760
760
  }
761
761
  }
762
762
  end
@@ -770,8 +770,8 @@ describe Cronofy::Client do
770
770
  describe "without uri supplied" do
771
771
  let(:correct_response_body) do
772
772
  {
773
- permissions_request: {
774
- accepted: true
773
+ "permissions_request" => {
774
+ "accepted" => true
775
775
  }
776
776
  }
777
777
  end
@@ -1072,16 +1072,16 @@ describe Cronofy::Client do
1072
1072
  let(:correct_response_code) { 200 }
1073
1073
  let(:correct_response_body) do
1074
1074
  {
1075
- 'resources' => [
1076
- {
1077
- 'email' => 'board-room-london@example.com',
1078
- 'name' => 'Board room (London)',
1079
- },
1080
- {
1081
- 'email' => 'board-room-madrid@example.com',
1082
- 'name' => 'Board room (Madrid)',
1083
- }
1084
- ]
1075
+ 'resources' => [
1076
+ {
1077
+ 'email' => 'board-room-london@example.com',
1078
+ 'name' => 'Board room (London)',
1079
+ },
1080
+ {
1081
+ 'email' => 'board-room-madrid@example.com',
1082
+ 'name' => 'Board room (Madrid)',
1083
+ }
1084
+ ]
1085
1085
  }
1086
1086
  end
1087
1087
 
@@ -1095,4 +1095,121 @@ describe Cronofy::Client do
1095
1095
  it_behaves_like 'a Cronofy request with mapped return value'
1096
1096
  end
1097
1097
  end
1098
+
1099
+ describe 'Availability', focus: true do
1100
+ describe '#availability' do
1101
+ let(:method) { :post }
1102
+ let(:request_url) { 'https://api.cronofy.com/v1/availability' }
1103
+ let(:request_headers) { json_request_headers }
1104
+
1105
+ let(:request_body) do
1106
+ {
1107
+ "participants" => [
1108
+ {
1109
+ "members" => [
1110
+ { "sub" => "acc_567236000909002" },
1111
+ { "sub" => "acc_678347111010113" }
1112
+ ],
1113
+ "required" => "all"
1114
+ }
1115
+ ],
1116
+ "required_duration" => { "minutes" => 60 },
1117
+ "available_periods" => [
1118
+ {
1119
+ "start" => "2017-01-03T09:00:00Z",
1120
+ "end" => "2017-01-03T18:00:00Z"
1121
+ },
1122
+ {
1123
+ "start" => "2017-01-04T09:00:00Z",
1124
+ "end" => "2017-01-04T18:00:00Z"
1125
+ }
1126
+ ]
1127
+ }
1128
+ end
1129
+
1130
+ let(:correct_response_code) { 200 }
1131
+ let(:correct_response_body) do
1132
+ {
1133
+ "available_periods" => [
1134
+ {
1135
+ "start" => "2017-01-03T09:00:00Z",
1136
+ "end" => "2017-01-03T11:00:00Z",
1137
+ "participants" => [
1138
+ { "sub" => "acc_567236000909002" },
1139
+ { "sub" => "acc_678347111010113" }
1140
+ ]
1141
+ },
1142
+ {
1143
+ "start" => "2017-01-03T14 =>00:00Z",
1144
+ "end" => "2017-01-03T16:00:00Z",
1145
+ "participants" => [
1146
+ { "sub" => "acc_567236000909002" },
1147
+ { "sub" => "acc_678347111010113" }
1148
+ ]
1149
+ },
1150
+ {
1151
+ "start" => "2017-01-04T11:00:00Z",
1152
+ "end" => "2017-01-04T17:00:00Z",
1153
+ "participants" => [
1154
+ { "sub" => "acc_567236000909002" },
1155
+ { "sub" => "acc_678347111010113" }
1156
+ ]
1157
+ },
1158
+ ]
1159
+ }
1160
+ end
1161
+
1162
+ let(:correct_mapped_result) do
1163
+ correct_response_body['available_periods'].map { |ap| Cronofy::AvailablePeriod.new(ap) }
1164
+ end
1165
+
1166
+ subject { client.availability(participants: participants, required_duration: required_duration, available_periods: available_periods) }
1167
+
1168
+ context "fully specified" do
1169
+ let(:participants) do
1170
+ [
1171
+ {
1172
+ members: [
1173
+ { sub: "acc_567236000909002" },
1174
+ { sub: "acc_678347111010113" },
1175
+ ],
1176
+ required: :all,
1177
+ }
1178
+ ]
1179
+ end
1180
+
1181
+ let(:required_duration) do
1182
+ { minutes: 60 }
1183
+ end
1184
+
1185
+ let(:available_periods) do
1186
+ [
1187
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1188
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1189
+ ]
1190
+ end
1191
+
1192
+ it_behaves_like 'a Cronofy request'
1193
+ it_behaves_like 'a Cronofy request with mapped return value'
1194
+ end
1195
+
1196
+ context "simple values to defaults" do
1197
+ let(:participants) do
1198
+ { members: %w{acc_567236000909002 acc_678347111010113} }
1199
+ end
1200
+
1201
+ let(:required_duration) { 60 }
1202
+
1203
+ let(:available_periods) do
1204
+ [
1205
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1206
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1207
+ ]
1208
+ end
1209
+
1210
+ it_behaves_like 'a Cronofy request'
1211
+ it_behaves_like 'a Cronofy request with mapped return value'
1212
+ end
1213
+ end
1214
+ end
1098
1215
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergii Paryzhskyi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-18 00:00:00.000000000 Z
12
+ date: 2017-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.6.8
151
+ rubygems_version: 2.6.6
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Cronofy - one API for all the calendars