youcanbookme 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +37 -0
  3. data/.github/workflows/test.yml +21 -0
  4. data/.gitignore +10 -0
  5. data/.rubocom.yml +69 -0
  6. data/CHANGELOG.md +7 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +119 -0
  11. data/Rakefile +12 -0
  12. data/bin/console +7 -0
  13. data/bin/setup +6 -0
  14. data/lib/youcanbookme.rb +22 -0
  15. data/lib/youcanbookme/client.rb +85 -0
  16. data/lib/youcanbookme/common_module.rb +32 -0
  17. data/lib/youcanbookme/configuration.rb +20 -0
  18. data/lib/youcanbookme/error.rb +15 -0
  19. data/lib/youcanbookme/http_command.rb +94 -0
  20. data/lib/youcanbookme/models/account.rb +125 -0
  21. data/lib/youcanbookme/models/action.rb +91 -0
  22. data/lib/youcanbookme/models/answer.rb +19 -0
  23. data/lib/youcanbookme/models/appointment_type.rb +7 -0
  24. data/lib/youcanbookme/models/booking.rb +167 -0
  25. data/lib/youcanbookme/models/booking_lobby.rb +13 -0
  26. data/lib/youcanbookme/models/calendar.rb +67 -0
  27. data/lib/youcanbookme/models/caligraph_calendar.rb +29 -0
  28. data/lib/youcanbookme/models/caligraph_event.rb +8 -0
  29. data/lib/youcanbookme/models/caligraph_link.rb +17 -0
  30. data/lib/youcanbookme/models/caligraph_local_account.rb +47 -0
  31. data/lib/youcanbookme/models/caligraph_permission.rb +32 -0
  32. data/lib/youcanbookme/models/caligraph_remote_account.rb +23 -0
  33. data/lib/youcanbookme/models/caligraph_safe_local_account.rb +13 -0
  34. data/lib/youcanbookme/models/card.rb +25 -0
  35. data/lib/youcanbookme/models/event.rb +98 -0
  36. data/lib/youcanbookme/models/instant.rb +9 -0
  37. data/lib/youcanbookme/models/link.rb +17 -0
  38. data/lib/youcanbookme/models/local_account.rb +180 -0
  39. data/lib/youcanbookme/models/model_utils.rb +88 -0
  40. data/lib/youcanbookme/models/name_and_address.rb +25 -0
  41. data/lib/youcanbookme/models/participant.rb +25 -0
  42. data/lib/youcanbookme/models/permission.rb +39 -0
  43. data/lib/youcanbookme/models/profile.rb +114 -0
  44. data/lib/youcanbookme/models/profile_afterwards.rb +34 -0
  45. data/lib/youcanbookme/models/profile_appointment_type.rb +23 -0
  46. data/lib/youcanbookme/models/profile_appointment_types.rb +27 -0
  47. data/lib/youcanbookme/models/profile_calendar.rb +21 -0
  48. data/lib/youcanbookme/models/profile_calendars.rb +19 -0
  49. data/lib/youcanbookme/models/profile_cancel_or_reschedule.rb +21 -0
  50. data/lib/youcanbookme/models/profile_display.rb +55 -0
  51. data/lib/youcanbookme/models/profile_local_account.rb +19 -0
  52. data/lib/youcanbookme/models/profile_payments.rb +23 -0
  53. data/lib/youcanbookme/models/profile_remote_account.rb +25 -0
  54. data/lib/youcanbookme/models/profile_remote_reminder.rb +15 -0
  55. data/lib/youcanbookme/models/profile_team_member.rb +33 -0
  56. data/lib/youcanbookme/models/profile_team_members.rb +29 -0
  57. data/lib/youcanbookme/models/profile_tentative.rb +16 -0
  58. data/lib/youcanbookme/models/profile_times.rb +79 -0
  59. data/lib/youcanbookme/models/profile_vouchers.rb +17 -0
  60. data/lib/youcanbookme/models/provider.rb +17 -0
  61. data/lib/youcanbookme/models/purchase.rb +126 -0
  62. data/lib/youcanbookme/models/purchases_sync_changes.rb +19 -0
  63. data/lib/youcanbookme/models/query.rb +8 -0
  64. data/lib/youcanbookme/models/question.rb +24 -0
  65. data/lib/youcanbookme/models/reminder.rb +21 -0
  66. data/lib/youcanbookme/models/remote_account.rb +63 -0
  67. data/lib/youcanbookme/models/team_member.rb +8 -0
  68. data/lib/youcanbookme/models/template_event.rb +17 -0
  69. data/lib/youcanbookme/models/transaction.rb +42 -0
  70. data/lib/youcanbookme/models/warning.rb +27 -0
  71. data/lib/youcanbookme/version.rb +5 -0
  72. data/youcanbookme.gemspec +41 -0
  73. metadata +244 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36f53dab6a17b2b18709b2b46f3b57bee4b27bced5172e1b5b1b478ef930a5ee
