Skip to content

Commit 0675ec0

Browse files
committed
Starting to stub things out
1 parent 2b6fc29 commit 0675ec0

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "0.11"
4+
- "0.10"
5+
- "0.8"

index.coffee

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Client = require './src/client'
2+
3+
module.exports = {
4+
Client
5+
}
6+
7+
module.exports.SlackClient = (token) ->
8+
new Client token

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "node-slack",
3+
"version": "0.0.1",
4+
"description": "A node library for creating a full Slack client",
5+
"main": "./index",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"slack"
11+
],
12+
"author": "Tiny Speck, Inc.",
13+
"license": "MIT",
14+
15+
"dependencies": {
16+
"coffee-script": "1.6.3"
17+
},
18+
19+
"engines": {
20+
"node": ">= 0.8.x",
21+
"npm": ">= 1.1.x"
22+
}
23+
}

src/client.coffee

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
https = require 'https'
2+
querystring = require 'querystring'
3+
4+
class Client
5+
6+
host: 'api.slack.com'
7+
8+
constructor: (@token) ->
9+
10+
login: ->
11+
@_apiCall 'users.login', {token: @token, agent: 'node-slack'}, @onLogin
12+
13+
onLogin: (data) ->
14+
if data
15+
if not data.ok
16+
console.error 'Cannot login: '+data.error
17+
else
18+
console.log 'Logged in to '+data.team.name+' as '+data.self.name
19+
20+
21+
_apiCall: (method, params, callback) ->
22+
params['token'] = @token
23+
24+
post_data = querystring.stringify(params)
25+
26+
options =
27+
hostname: @host,
28+
method: 'POST',
29+
path: '/api/' + method,
30+
headers:
31+
'Content-Type': 'application/x-www-form-urlencoded',
32+
'Content-Length': post_data.length
33+
34+
req = https.request(options)
35+
36+
req.on 'response', (res) =>
37+
buffer = ''
38+
res.on 'data', (chunk) ->
39+
buffer += chunk
40+
res.on 'end', =>
41+
if callback?
42+
if res.statusCode is 200
43+
value = JSON.parse(buffer)
44+
callback(value)
45+
else
46+
callback(null)
47+
48+
req.write('' + post_data)
49+
req.end()
50+
51+
module.exports = Client

0 commit comments

Comments
 (0)