tddium_client 0.1.5 → 0.2.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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tddium_client (0.1.5)
4
+ tddium_client (0.2.0)
5
5
  httparty (>= 0.8.1)
6
6
  json
7
7
 
@@ -3,5 +3,5 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
5
  module TddiumClient
6
- VERSION = "0.1.5"
6
+ VERSION = "0.2.0"
7
7
  end
data/lib/tddium_client.rb CHANGED
@@ -103,6 +103,10 @@ module TddiumClient
103
103
  end
104
104
 
105
105
  class InternalClient
106
+ include HTTParty
107
+
108
+ format :json
109
+
106
110
  def initialize(host, port=nil, scheme='https', version=1, caller_version=nil)
107
111
  @tddium_config = {"host" => host,
108
112
  "port" => port,
@@ -112,14 +116,14 @@ module TddiumClient
112
116
  end
113
117
 
114
118
  def call_api(method, api_path, params = {}, api_key = nil, retries = 5)
115
- headers = {}
119
+ headers = {'Content-Type' => 'application/json'}
116
120
  headers.merge!(API_KEY_HEADER => api_key) if api_key
117
121
  headers.merge!(CLIENT_VERSION_HEADER => version_header)
118
122
 
119
123
  tries = 0
120
124
 
121
125
  begin
122
- http = HTTParty.send(method, tddium_uri(api_path), :body => params, :headers => headers)
126
+ http = self.class.send(method, tddium_uri(api_path), :body => params.to_json, :headers => headers)
123
127
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Timeout::Error, OpenSSL::SSL::SSLError, OpenSSL::SSL::Session::SessionError
124
128
  tries += 1
125
129
  retry if retries > 0 && tries <= retries
@@ -177,6 +181,10 @@ module TddiumClient
177
181
  @environment = env
178
182
  end
179
183
 
184
+ def host
185
+ @tddium_config["host"]
186
+ end
187
+
180
188
  def port=(port)
181
189
  @tddium_config["port"] = port
182
190
  end
@@ -228,7 +228,8 @@ describe "TddiumClient" do
228
228
  end
229
229
 
230
230
  def parse_request_params
231
- Rack::Utils.parse_nested_query(FakeWeb.last_request.body)
231
+ #Rack::Utils.parse_nested_query(FakeWeb.last_request.body)
232
+ JSON.parse(FakeWeb.last_request.body)
232
233
  end
233
234
 
234
235
  let(:tddium_client) { TddiumClient::Client.new }
@@ -282,14 +283,14 @@ describe "TddiumClient" do
282
283
  end
283
284
 
284
285
  shared_examples_for "retry on exception" do
285
- before { HTTParty.stub(EXAMPLE_HTTP_METHOD).and_raise(raised_exception) }
286
+ before { TddiumClient::InternalClient.stub(EXAMPLE_HTTP_METHOD).and_raise(raised_exception) }
286
287
  it "should retry 5 times by default to contact the API" do
287
- HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(6).times
288
+ TddiumClient::InternalClient.should_receive(EXAMPLE_HTTP_METHOD).exactly(6).times
288
289
  expect { tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE) }.to raise_error(TddiumClient::Error::Timeout)
289
290
  end
290
291
 
291
292
  it "should retry as many times as we want to contact the API" do
292
- HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(3).times
293
+ TddiumClient::InternalClient.should_receive(EXAMPLE_HTTP_METHOD).exactly(3).times
293
294
  expect { tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, 2) }.to raise_error(TddiumClient::Error::Timeout)
294
295
  end
295
296
  end
@@ -358,7 +359,7 @@ describe "TddiumClient" do
358
359
  end
359
360
 
360
361
  it "should try to contact the api only once" do
361
- HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(1).times.and_return(mock(HTTParty).as_null_object)
362
+ TddiumClient::InternalClient.should_receive(EXAMPLE_HTTP_METHOD).exactly(1).times.and_return(mock(HTTParty).as_null_object)
362
363
  tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil) rescue {}
363
364
  end
364
365
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tddium_client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jay Moorthi
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-15 00:00:00 Z
13
+ date: 2012-04-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty