Skip to content

Commit

Permalink
Merge pull request #4 from mr-wildcard/feature/twitter
Browse files Browse the repository at this point in the history
Twitter API proposal
  • Loading branch information
clayallsopp committed Jan 18, 2016
2 parents bf12ede + 1038575 commit 1c8d2b4
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 4 deletions.
160 changes: 158 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,159 @@
node_modules/
dist/
# Created by https://www.gitignore.io/api/webstorm,node

### WebStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# .idea/shelf

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties


### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history


### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# .idea/shelf

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties


### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json

.env
dist/
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ deploy:
api_key:
secure: szhg+pTuFpxSAZEtNbGIue+ITt+F1QDfOIaK9iw4QHGKcrFrgQkXGDADSgHot4P01kQ6KpuOBw1Ryx3ce2ithebhl55zdaMXQfkKlh9vGSEO05R0yyY7SM6UUJWGebXIzZFf8G/vTbJh+jdyeBuvJ0uiDErIrKNctA5E5XFbXKWTSo3n5EDYYGEx1E89IkZX+Txs98xTfLdIZkQYG6JSF08KF6asPAbpBNXSyo8zGtXPEuB3t3pccPaHwnzSnVS4Ljhujtl6H4DmY+AnkCJpW4Tb0HAnqBX+kGnSoYyv3fG80qABkE1tUvjNzGInc0BMLFI6LrhUrLRRf8Spd4LR//tn6Wy2xLm0tsmLWHz+bE9WyopooLyWamUQRW1YUXdfRiw5CM1q5TTWii/cvdWzuuX1XBXM4FKX5LdON+hbdg/gciLQZMVyzllM7+58SNdyNiYQXObi7ioWVV6UUwv/+P++F2CwDncnjRXCUmx5ZRe8T9UnmTa5xg+YsyKcEHKz1ms9TZoQxKro4YJAxLRsn4gQd9+Sbe1WZeiQfv/JSV98VJujiCbVO8iSWMAW7Le7NxTy/Gih2u3Z13LteLSz4KF5LPAoSLO/2KDTEsZwl9uyjblGi2sVIbvkTd0P0SnAz03k73YG4qXN4R7/h3RnIl1OCk8eRGAF6eSCFpXQtjQ=
app: graphqlhub
env:
- TWITTER_CONSUMER_KEY=dummy_consumer_key TWITTER_CONSUMER_SECRET=dummy_consumer_secret
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This powers the server behind [GraphQLHub](http://www.graphqlhub.com/). It's bas
- [Hacker News](schemas/hn.js)
- [Reddit](schemas/reddit.js)
- [GitHub](schemas/github.js)
- [Twitter](schemas/twitter.js)
- [GraphQLHub](schemas/graphqlhub.js), which contains all the other schemas

## TODO
Expand Down
10 changes: 10 additions & 0 deletions apis/__tests__/twitter-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import test from 'tape';
import * as Twitter from '../twitter';

test('Twitter API', (t) => {
t.ok(Twitter.getUser, 'getUser should exist');
t.ok(Twitter.getTweet, 'getTweet should exist');
t.ok(Twitter.getTweets, 'getTweets should exist');
t.ok(Twitter.getRetweets, 'getRetweets should exist');
t.end();
});
39 changes: 39 additions & 0 deletions apis/twitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Twit from 'twit';
import _ from 'lodash';

const {
TWITTER_CONSUMER_KEY,
TWITTER_CONSUMER_SECRET
} = process.env;

const Twitter = new Twit({
consumer_key : TWITTER_CONSUMER_KEY,
consumer_secret : TWITTER_CONSUMER_SECRET,
app_only_auth : true
});

export const getUser = (identifier, identity) => __getPromise('users/show', { [identifier]: identity });
export const getTweets = (user_id, count) => __getPromise('statuses/user_timeline', { user_id, count });
export const getTweet = (id) => __getPromise('statuses/show', { id });
export const getRetweets = (id, count) => __getPromise('statuses/retweets', { id, count });
export const searchFor = (queryParams) => __getPromise("search/tweets", queryParams, 'statuses');

const __getPromise = (endpoint, parameters, resultPath = null) => {

return new Promise((resolve, reject) => {

Twitter.get(
endpoint,
parameters,
(error, result) => {

if (error) {
reject(error);
}
else {
resolve( resultPath !== null ? _.get(result, resultPath) : result );
}
}
)
});
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"lodash": "3.10.1",
"node-fetch": "1.3.2",
"qs": "5.1.0",
"react": "0.13.3"
"react": "0.13.3",
"twit": "2.1.1"
},
"devDependencies": {
"glob": "6.0.2",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1>GraphQLHub APIs:</h1>
<li><a href="/playground/hn">Explore Hacker News</a></li>
<li><a href="/playground/reddit">Explore Reddit</a></li>
<li><a href="/playground/github">Explore GitHub</a></li>
<li><a href="/playground/twitter">Explore Twitter</a></li>
<li><a href="/playground/keyvalue">Explore a Relay-compatible Key-Value store</a></li>
</ul>
<p>Follow <a href="http://twitter.com/GraphQLHub">@GraphQLHub</a> for more updates. This page intentionally unstyled, for now.</p>
Expand Down
2 changes: 1 addition & 1 deletion schemas/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ export const Schema = {
resolve() {
return {};
}
},
}
};
2 changes: 2 additions & 0 deletions schemas/graphqlhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { Schema as HN } from './hn';
import { Schema as REDDIT } from './reddit';
import { Schema as KEYVALUE } from './keyvalue';
import { Schema as GITHUB } from './github';
import { Schema as TWITTER } from './twitter';

let schemas = {
hn : HN,
reddit : REDDIT,
keyValue : KEYVALUE,
github : GITHUB,
twitter: TWITTER
};

let FIELDS = {
Expand Down
Loading

0 comments on commit 1c8d2b4

Please sign in to comment.