blob: 66ae3741a93e0e18b912bb6fd1ccc43a5e493569 [file] [log] [blame]
/**
Example Entity feed for Google Order Redirect. Create "src/main/generated" directory for generated proto classes.
Download lastest version of protoc from https://github.com/protocolbuffers/protobuf/releases.
Generate proto classes with:
protoc --java_out=src/main/java/generated --proto_path=../proto ../proto/entity.proto
See https://protobuf.dev/reference/java/java-generated/ for more details.
**/
package com.example.order_redirect;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.google.madden.ingestion.EntityFeed;
import com.google.madden.ingestion.Entity;
import com.google.madden.ingestion.PostalAddress;
import com.google.madden.ingestion.GeoCoordinates;
public class EntityFeedExample {
public static void main(String[] args) throws InvalidProtocolBufferException {
EntityFeedExample feed = new EntityFeedExample();
String feedJSON = feed.createEntityFeed();
System.out.println(feedJSON);
}
public String createEntityFeed() throws InvalidProtocolBufferException {
// Create Entity
Entity entity = Entity.newBuilder()
.setEntityId("merchant-1")
.setName("Mo's Dinner")
.setTelephone("+14567891234")
.setUrl("http://moesdinner.com")
.setLocation(
GeoCoordinates.newBuilder()
.setLatitude(41.525588)
.setLongitude(-90.507067)
.setAddress(
PostalAddress.newBuilder()
.setCountry("US")
.setLocality("Mountain View")
.setRegion("CA")
.setPostalCode("94043")
.setStreetAddress("1600 Amphitheatre Pkwy")
.build()
)
).build();
// Add to feed data
EntityFeed entityFeed = EntityFeed.newBuilder().addData(entity).build();
// Serialize feed to JSON string
return JsonFormat.printer()
.omittingInsignificantWhitespace()
.preservingProtoFieldNames()
.print(entityFeed);
}
}