bookingsync-api 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +13 -0
  4. data/lib/bookingsync/api/client.rb +21 -0
  5. data/lib/bookingsync/api/client/conversations.rb +75 -0
  6. data/lib/bookingsync/api/client/hosts.rb +51 -0
  7. data/lib/bookingsync/api/client/messages.rb +51 -0
  8. data/lib/bookingsync/api/client/participants.rb +51 -0
  9. data/lib/bookingsync/api/version.rb +1 -1
  10. data/spec/bookingsync/api/client/conversations_spec.rb +124 -0
  11. data/spec/bookingsync/api/client/hosts_spec.rb +79 -0
  12. data/spec/bookingsync/api/client/messages_spec.rb +77 -0
  13. data/spec/bookingsync/api/client/participants_spec.rb +77 -0
  14. data/spec/bookingsync/api/client_spec.rb +42 -0
  15. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_connect_booking_to_conversation/connects_given_conversation_with_booking.yml +154 -0
  16. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_conversation/returns_a_single_conversation.yml +82 -0
  17. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_conversations/returns_conversations.yml +83 -0
  18. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_create_conversation/creates_a_new_conversation.yml +81 -0
  19. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_disconnect_booking_from_conversation/disconnects_given_conversation_from_booking.yml +154 -0
  20. data/spec/fixtures/cassettes/BookingSync_API_Client_Conversations/_edit_conversation/updates_given_conversation_by_ID.yml +74 -0
  21. data/spec/fixtures/cassettes/BookingSync_API_Client_Hosts/_create_host/creates_a_new_host.yml +80 -0
  22. data/spec/fixtures/cassettes/BookingSync_API_Client_Hosts/_edit_host/updates_given_host_by_ID.yml +73 -0
  23. data/spec/fixtures/cassettes/BookingSync_API_Client_Hosts/_host/returns_a_single_host.yml +82 -0
  24. data/spec/fixtures/cassettes/BookingSync_API_Client_Hosts/_hosts/returns_hosts.yml +82 -0
  25. data/spec/fixtures/cassettes/BookingSync_API_Client_Messages/_create_message/creates_a_new_message.yml +81 -0
  26. data/spec/fixtures/cassettes/BookingSync_API_Client_Messages/_edit_message/updates_given_message_by_ID.yml +74 -0
  27. data/spec/fixtures/cassettes/BookingSync_API_Client_Messages/_message/returns_a_single_message.yml +82 -0
  28. data/spec/fixtures/cassettes/BookingSync_API_Client_Messages/_messages/returns_messages.yml +82 -0
  29. data/spec/fixtures/cassettes/BookingSync_API_Client_Participants/_create_participant/creates_a_new_participant.yml +80 -0
  30. data/spec/fixtures/cassettes/BookingSync_API_Client_Participants/_edit_participant/updates_given_participant_by_ID.yml +73 -0
  31. data/spec/fixtures/cassettes/BookingSync_API_Client_Participants/_participant/returns_a_single_participant.yml +82 -0
  32. data/spec/fixtures/cassettes/BookingSync_API_Client_Participants/_participants/returns_participants.yml +82 -0
  33. metadata +50 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 445f23d326e4331163eab11f0156f4571df34382
4
- data.tar.gz: 32a2bfa0eaf8902714af8a2dedea2a852cdf35eb
3
+ metadata.gz: 07875aceb5be5188713572808a3279c3ef1850ee
4
+ data.tar.gz: 9a346db370e70f7ad358e416a4ad28de91912dc8
5
5
  SHA512:
6
- metadata.gz: 12fde8daede41304f9a1707dcc609519e9130e8b1d912b7e02753069e551a3628add14970bb3f77a8453f25a9c313b76d39fac0eef31dac8831a15c9c124ecac
7
- data.tar.gz: 658aff5e26667bb67f6f629f126a36740c005f93a8e5ff3ff0255d99fa919ea6d2f78f4eb34e6c38507611ea2baa1fb9571c413e12b6f6a5c6447de2d86fb0ae
6
+ metadata.gz: 42a65dfbf9e155c9589377219aaf54d163f0e39fa96ad5ddd5a2295e60450dbfbdcc43d226e3b3e4204addb30bb0fd659d6e7f4aafb28a67052c4f5e2ec10dc5
7
+ data.tar.gz: ec176fddc4a0c67f9787e9eef645e5dbc065914ec1e2b31c811edb424131aa009f5221dd0a3e614313f53d40910c0517e3d3c8fef594a7782ae6a3ef555fb082
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ # master
4
+
5
+ ## 0.1.9 - 2018-04-30
6
+
7
+ - Enable dynamic override of headers per request.
8
+ - Add support for `inbox` endpoints.
9
+
3
10
  ## 0.1.8 - 2017-12-05
