sanford-protocol 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/sanford-protocol/request.rb +2 -0
- data/lib/sanford-protocol/response.rb +4 -3
- data/lib/sanford-protocol/response_status.rb +3 -3
- data/lib/sanford-protocol/version.rb +1 -1
- data/test/unit/request_tests.rb +4 -0
- data/test/unit/response_status_tests.rb +6 -2
- data/test/unit/response_tests.rb +10 -1
- metadata +13 -13
data/README.md
CHANGED
@@ -42,6 +42,12 @@ Requests are encoded as BSON hashes when transmitted in messages.
|
|
42
42
|
'name': 'some_service',
|
43
43
|
'params': 'something'
|
44
44
|
}
|
45
|
+
|
46
|
+
request = Sanford::Protocol::Request.parse(a_bson_request_hash)
|
47
|
+
request.version #=> "v1"
|
48
|
+
request.name #=> "some_service"
|
49
|
+
request.params #=> "something"
|
50
|
+
request.to_s #=> "[v1] some_service"
|
45
51
|
```
|
46
52
|
|
47
53
|
## Response
|
@@ -57,6 +63,16 @@ Responses are encoded as BSON hashes when transmitted in messages.
|
|
57
63
|
{ 'status': [ 200, 'The request was successful.' ]
|
58
64
|
'data': true
|
59
65
|
}
|
66
|
+
|
67
|
+
response = Sanford::Protocol::Response.parse(a_bson_response_hash)
|
68
|
+
response.status.code #=> 200
|
69
|
+
response.status.to_i #=> 200
|
70
|
+
response.status.name #=> "OK"
|
71
|
+
response.status.message #=> "The request was successful."
|
72
|
+
response.status.to_s #=> "[200, OK]"
|
73
|
+
response.code #=> 200
|
74
|
+
response.to_s #=> "[200, OK]"
|
75
|
+
response.data #=> true
|
60
76
|
```
|
61
77
|
|
62
78
|
### Status Codes
|
@@ -16,6 +16,9 @@ module Sanford::Protocol
|
|
16
16
|
super(build_status(status), data)
|
17
17
|
end
|
18
18
|
|
19
|
+
def code; status.code; end
|
20
|
+
def to_s; status.to_s; end
|
21
|
+
|
19
22
|
def to_hash
|
20
23
|
{ 'status' => [ status.code, status.message ],
|
21
24
|
'data' => data
|
@@ -24,9 +27,7 @@ module Sanford::Protocol
|
|
24
27
|
|
25
28
|
def inspect
|
26
29
|
reference = '0x0%x' % (self.object_id << 1)
|
27
|
-
"#<#{self.class}:#{reference}"
|
28
|
-
" @status=#{status.inspect}"\
|
29
|
-
" @data=#{data.inspect}>"
|
30
|
+
"#<#{self.class}:#{reference} @status=#{status} @data=#{data.inspect}>"
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
@@ -9,14 +9,14 @@ module Sanford::Protocol
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def code; code_obj.number; end
|
12
|
+
alias_method :to_i, :code
|
13
|
+
|
12
14
|
def name; code_obj.name; end
|
13
15
|
def to_s; code_obj.to_s; end
|
14
16
|
|
15
17
|
def inspect
|
16
18
|
reference = '0x0%x' % (self.object_id << 1)
|
17
|
-
"#<#{self.class}:#{reference}"
|
18
|
-
" @code=#{code_obj}"\
|
19
|
-
" @message=#{message.inspect}>"
|
19
|
+
"#<#{self.class}:#{reference} @code=#{code_obj} @message=#{message.inspect}>"
|
20
20
|
end
|
21
21
|
|
22
22
|
class Code < Struct.new(:number, :name)
|
data/test/unit/request_tests.rb
CHANGED
@@ -13,6 +13,10 @@ class Sanford::Protocol::Request
|
|
13
13
|
should have_instance_methods :version, :name, :params, :to_hash, :valid?
|
14
14
|
should have_class_methods :parse
|
15
15
|
|
16
|
+
should "return it's version and name with #to_s" do
|
17
|
+
assert_equal "[#{subject.version}] #{subject.name}", subject.to_s
|
18
|
+
end
|
19
|
+
|
16
20
|
should "return an instance of a Sanford::Protocol::Request given a hash using #parse" do
|
17
21
|
# using BSON messages are hashes
|
18
22
|
hash = {
|
@@ -11,7 +11,7 @@ class Sanford::Protocol::ResponseStatus
|
|
11
11
|
subject{ @status }
|
12
12
|
|
13
13
|
should have_readers :code_obj, :message
|
14
|
-
should have_instance_methods :code, :name
|
14
|
+
should have_instance_methods :code, :name, :to_i
|
15
15
|
|
16
16
|
should "know it's code name" do
|
17
17
|
named = Sanford::Protocol::ResponseStatus.new(200)
|
@@ -21,7 +21,7 @@ class Sanford::Protocol::ResponseStatus
|
|
21
21
|
assert_equal nil, unamed.name
|
22
22
|
end
|
23
23
|
|
24
|
-
should "know it's code
|
24
|
+
should "know it's code number" do
|
25
25
|
Code::NUMBERS.each do |name, value|
|
26
26
|
status = Sanford::Protocol::ResponseStatus.new(name)
|
27
27
|
assert_equal value, status.code
|
@@ -31,6 +31,10 @@ class Sanford::Protocol::ResponseStatus
|
|
31
31
|
assert_equal 0, unamed.code
|
32
32
|
end
|
33
33
|
|
34
|
+
should "return it's code number with #to_i" do
|
35
|
+
assert_equal subject.code, subject.to_i
|
36
|
+
end
|
37
|
+
|
34
38
|
should "return it's code number and code name with #to_s" do
|
35
39
|
named = Sanford::Protocol::ResponseStatus.new(200)
|
36
40
|
unamed = Sanford::Protocol::ResponseStatus.new(999)
|
data/test/unit/response_tests.rb
CHANGED
@@ -10,9 +10,17 @@ class Sanford::Protocol::Response
|
|
10
10
|
end
|
11
11
|
subject{ @response }
|
12
12
|
|
13
|
-
should have_instance_methods :status, :data, :to_hash
|
13
|
+
should have_instance_methods :status, :code, :data, :to_hash, :to_s
|
14
14
|
should have_class_methods :parse
|
15
15
|
|
16
|
+
should "return its status#code with #code" do
|
17
|
+
assert_equal subject.status.code, subject.code
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return its status#to_s with #to_s" do
|
21
|
+
assert_equal subject.status.to_s, subject.to_s
|
22
|
+
end
|
23
|
+
|
16
24
|
should "return an instance of a Sanford::Protocol::Response given a hash using #parse" do
|
17
25
|
# using BSON messages are hashes
|
18
26
|
hash = {
|
@@ -36,6 +44,7 @@ class Sanford::Protocol::Response
|
|
36
44
|
|
37
45
|
assert_equal expected, subject.to_hash
|
38
46
|
end
|
47
|
+
|
39
48
|
end
|
40
49
|
|
41
50
|
# Somewhat of a system test, want to make sure if Response is passed some
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanford-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Collin Redding
|
@@ -19,7 +19,7 @@ cert_chain: []
|
|
19
19
|
date: 2012-11-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: bson
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -30,11 +30,11 @@ dependencies:
|
|
30
30
|
- 1
|
31
31
|
- 7
|
32
32
|
version: "1.7"
|
33
|
-
requirement: *id001
|
34
|
-
name: bson
|
35
33
|
type: :runtime
|
36
|
-
|
34
|
+
requirement: *id001
|
37
35
|
prerelease: false
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: assert
|
38
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
@@ -45,11 +45,11 @@ dependencies:
|
|
45
45
|
- 0
|
46
46
|
- 8
|
47
47
|
version: "0.8"
|
48
|
-
requirement: *id002
|
49
|
-
name: assert
|
50
48
|
type: :development
|
51
|
-
|
49
|
+
requirement: *id002
|
52
50
|
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: assert-mocha
|
53
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
@@ -60,9 +60,9 @@ dependencies:
|
|
60
60
|
- 0
|
61
61
|
- 1
|
62
62
|
version: "0.1"
|
63
|
-
requirement: *id003
|
64
|
-
name: assert-mocha
|
65
63
|
type: :development
|
64
|
+
requirement: *id003
|
65
|
+
prerelease: false
|
66
66
|
description: Ruby implementation of Sanford's communication protocol.
|
67
67
|
email:
|
68
68
|
- collin.redding@me.com
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
requirements: []
|
128
128
|
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.24
|
131
131
|
signing_key:
|
132
132
|
specification_version: 3
|
133
133
|
summary: Ruby implementation of Sanford's communication protocol.
|