youcanbookme 0.0.2.alpha → 0.0.3.alpha

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
  SHA256:
3
- metadata.gz: d3491d5775ccc99d6cd9bf13615ec48e7fcb65d0253b4292e626506b81c49314
4
- data.tar.gz: 45f1ca0ad6d5cd1c0bad008f63a4bc8dbc62ec311af7f36ddbd49436c4f2c57c
3
+ metadata.gz: 7a0923f47ca98e10933774dd975b854f5d14e259e0cb6113e3626bf3cf09603c
4
+ data.tar.gz: 1bf5f156b9b1e11bbc145245cc8065f964f064c2e9209c3f8c1e12d298bb7fa8
5
5
  SHA512:
6
- metadata.gz: 65ec8367df8622ae84856c41dcb949437aa37e29ae6987b935b207cb07613f670fdc4c416f0a379bbb17929bd6f6f437e2d53cc0117a2b097551e104146c2242
7
- data.tar.gz: cfc49a92911acb2e580895e4c4ffb28c9f52d192b5d2e00b0dd7d791e8539e3a53ce153f5267c36f59cb7d7629e52585740e40c8bc1e6550bf6fe748378b945a
6
+ metadata.gz: 7b7df64ac8aafaf5f98f65a56fcae4f146071ea0f5fc7932a7495041ef01d01ec7d5b16865bde48ccfd30c785f3b2a51cdaddc6e8ee9fe9af464fdfd528ada53
7
+ data.tar.gz: b73049cf3e0090a44b3137b0a467c39b3d563698e49d41bc06e81e35024d469c862a9e55f5ef38bd65fac826a7156818e7a2aa2ca39977ab5e40b81cc52b5235
@@ -1,3 +1,10 @@
1
+ # 0.0.3.alpha
2
+
3
+ - support APIs
4
+ - GET `/v1/{accountId}/bookings`
5
+ - GET `/v1/{accountId}/profiles/{profileId}/bookings`
6
+ - GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
7
+
1
8
  # 0.0.2.alpha
2
9
 
3
10
  - support APIs
data/README.md CHANGED
@@ -37,11 +37,11 @@ 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`
40
+ - [x] GET `/v1/{accountId}/bookings`
41
41
  - [ ] GET `/v1/{accountId}/firedactions`
42
- - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings`
42
+ - [x] GET `/v1/{accountId}/profiles/{profileId}/bookings`
43
43
  - [ ] POST `/v1/{accountId}/profiles/{profileId}/bookings`
44
- - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
44
+ - [x] GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
45
45
  - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
46
46
  - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
47
47
  - [ ] GET `/v1/{accountId}/profiles/{profileId}/firedactions`
@@ -26,22 +26,89 @@ module YouCanBookMe
26
26
  # @param [Array<String>] fields the fields which are included in the response.
27
27
  # @return [Account]
28
28
  # @since 0.0.1
29
- def account(fields = nil)
30
- params = set_fields_into_params fields
29
+ def account(fields: nil)
30
+ params = build_fields_params fields
31
31
  res = @connection.get account_path, params
32
32
  Account.new res.body, self
33
33
  end
34
34
 
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
55
+ end
56
+
57
+ #
58
+ # Get List of Bookings.
59
+ #
60
+ # @param [Array<String>] fields the fields which are included in the response.
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
+
35
102
  #
36
103
  # Returns a single Profile by its id.
37
104
  #
38
- # @param [String] profile_id the profile's unique id.
105
+ # @param [String] profile_id the profile's unique id.
39
106
  # @param [Array<String>] fields the fields which are included in the response.
40
107
  # @return [Profile]
41
108
  # @since 0.0.2
42
- def profile(profile_id, fields = nil)
109
+ def profile(profile_id, fields: nil)
43
110
  check_not_empty profile_id, 'profile_id'
44
- params = set_fields_into_params fields
111
+ params = build_fields_params fields
45
112
  res = @connection.get profile_path(profile_id), params
46
113
  Profile.new res.body, self
47
114
  end
@@ -52,15 +119,10 @@ module YouCanBookMe
52
119
  # @param [Array<String>] fields the fields which are included in the response.
53
120
  # @return [Array<Profile>]
54
121
  # @since 0.0.2
55
- def profiles(fields = nil)
56
- params = set_fields_into_params fields
122
+ def profiles(fields: nil)
123
+ params = build_fields_params fields
57
124
  res = @connection.get profile_path, params