4
+ data.tar.gz: 7dcd566aa70a702c9fac08b16c8be40006588e1902620be6d9460f68b38f0c8c
5
+ SHA512:
6
+ metadata.gz: 86cf465f68b4b4d183504f0e5ef0d8cb814fcab79f8e1d8c6935abbf0f2c184d1f073b6026c4d8d3f5ea23b85f7e2756f6511924a1e547476d91956b6d8f08b1
7
+ data.tar.gz: 469f6024831bf01e032b14b4bb63d5232fc682cf11522f141536a05da78524f25765ded2c259e0bd910994b0625c4d2b9c39a8a1c54f79efefe0ab0e034e4de4
@@ -0,0 +1,37 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.6
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.6
18
+
19
+ - name: Build and test
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake test
24
+ env:
25
+ CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
26
+
27
+ - name: Publish to RubyGems
28
+ run: |
29
+ mkdir -p $HOME/.gem
30
+ touch $HOME/.gem/credentials
31
+ chmod 0600 $HOME/.gem/credentials
32
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
33
+ gem build *.gemspec
34
+ gem push *.gem
35
+ continue-on-error: true
36
+ env:
37
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
@@ -0,0 +1,21 @@
1
+ name: Test
2
+
3
+ on: pull_request
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.6
15
+ - name: Build and test
16
+ run: |
17
+ gem install bundler
18
+ bundle install --jobs 4 --retry 3
19
+ bundle exec rake test
20
+ env:
21
+ CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
@@ -0,0 +1,69 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Layout/AccessModifierIndentation:
5
+ EnforcedStyle: outdent
6
+
7
+ Layout/HashAlignment:
8
+ Enabled: false
9
+
10
+ Layout/DotPosition:
11
+ EnforcedStyle: trailing
12
+
13
+ Layout/SpaceInsideHashLiteralBraces:
14
+ EnforcedStyle: no_space
15
+
16
+ Lint/SuppressedException:
17
+ Enabled: false
18
+
19
+ Metrics/BlockLength:
20
+ Enabled: false
21
+
22
+ Metrics/BlockNesting:
23
+ Max: 2
24
+
25
+ Layout/LineLength:
26
+ AllowURI: true
27
+ Enabled: false
28
+
29
+ Metrics/MethodLength:
30
+ CountComments: false
31
+ Max: 15
32
+
33
+ Metrics/ParameterLists:
34
+ Max: 4
35
+ CountKeywordArgs: true
36
+
37
+ Metrics/AbcSize:
38
+ Enabled: false
39
+
40
+ Style/CollectionMethods:
41
+ PreferredMethods:
42
+ map: 'collect'
43
+ reduce: 'inject'
44
+ find: 'detect'
45
+ find_all: 'select'
46
+
47
+ Style/Documentation:
48
+ Enabled: false
49
+
50
+ Style/DoubleNegation:
51
+ Enabled: false
52
+
53
+ Style/EachWithObject:
54
+ Enabled: false
55
+
56
+ Style/Encoding:
57
+ Enabled: false
58
+
59
+ Style/ExpandPathArguments:
60
+ Enabled: false
61
+
62
+ Style/HashSyntax:
63
+ EnforcedStyle: hash_rockets
64
+
65
+ Style/Lambda:
66
+ Enabled: false
67
+
68
+ Style/RaiseArgs:
69
+ EnforcedStyle: compact
@@ -0,0 +1,7 @@
1
+ # 0.0.1.alpha
2
+
3
+ - Initial release.
4
+ - support APIs
5
+ - GET `/v1/{accountId}`
6
+ - GET `/v1/subdomains/{subdomain}`
7
+ - GET `/v1/suggestedsubdomains`
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at koshikawa2009@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in youcanbookme.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kenji Koshikawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,119 @@
1
+ # YouCanBook.me API Client
2
+
3
+ [![Test](https://github.com/koshilife/youcanbookme-api-ruby-client/workflows/Test/badge.svg)](https://github.com/koshilife/youcanbookme-api-ruby-client/actions?query=workflow%3ATest)
4
+ [![codecov](https://codecov.io/gh/koshilife/youcanbookme-api-ruby-client/branch/master/graph/badge.svg)](https://codecov.io/gh/koshilife/youcanbookme-api-ruby-client)
5
+ [![Gem Version](https://badge.fury.io/rb/youcanbookme.svg)](http://badge.fury.io/rb/youcanbookme)
6
+ [![license](https://img.shields.io/github/license/koshilife/youcanbookme-api-ruby-client)](https://github.com/koshilife/youcanbookme-api-ruby-client/blob/master/LICENSE.txt)
7
+
8
+ ## About
9
+
10
+ These client libraries are created for [YouCanBook.me API](https://api.youcanbook.me/docs/index.html).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'youcanbookme'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install youcanbookme
27
+
28
+ ## Supported statuses each YouCanBook.me API
29
+
30
+ - Account:
31
+ - [ ] POST `/v1/`
32
+ - [x] GET `/v1/{accountId}`
33
+ - [ ] PATCH `/v1/{accountId}`
34
+ - [ ] DELETE `/v1/{accountId}`
35
+ - Appointment Types:
36
+ - [ ] POST `/v1/{accountId}/profiles/{profileId}/appointmenttypes/items`
37
+ - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/appointmenttypes/items/{appointmentTypeId}`
38
+ - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/appointmenttypes/items/{appointmentTypeId}`
39
+ - Bookings:
40
+ - [ ] GET `/v1/{accountId}/bookings`
41
+ - [ ] GET `/v1/{accountId}/firedactions`
42
+ - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings`
43
+ - [ ] POST `/v1/{accountId}/profiles/{profileId}/bookings`
44
+ - [ ] GET `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
45
+ - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
46
+ - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/bookings/{bookingId}`
47
+ - [ ] GET `/v1/{accountId}/profiles/{profileId}/firedactions`
48
+ - [ ] 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
+ - 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}`
59
+ - 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}`
63
+ - Profile
64
+ - [ ] GET `/v1/{accountId}/profiles`
65
+ - [ ] POST `/v1/{accountId}/profiles`
66
+ - [ ] GET `/v1/{accountId}/profiles/{profileId}`
67
+ - [ ] PATCH `/v1/{accountId}/profiles/{profileId}`
68
+ - [ ] DELETE `/v1/{accountId}/profiles/{profileId}`
69
+ - [x] GET `/v1/subdomains/{subdomain}`
70
+ - [x] GET `/v1/suggestedsubdomains`
71
+ - Query
72
+ - [ ] POST `/v1/{localAccountId}/queries`
73
+ - 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}`
79
+ - Team Members:
80
+ - [ ] POST `/v1/{accountId}/profiles/{profileId}/teammembers/items`
81
+ - [ ] PATCH `/v1/{accountId}/profiles/{profileId}/teammembers/items/{teamMemberId}`
82
+ - [ ] DELETE `/v1/{accountId}/profiles/{profileId}/teammembers/items/{teamMemberId}`
83
+
84
+ ## Usage
85
+
86
+ The APIs client needs account email and password(or token).
87
+ This client setup step is below.
88
+
89
+ ```ruby
90
+ # set token by YouCanBookMe.configure methods.
91
+ YouCanBookMe.configure do |config|
92
+ config.username = 'foobar@example.com'
93
+ config.password_or_token = '<PASSWORD_OR_TOKEN>'
94
+ end
95
+ client = YouCanBookMe::Client.new
96
+
97
+ # set token by YouCanBookMe::Client initializer.
98
+ username = 'foobar@example.com'
99
+ password_or_token = '<PASSWORD_OR_TOKEN>'
100
+ client = YouCanBookMe::Client.new username, password_or_token
101
+ ```
102
+
103
+ This client basic usage is below.
104
+
105
+ ```ruby
106
+ TODO
107
+ ```
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/koshilife/youcanbookme-api-ruby-client). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
112
+
113
+ ## License
114
+
115
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
116
+
117
+ ## Code of Conduct
118
+
119
+ Everyone interacting in the youcanbookme Api Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/koshilife/youcanbookme-api-ruby-client/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'youcanbookme'
6
+ require 'irb'
7
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.inflector.inflect(
6
+ 'youcanbookme' => 'YouCanBookMe'
7
+ )
8
+ loader.collapse('**/models')
9
+ loader.setup
10
+
11
+ # module for YouCanBook.me apis client
12
+ module YouCanBookMe
13
+ class << self
14
+ def configure
15
+ yield configuration
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YouCanBookMe
4
+ # YouCanBookMe APIs client.
5
+ class Client
6
+ API_HOST = 'https://api.youcanbook.me'
7
+ API_VERSION = 'v1'
8
+
9
+ # @param [String] account_id a YouCanBook.me's account id(or email).
10
+ # @param [String] password_or_token a YouCanBook.me's account password or token.
11
+ # @raise [YouCanBookMe::Error] if the account_id is empty.
12
+ # @raise [YouCanBookMe::Error] if the password_or_token is empty.
13
+ def initialize(account_id = nil, password_or_token = nil)
14
+ @config = YouCanBookMe.configuration
15
+ @account_id = account_id || @config.account_id
16
+ @password_or_token = password_or_token || @config.password_or_token
17
+
18
+ check_not_empty @account_id, 'account_id'
19
+ check_not_empty @password_or_token, 'password_or_token'
20
+ @connection = HttpCommand.new @account_id, @password_or_token
21
+ end
22
+
23
+ #
24
+ # Account
25
+ #
26
+
27
+ def account_path
28
+ "/#{API_VERSION}/#{@account_id}"
29
+ end
30
+
31
+ #
32
+ # Get basic information about current account.
33
+ #
34
+ # @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
40
+ end
41
+
42
+ #
43
+ # Get suggested subdomains
44
+ #
45
+ # @return [Array<String>]
46
+ def suggested_subdomains
47
+ res = @connection.get "/#{API_VERSION}/suggestedsubdomains"
48
+ res.body
49
+ end
50
+
51
+ #
52
+ # Get the subdomain is available or not.
53
+ #
54
+ # @param [String] subdomain
55
+ # @return [Boolean]
56
+ # @raise [YouCanBookMe::Error] if the subdomain arg is empty.
57
+ def subdomain_available?(subdomain)
58
+ check_not_empty subdomain, 'subdomain'
59
+ res = @connection.get "/#{API_VERSION}/subdomains/#{subdomain}"
60
+ res.body[:free]
61
+ end
62
+
63
+ private
64
+
65
+ def check_not_empty(value, name)
66
+ raise YouCanBookMe::Error, "#{name} is required." if blank? value
67
+ end
68
+
69
+ def blank?(value)
70
+ return true if value.nil?
71
+ return true if value.to_s.empty?
72
+
73
+ false
74
+ end
75
+
76
+ def set_fields_into_params(fields, params = nil)
77
+ params ||= {}
78
+ return params unless fields
79
+ return params unless fields.is_a? Array
80
+ return params if fields.empty?
81
+
82
+ params.merge(fields: fields.join(','))
83
+ end
84
+ end
85
+ end