Skip to content

Commit 749ff68

Browse files
committed
Merge pull request #165 from BookingSync/booking-comments
Add bookings_comments endpoint
2 parents 88de2e1 + 9770d2c commit 749ff68

File tree

8 files changed

+159
-1
lines changed

8 files changed

+159
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"links": {
3+
"booking_comments.booking": "https://www.bookingsync.com/api/v3/bookings/{booking_comments.booking}"
4+
},
5+
"booking_comments": [
6+
{
7+
"links": {
8+
"booking": 1
9+
},
10+
"id": 3,
11+
"content": "Comment content",
12+
"editable": false,
13+
"created_at": "CREATED_AT",
14+
"updated_at": "UPDATED_AT"
15+
}
16+
],
17+
"meta": {
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"links": {
3+
"booking_comments.booking": "https://www.bookingsync.com/api/v3/bookings/{booking_comments.booking}"
4+
},
5+
"booking_comments": [
6+
{
7+
"links": {
8+
"booking": 1
9+
},
10+
"id": 3,
11+
"content": "Comment content",
12+
"editable": true,
13+
"created_at": "CREATED_AT",
14+
"updated_at": "UPDATED_AT"
15+
}
16+
],
17+
"meta": {
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"booking_id": 1,
3+
"booking_comments": [
4+
{
5+
"content": "Comment content"
6+
}
7+
]
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"booking_comments": [
3+
{
4+
"content": "Comment content"
5+
}
6+
]
7+
}

content/reference/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2016-05-09
4+
5+
* [api improvement] Add `booking_comments` endpoint.
6+
37
## 2016-04-20
48

59
* [doc fix] Fix sideloading example, `availability` is singular.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Booking Comments
2+
3+
1. TOC
4+
{:toc}
5+
6+
### Parameters
7+
<ul class="nav nav-pills" role="tablist">
8+
<li class="disabled"><a>OAuth Scopes:</a></li>
9+
<li class="active"><a href="#bookings_read" role="tab" data-toggle="pill">bookings_read</a></li>
10+
<li><a href="#bookings_write-bookings_write_owned" role="tab" data-toggle="pill">
11+
bookings_write / bookings_write_owned
12+
</a></li>
13+
</ul>
14+
<div class="tab-content" markdown="1">
15+
<div class="tab-pane active" id="bookings_read" markdown="1">
16+
Name | Type | Read/Write | Description
17+
-----------------|---------|------------|------------
18+
id | Integer | Read | Booking Comment's id.
19+
-----------------|---------|------------|------------
20+
content | String | Read | Booking Comment's content.
21+
editable | Boolean | Read | Booking Comment can be edited if true is returned.
22+
-----------------|---------|------------|------------
23+
created_at | [Time](/reference/enums#formats) | Read | Booking Comment's create time.
24+
updated_at | [Time](/reference/enums#formats) | Read | Booking Comment's update time.
25+
{: class="table table-bordered"}
26+
</div>
27+
<div class="tab-pane" id="bookings_write-bookings_write_owned" markdown="1">
28+
Name | Type | Read/Write | Description
29+
-----------------|---------|------------|------------
30+
id | Integer | Read | Booking Comment's id.
31+
booking_id | Integer | Write | **Required**. Booking id related to the Booking Comment.
32+
-----------------|---------|------------|------------
33+
content | String | Read/Write | **Required**. Booking Comment's content.
34+
editable | Boolean | Read | Booking Comment can be edited if true is returned.
35+
-----------------|---------|------------|------------
36+
created_at | [Time](/reference/enums#formats) | Read | Booking Comment's create time.
37+
updated_at | [Time](/reference/enums#formats) | Read | Booking Comment's update time.
38+
{: class="table table-bordered"}
39+
</div>
40+
</div>
41+
42+
## List booking comments
43+
44+
List all booking_comments for given account.
45+
46+
~~~
47+
GET /booking_comments
48+
~~~
49+
50+
<%= render 'json_response', endpoint: "booking_comments",
51+
scopes: %w(bookings_read bookings_write-bookings_write_owned) %>
52+
53+
## Get a single booking comment
54+
55+
Returns a single booking_comment identified by ID.
56+
57+
~~~
58+
GET /booking_comments/:booking_comment_id
59+
~~~
60+
61+
<%= render 'json_response', endpoint: "booking_comments",
62+
scopes: %w(bookings_read bookings_write-bookings_write_owned) %>
63+
64+
## Create a new booking comment
65+
66+
Creates a booking_comment for given season.
67+
68+
~~~
69+
POST /booking_comments
70+
~~~
71+
72+
<%= render 'json_response', endpoint: "booking_comments", request: "create",
73+
scopes: [{ "bookings_write-bookings_write_owned" => "bookings_write-bookings_write_owned" }] %>
74+
75+
## Update a booking comment
76+
77+
Returns an updated booking_comment identified by ID.
78+
79+
~~~
80+
PUT /booking_comments/:booking_comment_id
81+
~~~
82+
83+
<%= render 'json_response', endpoint: "booking_comments", request: "update",
84+
scopes: [{ "bookings_write-bookings_write_owned" => "bookings_write-bookings_write_owned" }] %>
85+
86+
## Destroy a booking comment
87+
88+
Required OAuth scope: `:bookings_write` or `:bookings_write_owned`
89+
90+
Returns an empty response with '204 No Content' status code on success.
91+
92+
~~~~~~
93+
DELETE /booking_comments/:booking_comment_id
94+
~~~~~~

layouts/reference.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ <h3 class="panel-title">Endpoints</h3>
3838
class: "list-group-item") %>
3939
<%= link_to_with_current("Bookings", "/reference/endpoints/bookings/",
4040
class: "list-group-item") %>
41+
<%= link_to_with_current("Booking Comments", "/reference/endpoints/booking_comments/",
42+
class: "list-group-item") %>
4143
<%= link_to_with_current("Bookings Fees", "/reference/endpoints/bookings_fees/",
4244
class: "list-group-item") %>
4345
<%= link_to_with_current("Bookings Payments", "/reference/endpoints/bookings_payments/",

lib/json_response.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ def days_from_now(days)
2828
end
2929

3030
def sort_response(response, resource_name)
31+
sorted_not_nested = sort_not_nested(response)
3132
sorted_links = sort_element(response, "links")
3233
sorted_resource = { resource_name => response[resource_name].map { |resource| sort_resource(resource) } }
3334
sorted_meta = sort_element(response, "meta")
3435

35-
sorted_links.merge(sorted_resource).merge(sorted_meta)
36+
sorted_not_nested.merge(sorted_links).merge(sorted_resource).merge(sorted_meta)
37+
end
38+
39+
def sort_not_nested(response)
40+
response.reject { |_, value| value.is_a?(Array) || value.is_a?(Hash) }.sort.to_h
3641
end
3742

3843
def sort_resource(resource)

0 commit comments

Comments
 (0)