4
11
 
5
12
  - Add support for `bookings_tags` endpoint.
data/README.md CHANGED
@@ -70,6 +70,19 @@ api.last_response.meta # => {"deleted_ids" => [1, 3, 4]}
70
70
  api.pagination_first_response.meta # => {"deleted_ids" => [1, 3, 4]}
71
71
  ```
72
72
 
73
+ ### Adjust headers dynamically
74
+
75
+ If you need to add custom headers you can use `#with_headers` method. It accepts hash of headers
76
+ that should be added to next request and yields client. It resets headers to default ones at the end
77
+ and returns result of last operation specified inside block.
78
+
79
+ ```ruby
80
+ api.with_headers("x-awesome-header" => "you-bet-i-am") do |adjusted_api_client|
81
+ adjusted_api_client.rentals
82
+ end
83
+ => [BookingSync::API::Resource, BookingSync::API::Resource]
84
+ ```
85
+
73
86
  ### Logging
74
87
 
75
88
  Sometimes it's useful to see what data bookingsync-api gem sends and what it
@@ -14,6 +14,7 @@ require "bookingsync/api/client/change_overs"
14
14
  require "bookingsync/api/client/clients"
15
15
  require "bookingsync/api/client/destinations"
16
16
  require "bookingsync/api/client/fees"
17
+ require "bookingsync/api/client/hosts"
17
18
  require "bookingsync/api/client/inquiries"
18
19
  require "bookingsync/api/client/living_rooms"
19
20
  require "bookingsync/api/client/nightly_rate_maps"
@@ -38,6 +39,9 @@ require "bookingsync/api/client/seasons"
38
39
  require "bookingsync/api/client/special_offers"
39
40
  require "bookingsync/api/client/sources"
40
41
  require "bookingsync/api/client/taxes"
42
+ require "bookingsync/api/client/conversations"
43
+ require "bookingsync/api/client/messages"
44
+ require "bookingsync/api/client/participants"
41
45
  require "bookingsync/api/error"
42
46
  require "bookingsync/api/relation"
43
47
  require "bookingsync/api/response"
@@ -62,13 +66,17 @@ module BookingSync::API
62
66
  include BookingSync::API::Client::BookingsTags
63
67
  include BookingSync::API::Client::BookingsTaxes
64
68
  include BookingSync::API::Client::ChangeOvers
69
+ include BookingSync::API::Client::Conversations
65
70
  include BookingSync::API::Client::Clients
66
71
  include BookingSync::API::Client::Destinations
67
72
  include BookingSync::API::Client::Fees
73
+ include BookingSync::API::Client::Hosts
68
74
  include BookingSync::API::Client::Inquiries
69
75
  include BookingSync::API::Client::LivingRooms
76
+ include BookingSync::API::Client::Messages
70
77
  include BookingSync::API::Client::NightlyRateMaps
71
78
  include BookingSync::API::Client::StrictBookings
79
+ include BookingSync::API::Client::Participants
72
80
  include BookingSync::API::Client::Periods
73
81
  include BookingSync::API::Client::Payments
74
82
  include BookingSync::API::Client::PaymentGateways
@@ -274,6 +282,19 @@ module BookingSync::API
274
282
  end
275
283
  end
276
284
 
285
+ # Yields client with temporarily modified headers.
286
+ #
287
+ # @param extra_headers [Hash] Additional headers added to next request.
288
+ # @yieldreturn [BookingSync::API::Client] Client with modified default headers.
289
+ # @return [Array<BookingSync::API::Resource>|BookingSync::API::Resource|String|Object] Client response
290
+ def with_headers(extra_headers = {}, &block)
291
+ original_headers = @conn.headers.dup
292
+ @conn.headers.merge!(extra_headers)
293
+ result = yield self
294
+ @conn.headers = original_headers
295
+ result
296
+ end
297
+
277
298
  private
278
299
 
279
300
  def middleware
