bookingsync-api 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -1
  4. data/CHANGELOG.md +3 -0
  5. data/lib/bookingsync/api/client.rb +10 -0
  6. data/lib/bookingsync/api/client/applications.rb +43 -0
  7. data/lib/bookingsync/api/client/applications_periods_rentals.rb +49 -0
  8. data/lib/bookingsync/api/client/booking_comments.rb +1 -1
  9. data/lib/bookingsync/api/client/contacts.rb +63 -0
  10. data/lib/bookingsync/api/client/rentals.rb +3 -2
  11. data/lib/bookingsync/api/version.rb +1 -1
  12. data/spec/bookingsync/api/client/applications_periods_rentals_spec.rb +70 -0
  13. data/spec/bookingsync/api/client/applications_spec.rb +44 -0
  14. data/spec/bookingsync/api/client/contacts_spec.rb +116 -0
  15. data/spec/fixtures/cassettes/BookingSync_API_Client_Applications/_application/returns_a_single_application.yml +84 -0
  16. data/spec/fixtures/cassettes/BookingSync_API_Client_Applications/_applications/returns_applications.yml +85 -0
  17. data/spec/fixtures/cassettes/BookingSync_API_Client_Applications/_edit_application/returns_updated_application.yml +73 -0
  18. data/spec/fixtures/cassettes/BookingSync_API_Client_Applications/_edit_application/updates_given_application_by_ID.yml +73 -0
  19. data/spec/fixtures/cassettes/BookingSync_API_Client_ApplicationsPeriodsRentals/_applications_periods_rental/returns_applications_periods_rental.yml +80 -0
  20. data/spec/fixtures/cassettes/BookingSync_API_Client_ApplicationsPeriodsRentals/_applications_periods_rentals/returns_applications_periods_rentals.yml +80 -0
  21. data/spec/fixtures/cassettes/BookingSync_API_Client_ApplicationsPeriodsRentals/_create_applications_periods_rental/creates_a_applications_periods_rental.yml +71 -0
  22. data/spec/fixtures/cassettes/BookingSync_API_Client_ApplicationsPeriodsRentals/_edit_applications_periods_rental/returns_updated_applications_periods_rental.yml +69 -0
  23. data/spec/fixtures/cassettes/BookingSync_API_Client_ApplicationsPeriodsRentals/_edit_applications_periods_rental/updates_given_applications_periods_rental_by_ID.yml +69 -0
  24. data/spec/fixtures/cassettes/BookingSync_API_Client_Bookings/_create_applications_periods_rental/creates_an_applications_periods_rental.yml +71 -0
  25. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_contact/returns_a_single_contact.yml +99 -0
  26. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_contact/returns_contact.yml +99 -0
  27. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_contacts/returns_contacts.yml +99 -0
  28. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_contacts/returns_contacts_by_ids.yml +99 -0
  29. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_create_contact/creates_a_new_contact.yml +74 -0
  30. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_delete_contact/deletes_given_contact.yml +63 -0
  31. data/spec/fixtures/cassettes/BookingSync_API_Client_Contacts/_edit_contact/updates_given_contact_by_ID.yml +71 -0
  32. metadata +46 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c8ad27849fc4a96f22ac1e26e6131969bb807ac
4
- data.tar.gz: 03cf348e183c9ba3cbfbec510f52cc68238ed399
2
+ SHA256:
3
+ metadata.gz: 5a09e07498321ef580ddd8236abc2981e51f1292ffe3816fd888247a4ce01d34
4
+ data.tar.gz: 8d5794b071cdb51115431a1598e5635ce8cde59fb11abe7ac564cf1f08700951
5
5
  SHA512:
6
- metadata.gz: 6d46384ec6e886b7c3f2a4643b21290a294790097c6233c71e4b350a81ef6984934e2de9afc74a37df0da57e70b83c55682bac43c29d701a17b2ac0aa4a9fc3f
7
- data.tar.gz: ef07295629c94241a06b2ea350a62a23aaaa20595822d3cfb740d118bc10982777b9a011ece6ace4750c822b966a44c24b493ecee551043bc50c4689da878909
6
+ metadata.gz: 42b832673aea07e5cf57c2a50ec5982f4f0972e05a8f2c7f5eeedba239eeb5e840ae2672b13bdbbd6528ab582a5b733e626b349c54f550c4fc98443aa50fefa3
7
+ data.tar.gz: 293aba124873f3f84bb6417ef9dc271e0efc1e2d64bbbf3e9865ed6101901432ad1bfd2a02df76d12153ef3ba17fead418d479bf40077d6f67514fc33c19558e
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  .bundle
4
+ .byebug_history
4
5
  .config
