youcanbookme 0.0.1.alpha → 0.0.6.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/{.rubocom.yml → .rubocop.yml} +12 -9
  3. data/CHANGELOG.md +37 -2
  4. data/README.md +22 -25
  5. data/lib/youcanbookme/client.rb +235 -13
  6. data/lib/youcanbookme/error.rb +1 -1
  7. data/lib/youcanbookme/http_command.rb +6 -1
  8. data/lib/youcanbookme/{common_module.rb → loggable.rb} +2 -2
  9. data/lib/youcanbookme/models/account.rb +153 -13
  10. data/lib/youcanbookme/models/account_allocation.rb +22 -0
  11. data/lib/youcanbookme/models/account_child.rb +20 -0
  12. data/lib/youcanbookme/models/{caligraph_safe_local_account.rb → account_parent.rb} +3 -2
  13. data/lib/youcanbookme/models/action.rb +5 -0
  14. data/lib/youcanbookme/models/answer.rb +0 -1
  15. data/lib/youcanbookme/models/booking.rb +8 -4
  16. data/lib/youcanbookme/models/booking_lobby.rb +2 -1
  17. data/lib/youcanbookme/models/calendar.rb +1 -1
  18. data/lib/youcanbookme/models/card.rb +0 -1
  19. data/lib/youcanbookme/models/event.rb +6 -9
  20. data/lib/youcanbookme/models/{participant.rb → event_participant.rb} +3 -2
  21. data/lib/youcanbookme/models/{reminder.rb → event_reminder.rb} +3 -3
  22. data/lib/youcanbookme/models/link.rb +0 -1
  23. data/lib/youcanbookme/models/model_utils.rb +8 -6
  24. data/lib/youcanbookme/models/name_and_address.rb +0 -1
  25. data/lib/youcanbookme/models/permission.rb +17 -5
  26. data/lib/youcanbookme/models/profile.rb +4 -3
  27. data/lib/youcanbookme/models/{profile_local_account.rb → profile_account.rb} +1 -2
  28. data/lib/youcanbookme/models/profile_afterwards.rb +0 -1
  29. data/lib/youcanbookme/models/profile_appointment_type.rb +0 -1
  30. data/lib/youcanbookme/models/profile_appointment_types.rb +0 -1
  31. data/lib/youcanbookme/models/profile_calendar.rb +6 -1
  32. data/lib/youcanbookme/models/profile_calendars.rb +0 -1
  33. data/lib/youcanbookme/models/profile_cancel_or_reschedule.rb +0 -1
  34. data/lib/youcanbookme/models/profile_display.rb +0 -1
  35. data/lib/youcanbookme/models/profile_payments.rb +1 -1
  36. data/lib/youcanbookme/models/profile_remote_account.rb +3 -2
  37. data/lib/youcanbookme/models/profile_remote_reminder.rb +0 -1
  38. data/lib/youcanbookme/models/profile_team_member.rb +0 -1
  39. data/lib/youcanbookme/models/profile_team_members.rb +1 -1
  40. data/lib/youcanbookme/models/profile_tentative.rb +0 -2
  41. data/lib/youcanbookme/models/profile_times.rb +1 -1
  42. data/lib/youcanbookme/models/profile_vouchers.rb +0 -1
  43. data/lib/youcanbookme/models/provider.rb +0 -1
  44. data/lib/youcanbookme/models/purchase.rb +8 -4
  45. data/lib/youcanbookme/models/purchases_sync_changes.rb +0 -1
  46. data/lib/youcanbookme/models/question.rb +1 -0
  47. data/lib/youcanbookme/models/remote_account.rb +8 -4
  48. data/lib/youcanbookme/models/template_event.rb +0 -1
  49. data/lib/youcanbookme/models/transaction.rb +6 -3
  50. data/lib/youcanbookme/models/warning.rb +0 -1
  51. data/lib/youcanbookme/version.rb +1 -1
  52. metadata +11 -20
  53. data/lib/youcanbookme/models/appointment_type.rb +0 -7
  54. data/lib/youcanbookme/models/caligraph_calendar.rb +0 -29
  55. data/lib/youcanbookme/models/caligraph_event.rb +0 -8
  56. data/lib/youcanbookme/models/caligraph_link.rb +0 -17
  57. data/lib/youcanbookme/models/caligraph_local_account.rb +0 -47
  58. data/lib/youcanbookme/models/caligraph_permission.rb +0 -32
  59. data/lib/youcanbookme/models/caligraph_remote_account.rb +0 -23
  60. data/lib/youcanbookme/models/instant.rb +0 -9
  61. data/lib/youcanbookme/models/local_account.rb +0 -180
  62. data/lib/youcanbookme/models/query.rb +0 -8
  63. data/lib/youcanbookme/models/team_member.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36f53dab6a17b2b18709b2b46f3b57bee4b27bced5172e1b5b1b478ef930a5ee