@@ -0,0 +1,75 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Conversations
4
+ # List conversations
5
+ #
6
+ # Returns all conversations 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 conversations.
10
+ #
11
+ # @example Get the list of conversations for the current account
12
+ # conversations = @api.conversations
13
+ # conversations.first.subject # => "Question"
14
+ # @see http://developers.bookingsync.com/reference/endpoints/conversations/#list-conversations
15
+ def conversations(options = {}, &block)
16
+ paginate "inbox/conversations", options, &block
17
+ end
18
+
19
+ # Get a single conversation
20
+ #
21
+ # @param conversation [BookingSync::API::Resource|Integer] Conversation or ID
22
+ # of the conversation.
23
+ # @return [BookingSync::API::Resource]
24
+ def conversation(conversation)
25
+ get("inbox/conversations/#{conversation}").pop
26
+ end
27
+
28
+ # Create a new conversation
29
+ #
30
+ # @param options [Hash] Conversation's attributes.
31
+ # @return [BookingSync::API::Resource] Newly created conversation.
32
+ def create_conversation(options = {})
33
+ post("inbox/conversations", conversations: [options]).pop
34
+ end
35
+
36
+ # Edit a conversation
37
+ #
38
+ # @param conversation [BookingSync::API::Resource|Integer] Conversation or ID of
39
+ # the conversation to be updated.
40
+ # @param options [Hash] Conversation attributes to be updated.
41
+ # @return [BookingSync::API::Resource] Updated conversation on success,
42
+ # exception is raised otherwise.
43
+ # @example
44
+ # conversation = @api.conversations.first
45
+ # @api.edit_conversation(conversation, { closed: true })
46
+ def edit_conversation(conversation, options = {})
47
+ put("inbox/conversations/#{conversation}", conversations: [options]).pop
48
+ end
49
+
50
+ # Connect conversation with booking
51
+ # @param conversation [BookingSync::API::Resource|Integer] Conversation or ID of
52
+ # the conversation to be connected to booking
53
+ # @param options [Hash] Id of booking to be connected to conversation.
54
+ # @return [BookingSync::API::Resource] Conversation with updated links on success,
55
+ # exception is raised otherwise.
56
+ # @example
57
+ # @api.connect_booking_to_conversation(conversation, { id: 5 })
58
+ def connect_booking_to_conversation(conversation, options)
59
+ put("inbox/conversations/#{conversation}/connect_booking", bookings: [options]).pop
60
+ end
61
+
62
+ # Disconnect conversation from booking
63
+ # @param conversation [BookingSync::API::Resource|Integer] Conversation or ID of
64
+ # the conversation connected to booking
65
+ # @param options [Hash] Id of booking to be disconnected from conversation.
66
+ # @return [BookingSync::API::Resource] Conversation with updated links on success,
67
+ # exception is raised otherwise.
68
+ # @example
69
+ # @api.disconnect_booking_from_conversation(conversation, { id: 5 })
70
+ def disconnect_booking_from_conversation(conversation, options)
71
+ put("inbox/conversations/#{conversation}/disconnect_booking", bookings: [options]).pop
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,51 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Hosts
4
+ # List hosts
5
+ #
6
+ # Returns all hosts 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 hosts.
10
+ #
11
+ # @example Get the list of hosts for the current account
12
+ # hosts = @api.hosts
13
+ # hosts.first.email # => "host_email@example.com"
14
+ # @see http://developers.bookingsync.com/reference/endpoints/hosts/#list-hosts
15
+ def hosts(options = {}, &block)
16
+ paginate :hosts, options, &block
17
+ end
18
+
19
+ # Get a single host
20
+ #
21
+ # @param host [BookingSync::API::Resource|Integer] Host or ID
22
+ # of the host.
23
+ # @return [BookingSync::API::Resource]
24
+ def host(host)
25
+ get("hosts/#{host}").pop
26
+ end
27
+
28
+ # Create a new host
29
+ #
30
+ # @param options [Hash] Host's attributes.
31
+ # @return [BookingSync::API::Resource] Newly created host.
32
+ def create_host(options = {})
33
+ post(:hosts, hosts: [options]).pop
34
+ end
35
+
36
+ # Edit a host
37
+ #
38
+ # @param host [BookingSync::API::Resource|Integer] Host or ID of
39
+ # the host to be updated.
40
+ # @param options [Hash] Host attributes to be updated.
41
+ # @return [BookingSync::API::Resource] Updated host on success,
42
+ # exception is raised otherwise.
43
+ # @example
44
+ # host = @api.hosts.first
45
+ # @api.edit_host(host, { firstname: "Johnny" })
46
+ def edit_host(host, options = {})
47
+ put("hosts/#{host}", hosts: [options]).pop
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Messages
4
+ # List messages
5
+ #
6
+ # Returns all messages 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 messages.
10
+ #
11
+ # @example Get the list of messages for the current account
12
+ # messages = @api.messages
13
+ # messages.first.content # => "Message content"
14
+ # @see http://developers.bookingsync.com/reference/endpoints/messages/#list-messages
15
+ def messages(options = {}, &block)
16
+ paginate "inbox/messages", options, &block
17
+ end
18
+
19
+ # Get a single message
20
+ #
21
+ # @param message [BookingSync::API::Resource|Integer] Message or ID
22
+ # of the message.
23
+ # @return [BookingSync::API::Resource]
24
+ def message(message)
25
+ get("inbox/messages/#{message}").pop
26
+ end
27
+
28
+ # Create a new message
29
+ #
30
+ # @param options [Hash] Message's attributes.
31
+ # @return [BookingSync::API::Resource] Newly created message.
32
+ def create_message(options = {})
33
+ post("inbox/messages", messages: [options]).pop
34
+ end
35
+
36
+ # Edit a message
37
+ #
38
+ # @param message [BookingSync::API::Resource|Integer] Message or ID of
39
+ # the message to be updated.
40
+ # @param options [Hash] Message attributes to be updated.
41
+ # @return [BookingSync::API::Resource] Updated message on success,
42
+ # exception is raised otherwise.
43
+ # @example
44
+ # message = @api.messages.first
45
+ # @api.edit_message(message, { content: "Updated message content" })
46
+ def edit_message(message, options = {})
47
+ put("inbox/messages/#{message}", messages: [options]).pop
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Participants
4
+ # List participants
5
+ #
6
+ # Returns all participants 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 participants.
10
+ #
11
+ # @example Get the list of participants for the current account
12
+ # participants = @api.participants
13
+ # participants.first.read_at # => "Fri, 02 Mar 2018 17:06:41 UTC +00:00"
14
+ # @see http://developers.bookingsync.com/reference/endpoints/participants/#list-participants
15
+ def participants(options = {}, &block)
16
+ paginate "inbox/participants", options, &block
17
+ end
18
+
19
+ # Get a single participant
20
+ #
21
+ # @param participant [BookingSync::API::Resource|Integer] Participant or ID
22
+ # of the participant.
23
+ # @return [BookingSync::API::Resource]
24
+ def participant(participant)
25
+ get("inbox/participants/#{participant}").pop
26
+ end
27
+
28
+ # Create a new participant
29
+ #
30
+ # @param options [Hash] Participant's attributes.
31
+ # @return [BookingSync::API::Resource] Newly created participant.
32
+ def create_participant(options)
33
+ post("inbox/participants", participants: [options]).pop
34
+ end
35
+
36
+ # Edit a participant
37
+ #
38
+ # @param participant [BookingSync::API::Resource|Integer] Participant or ID of
39
+ # the participant to be updated.
40
+ # @param options [Hash] Participant attributes to be updated.
41
+ # @return [BookingSync::API::Resource] Updated participant on success,
42
+ # exception is raised otherwise.
43
+ # @example
44
+ # participant = @api.participants.first
45
+ # @api.edit_participant(participant, { read: true })
46
+ def edit_participant(participant, options = {})
47
+ put("inbox/participants/#{participant}", participants: [options]).pop
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  module BookingSync
2
2
  module API