5
6
  .yardoc
6
7
  Gemfile.lock
data/.travis.yml CHANGED
@@ -2,8 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - "2.1"
4
4
  - "2.2"
5
+ - "2.4.4"
6
+ - "2.5.1"
5
7
  before_install:
6
8
  - gem install bundler -v 1.12.5
7
9
  script:
8
- - bundle exec rake style:rubocop:without_auto_correct
10
+ - bundle exec rake style:rubocop:without_auto_correct
9
11
  - bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  # master
4
4
 
5
+ ## 0.1.13 - 2019-10-08
6
+ - Add supports for `contacts` endpoint.
7
+
5
8
  ## 0.1.12 - 2018-05-25
6
9
  - updated Faraday and Net HTTP Persistent gem to remove workaround
7
10
 
@@ -1,6 +1,8 @@
1
1
  require "bookingsync/api/middleware/logger"
2
2
  require "bookingsync/api/client/accounts"
3
3
  require "bookingsync/api/client/amenities"
4
+ require "bookingsync/api/client/applications"
5
+ require "bookingsync/api/client/applications_periods_rentals"
4
6
  require "bookingsync/api/client/attachments"
5
7
  require "bookingsync/api/client/availabilities"
6
8
  require "bookingsync/api/client/bathrooms"
@@ -13,6 +15,7 @@ require "bookingsync/api/client/bookings_tags"
13
15
  require "bookingsync/api/client/bookings_taxes"
14
16
  require "bookingsync/api/client/change_overs"
15
17
  require "bookingsync/api/client/clients"
18
+ require "bookingsync/api/client/contacts"
16
19
  require "bookingsync/api/client/destinations"
17
20
  require "bookingsync/api/client/fees"
18
21
  require "bookingsync/api/client/hosts"
@@ -56,6 +59,8 @@ module BookingSync::API
56
59
  extend Forwardable
57
60
  include BookingSync::API::Client::Accounts
58
61
  include BookingSync::API::Client::Amenities
62
+ include BookingSync::API::Client::Applications
63
+ include BookingSync::API::Client::ApplicationsPeriodsRentals
59
64
  include BookingSync::API::Client::Attachments
60
65
  include BookingSync::API::Client::Availabilities
61
66
  include BookingSync::API::Client::Bathrooms
@@ -69,6 +74,7 @@ module BookingSync::API
69
74
  include BookingSync::API::Client::ChangeOvers
70
75
  include BookingSync::API::Client::Conversations
71
76
  include BookingSync::API::Client::Clients
77
+ include BookingSync::API::Client::Contacts
72
78
  include BookingSync::API::Client::Destinations
73
79
  include BookingSync::API::Client::Fees
74
80
  include BookingSync::API::Client::Hosts
@@ -415,5 +421,9 @@ module BookingSync::API
415
421
  def next_page(response, request_settings)
416
422
  response.relations[:next].call({}, { method: request_settings[:request_method] })
417
423
  end
424
+
425
+ def reject_blank_values(array)
426
+ array.reject { |value| value.nil? || value == "" }
427
+ end
418
428
  end
419
429
  end
