11package engineer .nightowl .sonos .api ;
22
3- import org .apache .commons .codec .binary .Base64 ;
4- import org .apache .commons .lang3 .builder .EqualsBuilder ;
5- import org .apache .commons .lang3 .builder .HashCodeBuilder ;
6- import org .apache .http .Header ;
7- import org .apache .http .message .BasicHeader ;
3+ import java .util .Base64 ;
4+ import java .util .Objects ;
85
96/**
10- * Configuration class to be built up and passed into a {@link engineer.nightowl.sonos.api.SonosApiClient}
7+ * Configuration class to be built up and passed into a
8+ * {@link engineer.nightowl.sonos.api.SonosApiClient}
119 * <p>
1210 * Loads defaults on construction.
1311 */
@@ -21,172 +19,92 @@ public class SonosApiConfiguration
2119 private String controlBaseUrl ;
2220 private Boolean clientSideValidationEnabled ;
2321
24- /**
25- * <p>Constructor for SonosApiConfiguration.</p>
26- */
27- public SonosApiConfiguration ()
28- {
22+ public SonosApiConfiguration () {
2923 loadDefaults ();
3024 }
3125
32- /**
33- * <p>Getter for the field <code>applicationId</code>.</p>
34- *
35- * @return a {@link java.lang.String} object.
36- */
37- public String getApplicationId ()
38- {
26+ public String getApplicationId () {
3927 return applicationId ;
4028 }
4129
42- /**
43- * <p>Setter for the field <code>applicationId</code>.</p>
44- *
45- * @param applicationId a {@link java.lang.String} object.
46- */
47- public void setApplicationId (final String applicationId )
48- {
30+ public void setApplicationId (final String applicationId ) {
4931 this .applicationId = applicationId ;
5032 }
5133
52- /**
53- * <p>Getter for the field <code>apiKey</code>.</p>
54- *
55- * @return a {@link java.lang.String} object.
56- */
57- public String getApiKey ()
58- {
34+ public String getApiKey () {
5935 return apiKey ;
6036 }
6137
62- /**
63- * <p>Setter for the field <code>apiKey</code>.</p>
64- *
65- * @param apiKey a {@link java.lang.String} object.
66- */
67- public void setApiKey (final String apiKey )
68- {
38+ public void setApiKey (final String apiKey ) {
6939 this .apiKey = apiKey ;
7040 }
7141
72- public String getApiSecret ()
73- {
42+ public String getApiSecret () {
7443 return apiSecret ;
7544 }
7645
77- /**
78- * <p>Setter for the field <code>apiSecret</code>.</p>
79- *
80- * @param apiSecret a {@link java.lang.String} object.
81- */
82- public void setApiSecret (final String apiSecret )
83- {
46+ public void setApiSecret (final String apiSecret ) {
8447 this .apiSecret = apiSecret ;
8548 }
8649
87- /**
88- * <p>Getter for the field <code>authBaseUrl</code>.</p>
89- *
90- * @return a {@link java.lang.String} object.
91- */
92- public String getAuthBaseUrl ()
93- {
50+ public String getAuthBaseUrl () {
9451 return authBaseUrl ;
9552 }
9653
97- public void setAuthBaseUrl (final String authBaseUrl )
98- {
54+ public void setAuthBaseUrl (final String authBaseUrl ) {
9955 this .authBaseUrl = authBaseUrl ;
10056 }
10157
102- /**
103- * <p>Getter for the field <code>controlBaseUrl</code>.</p>
104- *
105- * @return a {@link java.lang.String} object.
106- */
107- public String getControlBaseUrl ()
108- {
58+ public String getControlBaseUrl () {
10959 return controlBaseUrl ;
11060 }
11161
112- public void setControlBaseUrl (final String controlBaseUrl )
113- {
62+ public void setControlBaseUrl (final String controlBaseUrl ) {
11463 this .controlBaseUrl = controlBaseUrl ;
11564 }
11665
117- public Boolean isClientSideValidationEnabled ()
118- {
66+ public Boolean isClientSideValidationEnabled () {
11967 return clientSideValidationEnabled ;
12068 }
12169
122- public void setClientSideValidationEnabled (Boolean clientSideValidationEnabled )
123- {
70+ public void setClientSideValidationEnabled (Boolean clientSideValidationEnabled ) {
12471 this .clientSideValidationEnabled = clientSideValidationEnabled ;
12572 }
12673
127-
128- public void loadDefaults ()
129- {
74+ public void loadDefaults () {
13075 setAuthBaseUrl ("api.sonos.com" );
13176 setControlBaseUrl ("api.ws.sonos.com/control/api" );
13277 setClientSideValidationEnabled (Boolean .TRUE );
13378 }
13479
135- /**
136- * <p>getAuthorizationHeader.</p>
137- *
138- * @return a {@link org.apache.http.Header} object.
139- */
140- public Header getAuthorizationHeader ()
141- {
80+ public String getAuthorizationHeaderValue () {
14281 final byte [] authBytes = String .join (":" , getApiKey (), getApiSecret ()).getBytes ();
143- final String authBase64 = Base64 .encodeBase64String (authBytes );
144- final String headerValue = String .join (" " , "Basic" , authBase64 );
145- return new BasicHeader ("Authorization" , headerValue );
82+ final String authBase64 = Base64 .getEncoder ().encodeToString (authBytes );
83+ return String .join (" " , "Basic" , authBase64 );
14684 }
14785
14886 @ Override
149- public String toString ()
150- {
151- return "SonosApiConfiguration{" +
152- "applicationId='" + applicationId + '\'' +
153- ", apiKey='" + apiKey + '\'' +
154- ", apiSecret='" + apiSecret + '\'' +
155- ", authBaseUrl='" + authBaseUrl + '\'' +
156- ", controlBaseUrl='" + controlBaseUrl + '\'' +
157- ", clientSideValidationEnabled=" + clientSideValidationEnabled +
158- '}' ;
87+ public String toString () {
88+ return "SonosApiConfiguration [apiKey=" + apiKey + ", apiSecret=" + apiSecret + ", applicationId="
89+ + applicationId + ", authBaseUrl=" + authBaseUrl + ", clientSideValidationEnabled="
90+ + clientSideValidationEnabled + ", controlBaseUrl=" + controlBaseUrl + "]" ;
15991 }
16092
16193 @ Override
162- public boolean equals (Object o )
163- {
164- if (this == o ) return true ;
165-
166- if (o == null || getClass () != o .getClass ()) return false ;
167-
168- SonosApiConfiguration that = (SonosApiConfiguration ) o ;
169-
170- return new EqualsBuilder ()
171- .append (applicationId , that .applicationId )
172- .append (apiKey , that .apiKey )
173- .append (apiSecret , that .apiSecret )
174- .append (authBaseUrl , that .authBaseUrl )
175- .append (controlBaseUrl , that .controlBaseUrl )
176- .append (clientSideValidationEnabled , that .clientSideValidationEnabled )
177- .isEquals ();
94+ public boolean equals (Object obj ) {
95+ if (this == obj )
96+ return true ;
97+ if (!(obj instanceof SonosApiConfiguration ))
98+ return false ;
99+ SonosApiConfiguration other = (SonosApiConfiguration ) obj ;
100+ return Objects .equals (apiKey , other .apiKey ) && Objects .equals (apiSecret , other .apiSecret )
101+ && Objects .equals (applicationId , other .applicationId ) && Objects .equals (authBaseUrl , other .authBaseUrl )
102+ && Objects .equals (clientSideValidationEnabled , other .clientSideValidationEnabled )
103+ && Objects .equals (controlBaseUrl , other .controlBaseUrl );
178104 }
179105
180106 @ Override
181- public int hashCode ()
182- {
183- return new HashCodeBuilder (17 , 37 )
184- .append (applicationId )
185- .append (apiKey )
186- .append (apiSecret )
187- .append (authBaseUrl )
188- .append (controlBaseUrl )
189- .append (clientSideValidationEnabled )
190- .toHashCode ();
107+ public int hashCode () {
108+ return Objects .hash (apiKey , apiSecret , applicationId , authBaseUrl , clientSideValidationEnabled , controlBaseUrl );
191109 }
192110}
0 commit comments