commit
73afaeae7a
8 changed files with 92 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||||
|
.envrc |
||||
|
twit2blog |
@ -0,0 +1,9 @@ |
|||||
|
### Twit2Blog |
||||
|
|
||||
|
A simple tool to help make it easier to turn your tweet rants into real blog posts |
||||
|
|
||||
|
### Building |
||||
|
`nimble build` is all you'll need at this point. |
||||
|
|
||||
|
### Running |
||||
|
Requires `TWITTER_CONSUMER_KEY` and `TWITTER_CONSUMER_SECRET`, both of which you can only get if you have a registered developer account and an application created for twitter. |
@ -0,0 +1 @@ |
|||||
|
switch("define", "ssl") |
@ -0,0 +1,7 @@ |
|||||
|
# This is just an example to get you started. A typical hybrid package |
||||
|
# uses this file as the main entry point of the application. |
||||
|
|
||||
|
import twit2blogpkg/twitter |
||||
|
|
||||
|
when isMainModule: |
||||
|
echo "weskerfoot".listTweets.repr |
@ -0,0 +1,45 @@ |
|||||
|
# This is just an example to get you started. Users of your hybrid library will |
||||
|
# import this file by writing ``import twit2blogpkg/submodule``. Feel free to rename or |
||||
|
# remove this file altogether. You may create additional modules alongside |
||||
|
# this file as required. |
||||
|
|
||||
|
import httpClient, base64, uri, json, os, strformat |
||||
|
|
||||
|
proc buildAuthHeader() : string = |
||||
|
let consumerKey = "TWITTER_CONSUMER_KEY".getEnv |
||||
|
let secret = "TWITTER_CONSUMER_SECRET".getEnv |
||||
|
"Basic " & (consumerKey.encodeUrl & ":" & secret.encodeUrl).encode |
||||
|
|
||||
|
proc getToken*() : string = |
||||
|
var client = newHttpClient() |
||||
|
client.headers = newHttpHeaders( |
||||
|
{ |
||||
|
"Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8", |
||||
|
"Authorization" : buildAuthHeader() |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
let body = "grant_type=client_credentials" |
||||
|
|
||||
|
let response = client.request("https://api.twitter.com/oauth2/token", |
||||
|
httpMethod = HttpPost, |
||||
|
body = body).body.parseJson |
||||
|
|
||||
|
let responseType = response["token_type"].getStr |
||||
|
|
||||
|
assert(responseType == "bearer") |
||||
|
|
||||
|
"Bearer " & response["access_token"].getStr |
||||
|
|
||||
|
|
||||
|
proc listTweets*(user : string) : JsonNode = |
||||
|
var client = newHttpClient() |
||||
|
let reqTarget = fmt"/1.1/statuses/user_timeline.json?count=100&screen_name={user}" |
||||
|
let url = fmt"https://api.twitter.com{reqTarget}" |
||||
|
client.headers = newHttpHeaders( |
||||
|
{ |
||||
|
"Authorization" : getToken() |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
client.request(url, httpMethod = HttpGet).body.parseJson |
@ -0,0 +1 @@ |
|||||
|
switch("path", "$projectDir/../src") |
@ -0,0 +1,12 @@ |
|||||
|
# This is just an example to get you started. You may wish to put all of your |
||||
|
# tests into a single file, or separate them into multiple `test1`, `test2` |
||||
|
# etc. files (better names are recommended, just make sure the name starts with |
||||
|
# the letter 't'). |
||||
|
# |
||||
|
# To run these tests, simply execute `nimble test`. |
||||
|
|
||||
|
import unittest |
||||
|
|
||||
|
import twit2blogpkg/twitter |
||||
|
#test "correct welcome": |
||||
|
#check getWelcomeMessage() == "Hello, World!" |
@ -0,0 +1,15 @@ |
|||||
|
# Package |
||||
|
|
||||
|
version = "0.1.0" |
||||
|
author = "Wesley Kerfoot" |
||||
|
description = "Turn Your Tweets Into Blog Posts" |
||||
|
license = "MIT" |
||||
|
srcDir = "src" |
||||
|
installExt = @["nim"] |
||||
|
bin = @["twit2blog"] |
||||
|
|
||||
|
|
||||
|
|
||||
|
# Dependencies |
||||
|
|
||||
|
requires "nim >= 1.0.9" |
Loading…
Reference in new issue