4
- data.tar.gz: 7dcd566aa70a702c9fac08b16c8be40006588e1902620be6d9460f68b38f0c8c
3
+ metadata.gz: 220fc0b04f4037f4daa16043fba1337cdd69817f406ae3cc3dda763409f0d299
4
+ data.tar.gz: 398dad8620738536ad7be8ae689eee0683b710c5737083f5f8e3db57efb36aa4
5
5
  SHA512:
6
- metadata.gz: 86cf465f68b4b4d183504f0e5ef0d8cb814fcab79f8e1d8c6935abbf0f2c184d1f073b6026c4d8d3f5ea23b85f7e2756f6511924a1e547476d91956b6d8f08b1
7
- data.tar.gz: 469f6024831bf01e032b14b4bb63d5232fc682cf11522f141536a05da78524f25765ded2c259e0bd910994b0625c4d2b9c39a8a1c54f79efefe0ab0e034e4de4
6
+ metadata.gz: 572f0f500445237217e6953142531944efe96e98f452811d774e3d0d9d324e0981105a31fa7a3ebf5dd4aeb6aeafb56caf9719065a35319296bb5c3b6444a974
7
+ data.tar.gz: d72e03f30af127d22ba90a78a00797aab82a1efd670958b3cfbda5dd0f02cbc145a21f3cd5bb77d61826b20a503e0ae0d8bc4e6c02816321f63437afd53b4a1a
@@ -23,12 +23,12 @@ Metrics/BlockNesting:
23
23
  Max: 2
24
24
 
25
25
  Layout/LineLength:
26
- AllowURI: true
27
- Enabled: false
26
+ AllowURI: true
27
+ Max: 120
28
28
 
29
29
  Metrics/MethodLength:
30
30
  CountComments: false
31
- Max: 15
31
+ Max: 20
32
32
 
33
33
  Metrics/ParameterLists:
34
34
  Max: 4
@@ -39,10 +39,10 @@ Metrics/AbcSize:
39
39
 
40
40
  Style/CollectionMethods:
41
41
  PreferredMethods:
42
- map: 'collect'
43
- reduce: 'inject'
44
- find: 'detect'
45
- find_all: 'select'
42
+ map: "collect"
43
+ reduce: "inject"
44
+ find: "detect"
45
+ find_all: "select"
46
46
 
47
47
  Style/Documentation:
48
48
  Enabled: false
@@ -60,10 +60,13 @@ Style/ExpandPathArguments:
60
60
  Enabled: false
61
61
 
62
62
  Style/HashSyntax:
63
- EnforcedStyle: hash_rockets
63
+ EnforcedStyle: ruby19
64
64
 
65
65
  Style/Lambda:
66
66
  Enabled: false
67
67
 
68
68
  Style/RaiseArgs:
69
- EnforcedStyle: compact
69
+ EnforcedStyle: compact
70
+
71
+ Style/AsciiComments:
72
+ Enabled: false
@@ -1,7 +1,42 @@
1
- # 0.0.1.alpha
1
+ # CHANGELOG
2
+
3
+ ## 0.0.6.alpha
4
+
5
+ - support APIs below.
6
+ - GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars`
7
+ - GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
8
+ - GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
9
+
10
+ ## 0.0.5.alpha
11
+
12
+ - support APIs below.
13
+ - GET `/v1/{accountId}/remoteaccounts`
14
+ - GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}`
15
+
16
+ ## 0.0.4.alpha
17
+
18
+ redefine models in order to follow changed APIs below.
19
+
20
+ - LocalAccount was merged into Account.
21
+ - Caligraph APIs were removed.
22
+
23
+ ## 0.0.3.alpha
24
+
25
+ - support APIs below.
26
+ - GET `/v1/{accountId}/bookings`
27
+ - GET `/v1/{accountId}/profiles/{profileId}/bookings`
28
+ - GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
29
+
30
+ ## 0.0.2.alpha
31
+
32
+ - support APIs below.
33
+ - GET `/v1/{accountId}/profiles`
34
+ - GET `/v1/{accountId}/profiles/{profileId}`
35
+
36
+ ## 0.0.1.alpha
2
37
 
