jsender 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -14
- data/jsender.gemspec +1 -0
- data/lib/jsender/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0661843afe7b020404bc6a01adc660548d9b55
|
4
|
+
data.tar.gz: 84fcc7dd25a954ccd5e00f9fc7dcdb08627af972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbec52bcd8f5d0f92b67172eed08bc60161f1a351ad5334a9c564beba963b7e7af3d8d5bad8bcb2e0a84aa11e3aab7867196cb8566ff8723d7d8cec70264a302
|
7
|
+
data.tar.gz: 6a7a53dc0634d2e6c8f63cbceb41b7def6de00a4ded97ea0c3236771893fc777af1444f0d05cc0a49199b7d0e95c2e78d74fd1afa5c818f982f6816cfd662e8d
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Jsender
|
2
2
|
|
3
|
-
JSender facilitates a simple jsend implementation for ruby. You can report success, fail, success with data, fail with data. The jsend response contains 'status' and 'data'. 'data' contains what-ever you put in it, as well as a 'notifications' array. Helpers are provided to check whether a notification is present and whether a specific data key is present.
|
3
|
+
JSender facilitates a simple jsend implementation for ruby. You can report success, error, fail, success with data, fail with data. The jsend response contains 'status' and 'data'. 'data' contains what-ever you put in it, as well as a 'notifications' array. Helpers are provided to check whether a notification is present and whether a specific data key is present. On error the response contains 'message'.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -25,20 +25,41 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
class CodeClass
|
27
27
|
include Jsender
|
28
|
-
|
29
|
-
def action(code)
|
30
|
-
return success if code == 1
|
31
|
-
return success('code 2 selected') if code == 2
|
32
|
-
return success_data({ 'a' => 'A', 'b' => 'B' }) if code == 3
|
33
|
-
return success('some data for you', ['d', 'a', 't', 'a']) if code == 4
|
34
|
-
return fail('code 5 selected') if code == 5
|
35
|
-
return fail_data({ 'a' => 'A', 'b' => 'B' }) if code == 6
|
36
|
-
return fail('some errors for you', ['d', 'a', 't', 'a']) if code == 7
|
37
|
-
return error if code == 8
|
38
|
-
return error('something went wrong') if code == 9
|
39
|
-
fail
|
40
|
-
end
|
41
28
|
end
|
29
|
+
|
30
|
+
iut = CodeClass.new
|
31
|
+
iut.success
|
32
|
+
=> {"status"=>"success", "data"=>{"result"=>nil, "notifications"=>["success"]}}
|
33
|
+
|
34
|
+
iut.success('happy day')
|
35
|
+
=> {"status"=>"success", "data"=>{"result"=>nil, "notifications"=>["happy day"]}}
|
36
|
+
|
37
|
+
result = iut.success_data({ 'a' => 'A', 'b' => 'B' })
|
38
|
+
=> {"status"=>"success", "data"=>{"a"=>"A", "b"=>"B", "notifications"=>["success"]}}
|
39
|
+
iut.has_data?(result, 'b')
|
40
|
+
=> true
|
41
|
+
|
42
|
+
result = iut.success('some data for you', ['d', 'a', 't', 'a'])
|
43
|
+
=> {"status"=>"success", "data"=>{"result"=>["d", "a", "t", "a"], "notifications"=>["some data for you"]}}
|
44
|
+
iut.has_data?(result, 'result')
|
45
|
+
=> true
|
46
|
+
iut.notifications_include?(result, 'ata fo')
|
47
|
+
=> true
|
48
|
+
|
49
|
+
iut.error
|
50
|
+
=> {"status"=>"error", "message"=>nil}
|
51
|
+
|
52
|
+
iut.error('something went wrong')
|
53
|
+
=> {"status"=>"error", "message"=>"something went wrong"}
|
54
|
+
|
55
|
+
iut.fail
|
56
|
+
=> {"status"=>"fail", "data"=>{"result"=>nil, "notifications"=>["fail"]}}
|
57
|
+
|
58
|
+
iut.fail('a failure occurred')
|
59
|
+
=> {"status"=>"fail", "data"=>{"result"=>nil, "notifications"=>["a failure occurred"]}}
|
60
|
+
|
61
|
+
iut.fail('a failure occurred', ['d', 'a', 't', 'a'])
|
62
|
+
=> {"status"=>"fail", "data"=>{"result"=>["d", "a", "t", "a"], "notifications"=>["a failure occurred"]}}
|
42
63
|
```
|
43
64
|
|
44
65
|
```
|
data/jsender.gemspec
CHANGED
data/lib/jsender/version.rb
CHANGED