Skip to content

Commit

Permalink
Makes examples standalone and built from standard Gradle or Maven
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Jan 27, 2015
1 parent 31915a6 commit f4342dc
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 109 deletions.
10 changes: 10 additions & 0 deletions example-github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GitHub Example
===================

This is an example of a simple json client.

=== Building example with Gradle
Install and run `gradle` to produce `build/wikipedia`

=== Building example with Maven
Install and run `mvn` to produce `target/wikipedia`
22 changes: 11 additions & 11 deletions example-github/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
plugins {
id 'nebula.provided-base' version '2.0.1'
}
// NOTE: This module is intended to be a stand-alone example which does depend on nebula.
defaultTasks 'clean', 'fatJar'

apply plugin: 'java'

sourceCompatibility = 1.6
repositories {
mavenCentral()
}

configurations {
compile
}

dependencies {
compile 'com.netflix.feign:feign-core:5.3.0'
compile 'com.netflix.feign:feign-gson:5.3.0'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.netflix.feign:feign-core:7.1.0'
compile 'com.netflix.feign:feign-gson:7.1.0'
}

// create a self-contained jar that is executable
Expand Down Expand Up @@ -49,7 +53,3 @@ task fatJar(dependsOn: classes, type: Jar) {
srcFile.setExecutable(true, true)
}
}

artifacts {
archives fatJar
}
73 changes: 73 additions & 0 deletions example-github/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<groupId>com.netflix.feign</groupId>
<artifactId>feign-example-github</artifactId>
<packaging>jar</packaging>
<version>7.1.0</version>
<name>GitHub Example</name>

<dependencies>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-gson</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>feign.example.github.GitHubExample</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.skife.maven</groupId>
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<programFile>github</programFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>really-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
*/
package feign.example.github;

import dagger.Module;
import dagger.Provides;
import feign.Feign;
import feign.Logger;
import feign.Param;
import feign.RequestLine;
import feign.gson.GsonModule;

import javax.inject.Named;
import feign.gson.GsonDecoder;
import java.util.List;

/**
Expand All @@ -32,7 +29,7 @@ public class GitHubExample {

interface GitHub {
@RequestLine("GET /repos/{owner}/{repo}/contributors")
List<Contributor> contributors(@Named("owner") String owner, @Named("repo") String repo);
List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}

static class Contributor {
Expand All @@ -41,24 +38,16 @@ static class Contributor {
}

public static void main(String... args) throws InterruptedException {
GitHub github = Feign.create(GitHub.class, "https://api.github.com", new GsonModule(), new LogToStderr());
GitHub github = Feign.builder()
.decoder(new GsonDecoder())
.logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC)
.target(GitHub.class, "https://api.github.com");

System.out.println("Let's fetch and print a list of the contributors to this library.");
List<Contributor> contributors = github.contributors("netflix", "feign");
for (Contributor contributor : contributors) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
}

@Module(overrides = true, library = true, includes = GsonModule.class)
static class LogToStderr {

@Provides Logger.Level loggingLevel() {
return Logger.Level.BASIC;
}

@Provides Logger logger() {
return new Logger.ErrorLogger();
}
}
}
10 changes: 10 additions & 0 deletions example-wikipedia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Wikipedia Example
===================

This is an example of advanced json response parsing, including pagination.

=== Building example with Gradle
Install and run `gradle` to produce `build/wikipedia`

=== Building example with Maven
Install and run `mvn` to produce `target/wikipedia`
22 changes: 11 additions & 11 deletions example-wikipedia/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
plugins {
id 'nebula.provided-base' version '2.0.1'
}
// NOTE: This module is intended to be a stand-alone example which does depend on nebula.
defaultTasks 'clean', 'fatJar'

apply plugin: 'java'

sourceCompatibility = 1.6
repositories {
mavenCentral()
}

configurations {
compile
}

dependencies {
compile 'com.netflix.feign:feign-core:5.3.0'
compile 'com.netflix.feign:feign-gson:5.3.0'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.netflix.feign:feign-core:7.1.0'
compile 'com.netflix.feign:feign-gson:7.1.0'
}

// create a self-contained jar that is executable
Expand Down Expand Up @@ -49,7 +53,3 @@ task fatJar(dependsOn: classes, type: Jar) {
srcFile.setExecutable(true, true)
}
}

artifacts {
archives fatJar
}
78 changes: 78 additions & 0 deletions example-wikipedia/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<groupId>com.netflix.feign</groupId>
<artifactId>feign-example-wikipedia</artifactId>
<packaging>jar</packaging>
<version>7.1.0</version>
<name>Wikipedia Example</name>

<dependencies>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-gson</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>

<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>feign.example.wikipedia.WikipediaExample</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.skife.maven</groupId>
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<programFile>wikipedia</programFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>really-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,11 @@ public WikipediaExample.Response<X> read(JsonReader reader) throws IOException {
}
}
reader.endObject();
} else if ("query-continue".equals(nextName)) {
} else if ("continue".equals(nextName)) {
reader.beginObject();
while (reader.hasNext()) {
if ("search".equals(reader.nextName())) {
reader.beginObject();
while (reader.hasNext()) {
if ("gsroffset".equals(reader.nextName())) {
pages.nextOffset = reader.nextLong();
}
}
reader.endObject();
if ("gsroffset".equals(reader.nextName())) {
pages.nextOffset = reader.nextLong();
} else {
reader.skipValue();
}
Expand All @@ -79,7 +73,6 @@ public WikipediaExample.Response<X> read(JsonReader reader) throws IOException {
}
}
reader.endObject();
reader.close();
return pages;
}

Expand Down
Loading

0 comments on commit f4342dc

Please sign in to comment.