jimson 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.6.0 / 2012-03-14
2
+
3
+ * Minor enhancements
4
+
5
+ * Add ability to pass options to Rack and RestClient
6
+
1
7
  == 0.5.0 / 2012-03-06
2
8
 
3
9
  * Major enhancements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/lib/jimson/client.rb CHANGED
@@ -12,10 +12,12 @@ module Jimson
12
12
  rand(10**12)
13
13
  end
14
14
 
15
- def initialize(url)
15
+ def initialize(url, opts={})
16
16
  @url = url
17
17
  URI.parse(@url) # for the sake of validating the url
18
18
  @batch = []
19
+ @opts = opts
20
+ @opts[:content_type] = 'application/json'
19
21
  end
20
22
 
21
23
  def process_call(sym, args)
@@ -41,7 +43,7 @@ module Jimson
41
43
  'params' => args,
42
44
  'id' => self.class.make_id
43
45
  })
44
- resp = RestClient.post(@url, post_data, :content_type => 'application/json')
46
+ resp = RestClient.post(@url, post_data, @opts)
45
47
  if resp.nil? || resp.body.nil? || resp.body.empty?
46
48
  raise Client::Error::InvalidResponse.new
47
49
  end
@@ -51,7 +53,7 @@ module Jimson
51
53
 
52
54
  def send_batch_request(batch)
53
55
  post_data = MultiJson.encode(batch)
54
- resp = RestClient.post(@url, post_data, :content_type => 'application/json')
56
+ resp = RestClient.post(@url, post_data, @opts)
55
57
  if resp.nil? || resp.body.nil? || resp.body.empty?
56
58
  raise Client::Error::InvalidResponse.new
57
59
  end
@@ -152,8 +154,8 @@ module Jimson
152
154
  helper.send_batch
153
155
  end
154
156
 
155
- def initialize(url)
156
- @helper = ClientHelper.new(url)
157
+ def initialize(url, opts={})
158
+ @helper = ClientHelper.new(url, opts)
157
159
  end
158
160
 
159
161
  def method_missing(sym, *args, &block)
data/lib/jimson/server.rb CHANGED
@@ -26,7 +26,7 @@ module Jimson
26
26
 
27
27
  JSON_RPC_VERSION = '2.0'
28
28
 
29
- attr_accessor :handler, :host, :port
29
+ attr_accessor :handler, :host, :port, :opts
30
30
 
31
31
  #
32
32
  # +handler+ is an instance of the class to expose as a JSON-RPC server
@@ -36,23 +36,24 @@ module Jimson
36
36
  # * :port - the port to listen on
37
37
  # * :server - the rack handler to use, e.g. 'webrick' or 'thin'
38
38
  #
39
+ # Remaining options are forwarded to the underlying Rack server.
40
+ #
39
41
  def initialize(handler, opts = {})
40
42
  @handler = handler
41
- @host = opts[:host] || '0.0.0.0'
42
- @port = opts[:port] || 8999
43
- @server = opts[:server] || 'webrick'
43
+ @host = opts.delete(:host) || '0.0.0.0'
44
+ @port = opts.delete(:port) || 8999
45
+ @opts = opts
44
46
  end
45
47
 
46
48
  #
47
49
  # Starts the server so it can process requests
48
50
  #
49
51
  def start
50
- Rack::Server.start(
51
- :server => @server,
52
+ Rack::Server.start(opts.merge(
52
53
  :app => self,
53
54
  :Host => @host,
54
55
  :Port => @port
55
- )
56
+ ))
56
57
  end
57
58
 
58
59
  #
data/spec/client_spec.rb CHANGED
@@ -65,6 +65,14 @@ module Jimson
65
65
  client = Client.new(SPEC_URL)
66
66
  client.foo(1,2,3).should == 42
67
67
  end
68
+
69
+ it "sends a valid JSON-RPC request with custom options" do
70
+ response = MultiJson.encode(BOILERPLATE.merge({'result' => 42}))
71
+ RestClient.should_receive(:post).with(SPEC_URL, @expected, {:content_type => 'application/json', :timeout => 10000}).and_return(@resp_mock)
72
+ @resp_mock.should_receive(:body).at_least(:once).and_return(response)
73
+ client = Client.new(SPEC_URL, :timeout => 10000)
74
+ client.foo(1,2,3).should == 42
75
+ end
68
76
  end
69
77
  end
70
78
 
data/spec/server_spec.rb CHANGED
@@ -42,7 +42,7 @@ module Jimson
42
42
  'id' => nil
43
43
  }
44
44
  def app
45
- Server.new(TestHandler.new)
45
+ Server.new(TestHandler.new, :environment => "production")
46
46
  end
47
47
 
48
48
  def post_json(hash)
@@ -53,6 +53,10 @@ module Jimson
53
53
  @url = SPEC_URL
54
54
  end
55
55
 
56
+ it "exposes the given options" do
57
+ app.opts.should == { :environment => "production" }
58
+ end
59
+
56
60
  describe "receiving a request with positional parameters" do
57
61
  context "when no errors occur" do
58
62
  it "returns a response with 'result'" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000Z
12
+ date: 2012-03-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blankslate
16
- requirement: &12957520 !ruby/object:Gem::Requirement
16
+ requirement: &18659080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.1.2.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12957520
24
+ version_requirements: *18659080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &12956740 !ruby/object:Gem::Requirement
27
+ requirement: &18658140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12956740
35
+ version_requirements: *18658140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &12955960 !ruby/object:Gem::Requirement
38
+ requirement: &18657580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *12955960
46
+ version_requirements: *18657580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack
49
- requirement: &12955120 !ruby/object:Gem::Requirement
49
+ requirement: &18656860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '1.3'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *12955120
57
+ version_requirements: *18656860
58
58
  description:
59
59
  email:
60
60
  executables: []