@@ -0,0 +1,43 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Applications
4
+ # List applications
5
+ #
6
+ # Returns all applications supported in BookingSync.
7
+ # @param options [Hash] A customizable set of options.
8
+ # @option options [Array] fields: List of fields to be fetched.
9
+ # @return [Array<BookingSync::API::Resource>] Array of applications.
10
+ #
11
+ # @example Get the list of applications for the current account
12
+ # applications = @api.applications
13
+ # applications.first.title # => "Internet"
14
+ # @see http://developers.bookingsync.com/reference/endpoints/applications/#list-applications
15
+ def applications(options = {}, &block)
16
+ paginate :applications, options, &block
17
+ end
18
+
19
+ # Get a single application
20
+ #
21
+ # @param application [BookingSync::API::Resource|Integer] application or ID
22
+ # of the application.
23
+ # @return [BookingSync::API::Resource]
24
+ # @see http://developers.bookingsync.com/reference/endpoints/applications/#get-a-single-application
25
+ def application(application)
26
+ get("applications/#{application}").pop
27
+ end
28
+
29
+ # Edit an application
30
+ #
31
+ # @param application [BookingSync::API::Resource|Integer] application or ID of the application
32
+ # to be updated
33
+ # @param options [Hash] application attributes to be updated
34
+ # @return [BookingSync::API::Resource] Updated application on success, exception is raised otherwise
35
+ # @example
36
+ # application = @api.applications.first
37
+ # @api.edit_application(application, { default_price_increase: 3 })
38
+ def edit_application(application, options = {})
39
+ put("applications/#{application}", applications: [options]).pop
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module ApplicationsPeriodsRentals
4
+ # List applications_periods_rentals
5
+ #
6
+ # Returns all applications_periods_rentals supported in BookingSync.
7
+ # @param options [Hash] A customizable set of options.
8
+ # @option options [Array] fields: List of fields to be fetched.
9
+ # @return [Array<BookingSync::API::Resource>] Array of applications_periods_rentals.
10
+ #
11
+ # @example Get the list of applications_periods_rentals for the current account
12
+ # applications_periods_rentals = @api.applications_periods_rentals
13
+ # applications_periods_rentals.first.title # => "Internet"
14
+ def applications_periods_rentals(options = {}, &block)
15
+ paginate :applications_periods_rentals, options, &block
16
+ end
17
+
18
+ # Create a applications_periods_rental
19
+ #
20
+ # @param options [Hash] applications_periods_rental attributes.
21
+ # @return [BookingSync::API::Resource] Newly created applications_periods_rental.
22
+ def create_applications_periods_rental(options = {})
23
+ post("applications_periods_rentals", applications_periods_rental: options).pop
24
+ end
25
+
26
+ # Get a single applications_periods_rental
27
+ #
28
+ # @param applications_periods_rental [BookingSync::API::Resource|Integer] applications_periods_rental or ID
29
+ # of the applications_periods_rental.
30
+ # @return [BookingSync::API::Resource]
31
+ def applications_periods_rental(applications_periods_rental)
32
+ get("applications_periods_rentals/#{applications_periods_rental}").pop
33
+ end
34
+
35
+ # Edit an applications_periods_rental
36
+ #
37
+ # @param applications_periods_rental [BookingSync::API::Resource|Integer] applications_periods_rental or ID of the applications_periods_rental
38
+ # to be updated
39
+ # @param options [Hash] applications_periods_rental attributes to be updated
40
+ # @return [BookingSync::API::Resource] Updated applications_periods_rental on success, exception is raised otherwise
41
+ # @example
42
+ # applications_periods_rental = @api.applications_periods_rentals.first
43
+ # @api.edit_application(applications_periods_rental, { default_price_increase: 3 })
44
+ def edit_applications_periods_rental(applications_periods_rental, options = {})
45
+ put("applications_periods_rentals/#{applications_periods_rental}", applications_periods_rental: options).pop
46
+ end
47
+ end
48
+ end
49
+ end
@@ -53,7 +53,7 @@ module BookingSync::API
53
53
  # exception is raised otherwise.
54
54
  # @example
55
55
  # booking_comment = @api.booking_comments.first
56
- # @api.edit_booking_comment(8, {conent: "New conent"})
56
+ # @api.edit_booking_comment(8, {content: "New content"})
57
57
  # => {:links=>{:booking=>1}, :id=>8, :content=>"New content", :editable=>true, :created_at=>2016-04-18 13:31:40 UTC, :updated_at=>2016-04-18 13:46:06 UTC}
58
58
  def edit_booking_comment(booking_comment, options = {})
59
59
  put("booking_comments/#{booking_comment}", booking_comments: [options]).pop
@@ -0,0 +1,63 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Contacts
4
+ # List contacts
5
+ #
6
+ # Returns contacts for the account user is authenticated with.
7
+ # @param options [Hash] A customizable set of options.
8
+ # @option options [Array] fields: List of fields to be fetched.
9
+ # @return [Array<BookingSync::API::Resource>] Array of contacts.
10
+ #
11
+ # @example Get the list of contacts for the current account
12
+ # contacts = @api.contacts
13
+ # contacts.first.fullname # => "John Smith"
14
+ # @example Get the list of contacts only with fullname and phone for smaller response
15
+ # @api.contacts(fields: [:fullname, :phone])
16
+ # @see http://developers.bookingsync.com/reference/endpoints/contacts/#list-contacts
17
+ def contacts(options = {}, &block)
18
+ paginate :contacts, options, &block
19
+ end
20
+
21
+ # Get a single contact
22
+ #
23
+ # @param contact [BookingSync::API::Resource|Integer] Contact or ID
24
+ # of the contact.
25
+ # @param options [Hash] A customizable set of query options.
26
+ # @option options [Array] fields: List of fields to be fetched.
27
+ # @return [BookingSync::API::Resource]
28
+ def contact(contact, options = {})
29
+ get("contacts/#{contact}", options).pop
30
+ end
31
+
32
+ # Create a new contact
33
+ #
34
+ # @param options [Hash] Contact attributes
35
+ # @return [BookingSync::API::Resource] Newly created contact
36
+ def create_contact(options = {})
37
+ post(:contacts, contacts: [options]).pop
38
+ end
39
+
40
+ # Edit a contact
41
+ #
42
+ # @param contact [BookingSync::API::Resource|Integer] Contact or ID of the contact
43
+ # to be updated
44
+ # @param options [Hash] Contact attributes to be updated
45
+ # @return [BookingSync::API::Resource] Updated contact on success, exception is raised otherwise
46
+ # @example
47
+ # contact = @api.contacts.first
48
+ # @api.edit_contact(contact, { fullname: "Gary Smith" })
49
+ def edit_contact(contact, options = {})
50
+ put("contacts/#{contact}", contacts: [options]).pop
51
+ end
52
+
53
+ # Delete a contact
54
+ #
55
+ # @param contact [BookingSync::API::Resource|Integer] Contact or ID
56
+ # of the contact to be deleted.
57
+ # @return [NilClass] Returns nil on success.
58
+ def delete_contact(contact)
59
+ delete "contacts/#{contact}"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -30,7 +30,7 @@ module BookingSync::API
30
30
  # villas = @api.rentals_search(rental_type: "villa")
31
31
  def rentals_search(options = {}, &block)
32
32
  ids = Array(options.delete(:ids))
33
- path = ["rentals", ids.join(","), "search"].compact.join("/")
33
+ path = reject_blank_values(["rentals", ids.join(","), "search"]).join("/")
34
34
  defaults = { request_method: :post }
35
35
  paginate path, defaults.merge(options), &block
36
36
  end
@@ -79,7 +79,8 @@ module BookingSync::API
79
79
  # @param rentals [Array] IDs of Rentals, leave empty for all account's rentals
80
80
  # @return [BookingSync::API::Resource]
81
81
  def rentals_meta(rentals = nil)
82
- get(["rentals", Array(rentals).join(","), "meta"].compact.join("/")).pop
82
+ path = reject_blank_values(["rentals", Array(rentals).join(","), "meta"]).join("/")
83
+ get(path).pop
83
84
  end
84
85
  end
85
86
  end
@@ -1,5 +1,5 @@
1
1
  module BookingSync
2
2
  module API
3
- VERSION = "0.1.12"
3
+ VERSION = "0.1.13"
4
4
  end
5
5
  end