3
38
  - Initial release.
4
- - support APIs
39
+ - support APIs below.
5
40
  - GET `/v1/{accountId}`
6
41
  - GET `/v1/subdomains/{subdomain}`
7
42
  - GET `/v1/suggestedsubdomains`
data/README.md CHANGED
@@ -37,45 +37,42 @@ Or install it yourself as:
37
37
  - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/appointmenttypes/items/{appointmentTypeId}`
38
38
  - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/appointmenttypes/items/{appointmentTypeId}`
39
39
  - Bookings:
40
- - [ ] GET `/v1/{accountId}/bookings`
41
- - [ ] GET `/v1/{accountId}/firedactions`
42
- - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings`
40
+ - [x] GET `/v1/{accountId}/bookings`
41
+ - [x] GET `/v1/{accountId}/profiles/{profileId}/bookings`
43
42
  - [ ] POST `/v1/{accountId}/profiles/{profileId}/bookings`
44
- - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
43
+ - [x] GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
45
44
  - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
46
45
  - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
47
- - [ ] GET `/v1/{accountId}/profiles/{profileId}/firedactions`
48
46
  - [ ] GET `/v1/ics/{bookingSecret}/{bookingIdOrRef}.ics`
49
- - [ ] GET `/v1/profiles/{profileIdOrSubdomain}/bookings/{bookingIdOrRef}/lobby`
50
- - [ ] (Deprecated) GET `/v1/ics/{bookingRef}`
51
- - [ ] (Deprecated) GET `/v1/ics/{bookingRef}.ics`
52
47
  - Calendars:
53
- - [ ] GET `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars`
54
- - [ ] POST `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars`
55
- - [ ] GET `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
56
- - [ ] PUT `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
57
- - [ ] PATCH `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
58
- - [ ] DELETE `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
48
+ - [x] GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars`
49
+ - [ ] POST `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars`
50
+ - [x] GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
51
+ - [ ] PUT `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
52
+ - [ ] PATCH `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
53
+ - [ ] DELETE `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}`
59
54
  - Events:
60
- - [ ] POST `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events`
61
- - [ ] GET `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
62
- - [ ] DELETE `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
55
+ - [ ] POST `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events`
56
+ - [x] GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
57
+ - [ ] PATCH `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
58
+ - [ ] DELETE `/v1/{accountId}/remoteaccounts/{remoteAccountId}/calendars/{calendarId}/events/{eventId}`
63
59
  - Profile
64
- - [ ] GET `/v1/{accountId}/profiles`
60
+ - [x] GET `/v1/{accountId}/profiles`
65
61
  - [ ] POST `/v1/{accountId}/profiles`
66
- - [ ] GET `/v1/{accountId}/profiles/{profileId}`
62
+ - [x] GET `/v1/{accountId}/profiles/{profileId}`
67
63
  - [ ] PATCH `/v1/{accountId}/profiles/{profileId}`
68
64
  - [ ] DELETE `/v1/{accountId}/profiles/{profileId}`
65
+ - [ ] GET `/v1/{accountId}/profiles/{profileId}/suggestedactions`
69
66
  - [x] GET `/v1/subdomains/{subdomain}`
70
67
  - [x] GET `/v1/suggestedsubdomains`
71
68
  - Query
72
- - [ ] POST `/v1/{localAccountId}/queries`
69
+ - [ ] POST `/v1/{accountId}/queries`
73
70
  - Remote Account
74
- - [ ] GET `/v1/{localAccountId}/remoteaccounts`
75
- - [ ] POST `/v1/{localAccountId}/remoteaccounts`
76
- - [ ] GET `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}`
77
- - [ ] PATCH `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}`
78
- - [ ] DELETE `/v1/{localAccountId}/remoteaccounts/{remoteAccountId}`
71
+ - [x] GET `/v1/{accountId}/remoteaccounts`
72
+ - [ ] POST `/v1/{accountId}/remoteaccounts`
73
+ - [x] GET `/v1/{accountId}/remoteaccounts/{remoteAccountId}`
74
+ - [ ] PATCH `/v1/{accountId}/remoteaccounts/{remoteAccountId}`
75
+ - [ ] DELETE `/v1/{accountId}/remoteaccounts/{remoteAccountId}`
79
76
  - Team Members:
80
77
  - [ ] POST `/v1/{accountId}/profiles/{profileId}/teammembers/items`
81
78
  - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/teammembers/items/{teamMemberId}`
