| 1 | 0 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
package com.jcabi.github.mock; |
| 31 | |
|
| 32 | |
import com.jcabi.aspects.Immutable; |
| 33 | |
import com.jcabi.aspects.Loggable; |
| 34 | |
import com.jcabi.github.Content; |
| 35 | |
import com.jcabi.github.Coordinates; |
| 36 | |
import com.jcabi.github.Github; |
| 37 | |
import com.jcabi.github.Issue; |
| 38 | |
import com.jcabi.github.Repo; |
| 39 | |
import com.jcabi.github.Search; |
| 40 | |
import com.jcabi.github.User; |
| 41 | |
import com.jcabi.xml.XML; |
| 42 | |
import java.io.IOException; |
| 43 | |
import java.util.EnumMap; |
| 44 | |
import lombok.EqualsAndHashCode; |
| 45 | |
import lombok.ToString; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@Immutable |
| 55 | |
@Loggable(Loggable.DEBUG) |
| 56 | 0 | @ToString |
| 57 | 0 | @EqualsAndHashCode(of = { "storage", "self" }) |
| 58 | 0 | final class MkSearch implements Search { |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private final transient MkStorage storage; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
private final transient String self; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
MkSearch( |
| 77 | |
final MkStorage stg, |
| 78 | |
final String login |
| 79 | 4 | ) { |
| 80 | 4 | this.storage = stg; |
| 81 | 4 | this.self = login; |
| 82 | 4 | } |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public Github github() { |
| 86 | 0 | return new MkGithub(this.storage, this.self); |
| 87 | |
} |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
public Iterable<Repo> repos( |
| 91 | |
final String keywords, |
| 92 | |
final String sort, |
| 93 | |
final Order order |
| 94 | |
) throws IOException { |
| 95 | 2 | return new MkIterable<Repo>( |
| 96 | |
this.storage, |
| 97 | |
"/github/repos/repo", |
| 98 | 1 | new MkIterable.Mapping<Repo>() { |
| 99 | |
@Override |
| 100 | |
public Repo map(final XML xml) { |
| 101 | 0 | return new MkRepo( |
| 102 | 0 | MkSearch.this.storage, MkSearch.this.self, |
| 103 | 0 | new Coordinates.Simple(xml.xpath("@coords").get(0)) |
| 104 | |
); |
| 105 | |
} |
| 106 | |
} |
| 107 | |
); |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public Iterable<Issue> issues(final String keywords, final String sort, |
| 113 | |
final Order order, final EnumMap<Qualifier, String> qualifiers |
| 114 | |
) throws IOException { |
| 115 | 2 | return new MkIterable<Issue>( |
| 116 | |
this.storage, |
| 117 | |
"/github/repos/repo/issues/issue", |
| 118 | 1 | new MkIterable.Mapping<Issue>() { |
| 119 | |
@Override |
| 120 | |
public Issue map(final XML xml) { |
| 121 | 0 | return new MkIssue( |
| 122 | 0 | MkSearch.this.storage, MkSearch.this.self, |
| 123 | |
new Coordinates.Simple( |
| 124 | 0 | xml.xpath("../../@coords").get(0) |
| 125 | |
), |
| 126 | 0 | Integer.parseInt(xml.xpath("number/text()").get(0)) |
| 127 | |
); |
| 128 | |
} |
| 129 | |
} |
| 130 | |
); |
| 131 | |
} |
| 132 | |
|
| 133 | |
@Override |
| 134 | |
public Iterable<User> users( |
| 135 | |
final String keywords, |
| 136 | |
final String sort, |
| 137 | |
final Order order |
| 138 | |
) throws IOException { |
| 139 | 2 | return new MkIterable<User>( |
| 140 | |
this.storage, |
| 141 | |
"/github/users/user", |
| 142 | 1 | new MkIterable.Mapping<User>() { |
| 143 | |
@Override |
| 144 | |
public User map(final XML xml) { |
| 145 | |
try { |
| 146 | 0 | return new MkUser( |
| 147 | 0 | MkSearch.this.storage, |
| 148 | 0 | xml.xpath("login/text()").get(0) |
| 149 | |
); |
| 150 | 0 | } catch (final IOException ex) { |
| 151 | 0 | throw new IllegalStateException(ex); |
| 152 | |
} |
| 153 | |
} |
| 154 | |
} |
| 155 | |
); |
| 156 | |
} |
| 157 | |
|
| 158 | |
@Override |
| 159 | |
public Iterable<Content> codes( |
| 160 | |
final String keywords, |
| 161 | |
final String sort, |
| 162 | |
final Order order |
| 163 | |
) throws IOException { |
| 164 | 2 | return new MkIterable<Content>( |
| 165 | |
this.storage, |
| 166 | |
"/github/repos/repo/name", |
| 167 | 1 | new MkIterable.Mapping<Content>() { |
| 168 | |
@Override |
| 169 | |
public Content map(final XML xml) { |
| 170 | |
try { |
| 171 | 0 | return new MkContent( |
| 172 | 0 | MkSearch.this.storage, |
| 173 | 0 | MkSearch.this.self, |
| 174 | 0 | new Coordinates.Simple(MkSearch.this.self, "repo"), |
| 175 | |
"/path/to/search", |
| 176 | |
"master" |
| 177 | |
); |
| 178 | 0 | } catch (final IOException exception) { |
| 179 | 0 | throw new IllegalStateException(exception); |
| 180 | |
} |
| 181 | |
} |
| 182 | |
} |
| 183 | |
); |
| 184 | |
} |
| 185 | |
|
| 186 | |
} |