Skip to content
This repository
Browse code

f

  • Loading branch information...
commit efd7981954a11477c465c404d39086507e7e78fc 1 parent 0f75042
Micah Silverman authored

Showing 1 changed file with 31 additions and 409 deletions. Show diff stats Hide diff stats

  1. 440  README.md
440  README.md
Source Rendered
... ...
@@ -1,426 +1,48 @@
1  
-[![Build Status](https://secure.travis-ci.org/didit-tech/FastLegS.png)](http://travis-ci.org/didit-tech/FastLegS)
2  
-#FastLegS
  1
+# Some Node.js Trello API examples
  2
+[View Trello’s API documentation online][apidocs]. For information on Trello’s API development, visit [their Trello board][trellotrello], of course.
3 3
 
4  
-PostgreSQL ORM on top of node-postgres.
  4
+[apidocs]: https://trello.com/docs/
  5
+[trellotrello]: https://trello.com/board/trello-public-api/4ed7e27fe6abb2517a21383d
5 6
 
6  
-##Installation
  7
+## Install
  8
+```
  9
+npm install TrelloTools
  10
+```
7 11
 
8  
-    npm install FastLegS
  12
+### Getting your key and token
  13
+* [Generate your developer key][devkey] and supply it as the first constructor parameter.
  14
+* To read a user’s private information, get a token by directing them to `https://trello.com/1/connect?key=<PUBLIC_KEY>&name=MyApp&response_type=token&scope=read,write` replacing, of course, &lt;PUBLIC_KEY&gt; with the public key obtained in the first step.
  15
+* If you need write access as well as read, `&scope=read,write` to the request for your user token.
9 16
 
10  
-##Quickstart
  17
+[devkey]: https://trello.com/1/appKey/generate
11 18
 
12  
-**NOTE:** As of version```0.2.0```, both PostgreSQL and MySQL are supported. 
13  
-You indicate which database you are using at object instantiation time. All 
14  
-other operations and interfaces behave the same as older versions.
  19
+## Background
15 20
 
16  
-### Setup for versions < ```0.2.0```
  21
+This project uses the [peanut] function testing tool for node.js
17 22
 
18  
-    var FastLegS = require('FastLegS');
19  
-    ...
20  
-    FastLegS.connect(connectionParams);
21  
-    ...
  23
+The tests that are included are meant to get you familiar with the Trello API using the [node-trello] project.
22 24
 
23  
-### Setup for versions >= ```0.2.0```
  25
+[peaut]: https://github.com/didit-tech/peanut
  26
+[node-trello]: https://github.com/adunkman/node-trello
24 27
 
25  
-### MySQL:
  28
+Take a look at the code in: ```features/step_definitions``` to see what is going on in each scenario from ```features/trello.feature```
26 29
 
27  
-    var FastLegSBase = require('FastLegS');
28  
-    var FastLegS = new FastLegSBase('mysql');
29  
-    ...
30  
-    FastLegS.connect(connectionParams);
31  
-    ...
  30
+## Setup
32 31
 
33  
-### PostgreSQL:
  32
+You'll need to create a ```config/environments/test/settings.js``` based on the example file found there.
34 33
 
35  
-    var FastLegSBase = require('FastLegS');
36  
-    var FastLegS = new FastLegSBase('pg');
37  
-    ...
38  
-    FastLegS.connect(connectionParams);
39  
-    ...
  34
+You'll need to provide a ```key```, ```token``` and ```board``` name.
40 35
 
41  
-### Example:
  36
+***SUPER IMPORTANT NOTE***: When you run the tests, all existing lanes and cards on the named board will be archived. Do not, under any circumstances, reference a board that is currently in use. You should create a totally new board to reference for this code.
42 37
 
43  
-    var FastLegSBase = require('FastLegS');
  38
+Make sure that peanut is installed:
44 39
 
45  
-    // gonna use PostgreSQL
46  
-    var FastLegS = new FastLegSBase('pg');
  40
+```
  41
+npm install -g peanut
  42
+```
47 43
 
48  
-    var connectionParams = {
49  
-      user: 'shes'
50  
-    , password: 'got'
51  
-    , database: 'legs'
52  
-    , host: 'localhost'
53  
-    , port: 5432
54  
-    }
  44
+## Running
55 45
 
56  
-    FastLegS.connect(connectionParams);
57  
-
58  
-    var Post = FastLegS.Base.extend({
59  
-      tableName: 'posts',
60  
-      primaryKey: 'id'
61  
-    });
62  
-
63  
-    Post.create(
64  
-      { title: 'Some Title 1', body: 'Some body 1' }, 
65  
-      function(err, results) {
66  
-        Post.find(
67  
-          { 'title.ilike': '%title%' }, 
68  
-          { only: ['id', 'body'] }, 
69  
-          function(err, post) {
70  
-            // Hooray!
71  
-          }
72  
-        );
73  
-      }
74  
-    );
75  
-
76  
-#The Full Monty
77  
-
78  
-The following examples use these database tables as examples:
79  
-
80  
-### posts
81  
-
82  
-| id   | title        | blurb        | body        | published   |
83  
-|------|--------------|--------------|-------------|-------------|
84  
-| 1    | Some Title 1 | Some blurb 1 | Some body 1 | false       |
85  
-| 2    | Some Title 1 | Some blurb 2 | Some body 2 | true        |
86  
-| 3    | Some Title 1 | Some blurb 3 | Some body 3 | false       |
87  
-| 4    | Some Title 1 | Some blurb 4 | Some body 4 | true        |
88  
-
89  
-### comments
90  
-
91  
-| id | post_id | comment   | created_at |
92  
-|----|---------|-----------|------------|
93  
-|  1 |       1 | Comment 1 | 2012-12-11 |
94  
-|  2 |       1 | Comment 2 | 2012-12-11 |
95  
-|  3 |       2 | Comment 3 | 2012-12-11 |
96  
-|  4 |       2 | Comment 4 | 2012-12-11 |
97  
-|  5 |       3 | Comment 5 | 2012-12-11 |
98  
-|  6 |       3 | Comment 6 | 2012-12-11 |
99  
-|  7 |       4 | Comment 7 | 2012-12-11 |
100  
-|  8 |       4 | Comment 8 | 2012-12-11 |
101  
-
102  
-Given this setup:
103  
-
104  
-    var FastLegSBase = require('FastLegS');
105  
-
106  
-    // gonna use PostgreSQL
107  
-    var FastLegS = new FastLegSBase('pg');
108  
-
109  
-    var connectionParams = {
110  
-      user: 'shes', password: 'got',
111  
-      database: 'legs', host: 'localhost', port: 5432
112  
-    }
113  
-
114  
-    FastLegS.connect(connectionParams);
115  
-
116  
-    var callback = function(err, results) {
117  
-      console.dir(err);
118  
-      console.dir(results);
119  
-    }
120  
-    
121  
-    var Comment = FastLegS.Base.extend({
122  
-      tableName: 'comments',
123  
-      primaryKey: 'id'
124  
-    });
125  
-    
126  
-    var Post = FastLegS.Base.extend({
127  
-      tableName: 'posts',
128  
-      primaryKey: 'id'
129  
-    });
130  
-
131  
-The following are examples of basic CRUD operations:
132  
-
133  
-##Create
134  
-
135  
-Calls to ```create``` can take an object or an array of objects.
136  
-
137  
-    Post.create(
138  
-      { id: 5, title: 'Some Title 5', body: 'Some body 5' },
139  
-      callback
140  
-    )
141  
-
142  
-    Post.create(
143  
-      [{ id: 6, title: 'Some Title 6', body: 'Some body 6' },
144  
-       { id: 7, title: 'Some Title 7', body: 'Some body 7' }],
145  
-      callback
146  
-    )
147  
-
148  
-The ```results``` passed to the callback are different depending on the 
149  
-database.
150  
-
151  
-In the case of PostgreSQL, the ```results``` will be an object of the form:
152  
-
153  
-    {
154  
-      rows: [{ id: 5,
155  
-             title: 'Some Title 5',
156  
-             blurb: null,
157  
-             body: 'Some body 5',
158  
-             published: null }],
159  
-      command: INSERT,
160  
-      rowCount: 1,
161  
-      oid: 0
162  
-    }
163  
-
164  
-In the case of MySQL, the ```results``` will be an object of the form:
165  
-
166  
-    {
167  
-      fieldCount: 0,
168  
-      affectedRows: 1,
169  
-      insertId: 0,
170  
-      serverStatus: 2,
171  
-      warningCount: 0,
172  
-      message: ''
173  
-    }
174  
-
175  
-##Read
176  
-
177  
-The various forms of the ```find``` command are very flexible. We'll present a 
178  
-few of them here.
179  
-
180  
-####All:
181  
-
182  
-    Post.find({}, callback)
183  
-
184  
-outputs:
185  
-
186  
-    [ 
187  
-      { id: 1,
188  
-        title: 'Some Title 1',
189  
-        blurb: null,
190  
-        body: 'Some body 1',
191  
-        published: null,
192  
-        created_at: null,
193  
-        updated_at: null },
194  
-      ...
195  
-      { id: 5,
196  
-        title: 'Some Title 5',
197  
-        blurb: null,
198  
-        body: 'Some body 5',
199  
-        published: null,
200  
-        created_at: null,
201  
-        updated_at: null },
202  
-      { id: 6,
203  
-        title: 'Some Title 6',
204  
-        blurb: null,
205  
-        body: 'Some body 6',
206  
-        published: null,
207  
-        created_at: null,
208  
-        updated_at: null },
209  
-      { id: 7,
210  
-        title: 'Some Title 7',
211  
-        blurb: null,
212  
-        body: 'Some body 7',
213  
-        published: null,
214  
-        created_at: null,
215  
-        updated_at: null } 
216  
-    ]
217  
-
218  
-####By primary key:
219  
-
220  
-    Post.find(6, callback)
221  
-
222  
-outputs:
223  
-
224  
-    {
225  
-      id: 6,
226  
-      title: 'Some Title 6',
227  
-      blurb: null,
228  
-      body: 'Some body 6',
229  
-      published: null,
230  
-      created_at: null,
231  
-      updated_at: null
232  
-    }
233  
-
234  
-####Only show some fields:
235  
-
236  
-    Post.find(6, {only: ['id','title']}, callback)
237  
-
238  
-outputs:
239  
-
240  
-    { id: 6, title: 'Some Title 6' }
241  
-
242  
-####Some clauses:
243  
-
244  
-    Post.find({'title.like': 'Some%'}, callback)
245  
-    Post.find({'id.in': [6, 7]}, callback)
246  
-    Post.find({'id.nin': [6]}, callback)
247  
-    Post.find({'$or': {'id.equals': 5, 'body.like': '%body 7'}}, callback)
248  
-
249  
-####Order, offset, limit
250  
-
251  
-    Post.find({}, { order: ['-id'] }, callback)
252  
-    Post.find({}, { offset: 1, limit: 1 }, callback)
253  
-
254  
-####Count:
255  
-
256  
-    Post.find({}, {count: true}, callback)
257  
-
258  
-outputs:
259  
-
260  
-    { count: 7 }
261  
-
262  
-##Update
263  
-
264  
-    Post.update(
265  
-      { title: 'Some Title 6' },
266  
-      { title: 'Renamed title' },
267  
-      callback
268  
-    )
269  
-
270  
-##Delete
271  
-
272  
-    Post.destroy({ 'id.in': [5, 7]}, callback)
273  
-    Post.truncate(callback)
274  
-
275  
-##A Taste of Relationships
276  
-
277  
-You can call out relationships when you extend FastLegS.Base:
278  
-
279  
-    var Post = FastLegS.Base.extend({
280  
-      tableName: 'posts',
281  
-      primaryKey: 'id',
282  
-      many: [
283  
-        { 'comments': Comment, joinOn: 'post_id' }
284  
-      ]
285  
-    });
286  
-    
287  
-You can then create complex object relationships with join logic:
288  
-
289  
-    Post.find(
290  
-      {}, 
291  
-      { include: { comments: { only: ['id', 'comment'] } } },
292  
-      callback
293  
-    )
294  
-
295  
-outputs:
296  
-
297  
-    [
298  
-      {
299  
-          body: 'Some body 1',
300  
-          title: 'Some Title 1',
301  
-          id: 1,
302  
-          updated_at: null,
303  
-          published: false,
304  
-          blurb: 'Some blurb 1',
305  
-          created_at: null,
306  
-          comments: [
307  
-              { id: 1, comment: 'Comment 1' },
308  
-              { id: 2, comment: 'Comment 2' }
309  
-          ]
310  
-      },
311  
-      {
312  
-          body: 'Some body 2',
313  
-          title: 'Some Title 2',
314  
-          id: 2,
315  
-          updated_at: null,
316  
-          published: true,
317  
-          blurb: null,
318  
-          created_at: null,
319  
-          comments: [
320  
-              { id: 3, comment: 'Comment 3' },
321  
-              { id: 4, comment: 'Comment 4' }
322  
-          ]
323  
-      },
324  
-      ...
325  
-    ]
326  
-
327  
-Here's a many-to-many example based on these tables:
328  
-
329  
-### students
330  
-
331  
-| id | name      |
332  
-|----|-----------|
333  
-| 1  | Abe       |
334  
-| 2  | Ben       |
335  
-| 3  | Christine |
336  
-| 4  | Delia     |
337  
-| 5  | Egwene    |
338  
-
339  
-### professors
340  
-
341  
-| id | name   |
342  
-|----|--------|
343  
-| 6  | Felix  |
344  
-| 7  | Garret |
345  
-| 8  | Horton |
346  
-| 9  | Irene  |
347  
-| 10 | Jane   |
348  
-
349  
-### student_professor
350  
-
351  
-| student_id | professor_id |
352  
-|------------|--------------|
353  
-| 1          | 6            |
354  
-| 2          | 6            |
355  
-| 3          | 7            |
356  
-| 4          | 7            |
357  
-| 5          | 8            |
358  
-| 1          | 8            |
359  
-| 2          | 9            |
360  
-| 3          | 9            |
361  
-| 4          | 10           |
362  
-| 5          | 10           |
363  
-
364  
-
365  
-    var Student = FastLegS.Base.extend({
366  
-      tableName: 'students',
367  
-      primaryKey: 'id',
368  
-    });
369  
-
370  
-    var Professor = FastLegS.Base.extend({
371  
-      tableName: 'professors',
372  
-      primaryKey: 'id',
373  
-    })
374  
-
375  
-    var StudentProfessor = FastLegS.Base.extend({
376  
-      tableName: 'student_professor',
377  
-      foreignKeys: [
378  
-         { model: Student, key: 'student_id' },
379  
-         { model: Professor, key: 'professor_id' }
380  
-      ]
381  
-    })
382  
-
383  
-    Student.many = [{
384  
-      professors: Professor,
385  
-      assoc: StudentProfessor
386  
-    }]
387  
-
388  
-    Professor.many = [{
389  
-      students: Student,
390  
-      assoc: StudentProfessor
391  
-    }]
392  
-
393  
-    Professor.findOne(
394  
-      9,
395  
-      {include: { students: {} }},
396  
-      function(err, result) {
397  
-        inspect(result)
398  
-      }
399  
-    )
400  
-
401  
-outputs:
402  
-
403  
-    {
404  
-      id: 9,
405  
-      name: 'Irene',
406  
-      students: [
407  
-          { id: 2, name: 'Ben' },
408  
-          { id: 3, name: 'Christine' }
409  
-      ]
410  
-    }
411  
-
412  
-This shows that ```professor``` Irene has ```students``` Ben and Christine
413  
-
414  
-##Summary
415  
-
416  
-The tests are an excellent reference for the various modifiers and syntactic 
417  
-sugar you can use in FastLegS.
418  
-
419  
-##ToDo
420  
-
421  
-Right now, the codebase is split because of syntactic differences between 
422  
-PostgreSQL and MySQL. There is a lot of duplicated code, however. Future 
423  
-versions should abstract out the differences and merge the duplicated code.
424  
-
425  
-Watch for updates to examples in the near future to show features like 
426  
-relationships and advanced queries.
  46
+```
  47
+make
  48
+```

0 notes on commit efd7981

Please sign in to comment.
Something went wrong with that request. Please try again.