@@ -2,7 +2,7 @@
2
2
 
3
3
  module YouCanBookMe
4
4
  # YouCanBookMe APIs client.
5
- class Client
5
+ class Client # rubocop:disable Metrics/ClassLength
6
6
  API_HOST = 'https://api.youcanbook.me'
7
7
  API_VERSION = 'v1'
8
8
 
@@ -21,28 +21,166 @@ module YouCanBookMe
21
21
  end
22
22
 
23
23
  #
24
- # Account
24
+ # Get basic information about current account.
25
25
  #
26
+ # @param [Array<String>] fields the fields which are included in the response.
27
+ # @return [Account]
28
+ # @since 0.0.1
29
+ def account(fields: nil)
30
+ params = build_fields_params fields
31
+ res = @connection.get account_path, params
32
+ Account.new res.body, self
33
+ end
26
34
 
27
- def account_path
28
- "/#{API_VERSION}/#{@account_id}"
35
+ #
36
+ # Returns a single Booking by associated ids.
37
+ #
38
+ # @param [String] profile_id the profile's unique id.
39
+ # @param [String] booking_id the booking's unique id.
40
+ # @param [Array<String>] fields the fields which are included in the response.
41
+ # @param [Hash] options the optional request parameters.
42
+ # @option options [String] :bsec
43
+ # @option options [String] :displayTimeZone
44
+ # @option options [String] :osec
45
+ # @return [Booking]
46
+ # @since 0.0.3
47
+ def booking(profile_id, booking_id, fields: nil, options: nil)
48
+ check_not_empty profile_id, 'profile_id'
49
+ check_not_empty booking_id, 'booking_id'
50
+ path = booking_path profile_id, booking_id
51
+ opts_keys = %i[bsec displayTimeZone osec]
52
+ params = build_option_params options, opts_keys, fields: fields
53
+ res = @connection.get path, params
54
+ Booking.new res.body, self
29
55
  end
30
56
 
31
57
  #
32
- # Get basic information about current account.
58
+ # Get List of Bookings.
33
59
  #
34
60
  # @param [Array<String>] fields the fields which are included in the response.
35
- # @return [Account]
36
- def account(fields = nil)
37
- params = set_fields_into_params(fields)
38
- res = @connection.get account_path, params
39
- Account.new res.body, self
61
+ # @param [Hash] options the optional request parameters.
62
+ # @option options [String] :boundaryId
63
+ # @option options [String] :boundaryStartsAt
64
+ # @option options [String] :direction
65
+ # @option options [String] :displayTimeZone
66
+ # @option options [String] :jumpToDate
67
+ # @option options [String] :profileIds
68
+ # @option options [String] :search
69
+ # @return [Array<Booking>]
70
+ # @since 0.0.3
71
+ def bookings(fields: nil, options: nil)
72
+ opts_keys = %i[boundaryId boundaryStartsAt direction displayTimeZone jumpToDate profileIds search]
73
+ params = build_option_params options, opts_keys, fields: fields
74
+ res = @connection.get booking_path, params
75
+ map_as_collection res, Booking
76
+ end
77
+
78
+ #
79
+ # Get List of Bookings associated by profile_id.
80
+ #
81
+ # @param [String] profile_id the profile's unique id.
82
+ # @param [Array<String>] fields the fields which are included in the response.
83
+ # @param [Hash] options the optional request parameters.
84
+ # @option options [String] :boundaryId
85
+ # @option options [String] :boundaryStartsAt
86
+ # @option options [String] :direction
87
+ # @option options [String] :displayTimeZone
88
+ # @option options [String] :jumpToDate
89
+ # @option options [String] :profileIds
90
+ # @option options [String] :search
91
+ # @return [Array<Booking>]
92
+ # @since 0.0.3
93
+ def profile_bookings(profile_id, fields: nil, options: nil)
94
+ check_not_empty profile_id, 'profile_id'
95
+ path = booking_path profile_id
96
+ opts_keys = %i[boundaryId boundaryStartsAt direction displayTimeZone jumpToDate profileIds search]
97
+ params = build_option_params options, opts_keys, fields: fields
98
+ res = @connection.get path, params
99
+ map_as_collection res, Booking
100
+ end
101
+
102
+ #
103
+ # Returns a single Calendar by its id.
104
+ #
105
+ # @param [String] remote_account_id the remote_account's unique id.
106
+ # @param [String] calendar_id the calendar's unique id.
107
+ # @param [Array<String>] fields the fields which are included in the response.
108
+ # @return [Calendar]
109
+ # @since 0.0.6
110
+ def calendar(remote_account_id, calendar_id, fields: nil)
111
+ check_not_empty remote_account_id, 'remote_account_id'
112
+ check_not_empty calendar_id, 'calendar_id'
113
+ params = build_fields_params fields
114
+ path = calendar_path remote_account_id, calendar_id
115
+ res = @connection.get path, params
116
+ Calendar.new res.body, self
117
+ end
118
+
119
+ #
120
+ # Get List of Calendar.
121
+ #
122
+ # @param [String] remote_account_id the remote_account's unique id.
123
+ # @param [Array<String>] fields the fields which are included in the response.
124
+ # @return [Array<Calendar>]
125
+ # @since 0.0.6
126
+ def calendars(remote_account_id, fields: nil)
127
+ check_not_empty remote_account_id, 'remote_account_id'
128
+ params = build_fields_params fields
129
+ path = calendar_path remote_account_id
130
+ res = @connection.get path, params
131
+ map_as_collection res, Calendar
132
+ end
133
+
134
+ #
135
+ # Returns a single Event by its id.
136
+ #
137
+ # @param [String] remote_account_id the remote_account's unique id.
138
+ # @param [String] calendar_id the calendar's unique id.
139
+ # @param [String] event_id the event's unique id.
140
+ # @param [Array<String>] fields the fields which are included in the response.
141
+ # @return [Event]
142
+ # @since 0.0.6
143
+ def event(remote_account_id, calendar_id, event_id, fields: nil)
144
+ check_not_empty remote_account_id, 'remote_account_id'
145
+ check_not_empty calendar_id, 'calendar_id'
146
+ check_not_empty event_id, 'event_id'
147
+ params = build_fields_params fields
148
+ path = event_path remote_account_id, calendar_id, event_id
149
+ res = @connection.get path, params
150
+ Event.new res.body, self
151
+ end
152
+
153
+ #
154
+ # Returns a single Profile by its id.
155
+ #
156
+ # @param [String] profile_id the profile's unique id.
157
+ # @param [Array<String>] fields the fields which are included in the response.
158
+ # @return [Profile]
159
+ # @since 0.0.2
160
+ def profile(profile_id, fields: nil)
161
+ check_not_empty profile_id, 'profile_id'
162
+ params = build_fields_params fields
163
+ res = @connection.get profile_path(profile_id), params
164
+ Profile.new res.body, self
165
+ end
166
+
167
+ #
168
+ # Get List of Profile.
169
+ #
170
+ # @param [Array<String>] fields the fields which are included in the response.
171
+ # @return [Array<Profile>]
172
+ # @since 0.0.2
173
+ def profiles(fields: nil)
174
+ params = build_fields_params fields
175
+ res = @connection.get profile_path, params
176
+ map_as_collection res, Profile
40
177
  end
41
178
 
42
179
  #
43
180
  # Get suggested subdomains
44
181
  #
45
182
  # @return [Array<String>]
183
+ # @since 0.0.1
46
184
  def suggested_subdomains
47
185
  res = @connection.get "/#{API_VERSION}/suggestedsubdomains"
48
186
  res.body
@@ -54,16 +192,45 @@ module YouCanBookMe
54
192
  # @param [String] subdomain
55
193
  # @return [Boolean]
56
194
  # @raise [YouCanBookMe::Error] if the subdomain arg is empty.
195
+ # @since 0.0.1
57
196
  def subdomain_available?(subdomain)
58
197
  check_not_empty subdomain, 'subdomain'
59
198
  res = @connection.get "/#{API_VERSION}/subdomains/#{subdomain}"
60
199
  res.body[:free]
61
200
  end
62
201
 
63
- private
202
+ #
203
+ # Returns a single RemoteAccount by its id.
204
+ #
205
+ # @param [String] remote_account_id the remote account's unique id.
206
+ # @param [Array<String>] fields the fields which are included in the response.
207
+ # @return [YouCanBookMe::RemoteAccount]
208
+ # @raise [YouCanBookMe::Error] if the subdomain arg is empty.
209
+ # @since 0.0.5
210
+ def remote_account(remote_account_id, fields: nil)
211
+ check_not_empty remote_account_id, 'remote_account_id'
212
+ params = build_fields_params fields
213
+ path = remote_account_path(remote_account_id)
214
+ res = @connection.get path, params
215
+ RemoteAccount.new res.body, self
216
+ end
217
+
218
+ #
219
+ # Get List of Remote Account.
220
+ #
221
+ # @param [Array<String>] fields the fields which are included in the response.
222
+ # @return [Array<YouCanBookMe::RemoteAccount>]
223
+ # @since 0.0.5
224
+ def remote_accounts(fields: nil)
225
+ params = build_fields_params fields
226
+ res = @connection.get remote_account_path, params
227
+ map_as_collection res, RemoteAccount
228
+ end
229
+
230
+ private
64
231
 
65
232
  def check_not_empty(value, name)
66
- raise YouCanBookMe::Error, "#{name} is required." if blank? value
233
+ raise YouCanBookMe::Error.new("#{name} is required.") if blank? value
67
234
  end
68
235
 
69
236
  def blank?(value)
@@ -73,7 +240,55 @@ module YouCanBookMe
73
240
  false
74
241
  end
75
242
 
76
- def set_fields_into_params(fields, params = nil)
243
+ def account_path
244
+ "/#{API_VERSION}/#{@account_id}"
245
+ end
246
+
247
+ def booking_path(profile_id = nil, booking_id = nil)
248
+ return "#{account_path}/bookings" unless profile_id
249
+
250
+ path = "#{profile_path(profile_id)}/bookings"
251
+ return path unless booking_id
252
+
253
+ "#{path}/#{booking_id}"
254
+ end
255
+
256
+ def calendar_path(remote_account_id, calendar_id = nil)
257
+ remote_path = remote_account_path remote_account_id
258
+ path = "#{remote_path}/calendars"
259
+ return path unless calendar_id
260
+
261
+ "#{path}/#{calendar_id}"
262
+ end
263
+
264
+ def event_path(remote_account_id, calendar_id, event_id = nil)
265
+ cal_path = calendar_path remote_account_id, calendar_id
266
+ path = "#{cal_path}/events"
267
+ return path unless event_id
268
+
269
+ "#{path}/#{event_id}"
270
+ end
271
+
272
+ def profile_path(profile_id = nil)
273
+ path = "#{account_path}/profiles"
274
+ return path unless profile_id
275
+
276
+ "#{path}/#{profile_id}"
277
+ end
278
+
279
+ def remote_account_path(remote_account_id = nil)
280
+ path = "#{account_path}/remoteaccounts"
281
+ return path unless remote_account_id
282
+
283
+ "#{path}/#{remote_account_id}"
284
+ end
285
+
286
+ def build_option_params(options, filters, fields: nil)
287
+ options ||= {}
288
+ build_fields_params fields, options.slice(*filters)
289
+ end
290
+
291
+ def build_fields_params(fields, params = nil)
77
292
  params ||= {}
78
293
  return params unless fields
79
294
  return params unless fields.is_a? Array
@@ -81,5 +296,12 @@ module YouCanBookMe
81
296
 
82
297
  params.merge(fields: fields.join(','))
83
298
  end
299
+
300
+ def map_as_collection(response, klass)
301
+ items = response.body
302
+ raise YouCanBookMe::Error.new('the response data is not Array.') unless items.is_a? Array
303
+
304
+ items.map { |item| klass.new item, self }
305
+ end
84
306
  end
85
307
  end