@@ -0,0 +1,70 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::ApplicationsPeriodsRentals do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ before { |ex| @casette_base_path = casette_path(casette_dir, ex.metadata) }
7
+
8
+ describe ".applications_periods_rentals", :vcr do
9
+ it "returns applications_periods_rentals" do
10
+ expect(client.applications_periods_rentals).not_to be_empty
11
+ assert_requested :get, bs_url("applications_periods_rentals")
12
+ end
13
+ end
14
+
15
+ describe ".applications_periods_rental", :vcr do
16
+ let(:prefetched_applications_periods_rental) {
17
+ find_resource("#{@casette_base_path}_applications_periods_rentals/returns_applications_periods_rentals.yml", "applications_periods_rentals")
18
+ }
19
+
20
+ it "returns applications_periods_rental" do
21
+ applications_periods_rental = client.applications_periods_rental(prefetched_applications_periods_rental[:id])
22
+ expect(applications_periods_rental.price_increase).to eq(prefetched_applications_periods_rental[:price_increase])
23
+ end
24
+ end
25
+
26
+ describe ".create_applications_periods_rental", :vcr do
27
+ let(:attributes) {
28
+ {
29
+ rental_id: 1,
30
+ application_id: 9,
31
+ start_date: "2017-01-03",
32
+ end_date: "2017-01-04",
33
+ price_increase: 15.0
34
+ }
35
+ }
36
+
37
+ it "creates a applications_periods_rental" do
38
+ client.create_applications_periods_rental(attributes)
39
+ assert_requested :post, bs_url("applications_periods_rentals"),
40
+ body: { applications_periods_rental: attributes }.to_json
41
+ end
42
+
43
+ it "returns newly created applications_periods_rental" do
44
+ VCR.use_cassette("BookingSync_API_Client_Bookings/_create_applications_periods_rental/creates_an_applications_periods_rental") do
45
+ applications_periods_rental = client.create_applications_periods_rental(attributes)
46
+ expect(applications_periods_rental).to be_kind_of(BookingSync::API::Resource)
47
+ expect(applications_periods_rental.price_increase).to eq(attributes[:price_increase].to_s)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe ".edit_applications_periods_rental", :vcr do
53
+ let(:prefetched_edit_applications_periods_rental) {
54
+ find_resource("#{@casette_base_path}_applications_periods_rentals/returns_applications_periods_rentals.yml", "applications_periods_rentals")
55
+ }
56
+ let(:price_increase) { 3.1 }
57
+
58
+ it "updates given applications_periods_rental by ID" do
59
+ client.edit_applications_periods_rental(prefetched_edit_applications_periods_rental, price_increase: price_increase)
60
+ assert_requested :put, bs_url("applications_periods_rentals/#{prefetched_edit_applications_periods_rental}"),
61
+ body: { applications_periods_rental: { price_increase: price_increase } }.to_json
62
+ end
63
+
64
+ it "returns updated applications_periods_rental" do
65
+ applications_periods_rental = client.edit_applications_periods_rental(prefetched_edit_applications_periods_rental, price_increase: price_increase)
66
+ expect(applications_periods_rental).to be_kind_of(BookingSync::API::Resource)
67
+ expect(applications_periods_rental.price_increase).to eq(price_increase.to_s)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::Applications do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ before { |ex| @casette_base_path = casette_path(casette_dir, ex.metadata) }
7
+
8
+ describe ".applications", :vcr do
9
+ it "returns applications" do
10
+ expect(client.applications).not_to be_empty
11
+ assert_requested :get, bs_url("applications")
12
+ end
13
+ end
14
+
15
+ describe ".application", :vcr do
16
+ let(:prefetched_application_id) {
17
+ find_resource("#{@casette_base_path}_applications/returns_applications.yml", "applications")[:id]
18
+ }
19
+
20
+ it "returns a single application" do
21
+ application = client.application(prefetched_application_id)
22
+ expect(application.id).to eq prefetched_application_id
23
+ end
24
+ end
25
+
26
+ describe ".edit_application", :vcr do
27
+ let(:prefetched_application_id) {
28
+ find_resource("#{@casette_base_path}_applications/returns_applications.yml", "applications")[:id]
29
+ }
30
+ let(:default_price_increase) { 1.1 }
31
+
32
+ it "updates given application by ID" do
33
+ client.edit_application(prefetched_application_id, default_price_increase: default_price_increase)
34
+ assert_requested :put, bs_url("applications/#{prefetched_application_id}"),
35
+ body: { applications: [{ default_price_increase: default_price_increase }] }.to_json
36
+ end
37
+
38
+ it "returns updated application" do
39
+ application = client.edit_application(prefetched_application_id, default_price_increase: default_price_increase)
40
+ expect(application).to be_kind_of(BookingSync::API::Resource)
41
+ expect(application.default_price_increase).to eq(default_price_increase.to_s)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,116 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::Contacts do
4
+ let(:api) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ before { |ex| @casette_base_path = casette_path(casette_dir, ex.metadata) }
7
+
8
+ describe ".contacts", :vcr do
9
+ subject(:contacts) { api.contacts }
10
+ subject(:contacts_by_ids) { api.contacts(ids: contact_ids) }
11
+ let(:contact_ids) do
12
+ find_resources("#{@casette_base_path}_contacts/returns_contacts.yml", "contacts").map { |r| r["id"] }[0..1]
13
+ end
14
+
15
+ it "returns contacts" do
16
+ expect(contacts).not_to be_empty
17
+ assert_requested :get, bs_url("contacts")
18
+ end
19
+
20
+ it "returns contacts by ids" do
21
+ expect(contacts_by_ids.size).to eq(1)
22
+ assert_requested :get, bs_url("contacts/#{contact_ids.join(',')}")
23
+ end
24
+ end
25
+
26
+ describe ".contact", :vcr do
27
+ subject(:contact) { api.contact(1) }
28
+
29
+ it "returns contact" do
30
+ expect(contact).not_to be_empty
31
+ assert_requested :get, bs_url("contacts/1")
32
+ end
33
+ end
34
+
35
+ describe ".contact", :vcr do
36
+ subject(:contact) { api.contact(prefetched_contact_id) }
37
+
38
+ let(:prefetched_contact_id) {
39
+ find_resource("#{@casette_base_path}_contacts/returns_contacts.yml", "contacts")[:id]
40
+ }
41
+
42
+ it "returns a single contact" do
43
+ expect(contact.id).to eq prefetched_contact_id
44
+ end
45
+ end
46
+
47
+ describe ".create_contact", :vcr do
48
+ subject(:create_contact) { api.create_contact(attributes) }
49
+
50
+ let(:attributes) do
51
+ {
52
+ firstname: "John",
53
+ lastname: "Doe",
54
+ email: "halldor@example.com",
55
+ website: "http://www.demo.com",
56
+ address1: "Demo address",
57
+ gender: "male",
58
+ phones: [{ label: "default", number: "123456789" }],
59
+ country_code: "IS",
60
+ city: "Reykjavik",
61
+ zip: "33209",
62
+ state: "Demo",
63
+ spoken_languages: [:en]
64
+ }
65
+ end
66
+
67
+ it "creates a new contact" do
68
+ create_contact
69
+ assert_requested :post, bs_url("contacts"),
70
+ body: { contacts: [attributes] }.to_json
71
+ end
72
+
73
+ it "returns newly created contact" do
74
+ VCR.use_cassette("BookingSync_API_Client_Contacts/_create_contact/creates_a_new_contact") do
75
+ contact = create_contact
76
+ expect(contact.email).to eq "halldor@example.com"
77
+ expect(contact.fullname).to eq ("John Doe")
78
+ end
79
+ end
80
+ end
81
+
82
+ describe ".edit_contact", :vcr do
83
+ subject(:edit_contact) { api.edit_contact(created_contact_id, firstname: "Knut", lastname: "Eljassen") }
84
+
85
+ let(:created_contact_id) {
86
+ find_resource("#{@casette_base_path}_create_contact/creates_a_new_contact.yml", "contacts")[:id]
87
+ }
88
+
89
+ it "updates given contact by ID" do
90
+ edit_contact
91
+ assert_requested :put, bs_url("contacts/#{created_contact_id}"),
92
+ body: { contacts: [{ firstname: "Knut", lastname: "Eljassen" }] }.to_json
93
+ end
94
+
95
+ it "returns updated contact" do
96
+ VCR.use_cassette("BookingSync_API_Client_Contacts/_edit_contact/updates_given_contact_by_ID") do
97
+ contact = edit_contact
98
+ expect(contact).to be_kind_of(BookingSync::API::Resource)
99
+ expect(contact.fullname).to eq("Knut Eljassen")
100
+ end
101
+ end
102
+ end
103
+
104
+ describe ".delete_contact", :vcr do
105
+ subject(:delete_contact) { api.delete_contact(created_contact_id) }
106
+
107
+ let(:created_contact_id) {
108
+ find_resource("#{casette_dir}/BookingSync_API_Client_Contacts/_create_contact/creates_a_new_contact.yml", "contacts")[:id]
109
+ }
110
+
111
+ it "deletes given contact" do
112
+ delete_contact
113
+ assert_requested :delete, bs_url("contacts/#{created_contact_id}")
114
+ end
115
+ end
116
+ end