Skip to content

Commit

Permalink
[Twitter] 3.0 Twitter Binding (openhab#10241)
Browse files Browse the repository at this point in the history
* [twitter][WIP] Initial contribution

using the 1.x binding as a template, I created a new Twitter Binding.

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com> (github: computergeek1507)
Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* trying to fix twitter4j dependency stuff

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* add to bundle POM

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* trying to fix build

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* Fixed dependency issues, Got Actions working

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* updating readme

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* fix class name

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* Fixes based on review

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* Cleanup based on review and mvn checks

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* grammar fix

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* remove Apache dependencies

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* added Null Checks based on review

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>

* change null check around

Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>
Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
  • Loading branch information
computergeek1507 authored and dschoepel committed Nov 9, 2021
1 parent 3e42e7b commit 2df0ec9
Show file tree
Hide file tree
Showing 14 changed files with 769 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
/bundles/org.openhab.binding.tplinksmarthome/ @Hilbrand
/bundles/org.openhab.binding.tr064/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.tradfri/ @cweitkamp @kaikreuzer
/bundles/org.openhab.binding.twitter/ @computergeek1507
/bundles/org.openhab.binding.unifi/ @mgbowman
/bundles/org.openhab.binding.unifiedremote/ @GiviMAD
/bundles/org.openhab.binding.upb/ @marcusb
Expand Down
22 changes: 22 additions & 0 deletions bundles/org.openhab.binding.twitter/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This content is produced and maintained by the openHAB project.

* Project home: https://www.openhab.org

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/openhab/openhab-addons

== Third-party Content

twitter4j
* License: Apache License 2.0
* Project: https://twitter4j.org/
* Source: https://github.com/Twitter4J/Twitter4J


66 changes: 66 additions & 0 deletions bundles/org.openhab.binding.twitter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Twitter Binding

The Twitter binding allows your home to Tweet 280 characters at a time. It also supports direct messages and tweeting with media.

## Supported Things

```
account - Twitter Account.
```

## Thing Configuration

The Twitter Account Thing requires you to create a Twitter App in the Twitter Developer Page.

| Property | Default | Required | Description |
|-------------------|---------|:--------:|-----------------------------------|
| consumerKey | | Yes | Consumer API Key |
| consumerSecret | | Yes | Consumer API Secret |
| accessToken | | Yes | Access Token |
| accessTokenSecret | | Yes | Access Token Secret |
| refresh | 30 | No | Tweet refresh interval in minutes |


## Channels

| channel | type | description |
|------------|--------|------------------------------------------------|
| lasttweet | String | This channel provides the Latest Tweet message |


## Full Example

twitter.things:

```
Thing twitter:account:sampleaccount [ consumerKey="11111", consumerSecret="22222", accessToken="33333", accessTokenSecret="444444" ]
```

twitter.items:

```
String sample_tweet "Latest Tweet: [%s]" { channel="twitter:account:sampleaccount:lasttweet" }
```

## Rule Action

This binding includes rule actions for sending tweets and direct messages.

* `boolean success = sendTweet(String text)`
* `boolean success = sendTweetWithAttachment(String text, String URL)`
* `boolean success = sendDirectMessage(String recipientID, String text)`

Examples:

```
val tweetActions = getActions("twitter","twitter:account:sampleaccount")
val success = tweetActions.sendTweet("This is A Tweet")
val success2 = tweetActions.sendTweetWithAttachment("This is A Tweet with a Pic", file:///tmp/201601011031.jpg)
val success3 = tweetActions.sendTweetWithAttachment("Windows Picture", "D:\\Test.png" )
val success4 = tweetActions.sendTweetWithAttachment("HTTP Picture", "http://www.mywebsite.com/Test.png" )
val success5 = tweetActions.sendDirectMessage("1234567", "Wake Up" )
```
29 changes: 29 additions & 0 deletions bundles/org.openhab.binding.twitter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.twitter</artifactId>

<name>openHAB Add-ons :: Bundles :: Twitter Binding</name>

<properties>
<bnd.importpackage>!android.*,!com.android.org.*,!dalvik.*,!javax.annotation.meta.*,!org.apache.harmony.*,!org.conscrypt.*,!sun.*,!com.google.appengine.api.*</bnd.importpackage>
</properties>

<dependencies>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.twitter-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-twitter" description="Twitter Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.twitter/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.twitter.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link TwitterBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Scott Hanson - Initial contribution
*/
@NonNullByDefault
public class TwitterBindingConstants {

private static final String BINDING_ID = "twitter";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_ACCOUNT = new ThingTypeUID(BINDING_ID, "account");

// List of all Channel ids
public static final String CHANNEL_LASTTWEET = "lasttweet";
}
Loading

0 comments on commit 2df0ec9

Please sign in to comment.