sanford-protocol 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,20 +33,20 @@ A request is made up of 3 required parts: the version, the name, and the params.
33
33
 
34
34
  * **version** - (string) version of the requested API.
35
35
  * **name** - (string) name of the requested API service.
36
- * **params** - (object) data for the service call - can be any BSON serializable object.
36
+ * **params** - (document) data for the service call - must be a BSON document (ruby Hash, python dict, Javascript Object).
37
37
 
38
38
  Requests are encoded as BSON hashes when transmitted in messages.
39
39
 
40
40
  ```ruby
41
- { 'version': 'v1',
42
- 'name': 'some_service',
43
- 'params': 'something'
41
+ { 'version' => 'v1',
42
+ 'name' => 'some_service',
43
+ 'params' => { 'key' => 'value' }
44
44
  }
45
45
 
46
46
  request = Sanford::Protocol::Request.parse(a_bson_request_hash)
47
47
  request.version #=> "v1"
48
48
  request.name #=> "some_service"
49
- request.params #=> "something"
49
+ request.params #=> { 'key' => 'value' }
50
50
  request.to_s #=> "[v1] some_service"
51
51
  ```
52
52
 
@@ -60,8 +60,8 @@ A response is made up of 2 parts: the status and the data.
60
60
  Responses are encoded as BSON hashes when transmitted in messages.
61
61
 
62
62
  ```ruby
63
- { 'status': [ 200, 'The request was successful.' ]
64
- 'data': true
63
+ { 'status' => [ 200, 'The request was successful.' ]
64
+ 'data' => true
65
65
  }
66
66
 
67
67
  response = Sanford::Protocol::Response.parse(a_bson_response_hash)
@@ -108,7 +108,7 @@ incoming_data = connection.read
108
108
  connection.write(outgoing_data)
109
109
  ```
110
110
 
111
- For incoming messages, it reads them off the socket, validate them, and return the decoded body data. For outgoing messages, it encodes the message body from given data, adds the appropiate message headers, and writes the message to the socket.
111
+ For incoming messages, it reads them off the socket, validates them, and returns the decoded body data. For outgoing messages, it encodes the message body from given data, adds the appropiate message headers, and writes the message to the socket.
112
112
 
113
113
  #### Timeout
114
114
 
@@ -24,6 +24,8 @@ module Sanford::Protocol
24
24
  [ false, "The request doesn't contain a version." ]
25
25
  elsif !name
26
26
  [ false, "The request doesn't contain a name." ]
27
+ elsif !params.kind_of?(Hash)
28
+ [ false, "The request's params are not a valid BSON document." ]
27
29
  else
28
30
  [ true ]
29
31
  end
@@ -1,5 +1,5 @@
1
1
  module Sanford
2
2
  module Protocol
3
- GEM_VERSION = "0.4.0"
3
+ GEM_VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ class Sanford::Protocol::Request
6
6
  class BaseTests < Assert::Context
7
7
  desc "Sanford::Protocol::Request"
8
8
  setup do
9
- @request = Sanford::Protocol::Request.new('v1', 'some_service', [ true ])
9
+ @request = Sanford::Protocol::Request.new('v1', 'some_service', { 'key' => 'value' })
10
10
  end
11
11
  subject{ @request }
12
12
 
@@ -22,7 +22,7 @@ class Sanford::Protocol::Request
22
22
  hash = {
23
23
  'name' => 'service_name',
24
24
  'version' => 'service_version',
25
- 'params' => 'service_params'
25
+ 'params' => { 'service_params' => 'yes' }
26
26
  }
27
27
  request = Sanford::Protocol::Request.parse(hash)
28
28
 
@@ -37,7 +37,7 @@ class Sanford::Protocol::Request
37
37
  expected = {
38
38
  'version' => 'v1',
39
39
  'name' => 'some_service',
40
- 'params' => [ true ]
40
+ 'params' => { 'key' => 'value' }
41
41
  }
42
42
 
43
43
  assert_equal expected, subject.to_hash
@@ -48,7 +48,7 @@ class Sanford::Protocol::Request
48
48
  desc "valid?"
49
49
 
50
50
  should "return true and no message with a valid request" do
51
- request = Sanford::Protocol::Request.new('name', 'v1', {})
51
+ request = Sanford::Protocol::Request.new('v1', 'name', {})
52
52
  is_valid, message = request.valid?
53
53
 
54
54
  assert_equal true, is_valid
@@ -70,6 +70,14 @@ class Sanford::Protocol::Request
70
70
  assert_equal false, is_valid
71
71
  assert_equal "The request doesn't contain a version.", message
72
72
  end
73
+
74
+ should "return false and a message when the params are not a Hash" do
75
+ request = Sanford::Protocol::Request.new('v1', 'name', true)
76
+ is_valid, message = request.valid?
77
+
78
+ assert_equal false, is_valid
79
+ assert_equal "The request's params are not a valid BSON document.", message
80
+ end
73
81
  end
74
82
 
75
83
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding
@@ -16,10 +16,10 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-11-15 00:00:00 Z
19
+ date: 2012-11-28 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: bson
22
+ prerelease: false
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
- type: :runtime
34
33
  requirement: *id001
35
- prerelease: false
34
+ name: bson
35
+ type: :runtime
36
36
  - !ruby/object:Gem::Dependency
37
- name: assert
37
+ prerelease: false
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
- type: :development
49
48
  requirement: *id002
50
- prerelease: false
49
+ name: assert
50
+ type: :development
51
51
  - !ruby/object:Gem::Dependency
52
- name: assert-mocha
52
+ prerelease: false
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
- type: :development
64
63
  requirement: *id003
65
- prerelease: false
64
+ name: assert-mocha
65
+ type: :development
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.24
130
+ rubygems_version: 1.8.15
131
131
  signing_key:
132
132
  specification_version: 3
133
133
  summary: Ruby implementation of Sanford's communication protocol.