Commit graph

66 commits

Author SHA1 Message Date
Sampriti Panda 16b1be15c0 urls: Move /messages/render to POST endpoint 2017-01-13 16:11:51 -08:00
Rafid Aslam 229471c70f Change error handling in get_subscribers() in Zulip API client.
Fixes #3281.
2017-01-13 07:14:50 -08:00
Rafid Aslam 6972ce61c8 Move endpoints to use stream_id instead of stream_name in their URLs
- Change `stream_name` into `stream_id` on some API endpoints that use
`stream_name` in their URLs to prevent confusion of `views` selection.

For example:
If the stream name is "foo/members", the URL would be trigger
"^streams/(?P<stream_name>.*)/members$" and it would be confusing because
we intend to use the endpoint with "^streams/(?P<stream_name>.*)$" regex.

All stream-related endpoints now use stream id instead of stream name,
except for a single endpoint that lets you convert stream names to stream ids.

See https://github.com/zulip/zulip/issues/2930#issuecomment-269576231

- Add `get_stream_id()` method to Zulip API client, and change
`get_subscribers()` method to comply with the new stream API
(replace `stream_name` with `stream_id`).

Fixes #2930.
2017-01-12 15:23:31 -08:00
Yago González cb6ae09bc8 api: Support file uploads to the API.
Now, the `Client.do_api_query()` method supports sending files to the
API.

This has allowed the implementation of a new method,
`Client.upload_file(file)`.  It simply uploads the file set in the
parameter, and returns the API's response (that includes the URI).

Despite the fact that `do_api_query()` supports multiple files as
parameters, `upload_file()` doesn't, because right now the API isn't
capable of managing more than a file in the same request.
2017-01-10 17:46:00 -08:00
Jackson 630ee0be92 Clean PUT /users to POST /users 2017-01-03 15:40:00 -08:00
Rishi Gupta eb983e0bbc mypy: Convert api/ and docs/ to use typing.Text. 2016-12-26 16:11:37 -08:00
Steve Howell 14ee40bf52 Simplify, document, and fix the API code.
We used to create endpoints with Client._register.

Now we now have explicit methods for the endpoints.

This allows us to add docstrings and stricter mypy annotations.

