fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

Change addToWatchlist() request method #10

Closed GregerLindblom closed 6 years ago

GregerLindblom commented 6 years ago

The endpoint at WATCHLISTS_ADD_PATH is expecting a PUT or DELETE request. However the current addToWatchlist() function is sending a GET request.

This PR fixes addToWatchlist() and adds removeFromWatchlist(). The WATCHLISTS_ADD_PATH is renamed WATCHLISTS_ADD_DELETE_PATH.

In order to run the tests on windows I had to add cross-env to devDependency to set NODE_ENV correctly. The USERNAME environment variable is already set on windows which dotenv doesn't override. This forced me to prefix all variables in .env.example with AVANZA_.

{ statusCode: 405,
  statusMessage: 'Request method \'GET\' not supported',
  headers:
   { date: 'Thu, 05 Oct 2017 06:35:03 GMT',
     server: 'Apache',
     allow: 'PUT, DELETE',
     'cache-control': 'must-revalidate,no-cache,no-store',
     'content-type': 'text/html;charset=iso-8859-1',
     'content-length': '352',
     connection: 'close' },
  body: '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>\n<title>Error 405 Request meth
od &apos;GET&apos; not supported</title>\n</head>\n<body><h2>HTTP ERROR 405</h2>\n<p>Problem accessing /_api/usercontent/wa
tchlist/<<AVANZA_WATCHLIST>>/orderbooks/5479. Reason:\n<pre>    Request method &apos;GET&apos; not supported</pre></p>\n</body>\n</html>
\n' }

All tests passed and docs updated.

Thank you for making this module!