lib/youcanbookme/client.rb in youcanbookme-0.0.4.alpha vs lib/youcanbookme/client.rb in youcanbookme-0.0.5.alpha
- old
+ new
@@ -1,10 +1,10 @@
# frozen_string_literal: true
module YouCanBookMe
# YouCanBookMe APIs client.
- class Client
+ class Client # rubocop:disable Metrics/ClassLength
API_HOST = 'https://api.youcanbook.me'
API_VERSION = 'v1'
# @param [String] account_id a YouCanBook.me's account id(or email).
# @param [String] password_or_token a YouCanBook.me's account password or token.
@@ -146,10 +146,38 @@
check_not_empty subdomain, 'subdomain'
res = @connection.get "/#{API_VERSION}/subdomains/#{subdomain}"
res.body[:free]
end
+ #
+ # Returns a single RemoteAccount by its id.
+ #
+ # @param [String] remote_account_id the remote account's unique id.
+ # @param [Array<String>] fields the fields which are included in the response.
+ # @return [YouCanBookMe::RemoteAccount]
+ # @raise [YouCanBookMe::Error] if the subdomain arg is empty.
+ # @since 0.0.5
+ def remote_account(remote_account_id, fields: nil)
+ check_not_empty remote_account_id, 'remote_account_id'
+ params = build_fields_params fields
+ path = remote_account_path(remote_account_id)
+ res = @connection.get path, params
+ RemoteAccount.new res.body, self
+ end
+
+ #
+ # Get List of Remote Account.
+ #
+ # @param [Array<String>] fields the fields which are included in the response.
+ # @return [Array<YouCanBookMe::RemoteAccount>]
+ # @since 0.0.5
+ def remote_accounts(fields: nil)
+ params = build_fields_params fields
+ res = @connection.get remote_account_path, params
+ map_as_collection res, RemoteAccount
+ end
+
private
def check_not_empty(value, name)
raise YouCanBookMe::Error.new("#{name} is required.") if blank? value
end
@@ -177,9 +205,16 @@
path = "#{profile_path(profile_id)}/bookings"
return path unless booking_id
"#{path}/#{booking_id}"
+ end
+
+ def remote_account_path(remote_account_id = nil)
+ path = "#{account_path}/remoteaccounts"
+ return path unless remote_account_id
+
+ "#{path}/#{remote_account_id}"
end
def build_option_params(options, filters, fields: nil)
options ||= {}
build_fields_params fields, options.slice(*filters)