58
- items = res.body
59
- unless items.is_a? Array
60
- raise YouCanBookMe::Error, 'the response data is not Array.'
61
- end
62
-
63
- items.map { |item| Profile.new item, self }
125
+ map_as_collection res, Profile
64
126
  end
65
127
 
66
128
  #
@@ -99,15 +161,6 @@ module YouCanBookMe
99
161
  false
100
162
  end
101
163
 
102
- def set_fields_into_params(fields, params = nil)
103
- params ||= {}
104
- return params unless fields
105
- return params unless fields.is_a? Array
106
- return params if fields.empty?
107
-
108
- params.merge(fields: fields.join(','))
109
- end
110
-
111
164
  def account_path
112
165
  "/#{API_VERSION}/#{@account_id}"
113
166
  end
@@ -118,5 +171,37 @@ module YouCanBookMe
118
171
 
119
172
  "#{path}/#{profile_id}"
120
173
  end
174
+
175
+ def booking_path(profile_id = nil, booking_id = nil)
176
+ return "#{account_path}/bookings" unless profile_id
177
+
178
+ path = "#{profile_path(profile_id)}/bookings"
179
+ return path unless booking_id
180
+
181
+ "#{path}/#{booking_id}"
182
+ end
183
+
184
+ def build_option_params(options, filters, fields: nil)
185
+ options ||= {}
186
+ build_fields_params fields, options.slice(*filters)
187
+ end
188
+
189
+ def build_fields_params(fields, params = nil)
190
+ params ||= {}
191
+ return params unless fields
192
+ return params unless fields.is_a? Array
193
+ return params if fields.empty?
194
+
195
+ params.merge(fields: fields.join(','))
196
+ end
197
+
198
+ def map_as_collection(response, klass)
199
+ items = response.body
200
+ unless items.is_a? Array
201
+ raise YouCanBookMe::Error, 'the response data is not Array.'
202
+ end
203
+
204
+ items.map { |item| klass.new item, self }
205
+ end
121
206
  end
122
207
  end
@@ -3,7 +3,7 @@
3
3
  module YouCanBookMe
4
4
  # YouCanBookMe module's base error object
5
5
  class Error < StandardError
6
- include CommonModule
6
+ include Loggable
7
7
 
8
8
  def initialize(message = nil)
9
9
  msg = "#{self.class} occured."
@@ -6,7 +6,7 @@ require 'faraday_middleware'
6
6
  module YouCanBookMe
7
7
  # Command for HTTP request.
8
8
  class HttpCommand
9
- include CommonModule
9
+ include Loggable
10
10
 
11
11
  def initialize(account_id, password_or_token, host = nil)
12
12
  @account_id = account_id
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouCanBookMe
4
- # YouCanBook.me utility module.
5
- module CommonModule
4
+ # YouCanBook.me logger utility module.
5
+ module Loggable
6
6
  def error_log(msg)
7
7
  log msg, :error
8
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouCanBookMe
4
- VERSION = '0.0.2.alpha'
4
+ VERSION = '0.0.3.alpha'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youcanbookme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.alpha
4
+ version: 0.0.3.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenji Koshikawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -157,10 +157,10 @@ files:
157
157
  - bin/setup
158
158
  - lib/youcanbookme.rb
159
159
  - lib/youcanbookme/client.rb
160
- - lib/youcanbookme/common_module.rb
161
160
  - lib/youcanbookme/configuration.rb
162
161
  - lib/youcanbookme/error.rb
163
162
  - lib/youcanbookme/http_command.rb
163
+ - lib/youcanbookme/loggable.rb
164
164
  - lib/youcanbookme/models/account.rb
165
165
  - lib/youcanbookme/models/action.rb
166
166
  - lib/youcanbookme/models/answer.rb
@@ -221,7 +221,7 @@ metadata:
221
221
  homepage_uri: https://github.com/koshilife/youcanbookme-api-ruby-client
222
222
  source_code_uri: https://github.com/koshilife/youcanbookme-api-ruby-client
223
223
  changelog_uri: https://github.com/koshilife/youcanbookme-api-ruby-client/blob/master/CHANGELOG.md
224
- documentation_uri: https://www.rubydoc.info/gems/youcanbookme/0.0.2.alpha
224
+ documentation_uri: https://www.rubydoc.info/gems/youcanbookme/0.0.3.alpha
225
225
  post_install_message:
226
226
  rdoc_options: []
227
227
  require_paths: