Skip to content

Commit

Permalink
v3: Add links to usage events
Browse files Browse the repository at this point in the history
[#173239356]

Co-authored-by: Belinda Liu <[email protected]>
Co-authored-by: Sarah Weinstein <[email protected]>
  • Loading branch information
belinda-liu and sweinstein22 committed Jun 9, 2020
1 parent 327bb97 commit 25395d9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/presenters/v3/app_usage_event_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def to_hash
instance_count: {
current: usage_event.instance_count,
previous: usage_event.previous_instance_count,
}
},
links: build_links
}
end

Expand All @@ -50,5 +51,11 @@ def to_hash
def usage_event
@resource
end

def build_links
{
self: { href: url_builder.build_url(path: "/v3/app_usage_events/#{usage_event.guid}") }
}
end
end
end
9 changes: 8 additions & 1 deletion app/presenters/v3/service_usage_event_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def to_hash
service_broker: {
guid: usage_event.service_broker_guid,
name: usage_event.service_broker_name,
}
},
links: build_links
}
end

Expand All @@ -40,5 +41,11 @@ def to_hash
def usage_event
@resource
end

def build_links
{
self: { href: url_builder.build_url(path: "/v3/service_usage_events/#{usage_event.guid}") }
}
end
end
end
10 changes: 10 additions & 0 deletions docs/v3/source/includes/api_resources/_app_usage_events.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"instance_count": {
"current": 10,
"previous": 5
},
"links": {
"self": {
"href": "https://api.example.org/v3/app_usage_events/a595fe2f-01ff-4965-a50c-290258ab8582"
}
}
}
<% end %>
Expand Down Expand Up @@ -96,6 +101,11 @@
"instance_count": {
"current": 10,
"previous": 5
},
"links": {
"self": {
"href": "https://api.example.org/v3/app_usage_events/a595fe2f-01ff-4965-a50c-290258ab8582"
}
}
}
]
Expand Down
10 changes: 10 additions & 0 deletions docs/v3/source/includes/api_resources/_service_usage_events.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"service_broker": {
"guid": "guid-7cc11646-bf38-4f4e-b6e0-9581916a74d9",
"name": "name-2929"
},
"links": {
"self": {
"href": "https://api.example.org/v3/service_usage_events/c9976002-96f4-435a-888e-db1e1178df62"
}
}
}
<% end %>
Expand Down Expand Up @@ -76,6 +81,11 @@
"service_broker": {
"guid": "guid-7cc11646-bf38-4f4e-b6e0-9581916a74d9",
"name": "name-2929"
},
"links": {
"self": {
"href": "https://api.example.org/v3/service_usage_events/c9976002-96f4-435a-888e-db1e1178df62"
}
}
}
]
Expand Down
3 changes: 3 additions & 0 deletions spec/request/app_usage_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def build_usage_event_json(app_usage_event)
'instance_count' => {
'current' => app_usage_event.instance_count,
'previous' => nil
},
'links' => {
'self' => { 'href' => "#{link_prefix}/v3/app_usage_events/#{app_usage_event.guid}" },
}
}
end
Expand Down
3 changes: 3 additions & 0 deletions spec/request/service_usage_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def build_usage_event_json(service_usage_event)
'service_broker' => {
'guid' => service_usage_event.service_broker_guid,
'name' => service_usage_event.service_broker_name,
},
'links' => {
'self' => { 'href' => "#{link_prefix}/v3/service_usage_events/#{service_usage_event.guid}" },
}
}
end
Expand Down
1 change: 1 addition & 0 deletions spec/unit/presenters/v3/app_usage_event_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
expect(result[:memory_in_mb_per_instance][:previous]).to eq nil
expect(result[:instance_count][:current]).to eq usage_event.instance_count
expect(result[:instance_count][:previous]).to eq nil
expect(result[:links][:self][:href]).to eq "#{link_prefix}/v3/app_usage_events/#{usage_event.guid}"
end

context 'when the usage event is for a task' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
expect(result[:service_offering][:name]).to eq usage_event.service_label
expect(result[:service_broker][:guid]).to eq usage_event.service_broker_guid
expect(result[:service_broker][:name]).to eq usage_event.service_broker_name
expect(result[:links][:self][:href]).to eq "#{link_prefix}/v3/service_usage_events/#{usage_event.guid}"
end
end
end

0 comments on commit 25395d9

Please sign in to comment.