This fix also introduces a call_endpoint() method that avoids
the need for manually building urls with API_VERSTRING when you
know the URL pattern of the endpoint you want to hit (and when
the API doesn't have a convenient wrapper).

I fixed a bug with create_users where it now uses PUT instead
of POST.

I also removed client.export(), which was just broken.

I had to change recent-messages and zulip-export, which were
using client.do_api_query and Client._register.

Now it's easier to just call client.call_endpoint() for
situations where our API doesn't have convenient wrappers,
so that's what I did with those scripts.
2016-12-21 11:22:42 -08:00
Steve Howell 0272d6abe7 Remove deprecated get_messages() API.
This also eliminates a very short script that basically
does nothing but call the long-dead API, so there's not
much to salvage there.
2016-12-13 20:33:20 -08:00
reallyly 9d6e7cfea5 pep8: Fix E128 violations.
With some line-wrapping tweaks by tabbott.
2016-12-13 10:50:14 -08:00
bulat22101 47488217b1 pep8: Fix E129 violations 2016-12-03 10:56:36 -08:00
bulat22101 dc48a41efe pep8: Fix E502 violations 2016-12-03 10:56:36 -08:00
Juan Verhook 25a8315f71 Annotate api/zulip/__init__.py.
Note that we still can't run mypy against this file and other files,
because of how the interface is dynamically created via _register.  We
will need to change that or use a stub file to make it possible to
annotate this.

This was tweaked by tabbott to fix some bugs.
2016-12-02 18:26:47 -08:00
AZtheAsian 73bd3572cf pep8: Fix E111 violations 2016-12-01 14:18:11 -08:00
Rafid Aslam 1ae8ac85d8 pep8: Fix E301 pep8 violations.
Fix "E301: expected (1 or 2) blank line" pep8 violations.
2016-11-29 08:51:44 -08:00
Rafid Aslam d4410365ea pep8: Fix E225 pep8 violations. 2016-11-28 15:21:15 -08:00
umkay cac0d1c394 api: Add default protocol for localhost.
Add default "http://" to site argument locally if it is not specified
in an api call.

This fixes a problem where if you didn't manually specify `http://`
when connecting to a development server, the API bindings would hang
trying to connect using HTTPS.
2016-11-03 18:09:26 -07:00
reyha 4cdc59a3e4 API bindings: Raise error if site param not defined.
Stops defaulting the site parameter to the now-nonexistent
https://zulip.com, and ask the user to enter the site via --site or
~/.zuliprc if not provided.

Fixes #2039.
2016-10-25 18:08:46 -07:00
Alex Dehnert ad94b57e2f Add support for client certs to the Python API.
This adds support for passing a client cert (in the format expected by the
`requests` library) to the `Client` constructor, as well as for specifying
one on the command line or in .zuliprc (through new `client_cert` and
`client_cert_key` options).
2016-07-19 14:40:26 -07:00
Taranjeet 6034ae7b9a Wrap some lines with length greater than 120.
With some tweaks by tabbott.
2016-07-06 14:35:16 -07:00
Eklavya Sharma d198eedbcd api/zulip/__init__.py: Make compatible with newer mypy. 2016-06-27 21:00:09 +05:30
Nathan Florea b2c73d5346 Changed make_request lambda to more readable function. 2016-06-03 09:17:04 -07:00
Nathan Florea 25d7e844a2 api: Remove some mutable default arguments.
This could be more succinct with a conditional expression, but this is
easier to read.
2016-06-03 09:16:52 -07:00
Eklavya Sharma 03adee4c19 Make api/zulip/__init__.py pass mypy check. 2016-05-18 17:10:17 +05:30
Eklavya Sharma 5e3013d2c2 Partially apply Python 3 libmodernize.fixes.fix_dict_six.
Refer to #256
2016-03-19 15:52:58 -07:00
Tim Abbott a8c4facc67 Switch to using Python 3 style division everywhere.
Also add testing for this to our Python 3 compatibility test suite.
2016-01-26 21:09:43 -08:00
Tim Abbott 4dc5761ce2 Switch all urllib/urlparse usage to six.moves.urllib.
This provides Python 2+3 compatibility for our use of urllib.

Also add a test to avoid future regressions.
2016-01-26 21:09:43 -08:00
Tim Abbott 91d851c448 Apply modernize transform libmodernize.fixes.fix_file.
This replaces use of file() with open() which is python 3 compatible,
and also adds it to our python 3 support test suite.
2016-01-26 21:09:42 -08:00
Tim Abbott 9db342950e Release API version 0.2.5. 2016-01-23 11:38:47 -08:00
Tim Abbott 48f2caf12c Apply Python 3 futurize transform libmodernize.fixes.fix_unicode_type. 2015-11-01 09:35:06 -08:00
Tim Abbott 239d080616 Apply Python 3 futurize transform libmodernize.fixes.fix_imports_six. 2015-11-01 09:26:16 -08:00
Tim Abbott 328816a329 Apply Python 3 futurize transform libfuturize.fixes.fix_print_with_import. 2015-11-01 09:26:16 -08:00
Tim Abbott a49e641719 Apply Python 3 futurize transform lib2to3.fixes.fix_funcattrs. 2015-11-01 08:09:54 -08:00
Shane Kearns 2f573bbb10 python api: allow control over the server certificate verification
The --insecure option ("insecure=true" in .zuliprc) disables
verification entirely, similar to other tools like curl.

The --cert_bundle ("cert_bundle=<file>" in .zuliprc) allows
a file to be specified containing the CA certificates to verify
against.
When using self-signed certificates, the server's public key
can be used as the only cerificate in the file.

This change incidentally fixes an issue where the "site" parameter
in .zuliprc was ignored when specifying --user and --api-key on
the command line.

Fixes: #104
2015-10-31 21:20:34 -07:00
Tim Abbott 41c2b62da0 Fix a bunch of Zulip Voyager related comments.
(imported from commit 176e875cbc310ba00d6137930ddb718bd68f1866)
2015-08-21 10:40:54 -07:00
David Roe 3d7c94c1a8 Enterprise => Voyager.
(imported from commit 41b9a67301aeaf5fd40bbbb8f34a326ca98431fd)
2015-08-21 10:33:35 -07:00
Jonathan Dahan ddd6ee9988 Add GET /export endpoint, which dumps important tables in json.
Meant to be used in tandem with the manage.py import command.
The following sensitive data is scrubbed:

  * user api keys
  * user password hashes
  * stream email keys
  * invite-only streams
  * messages from invite-only streams
  * messages from users from other domains

(imported from commit 8e58dcdcb80ef1c7127d3ab15accf40c6187633f)
2015-08-19 15:31:08 -07:00
Zev Benjamin 8694b14016 Handle platform.system() throwing an IOError
This can happen if the calling process is handling SIGCHLD.  See
http://bugs.python.org/issue9127

We ran into this in the zephyr_mirror.

(imported from commit 80fade2274714b7c2c4b9fe38c66a1db8cc63234)
2014-05-20 17:29:29 -07:00
Jason Michalski 502f184ee7 Add missing logger
(imported from commit e27d78f04fb8cb60b0cbdf4a544a047265abf9d5)
2014-04-28 19:51:04 -04:00
Zev Benjamin 4e02777aaa api: Add an option to backoff classes for making the passage of time count as a success
The idea here is that for usages like in the zephyr mirror bot:

  backoff = RandomExponentialBackoff()
  while backoff.keep_going():
      print "Starting zephyr mirroring bot"
      try:
          subprocess.call(args)
      except:
          traceback.print_exc()
      backoff.fail()

we want it to be the case that the mirror bot running for a while counts as a
success so that the bot doesn't have a finite number of crashes over its entire
lifetime.  We only want the mirror bot to stop retrying if it fails too many
times in a row.

(imported from commit 7b10704d3ce9a5ffb3472cbb4dfa168c9c05ae7a)
2014-04-23 11:31:04 -07:00
Zev Benjamin 41a782e011 Move backoff classes to the Zulip API
(imported from commit 76c5d499874f0397c505ab3fcda631a1a46847b6)
2014-04-23 11:31:03 -07:00
Zev Benjamin de1432aedc api: Expose function for getting the default Zulip config file
(imported from commit 89d6b48f9393670429aa960ad0ff27f030166e34)
2014-03-03 17:30:58 -05:00
Zev Benjamin 2045b73ea4 api: Add get_subscribers method
(imported from commit 801021768431a04cfecf146b58f4d118e1dc7508)
2014-03-03 17:29:54 -05:00
Zev Benjamin 4db2dab645 api: Disambiguate the names of Zulip options
(imported from commit 67525764cc2f2a26081640063e2d78852f6229ca)
2014-03-03 17:29:52 -05:00
Zev Benjamin 314f03a5bb api: Let generate_option_group prepend a prefix to added options
(imported from commit 41cdd90a83914139c92cb3ea649cb5653f56d4ca)
2014-03-03 17:29:52 -05:00
Zev Benjamin 744ca9ac72 api: Clarify that the API option group is for the Zulip API
(imported from commit e471fb60c04c4cf8d5e1ceb8cbd639dc3460fc48)
2014-03-03 17:29:52 -05:00
Jessica McKellar 0b1cd703dd Update copyright to 2014.
(imported from commit 733baed61e26be0c07a7e7a605618087df6b0866)
2014-02-04 15:51:53 -05:00
Luke Faraone cc6e16b2d1 API release 0.2.4
(imported from commit 42145c829f5bd2282b72c2658f19766cf2346a2b)
2014-01-11 15:52:21 -05:00
Tim Abbott 65e6a35f63 Add support for event queues with an included narrow.
This will allow us to substantially decrease the server-side work that
we do to support our Mirroring systems (since the personal mirrors can
request only messages that user sent) and also is what we need to
support a single-stream Zulip widget that we embed in webpages.

(imported from commit 055f2e9a523920719815181f8fdb44d3384e4a34)
2013-12-12 17:36:39 -05:00
Tim Abbott 20d36e5df8 Add admin API endpoint for creating users.
(imported from commit a8b919c7d21b28dfd75b6b95736a375874ead15f)
2013-12-10 13:21:33 -05:00
Luke Faraone edf6166898 api: Let users of init_from_options specify a default client.
This way command-line scripts that use our `optparse` populator can
still specify a custom client without munging their `parser` object.

(imported from commit df8d28a46a4d4574523b106030dbfed2d9ac931e)
2013-12-09 11:47:20 -05:00