3
- VERSION = "0.1.8"
3
+ VERSION = "0.1.9"
4
4
  end
5
5
  end
@@ -0,0 +1,124 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::Conversations 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 ".conversations", :vcr do
9
+ it "returns conversations" do
10
+ expect(client.conversations).not_to be_empty
11
+ assert_requested :get, bs_url("inbox/conversations")
12
+ end
13
+ end
14
+
15
+ describe ".conversation", :vcr do
16
+ let(:prefetched_conversation_id) {
17
+ find_resource("#{@casette_base_path}_conversations/returns_conversations.yml", "conversations")[:id]
18
+ }
19
+
20
+ it "returns a single conversation" do
21
+ conversation = client.conversation(prefetched_conversation_id)
22
+ expect(conversation.id).to eq prefetched_conversation_id
23
+ end
24
+ end
25
+
26
+ describe ".create_conversation", :vcr do
27
+ let(:assignee) { BookingSync::API::Resource.new(client, id: 1) }
28
+ let(:source) { BookingSync::API::Resource.new(client, id: 1) }
29
+ let(:attributes) do
30
+ { subject: "New Question", assignee_id: assignee.id, source_id: source.id }
31
+ end
32
+
33
+ it "creates a new conversation" do
34
+ client.create_conversation(attributes)
35
+ assert_requested :post, bs_url("inbox/conversations"),
36
+ body: { conversations: [attributes] }.to_json
37
+ end
38
+
39
+ it "returns newly created conversation" do
40
+ VCR.use_cassette("BookingSync_API_Client_Conversations/_create_conversation/creates_a_new_conversation") do
41
+ conversation = client.create_conversation(attributes)
42
+ expect(conversation.subject).to eq("New Question")
43
+ expect(conversation[:links][:assignee]).to eq(assignee.id)
44
+ expect(conversation[:links][:source]).to eq(source.id)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe ".edit_conversation", :vcr do
50
+ let(:new_conversation_assignee) { BookingSync::API::Resource.new(client, id: 2) }
51
+ let(:created_conversation_id) {
52
+ find_resource("#{@casette_base_path}_create_conversation/creates_a_new_conversation.yml", "conversations")[:id]
53
+ }
54
+ let(:attributes) {
55
+ { closed: true, assignee_id: new_conversation_assignee.id }
56
+ }
57
+
58
+ it "updates given conversation by ID" do
59
+ client.edit_conversation(created_conversation_id, attributes)
60
+ assert_requested :put, bs_url("inbox/conversations/#{created_conversation_id}"),
61
+ body: { conversations: [attributes] }.to_json
62
+ end
63
+
64
+ it "returns updated conversation" do
65
+ VCR.use_cassette("BookingSync_API_Client_Conversations/_edit_conversation/updates_given_conversation_by_ID") do
66
+ conversation = client.edit_conversation(created_conversation_id, attributes)
67
+ expect(conversation).to be_kind_of(BookingSync::API::Resource)
68
+ expect(conversation[:links][:assignee]).to eq(new_conversation_assignee.id)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe ".connect_booking_to_conversation", :vcr do
74
+ let(:booking_to_be_connected) { BookingSync::API::Resource.new(client, id: 40) }
75
+ let(:prefetched_conversation_id) {
76
+ find_resource("#{@casette_base_path}_conversations/returns_conversations.yml", "conversations")[:id]
77
+ }
78
+ let(:attributes) { { id: booking_to_be_connected.id } }
79
+
80
+ it "connects given conversation with booking" do
81
+ client.connect_booking_to_conversation(prefetched_conversation_id, attributes)
82
+ assert_requested :put, bs_url("inbox/conversations/#{prefetched_conversation_id}/connect_booking"),
83
+ body: { bookings: [attributes] }.to_json
84
+ end
85
+
86
+ it "returns conversation with updated links" do
87
+ casette_path = "BookingSync_API_Client_Conversations/_connect_booking_to_conversation" \
88
+ "/connects_given_conversation_with_booking"
89
+ VCR.use_cassette(casette_path) do
90
+ initial_conversation = client.conversation(prefetched_conversation_id)
91
+ expect(initial_conversation[:links][:bookings]).to match_array []
92
+ conversation = client.connect_booking_to_conversation(prefetched_conversation_id, attributes)
93
+ expect(conversation).to be_kind_of(BookingSync::API::Resource)
94
+ expect(conversation[:links][:bookings]).to match_array [booking_to_be_connected.id]
95
+ end
96
+ end
97
+ end
98
+
99
+ describe ".disconnect_booking_from_conversation", :vcr do
100
+ let(:booking_to_be_disconnected) { BookingSync::API::Resource.new(client, id: 40) }
101
+ let(:prefetched_conversation_id) {
102
+ find_resource("#{@casette_base_path}_conversations/returns_conversations.yml", "conversations")[:id]
103
+ }
104
+ let(:attributes) { { id: booking_to_be_disconnected.id } }
105
+
106
+ it "disconnects given conversation from booking" do
107
+ client.disconnect_booking_from_conversation(prefetched_conversation_id, attributes)
108
+ assert_requested :put, bs_url("inbox/conversations/#{prefetched_conversation_id}/disconnect_booking"),
109
+ body: { bookings: [attributes] }.to_json
110
+ end
111
+
112
+ it "returns conversation with updated links" do
113
+ casette_path = "BookingSync_API_Client_Conversations/_disconnect_booking_from_conversation" \
114
+ "/disconnects_given_conversation_from_booking"
115
+ VCR.use_cassette(casette_path) do
116
+ initial_conversation = client.conversation(prefetched_conversation_id)
117
+ expect(initial_conversation[:links][:bookings]).to match_array [booking_to_be_disconnected.id]
118
+ conversation = client.disconnect_booking_from_conversation(prefetched_conversation_id, attributes)
119
+ expect(conversation).to be_kind_of(BookingSync::API::Resource)
120
+ expect(conversation[:links][:bookings]).to match_array []
121
+ end
122
+ end
123
+ end
124
+ end