Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Send Yo with text using Yo API v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ymyzk committed Nov 30, 2015
1 parent e3bd312 commit 3effe3a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions channels/backends/yo.py
Expand Up @@ -22,6 +22,10 @@ def send(self, message, fail_silently=False, options=None):
if self.username is not None:
payload["username"] = self.username

if message is not None:
# 30 characters max
payload["text"] = message

self._set_payload_from_options(payload, options, "yo", [
"username", "link", "location"])

Expand Down
20 changes: 17 additions & 3 deletions docs/source/backends/yo.rst
Expand Up @@ -24,6 +24,18 @@ You can obtain an API token from `Yo Dashboard`_.
}
}
Text
----
You can send Yo with text (30 characters max) with Yo API v2.0.

.. code-block:: python
import channels
# Yo with text
self.channel.send("text")
Options
-------
You can send Yo Location or Yo Link by specifying options. For example:
Expand All @@ -32,13 +44,15 @@ You can send Yo Location or Yo Link by specifying options. For example:
import channels
self.channel.send("Yo Link", options={
# Yo Link
self.channel.send(None, options={
"yo": {
"link": "http://docs.justyo.co/v1.0/docs/yo"
}
})
self.channel.send("Yo Location", options={
# Yo Location
self.channel.send(None, options={
"yo": {
"location": "35.0261581,135.7818476"
}
Expand All @@ -47,5 +61,5 @@ You can send Yo Location or Yo Link by specifying options. For example:
Please note that you can only send link or location, but not both.

.. _Yo: https://www.justyo.co
.. _API: http://docs.justyo.co/v1.0/docs/yo
.. _API: http://docs.justyo.co/v2.0/docs/yo
.. _Yo Dashboard: https://dev.justyo.co
16 changes: 11 additions & 5 deletions tests/tests/backends/test_yo.py
Expand Up @@ -26,12 +26,18 @@ def test_send(self, m):
response.status_code = requests.codes.ok
m.return_value = response

self.channel.send("Just Yo")
# Just Yo
self.channel.send(None)

self.channel.send("Yo Link", options={
# Yo with text
self.channel.send("🍣")

# Yo Link
self.channel.send(None, options={
"yo": {"link": "http://docs.justyo.co/v1.0/docs/yo"}})

self.channel.send("Yo Location", options={
# Yo Location
self.channel.send(None, options={
"yo": {"location": "35.0261581,135.7818476"}})

@mock.patch("requests.post")
Expand All @@ -41,6 +47,6 @@ def test_send_fail(self, m):
m.return_value = response

with self.assertRaises(HttpError):
self.channel.send("Yo", fail_silently=False)
self.channel.send(None, fail_silently=False)

self.channel.send("Yo", fail_silently=True)
self.channel.send(None, fail_silently=True)

0 comments on commit 3effe3a

Please sign in to comment.