accept t/f for boolean in Api

and document boolean parameter formats

Change-Id: I70b295e93c6f19b471bfc6f4b31f3a7c3642d8f4
Reviewed-on: https://gerrit.instructure.com/70861
Tested-by: Jenkins
Reviewed-by: Simon Williams <simon@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2016-01-22 12:57:47 -07:00
parent 6a39d7a0c3
commit 3d6658f0ce
3 changed files with 11 additions and 4 deletions

View File

@ -17,6 +17,8 @@ All API responses are in <a href="http://www.json.org/">JSON format</a>.
All integer ids in Canvas are 64 bit integers.
All boolean parameters can be passed as true/false, t/f, yes/no, y/n, on/off, or 1/0. When using JSON format, a literal true/false is preferred, rather than as a string.
For POST and PUT requests, parameters are sent using standard
<a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4">HTML form
encoding</a> (the application/x-www-form-urlencoded content type).
@ -26,13 +28,13 @@ POST and PUT requests may also optionally be sent in <a href="http://www.json.or
As an example, this HTML form request:
```bash
name=test+name&file_ids[]=1&file_ids[]=2&sub[name]=foo&sub[message]=bar
name=test+name&file_ids[]=1&file_ids[]=2&sub[name]=foo&sub[message]=bar&flag=y
```
would translate into this JSON request:
```json
{ "name": "test name", "file_ids": [1,2], "sub": { "name": "foo", "message": "bar" } }
{ "name": "test name", "file_ids": [1,2], "sub": { "name": "foo", "message": "bar" }, "flag": true }
```
With either encoding, all timestamps are sent and returned in ISO 8601 format (UTC time zone):

View File

@ -178,8 +178,8 @@ module Canvas
def self.value_to_boolean(value)
if value.is_a?(String) || value.is_a?(Symbol)
return true if ["yes", "true", "on", "1"].include?(value.to_s.downcase)
return false if ["no", "false", "off", "0"].include?(value.to_s.downcase)
return true if ["yes", "y", "true", "t", "on", "1"].include?(value.to_s.downcase)
return false if ["no", "n", "false", "f", "off", "0"].include?(value.to_s.downcase)
end
return value if [true, false].include?(value)
return value.to_i != 0

View File

@ -24,5 +24,10 @@ describe Canvas::Plugin do
expect(Canvas::Plugin.value_to_boolean('0')).to eq false
expect(Canvas::Plugin.value_to_boolean('1')).to eq true
end
it "accepts t/f" do
expect(Canvas::Plugin.value_to_boolean('f')).to eq false
expect(Canvas::Plugin.value_to_boolean('t')).to eq true
end
end
end