Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 25395d9

Browse files
v3: Add links to usage events
[#173239356] Co-authored-by: Belinda Liu <bliu@pivotal.io> Co-authored-by: Sarah Weinstein <sweinstein@pivotal.io>
1 parent 327bb97 commit 25395d9

8 files changed

Lines changed: 44 additions & 2 deletions

File tree

app/presenters/v3/app_usage_event_presenter.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def to_hash
4141
instance_count: {
4242
current: usage_event.instance_count,
4343
previous: usage_event.previous_instance_count,
44-
}
44+
},
45+
links: build_links
4546
}
4647
end
4748

@@ -50,5 +51,11 @@ def to_hash
5051
def usage_event
5152
@resource
5253
end
54+
55+
def build_links
56+
{
57+
self: { href: url_builder.build_url(path: "/v3/app_usage_events/#{usage_event.guid}") }
58+
}
59+
end
5360
end
5461
end

app/presenters/v3/service_usage_event_presenter.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def to_hash
3131
service_broker: {
3232
guid: usage_event.service_broker_guid,
3333
name: usage_event.service_broker_name,
34-
}
34+
},
35+
links: build_links
3536
}
3637
end
3738

@@ -40,5 +41,11 @@ def to_hash
4041
def usage_event
4142
@resource
4243
end
44+
45+
def build_links
46+
{
47+
self: { href: url_builder.build_url(path: "/v3/service_usage_events/#{usage_event.guid}") }
48+
}
49+
end
4350
end
4451
end

docs/v3/source/includes/api_resources/_app_usage_events.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"instance_count": {
3838
"current": 10,
3939
"previous": 5
40+
},
41+
"links": {
42+
"self": {
43+
"href": "https://api.example.org/v3/app_usage_events/a595fe2f-01ff-4965-a50c-290258ab8582"
44+
}
4045
}
4146
}
4247
<% end %>
@@ -96,6 +101,11 @@
96101
"instance_count": {
97102
"current": 10,
98103
"previous": 5
104+
},
105+
"links": {
106+
"self": {
107+
"href": "https://api.example.org/v3/app_usage_events/a595fe2f-01ff-4965-a50c-290258ab8582"
108+
}
99109
}
100110
}
101111
]

docs/v3/source/includes/api_resources/_service_usage_events.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"service_broker": {
2828
"guid": "guid-7cc11646-bf38-4f4e-b6e0-9581916a74d9",
2929
"name": "name-2929"
30+
},
31+
"links": {
32+
"self": {
33+
"href": "https://api.example.org/v3/service_usage_events/c9976002-96f4-435a-888e-db1e1178df62"
34+
}
3035
}
3136
}
3237
<% end %>
@@ -76,6 +81,11 @@
7681
"service_broker": {
7782
"guid": "guid-7cc11646-bf38-4f4e-b6e0-9581916a74d9",
7883
"name": "name-2929"
84+
},
85+
"links": {
86+
"self": {
87+
"href": "https://api.example.org/v3/service_usage_events/c9976002-96f4-435a-888e-db1e1178df62"
88+
}
7989
}
8090
}
8191
]

spec/request/app_usage_events_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def build_usage_event_json(app_usage_event)
189189
'instance_count' => {
190190
'current' => app_usage_event.instance_count,
191191
'previous' => nil
192+
},
193+
'links' => {
194+
'self' => { 'href' => "#{link_prefix}/v3/app_usage_events/#{app_usage_event.guid}" },
192195
}
193196
}
194197
end

spec/request/service_usage_events_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def build_usage_event_json(service_usage_event)
209209
'service_broker' => {
210210
'guid' => service_usage_event.service_broker_guid,
211211
'name' => service_usage_event.service_broker_name,
212+
},
213+
'links' => {
214+
'self' => { 'href' => "#{link_prefix}/v3/service_usage_events/#{service_usage_event.guid}" },
212215
}
213216
}
214217
end

spec/unit/presenters/v3/app_usage_event_presenter_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
expect(result[:memory_in_mb_per_instance][:previous]).to eq nil
3030
expect(result[:instance_count][:current]).to eq usage_event.instance_count
3131
expect(result[:instance_count][:previous]).to eq nil
32+
expect(result[:links][:self][:href]).to eq "#{link_prefix}/v3/app_usage_events/#{usage_event.guid}"
3233
end
3334

3435
context 'when the usage event is for a task' do

spec/unit/presenters/v3/service_usage_event_presenter_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
expect(result[:service_offering][:name]).to eq usage_event.service_label
2525
expect(result[:service_broker][:guid]).to eq usage_event.service_broker_guid
2626
expect(result[:service_broker][:name]).to eq usage_event.service_broker_name
27+
expect(result[:links][:self][:href]).to eq "#{link_prefix}/v3/service_usage_events/#{usage_event.guid}"
2728
end
2829
end
2930
end

0 commit comments

Comments
 (0)