5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http://www.apache.org/licenses/LICENSE-2.0
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
25
25
import java .net .MalformedURLException ;
26
26
import java .util .List ;
27
27
import rx .Observable ;
28
- import rx .Subscriber ;
29
28
30
29
/**
31
30
* {@link RestApi} implementation for retrieving data from the network.
@@ -51,49 +50,43 @@ public RestApiImpl(Context context, UserEntityJsonMapper userEntityJsonMapper) {
51
50
52
51
@ RxLogObservable
53
52
@ Override public Observable <List <UserEntity >> userEntityList () {
54
- return Observable .create (new Observable .OnSubscribe <List <UserEntity >>() {
55
- @ Override public void call (Subscriber <? super List <UserEntity >> subscriber ) {
56
-
57
- if (isThereInternetConnection ()) {
58
- try {
59
- String responseUserEntities = getUserEntitiesFromApi ();
60
- if (responseUserEntities != null ) {
61
- subscriber .onNext (userEntityJsonMapper .transformUserEntityCollection (
62
- responseUserEntities ));
63
- subscriber .onCompleted ();
64
- } else {
65
- subscriber .onError (new NetworkConnectionException ());
66
- }
67
- } catch (Exception e ) {
68
- subscriber .onError (new NetworkConnectionException (e .getCause ()));
53
+ return Observable .create (subscriber -> {
54
+ if (isThereInternetConnection ()) {
55
+ try {
56
+ String responseUserEntities = getUserEntitiesFromApi ();
57
+ if (responseUserEntities != null ) {
58
+ subscriber .onNext (userEntityJsonMapper .transformUserEntityCollection (
59
+ responseUserEntities ));
60
+ subscriber .onCompleted ();
61
+ } else {
62
+ subscriber .onError (new NetworkConnectionException ());
69
63
}
70
- } else {
71
- subscriber .onError (new NetworkConnectionException ());
64
+ } catch ( Exception e ) {
65
+ subscriber .onError (new NetworkConnectionException (e . getCause () ));
72
66
}
67
+ } else {
68
+ subscriber .onError (new NetworkConnectionException ());
73
69
}
74
70
});
75
71
}
76
72
77
73
@ RxLogObservable
78
74
@ Override public Observable <UserEntity > userEntityById (final int userId ) {
79
- return Observable .create (new Observable .OnSubscribe <UserEntity >() {
80
- @ Override public void call (Subscriber <? super UserEntity > subscriber ) {
81
-
82
- if (isThereInternetConnection ()) {
83
- try {
84
- String responseUserDetails = getUserDetailsFromApi (userId );
85
- if (responseUserDetails != null ) {
86
- subscriber .onNext (userEntityJsonMapper .transformUserEntity (responseUserDetails ));
87
- subscriber .onCompleted ();
88
- } else {
89
- subscriber .onError (new NetworkConnectionException ());
90
- }
91
- } catch (Exception e ) {
92
- subscriber .onError (new NetworkConnectionException (e .getCause ()));
75
+ return Observable .create (subscriber -> {
76
+ if (isThereInternetConnection ()) {
77
+ try {
78
+ String responseUserDetails = getUserDetailsFromApi (userId );
79
+ if (responseUserDetails != null ) {
80
+ subscriber .onNext (userEntityJsonMapper .transformUserEntity (responseUserDetails ));
81
+ subscriber .onCompleted ();
82
+ } else {
83
+ subscriber .onError (new NetworkConnectionException ());
93
84
}
94
- } else {
95
- subscriber .onError (new NetworkConnectionException ());
85
+ } catch ( Exception e ) {
86
+ subscriber .onError (new NetworkConnectionException (e . getCause () ));
96
87
}
88
+ } else {
89
+ subscriber .onError (new NetworkConnectionException ());
97
90
}
98
91
});
99
92
}
0 commit comments