Coverage Report - com.jcabi.github.RtUsers
 
Classes in this File Line Coverage Branch Coverage Complexity
RtUsers
75%
9/12
0%
0/16
1
RtUsers$1
100%
2/2
N/A
1
RtUsers$AjcClosure1
0%
0/1
N/A
1
RtUsers$AjcClosure3
100%
1/1
N/A
1
RtUsers$AjcClosure5
100%
1/1
N/A
1
RtUsers$AjcClosure7
100%
1/1
N/A
1
 
 1  8
 /**
 2  
  * Copyright (c) 2013-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import com.jcabi.http.Request;
 35  
 import javax.json.JsonObject;
 36  
 import javax.validation.constraints.NotNull;
 37  
 import lombok.EqualsAndHashCode;
 38  
 
 39  
 /**
 40  
  * Github users.
 41  
  *
 42  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 43  
  * @version $Id$
 44  
  * @since 0.4
 45  
  */
 46  
 @Immutable
 47  
 @Loggable(Loggable.DEBUG)
 48  0
 @EqualsAndHashCode(of = { "ghub", "request" })
 49  
 final class RtUsers implements Users {
 50  
 
 51  
     /**
 52  
      * API entry point.
 53  
      */
 54  
     private final transient Request entry;
 55  
 
 56  
     /**
 57  
      * Github.
 58  
      */
 59  
     private final transient Github ghub;
 60  
 
 61  
     /**
 62  
      * RESTful request.
 63  
      */
 64  
     private final transient Request request;
 65  
 
 66  
     /**
 67  
      * Public ctor.
 68  
      * @param github Github
 69  
      * @param req Request
 70  
      */
 71  
     RtUsers(
 72  
         @NotNull(message = "github can't be NULL") final Github github,
 73  
         @NotNull(message = "req can't be NULL") final Request req
 74  5
     ) {
 75  5
         this.entry = req;
 76  5
         this.ghub = github;
 77  5
         this.request = this.entry.uri().path("/users").back();
 78  5
     }
 79  
 
 80  
     @Override
 81  
     @NotNull(message = "toString is never NULL")
 82  
     public String toString() {
 83  0
         return this.request.uri().get().toString();
 84  
     }
 85  
 
 86  
     @Override
 87  
     @NotNull(message = "github is never NULL")
 88  
     public Github github() {
 89  0
         return this.ghub;
 90  
     }
 91  
 
 92  
     @Override
 93  
     @NotNull(message = "user is never NULL")
 94  
     public User self() {
 95  2
         return new RtUser(this.ghub, this.entry, "");
 96  
     }
 97  
 
 98  
     @Override
 99  
     @NotNull(message = "user is never NULL")
 100  
     public User get(@NotNull(message = "login can't be NULL")
 101  
         final String login) {
 102  8
         return new RtUser(this.ghub, this.entry, login);
 103  
     }
 104  
 
 105  
     @Override
 106  
     @NotNull(message = "Iterable of users is never NULL")
 107  
     public Iterable<User> iterate(
 108  
         @NotNull(message = "identifier is never NULL") final String identifier
 109  
     ) {
 110  2
         return new RtPagination<User>(
 111  
             this.request.uri().queryParam("since", identifier).back(),
 112  3
             new RtValuePagination.Mapping<User, JsonObject>() {
 113  
                 @Override
 114  
                 public User map(final JsonObject object) {
 115  2
                     return RtUsers.this.get(object.getString("id"));
 116  
                 }
 117  
             }
 118  
         );
 119  
     }
 120  
 
 121  
 }