Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
egit-github => jcabi-github; fixes #98
- Loading branch information
Showing
11 changed files
with
89 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/scala/com/chrisrebert/lmvtfy/github/Credentials.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.chrisrebert.lmvtfy.github | ||
|
||
import com.jcabi.github.{Github, RtGithub} | ||
import com.chrisrebert.lmvtfy.http.{UserAgent, SuperWire} | ||
|
||
case class Credentials(username: String, password: String) { | ||
private def basicGithub: Github = new RtGithub(username, password) | ||
def github(threshold: Int)(implicit userAgent: UserAgent): Github = new RtGithub(basicGithub.entry.through(classOf[SuperWire], userAgent, new Integer(threshold))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/main/scala/com/chrisrebert/lmvtfy/github/GitHubJsonProtocol.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/scala/com/chrisrebert/lmvtfy/github/implicits/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.chrisrebert.lmvtfy.github | ||
|
||
import com.jcabi.github.Comment | ||
import com.jcabi.github.Comment.{Smart=>SmartComment} | ||
|
||
package object implicits { | ||
implicit class RichComment(comment: Comment) { | ||
def smart: SmartComment = new SmartComment(comment) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/scala/com/chrisrebert/lmvtfy/http/SuperWire.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.chrisrebert.lmvtfy.http | ||
|
||
import java.util.{Collection=>JavaCollection} | ||
import java.util.Map.{Entry=>MapEntry} | ||
import java.io.InputStream | ||
import com.jcabi.github.wire.RetryCarefulWire | ||
import com.jcabi.http.{Wire,Request,Response} | ||
|
||
case class SuperWire(private val wire: Wire, userAgent: UserAgent, threshold: Int) extends Wire { | ||
private val wrappedWire = UserAgentWire(wire = new RetryCarefulWire(wire, threshold), userAgent = userAgent) | ||
|
||
@Override | ||
def send( | ||
request: Request, | ||
home: String, | ||
method: String, | ||
headers: JavaCollection[MapEntry[String, String]], | ||
content: InputStream | ||
): Response = wrappedWire.send(request, home, method, headers, content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.chrisrebert.lmvtfy.http | ||
|
||
case class UserAgent(userAgent: String) |
25 changes: 25 additions & 0 deletions
25
src/main/scala/com/chrisrebert/lmvtfy/http/UserAgentWire.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.chrisrebert.lmvtfy.http | ||
|
||
import java.util.{Collection=>JavaCollection} | ||
import java.util.Map.{Entry=>MapEntry} | ||
import java.io.InputStream | ||
import scala.collection.JavaConverters._ | ||
import com.jcabi.http._ | ||
|
||
object UserAgentWire { | ||
private val userAgentHeader = "User-Agent" | ||
} | ||
case class UserAgentWire(private val wire: Wire, userAgent: UserAgent) extends Wire { | ||
@Override | ||
def send( | ||
request: Request, | ||
home: String, | ||
method: String, | ||
headers: JavaCollection[MapEntry[String, String]], | ||
content: InputStream | ||
): Response = { | ||
val header = new ImmutableHeader(UserAgentWire.userAgentHeader, userAgent.userAgent) | ||
val newHeaders = header +: headers.asScala.filter{ _.getKey != UserAgentWire.userAgentHeader}.toSeq | ||
wire.send(request, home, method, newHeaders.asJava, content) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters