Clone this repo to have your very own CLI Twitter Application that will allow you to post status updates and check your personal Twitter feed from the comfort of your command line.
Note: This application runs with Java, so Java must be installed on your computer. (Java Download Resources)
- Create a Twitter account, if you don't have one already, by visiting the Twitter Sign Up page and filling out the form.
- Log in to Twitter.
- Visit the Twitter Developers page. In the dropdown menu under your Twitter handle select Apps.
- On the new page that loads, click on the blue Create an app button and fill out the necessary details to receive your API keys.
- Once your app has been set up, go back to the Apps page and click on the Details button of your new application.
- Click on the Permissions tab on the new page that loads. Click the blue Edit button, and make sure your Access permission is set to "Read and write."
- Now select the "Keys and tokens" tab of your application to view your keys and tokens.
- Create a TwitterAppConfiguration.yml file, using the TwitterAppConfiguration-example.yml as an example, and copy your keys and tokens to their corresponding fields in your new configuration YML file.
- You'll want to add this file to your .gitignore file to hide your keys and tokens.
- Install Maven if it's not already installed on your computer.
- Initialize your Maven project by following the Creating a Project Maven insructions. Make sure the groupId is com.khoros.twitterapp and the artifactId is TwitterApp.
- Copy your twitter4j.properties file into a new 'resources' directory in the TwiterApp/src/main directory.
- Add a file 'configuration.yml' to your root directory and add the following text to the file and save it:
server: type: simple applicationContextPath: /api/1.0/twitter/ connector: type: http port: 8080
- Make sure you have an updated pom.xml file that includes dropwizard as a dependency. You can use Dropwizard's Tutorial to get maven set up with Dropwizard.
- Once your pom.xml file is updated, you can reimport your project with Maven in IntelliJ.
- Right click on your pom.xml file in IntelliJ.
- Hover over "Maven" until the submenu opens.
- Click on reimport.
- Give your library a couple of minutes to update.
- Dropwizard should now be integrated into your Maven project.
- Compile and package your Maven project by running the following command in the command line:
mvn package
- There should now be a new 'target' directory with two JAR files in it.
- To run your fat-JAR file and start the Dropwizard server use the following command:
java -jar target/TwitterApp-1.0-SNAPSHOT-launcher.jar server configuration.yml
- Your server should now be listening to client requests.
- You can use
curl
to make a POST request to http://localhost:8080/api/1.0/twitter/tweet as such:curl -X POST --data-urlencode message="<your message>" http://localhost:8080/api/1.0/twitter/tweet
- To make GET request to http://localhost:8080/api/1.0/twitter/timeline you can use curl or the browser:
- Using curl:
curl -X GET http://localhost:8080/api/1.0/twitter/timeline
- Using the browser: Open http://localhost:8080/api/1.0/twitter/timeline in the browser of your choice.
- Using curl:
- Make sure the following xml is included in your POM file in the section to add the JaCoCO plugin:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.4</version> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>default-report</id> <configuration> <excludes> <exclude>**/TwitterApp.class</exclude> <exclude>**/LengthException.class</exclude> <exclude>**/CommandNotFoundException.class</exclude> <exclude>**/TwitterAppConfiguration.class</exclude> </excludes> </configuration> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>
- Type the following command into the command line to generate a test coverage report:
mvn jacoco:report verify
- To view the report open the index.html file (located in your
target/site/jacoco/
) in your browser.