Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service setting attributes added to api response #837

Merged
merged 1 commit into from Jun 7, 2019

Conversation

guicassolato
Copy link
Contributor

@guicassolato guicassolato commented Jun 4, 2019

What this PR does / why we need it:

This PR adds the following attributes to the response for Service Read API endpoint:

  • intentions_required (boolean)
  • buyers_manage_apps (boolean)
  • buyers_manage_keys (boolean)
  • referrer_filters_required (boolean)
  • custom_keys_enabled (boolean)
  • buyer_key_regenerate_enabled (boolean)
  • mandatory_app_key (boolean)
  • buyer_can_select_plan (boolean)
  • buyer_plan_change_permission (enum: request, direct, credit_card, request_credit_card, none)
  • notification_settings (complex attribute – child attributes: web_provider, email_provider, web_buyer, email_buyer – array of integers)
$ curl 'http://provider-admin.example.com/admin/api/services/2.json?access_token=<my-secret-access-token>'
{"service":{"id":2,"name":"API","state":"incomplete","system_name":"api","end_user_registration_required":true,"backend_version":"1","deployment_option":"hosted","support_email":"admin@provider.example.com","intentions_required":false,"buyers_manage_apps":true,"buyers_manage_keys":true,"referrer_filters_required":false,"custom_keys_enabled":true,"buyer_key_regenerate_enabled":true,"mandatory_app_key":true,"buyer_can_select_plan":false,"buyer_plan_change_permission":"request","notification_settings":{"web_provider":[0,80],"email_provider":[0,100,120,200],"web_buyer":[0,300],"email_buyer":[0,50,300]},"created_at":"2019-06-04T08:07:41Z","updated_at":"2019-06-04T09:14:59Z","links":[{"rel":"metrics","href":"http://provider-admin.example.com/admin/api/services/2/metrics"},{"rel":"end_user_plans","href":"http://provider-admin.example.com/admin/api/services/2/end_user_plans"},{"rel":"self","href":"http://provider-admin.example.com/admin/api/services/2"},{"rel":"service_plans","href":"http://provider-admin.example.com/admin/api/services/2/service_plans"},{"rel":"application_plans","href":"http://provider-admin.example.com/admin/api/services/2/application_plans"},{"rel":"features","href":"http://provider-admin.example.com/admin/api/services/2/features"}]}}

$ curl 'http://provider-admin.example.com/admin/api/services/2.xml?access_token=<my-secret-access-token>'
<?xml version="1.0" encoding="UTF-8"?><service><id>2</id><account_id>2</account_id><name>API</name><state>incomplete</state><system_name>api</system_name><backend_version>1</backend_version><description/><intentions_required>false</intentions_required><buyers_manage_apps>true</buyers_manage_apps><buyers_manage_keys>true</buyers_manage_keys><referrer_filters_required>false</referrer_filters_required><custom_keys_enabled>true</custom_keys_enabled><buyer_key_regenerate_enabled>true</buyer_key_regenerate_enabled><mandatory_app_key>true</mandatory_app_key><buyer_can_select_plan>false</buyer_can_select_plan><buyer_plan_change_permission>request</buyer_plan_change_permission><notification_settings><web_provider>[0, 80]</web_provider><email_provider>[0, 100, 120, 200]</email_provider><web_buyer>[0, 300]</web_buyer><email_buyer>[0, 50, 300]</email_buyer></notification_settings><deployment_option>hosted</deployment_option><support_email>admin@provider.example.com</support_email><end_user_registration_required>true</end_user_registration_required><metrics><metric><id>5</id><name>hits</name><system_name>hits</system_name><friendly_name>Hits</friendly_name><service_id>2</service_id><description>Number of API hits</description><unit>hit</unit></metric></metrics></service>

Which issue(s) this PR fixes

Closes
THREESCALE-2086

@guicassolato guicassolato self-assigned this Jun 4, 2019
@guicassolato guicassolato requested a review from a team June 4, 2019 10:27
@Martouta Martouta self-requested a review June 4, 2019 10:38
@@ -40,7 +53,11 @@

context 'service' do
subject(:service) { Hash.from_xml(serialized).fetch(root) }
it { should include('id' => resource.id.to_s, 'system_name' => resource.system_name) }
it { should include(attributes.map do |attr_name|
next if (attr_value = resource.public_send(attr_name)).blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this line having the compact later, no? It should work like this:

it { should include(attributes.map { |attr_name| [attr_name, resource.public_send(attr_name).to_s.presence] }.compact.to_h) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. If we just collect the pairs without skipping when blank and without compact, it will work for this test in particular. However it's more about communicating through what's expected. If an attribute of resource is blank, it won't be included. I know, I should have added another test, but it was never there even though it's been the behavior expected since ever.

@guicassolato guicassolato merged commit 6da26f9 into master Jun 7, 2019
@guicassolato guicassolato deleted the THREESCALE-2086-api-service-attrs branch June 7, 2019 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants