├── .gitignore
├── LICENSE
├── README.md
├── asciilogo.js
├── bm.js
├── index.js
├── package-lock.json
├── package.json
└── testwilio.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | node_modules
26 |
27 | # Users Environment Variables
28 | .lock-wscript
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # beeminderjs
2 | NodeJS wrapper for the Beeminder API. Created for integration with [Complice](https://complice.co), a productivity app that's more *qualified*-self than quantified-self.
3 |
4 | BeeminderJS is designed for use within NodeJS apps, although it also works in a very basic rudimentary way from command-line. I'm open to people contributing new functions to either purpose!
5 |
6 | ## Install to your node project
7 |
8 | ```bash
9 | npm install --save beeminder
10 | ```
11 |
12 | ### Usage as a library
13 |
14 | As of 2.0.0, promises only. Errors may also be slightly different, due to using `fetch` instead of `curlrequest`.
15 |
16 | Refer to the [Beeminder API docs](http://api.beeminder.com/#beeminder-api-reference) for information on goal creation parameters or what will be returned when calling these endpoints.
17 |
18 | ```javascript
19 | var beeminder = require('beeminder')
20 | var bm = beeminder(auth_token)
21 |
22 | bm.getUser(function (err, result) {
23 | console.log(err || result)
24 | // do something
25 | })
26 |
27 | bm.getGoal('goalslug', function (err, result) {...})
28 |
29 | bm.createGoal('goalslug', params, function (err, result) {...})
30 |
31 | bm.getDatapoints('goalslug', function (err, result) {...})
32 |
33 | bm.createDatapoint('goalslug', {
34 | value: 1, // {type: Number, required: true},
35 | timestamp: new Date("2015-02-21").valueOf() // {type: Number, default: now},
36 | comment: 'updated readme',
37 | sendmail: true, // if you want the user to be emailed
38 | // requestid allows you to run command again without creating duplicate datapoints
39 | requestid: 'thisHasToBeAlphanumericWhichIsWhyThereAreNoSpaces',
40 | }, function (err, result) {...})
41 |
42 | bm.createGoal('goalslug', params).then(function () {
43 | return bm.createDatapoints('goalslug', [{...}])
44 | }).then(function () {
45 | res.send('Created goal and added datapoints')
46 | }).catch(...)
47 |
48 | ```
49 |
50 | ## Install as a command-line tool
51 |
52 | ```bash
53 | sudo npm install --global beeminder
54 |
55 | bm # run this once to ensure you're authenticated
56 | ```
57 |
58 | ### Usage as a command-line tool
59 |
60 | ```bash
61 | bm user
62 | bm status # outputs a list of goals sorted by derail time
63 | bm goal
64 | bm datapoints
65 | bm createdatapoint []
66 | bm cd # same as createdatapoint
67 | ```
68 |
69 | ### Example
70 |
71 | I have the following in `.bash_aliases`, which allows me to post a [user-visible improvement](http://blog.beeminder.com/uvi/) simultaneously to beeminder ([m/complice-uvi](https://beeminder.com/m/complice-uvi)) and twitter ([@compluvi](https://twitter.com/compluvi)). Requires the twitter bash client `t`, available [here](https://github.com/sferik/t) (although barely still supported since it uses an old version of Ruby and an unavailable-for-new-apps Twitter API).
72 |
73 | ```bash
74 | uvi () {
75 | bm cd complice-uvi 1 "$@"
76 | t update "$@"
77 | }
78 |
79 | # example
80 | uvi "UVIs will be posted more frequently because I can now post them from command line :D"
81 | ```
82 |
83 | ## todo
84 |
85 | - implement other endpoints (feel free to ask for them or to submit pull requests)
86 |
--------------------------------------------------------------------------------
/asciilogo.js:
--------------------------------------------------------------------------------
1 | module.exports = function () {
2 | console.log(" `·++', ,'++;`");
3 | console.log(" '+++++++++, .+++++++++'");
4 | console.log(" ++++++++++++++++++++++++++++");
5 | console.log(" `++++;···;+++++++++++···;++++.");
6 | console.log(" +++++,····++···;++;····+++++");
7 | console.log(" `+++++················+++++,");
8 | console.log(" +++++···············+++++,");
9 | console.log(" ;++++++++++'++++·················+++++;++++++++++");
10 | console.log(" +++++++++++++++++++···············;++++++++++++++++++,");
11 | console.log(" ++++++····,'+++++++++++,·········+++++++++++····,'++++++");
12 | console.log(" +++++,·········;++++++++++'····+++++++++++,·········'++++·");
13 | console.log(" ;++++··············;++++++++++++++++++++··············+++++");
14 | console.log(" +++++················,'++++++++++++++·················;++++");
15 | console.log(" +++++··················'++++++++++++···················++++`");
16 | console.log(" '++++,··············;++++++++++++++++++···············+++++");
17 | console.log(" ++++'············++++++++++',·+++++++++++,···········+++++");
18 | console.log(" ;+++++,·······+++++++++++,·······++++++++++',······;+++++");
19 | console.log(" ,++++++++++++++++++++·············;++++++++++++++++++++");
20 | console.log(" '+++++++++++++++··+++++++++++++++,·'+++++++++++++++");
21 | console.log(" ;''''++++'························++++';'';.");
22 | console.log(" +++++························++++.");
23 | console.log(" .++++'·····················,+++++");
24 | console.log(" +++++·····,+++++++++;·····+++++\`");
25 | console.log(" +++++;··················+++++·");
26 | console.log(" ++++++··············,++++++,");
27 | console.log(" .++++++'·········,+++++++");
28 | console.log(" ,+++++++,·····+++++++");
29 | console.log(" `+++++++,;++++++'");
30 | console.log(" +++++++++++,");
31 | console.log(" '++++++`");
32 | };
33 |
--------------------------------------------------------------------------------
/bm.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 | var Bee = require('./')
3 | var exec = require('child_process').exec
4 | var prompt = require('prompt')
5 | var fs = require('fs')
6 |
7 | var argv = require('minimist')(process.argv.slice(2))
8 |
9 | var userhome = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']
10 | var rc_path = userhome+"/.bmndrrc"
11 |
12 | var exists = fs.existsSync(rc_path)
13 | var rc = exists && fs.readFileSync(rc_path, 'utf8')
14 |
15 | function onErr (err) {
16 | console.error(err)
17 | return 1
18 | }
19 |
20 | function logBmResult (result) {
21 | console.log("Successfully executed command: \n", result)
22 | }
23 |
24 | function printHelp () {
25 | console.log("usage: bm []\n")
26 | console.log("The commands currently available are:")
27 | console.log("\tuser\t\t\t"+"retrieve properties of the user")
28 | console.log("\tstatus\t\t\t"+"display all goals sorted by derail time")
29 | console.log("\tgoal\t\t\t"+"retrieve properties of a goal")
30 | console.log("\tdatapoints\t\t"+"retrieve all datapoints of a goal")
31 | console.log("\tcreatedatapoint, cd\t"+"post a new datapoint")
32 | console.log("")
33 | console.log("`user` takes no arguments. `goal` and `datapoints` take a single argument")
34 | console.log("that is the goal's slug (beeminder.com/username/slug) ie:\n")
35 | console.log("\tbm goal ")
36 | console.log("\tbm datapoints ")
37 | console.log("")
38 | console.log("The argument format for `createdatapoint` is as follows:\n")
39 | console.log("\tbm createdatapoint []")
40 | }
41 |
42 | function padL (s, n) {
43 | return (" " + s).slice(-n)
44 | }
45 |
46 | function padR (s, n) {
47 | return (s + " ").slice(0, n)
48 | }
49 |
50 | function makeid (n) {
51 | var longId = ''
52 | for (var i = 0; i <= n/14; i++) {
53 | longId += (Math.random() + 1).toString(36).substr(2)
54 | }
55 | return longId.substring(0, n)
56 | }
57 |
58 | let token
59 | if (argv.access_token) {
60 | token = {access_token: argv.access_token}
61 | } else if (argv.auth_token) {
62 | token = {auth_token: argv.auth_token}
63 | } else if (rc && rc.split("auth_token: ")[1]) {
64 | token = {auth_token: rc.split("auth_token: ")[1].trim()}
65 | }
66 |
67 | if (argv.help) {
68 | printHelp()
69 | } else if (argv.logo || argv._ && argv._[0] === 'logo') {
70 | Bee.printLogo()
71 | } else if (token) {
72 | var bm = Bee(token)
73 | var command = argv._[0]
74 | if (command == "createdatapoint" || command == "cd") {
75 | var goalname = argv.goalname || argv.g || argv._[1]
76 | var value = argv.value || argv._[2]
77 | var comment = argv.comment || argv._[3]
78 | var id = argv.id || argv._[4]
79 | if (!goalname || value === undefined) {
80 | console.error("Incorrect format. Correct format is:")
81 | console.log("\tbm createdatapoint []")
82 | process.exit(1)
83 | }
84 | // ensureNumber(value)
85 | if (value && isNaN(parseFloat(value)) && !comment) {
86 | comment = value
87 | value = 1
88 | }
89 | var params = {
90 | value: parseFloat(value)
91 | }
92 | if (comment) {params.comment = comment}
93 | if (id) {params.requestid = id}
94 | bm.createDatapoint(goalname, params)
95 | .then(datapoint => console.log(goalname + " ▶ " + datapoint.canonical))
96 | .catch(onErr)
97 | } else if (command == "updatedatapoint") {
98 | var goalname = argv.goalname || argv.g || argv._[1]
99 | var value = argv.value || argv._[2]
100 | var comment = argv.comment || argv._[3]
101 | var id = argv.id || argv._[4]
102 | if (!id) {
103 | id = makeid(10)
104 | console.log("random id generated: " + id)
105 | }
106 | if (!goalname || value === undefined) {
107 | console.error("Incorrect format. Correct format is:")
108 | console.log("\tbm createdatapoint []")
109 | process.exit(1)
110 | }
111 | // ensureNumber(value)
112 | if (value && isNaN(parseFloat(value)) && !comment) {
113 | comment = value
114 | value = 1
115 | }
116 | var params = {
117 | value: parseFloat(value),
118 | requestid: id,
119 | }
120 | if (comment) {params.comment = comment}
121 | bm.updateDatapoint(goalname, params).then(datapoint => {
122 | console.log(goalname + " ▶ " + datapoint.canonical)
123 | }, onErr)
124 | } else if (command == "goal") {
125 | var goalname = argv.goalname || argv.g || argv._[1]
126 | bm.getGoal(goalname).then(logBmResult, onErr)
127 | } else if (command == "creategoal") {
128 | var params = {}
129 | params.slug = argv.goalname || argv.slug || argv.g || argv._[1]
130 | params.title = argv.title || params.slug
131 | params.goal_type = argv.goal_type || 'hustler'
132 | params.goaldate = argv.goaldate
133 | params.goalval = argv.goalval
134 | params.rate = argv.rate
135 | if (argv.panic) {params.panic = parseInt(argv.panic)}
136 | if (argv.dryrun) {params.dryrun = true}
137 | if (argv.secret) {params.secret = true}
138 | if (argv.datapublic) {params.datapublic = true}
139 | bm.createGoal(params.slug, params).then(logBmResult, onErr)
140 | } else if (command == "status") {
141 | var goalname = argv.goalname || argv.g || argv._[1]
142 | bm.getStatus().then(user => {
143 | var lines = []
144 | lines.push("-----------------------------------------------------------------")
145 | function pad8 (match) {return padL(match, 8)}
146 | var next24h = true
147 | for (var i in user.goals) {
148 | var goal = user.goals[i]
149 | if (goal.losedate - Math.ceil(Date.now()/1000) > (18*60*60) && next24h) {
150 | lines.push("-----------------------------------------------------------------")
151 | next24h = false
152 | }
153 | lines.push(" " + user.username + "/" + padR(goal.slug, 16) + padR(goal.delta_text, 22) + goal.derailtime.replace(/(.*? )/, pad8))
154 | }
155 | lines.push("-----------------------------------------------------------------")
156 | for (var l in lines) {
157 | console.log(lines[l])
158 | }
159 | }, onErr)
160 | } else if (command == "datapoints") {
161 | var goalname = argv.goalname || argv.g || argv._[1]
162 | bm.getDatapoints(goalname).then(logBmResult, onErr)
163 | } else if (command == "user") {
164 | bm.getUser().then(logBmResult, onErr)
165 | } else if (command == "onedatapoint") {
166 | bm.getUserOneDatapoint(function (err, result) {
167 | console.log("getUserOneDatapoint keys", Object.keys(result))
168 | })
169 | } else if (command == "skinny") {
170 | bm.getUserSkinny().then(function (result) {
171 | console.log("getUserSkinny keys", Object.keys(result))
172 | }).catch(onErr)
173 | } else if (command == "charge") {
174 | var amount = argv.amount || argv._[1]
175 | var note = argv.note || argv._[2]
176 | var dryrun = argv.dryrun || argv._[3]
177 | if (!amount || isNaN(parseFloat(amount))) {
178 | console.error("Incorrect format. Correct format is:")
179 | console.log("\tbm charge []")
180 | process.exit(1)
181 | }
182 | params = {
183 | amount: parseFloat(amount)
184 | }
185 | if (note) {params.note = note}
186 | if (dryrun) {params.dryrun = true}
187 | bm.charge(params).then(logBmResult, onErr)
188 | } else {
189 | printHelp()
190 | }
191 | } else {
192 | console.log("No ~/.bmndrrc detected... starting authentication process...")
193 | var open
194 | if (process.platform === 'linux') {
195 | open = 'xdg-open'
196 | } else if (process.platform === 'darwin') {
197 | open = 'open'
198 | }
199 |
200 | exec(open + ' https://www.beeminder.com/api/v1/auth_token.json', function () {
201 | console.log("A browser window has opened that will show you your auth_token.\nCopy that and paste it here.")
202 |
203 | prompt.start()
204 | prompt.get('auth_token', function (err, result) {
205 | if (err) {return onErr(err)}
206 | fs.writeFile(rc_path, "[account]\nauth_token: "+result.auth_token+"\n", function (errf) {
207 | if (errf) {return onErr(errf)}
208 | console.log("Successfully wrote auth_token to ~/.bmndrrc")
209 | })
210 | })
211 | })
212 | }
213 |
214 | // http://blog.npmjs.org/post/119317128765/adding-subcommands-to-your-command-line-tool
215 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const fetch = require('node-fetch')
2 | var querystring = require('querystring')
3 | const version = require('./package.json').version
4 | let useragent = `BeeminderJS/${version}`
5 | let ignoreDupes = false
6 |
7 | module.exports = function (token) {
8 | if (typeof token == "string") {
9 | token = {auth_token: token}
10 | }
11 | var host = 'https://www.beeminder.com/api/v1'
12 | var self = this
13 | var tokenString = querystring.stringify(token) + "&"
14 |
15 | this.getUserWithParams = function (params) {
16 | return self.callApi('/users/me.json', params || null, 'GET')
17 | }
18 |
19 | this.getUser = function () {
20 | return self.getUserWithParams()
21 | }
22 |
23 | this.getUserOneDatapoint = function () {
24 | return self.getUserWithParams({
25 | associations: true,
26 | datapoints_count: 1,
27 | })
28 | }
29 |
30 | this.getUserSkinny = function () {
31 | return self.getUserWithParams({
32 | diff_since: 0,
33 | skinny: true,
34 | })
35 | }
36 |
37 | this.getStatus = async function () {
38 | const user = await self.getUserSkinny()
39 | const goals = user.goals
40 | goals.sort((a, b) => a.losedate - b.losedate)
41 | const simplegoals = []
42 | for (let i in goals) {
43 | const goal = goals[i]
44 | let derailsecs = goal.losedate - Math.ceil(Date.now()/1000)
45 | const deraildays = Math.floor(derailsecs/(60*60*24))
46 | derailsecs %= (60*60*24)
47 | const derailhours = Math.floor(derailsecs/(60*60))
48 | derailsecs %= (60*60)
49 | const derailmins = Math.floor(derailsecs/60)
50 | derailsecs %= 60
51 | const derailtime = goal.limsum.replace(" 0 days", " " +
52 | (derailhours ? derailhours + " hours" :
53 | (derailmins ? derailmins + " mins" :
54 | derailsecs + " secs")))
55 | simplegoals.push({
56 | title: goal.title,
57 | slug: goal.slug,
58 | delta_text: goal.delta_text,
59 | next_delta: (goal.limsum || '').split(' ')[0],
60 | losedate: goal.losedate,
61 | autodata: goal.autodata,
62 | derailtime: derailtime,
63 | lastvalue: goal.last_datapoint && goal.last_datapoint.value,
64 | })
65 | }
66 | return {username: user.username, goals: simplegoals}
67 | }
68 |
69 | this.getGoal = function (slug) {
70 | const path = '/users/me/goals/'+slug+'.json'
71 | return self.callApi(path, null, 'GET')
72 | }
73 |
74 | /** slug is kept as a top level param to be more consistent with
75 | * the other methods
76 | * params = {
77 | * title (string)
78 | * goal_type (string)
79 | * goaldate (number or null)
80 | * goalval (number or null)
81 | * rate (number or null)
82 | * initval (number): Initial value for today’s date. Default: 0.
83 | * [panic] (number)
84 | * [secret] (boolean)
85 | * [datapublic] (boolean)
86 | * dryrun (boolean). Pass this to test the endpoint without actually creating a goal. Defaults to false.
87 | * Exactly two out of three of goaldate, goalval, and rate are required.
88 | * }
89 | */
90 | this.createGoal = async function (slug, params) {
91 | const path = '/users/me/goals.json'
92 | let n = 0
93 | if (params.goaldate) {n++}
94 | if (params.goalval) {n++}
95 | if (params.rate) {n++}
96 | if (n !== 2) {
97 | throw {err: 'Invalid input. Required: 2 of [goaldate, goalval, rate]. Provided: ' + n}
98 | }
99 | if (!params.slug) {
100 | params.slug = slug
101 | }
102 | return self.callApi(path, params, 'POST')
103 | }
104 |
105 | this.getDatapoints = function (slug) {
106 | const path = '/users/me/goals/'+slug+'/datapoints.json'
107 | return self.callApi(path, null, 'GET')
108 | }
109 |
110 | /** params = {
111 | * value: {type: Number, required: true},
112 | * timestamp: {type: Number, default: now},
113 | * comment: {type: String, default: ''},
114 | * sendmail: {type: Boolean, default: false},
115 | * requestid: {type: String.alphanumeric},
116 | * }
117 | */
118 | this.createDatapoint = function (slug, params) {
119 | const path = '/users/me/goals/'+slug+'/datapoints.json'
120 | return self.callApi(path, params, 'POST')
121 | }
122 |
123 | /** datapoints: Array of Objects containing the same keys as for `createDatapoint`
124 | */
125 | this.createDatapoints = function (slug, datapoints) {
126 | const path = '/users/me/goals/'+slug+'/datapoints/create_all.json'
127 | return self.callApi(path, {datapoints: JSON.stringify(datapoints)}, 'POST')
128 | }
129 |
130 | /** params = {
131 | * value: {type: Number, required: true},
132 | * timestamp: {type: Number, default: now},
133 | * comment: {type: String, default: ''},
134 | * sendmail: {type: Boolean, default: false},
135 | * requestid: {type: String.alphanumeric, required: true}, // required for update & upsert
136 | * }
137 | */
138 | this.updateDatapoint = function (slug, params) {
139 | const path = '/users/me/goals/'+slug+'/datapoints/'+params.requestid+'.json'
140 | return self.callApi(path, params, 'PUT')
141 | }
142 |
143 | /** params = {
144 | * amount: Number, // in USD
145 | * [note]: String, // An explanation of why the charge was made.
146 | * [dryrun]: Boolean, // (if true, JSON returned as normal but no actual charge)
147 | * }
148 | */
149 | this.charge = function (params) {
150 | const path = '/charges.json'
151 | return self.callApi(path, params, 'POST')
152 | }
153 |
154 | this.callApi = async function (path, obj, method) {
155 | const query = obj ? querystring.stringify(obj) : ''
156 | // const url = host + '/nope' + path + "?" + tokenString + query
157 | const url = host + path + "?" + tokenString + query
158 | const details = method == 'GET' ? {headers: {'User-Agent': useragent}} : {
159 | method: method,
160 | body: obj ? JSON.stringify(obj) : undefined,
161 | headers: {
162 | 'Content-Type': 'application/json',
163 | 'User-Agent': useragent,
164 | },
165 | }
166 | let error
167 | const result = await fetch(url, details).catch(err => {
168 | details.url = url
169 | error = {
170 | name: 'Network error. Either beeminder.js is offline or the Beeminder API is down.',
171 | status: 0,
172 | request: details,
173 | }
174 | throw error
175 | })
176 | details.url = url
177 | const resultText = await result.text()
178 | let resultJson
179 | try {
180 | resultJson = JSON.parse(resultText)
181 | } catch (err) {
182 | error = {
183 | name: 'Non-JSON response received. Beeminder is probably down.',
184 | status: 503,
185 | message: resultText,
186 | request: details,
187 | }
188 | throw error
189 | }
190 | if (result.status == 422 && ignoreDupes) { // duplicate request
191 | result.status = 200
192 | } else if (result.status > 300) {
193 | error = {
194 | name: 'Some unknown error; treat as Beeminder probably down.',
195 | status: result.status,
196 | message: resultJson,
197 | }
198 | } else if (result.error) {
199 | error = result.error
200 | }
201 | if (!error) {
202 | return resultJson
203 | } else {
204 | error.request = details
205 | throw error
206 | }
207 | }
208 | return this
209 | }
210 | module.exports.printLogo = require('./asciilogo')
211 | module.exports.appendToUserAgent = function (ua) {
212 | useragent += ' ' + ua
213 | }
214 | module.exports.setIgnoreDupes = function (now=true) {
215 | ignoreDupes = now
216 | }
217 |
218 |
219 | /* new offline error
220 |
221 | FetchError: request to https://www.beeminder.com/api/v1/users/me/goals/pushups/datapoints.json?auth_token=TOKEN&value=10 failed, reason: getaddrinfo EAI_AGAIN www.beeminder.com
222 | at ClientRequest. (/home/malcolm/dev/beeminderjs/node_modules/node-fetch/lib/index.js:1491:11)
223 | at ClientRequest.emit (node:events:390:28)
224 | at TLSSocket.socketErrorListener (node:_http_client:447:9)
225 | at TLSSocket.emit (node:events:390:28)
226 | at emitErrorNT (node:internal/streams/destroy:157:8)
227 | at emitErrorCloseNT (node:internal/streams/destroy:122:3)
228 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
229 | type: 'system',
230 | errno: 'EAI_AGAIN',
231 | code: 'EAI_AGAIN'
232 | }
233 |
234 |
235 | */
236 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "beeminder",
3 | "version": "2.0.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "beeminder",
9 | "version": "2.0.0",
10 | "license": "GPL-2.0",
11 | "dependencies": {
12 | "minimist": "^1.1.0",
13 | "node-fetch": "^2.6.1",
14 | "prompt": "^1.2.1"
15 | },
16 | "bin": {
17 | "bm": "bm.js"
18 | }
19 | },
20 | "node_modules/async": {
21 | "version": "0.9.2",
22 | "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
23 | "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
24 | },
25 | "node_modules/colors": {
26 | "version": "1.4.0",
27 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
28 | "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
29 | "engines": {
30 | "node": ">=0.1.90"
31 | }
32 | },
33 | "node_modules/cycle": {
34 | "version": "1.0.3",
35 | "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
36 | "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=",
37 | "engines": {
38 | "node": ">=0.4.0"
39 | }
40 | },
41 | "node_modules/eyes": {
42 | "version": "0.1.8",
43 | "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
44 | "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=",
45 | "engines": {
46 | "node": "> 0.1.90"
47 | }
48 | },
49 | "node_modules/isstream": {
50 | "version": "0.1.2",
51 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
52 | "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
53 | },
54 | "node_modules/minimist": {
55 | "version": "1.2.8",
56 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
57 | "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
58 | "funding": {
59 | "url": "https://github.com/sponsors/ljharb"
60 | }
61 | },
62 | "node_modules/mute-stream": {
63 | "version": "0.0.8",
64 | "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
65 | "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
66 | },
67 | "node_modules/node-fetch": {
68 | "version": "2.6.7",
69 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
70 | "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
71 | "dependencies": {
72 | "whatwg-url": "^5.0.0"
73 | },
74 | "engines": {
75 | "node": "4.x || >=6.0.0"
76 | },
77 | "peerDependencies": {
78 | "encoding": "^0.1.0"
79 | },
80 | "peerDependenciesMeta": {
81 | "encoding": {
82 | "optional": true
83 | }
84 | }
85 | },
86 | "node_modules/prompt": {
87 | "version": "1.2.1",
88 | "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.2.1.tgz",
89 | "integrity": "sha512-B4+2QeNDn5Cdp4kK2iOwV8qvrWpiPKlZKI9ZKkPl0C9KgeMW6DyWWqhqHiFq9vZf6zTniv+rYalK0ZlgktSwiw==",
90 | "dependencies": {
91 | "async": "~0.9.0",
92 | "colors": "1.4.0",
93 | "read": "1.0.x",
94 | "revalidator": "0.1.x",
95 | "winston": "2.x"
96 | },
97 | "engines": {
98 | "node": ">= 0.6.6"
99 | }
100 | },
101 | "node_modules/read": {
102 | "version": "1.0.7",
103 | "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
104 | "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
105 | "dependencies": {
106 | "mute-stream": "~0.0.4"
107 | },
108 | "engines": {
109 | "node": ">=0.8"
110 | }
111 | },
112 | "node_modules/revalidator": {
113 | "version": "0.1.8",
114 | "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
115 | "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs=",
116 | "engines": {
117 | "node": ">= 0.4.0"
118 | }
119 | },
120 | "node_modules/stack-trace": {
121 | "version": "0.0.10",
122 | "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
123 | "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=",
124 | "engines": {
125 | "node": "*"
126 | }
127 | },
128 | "node_modules/tr46": {
129 | "version": "0.0.3",
130 | "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
131 | "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
132 | },
133 | "node_modules/webidl-conversions": {
134 | "version": "3.0.1",
135 | "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
136 | "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
137 | },
138 | "node_modules/whatwg-url": {
139 | "version": "5.0.0",
140 | "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
141 | "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
142 | "dependencies": {
143 | "tr46": "~0.0.3",
144 | "webidl-conversions": "^3.0.0"
145 | }
146 | },
147 | "node_modules/winston": {
148 | "version": "2.4.5",
149 | "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz",
150 | "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==",
151 | "dependencies": {
152 | "async": "~1.0.0",
153 | "colors": "1.0.x",
154 | "cycle": "1.0.x",
155 | "eyes": "0.1.x",
156 | "isstream": "0.1.x",
157 | "stack-trace": "0.0.x"
158 | },
159 | "engines": {
160 | "node": ">= 0.10.0"
161 | }
162 | },
163 | "node_modules/winston/node_modules/async": {
164 | "version": "1.0.0",
165 | "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
166 | "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
167 | },
168 | "node_modules/winston/node_modules/colors": {
169 | "version": "1.0.3",
170 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
171 | "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=",
172 | "engines": {
173 | "node": ">=0.1.90"
174 | }
175 | }
176 | },
177 | "dependencies": {
178 | "async": {
179 | "version": "0.9.2",
180 | "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
181 | "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
182 | },
183 | "colors": {
184 | "version": "1.4.0",
185 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
186 | "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
187 | },
188 | "cycle": {
189 | "version": "1.0.3",
190 | "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
191 | "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
192 | },
193 | "eyes": {
194 | "version": "0.1.8",
195 | "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
196 | "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
197 | },
198 | "isstream": {
199 | "version": "0.1.2",
200 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
201 | "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
202 | },
203 | "minimist": {
204 | "version": "1.2.8",
205 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
206 | "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="
207 | },
208 | "mute-stream": {
209 | "version": "0.0.8",
210 | "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
211 | "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
212 | },
213 | "node-fetch": {
214 | "version": "2.6.7",
215 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
216 | "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
217 | "requires": {
218 | "whatwg-url": "^5.0.0"
219 | }
220 | },
221 | "prompt": {
222 | "version": "1.2.1",
223 | "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.2.1.tgz",
224 | "integrity": "sha512-B4+2QeNDn5Cdp4kK2iOwV8qvrWpiPKlZKI9ZKkPl0C9KgeMW6DyWWqhqHiFq9vZf6zTniv+rYalK0ZlgktSwiw==",
225 | "requires": {
226 | "async": "~0.9.0",
227 | "colors": "1.4.0",
228 | "read": "1.0.x",
229 | "revalidator": "0.1.x",
230 | "winston": "2.x"
231 | }
232 | },
233 | "read": {
234 | "version": "1.0.7",
235 | "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
236 | "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
237 | "requires": {
238 | "mute-stream": "~0.0.4"
239 | }
240 | },
241 | "revalidator": {
242 | "version": "0.1.8",
243 | "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
244 | "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs="
245 | },
246 | "stack-trace": {
247 | "version": "0.0.10",
248 | "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
249 | "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
250 | },
251 | "tr46": {
252 | "version": "0.0.3",
253 | "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
254 | "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
255 | },
256 | "webidl-conversions": {
257 | "version": "3.0.1",
258 | "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
259 | "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
260 | },
261 | "whatwg-url": {
262 | "version": "5.0.0",
263 | "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
264 | "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
265 | "requires": {
266 | "tr46": "~0.0.3",
267 | "webidl-conversions": "^3.0.0"
268 | }
269 | },
270 | "winston": {
271 | "version": "2.4.5",
272 | "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz",
273 | "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==",
274 | "requires": {
275 | "async": "~1.0.0",
276 | "colors": "1.0.x",
277 | "cycle": "1.0.x",
278 | "eyes": "0.1.x",
279 | "isstream": "0.1.x",
280 | "stack-trace": "0.0.x"
281 | },
282 | "dependencies": {
283 | "async": {
284 | "version": "1.0.0",
285 | "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
286 | "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
287 | },
288 | "colors": {
289 | "version": "1.0.3",
290 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
291 | "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
292 | }
293 | }
294 | }
295 | }
296 | }
297 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "beeminder",
3 | "version": "2.0.1",
4 | "description": "NodeJS wrapper for the Beeminder API",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/malcolmocean/beeminderjs.git"
12 | },
13 | "keywords": [
14 | "beeminder",
15 | "beeminderjs",
16 | "api"
17 | ],
18 | "author": "Malcolm Ocean (http://malcolmocean.com/)",
19 | "license": "GPL-2.0",
20 | "bugs": {
21 | "url": "https://github.com/malcolmocean/beeminderjs/issues"
22 | },
23 | "dependencies": {
24 | "minimist": "^1.1.0",
25 | "node-fetch": "^2.6.1",
26 | "prompt": "^1.2.1"
27 | },
28 | "bin": {
29 | "bm": "bm.js"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/testwilio.js:
--------------------------------------------------------------------------------
1 | var curl = require('curlrequest');
2 | var querystring = require('querystring');
3 |
4 | var obj = {
5 | From: "+12267506789",
6 | Body: "LOOK AT MAH BODY"
7 | }
8 | var data = obj ? querystring.stringify(obj) : '';
9 | var req = {
10 | url: 'http://localhost:5000/twilio/sms' + "?" + data,
11 | method: 'POST',
12 | };
13 | curl.request(req, function (err, result) {
14 | console.log("err", err);
15 | console.log("result", result);
16 | });
17 |
--------------------------------------------------------------------------------