tddium_client 0.0.10 → 0.0.12

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,20 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tddium_client (0.0.9)
4
+ tddium_client (0.0.12)
5
5
  httparty
6
6
  json
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- crack (0.1.8)
12
11
  diff-lcs (1.1.2)
13
12
  fakefs (0.3.1)
14
13
  fakeweb (1.3.0)
15
- httparty (0.7.4)
16
- crack (= 0.1.8)
17
- json (1.5.1)
14
+ httparty (0.8.1)
15
+ multi_json
16
+ multi_xml
17
+ json (1.6.1)
18
+ multi_json (1.0.3)
19
+ multi_xml (0.4.1)
18
20
  rack (1.2.2)
19
21
  rack-test (0.5.7)
20
22
  rack (>= 1.0)
@@ -3,5 +3,5 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
5
  module TddiumClient
6
- VERSION = "0.0.10"
6
+ VERSION = "0.0.12"
7
7
  end
data/lib/tddium_client.rb CHANGED
@@ -5,9 +5,12 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
5
5
  require 'rubygems'
6
6
  require 'httparty'
7
7
  require 'json'
8
+ require File.expand_path("../tddium_client/version", __FILE__)
9
+ require "tddium_client/version"
8
10
 
9
11
  module TddiumClient
10
12
  API_KEY_HEADER = "X-tddium-api-key"
13
+ CLIENT_VERSION_HEADER = "X-tddium-client-version"
11
14
  API_ERROR_TEXT = "An error occured: "
12
15
 
13
16
  module Error
@@ -90,35 +93,50 @@ module TddiumClient
90
93
  end
91
94
 
92
95
  class InternalClient
93
- def initialize(host, port=nil, scheme='https', version=1)
96
+ def initialize(host, port=nil, scheme='https', version=1, caller_version=nil)
94
97
  @tddium_config = {"host" => host,
95
98
  "port" => port,
96
99
  "scheme" => scheme,
97
- "version" => version}
100
+ "version" => version,
101
+ "caller_version" => caller_version}
98
102
  end
99
103
 
100
104
  def call_api(method, api_path, params = {}, api_key = nil, retries = 5)
101
- headers = { API_KEY_HEADER => api_key } if api_key
105
+ headers = {}
106
+ headers.merge!(API_KEY_HEADER => api_key) if api_key
107
+ headers.merge!(CLIENT_VERSION_HEADER => version_header)
102
108
 
103
- done = false
104
109
  tries = 0
105
- while (retries < 0 || tries <= retries) && !done
106
- begin
107
- http = HTTParty.send(method, tddium_uri(api_path), :body => params, :headers => headers)
108
- done = true
109
- rescue Timeout::Error
110
- ensure
111
- tries += 1
112
- end
110
+
111
+ begin
112
+ http = HTTParty.send(method, tddium_uri(api_path), :body => params, :headers => headers)
113
+ rescue Timeout::Error, OpenSSL::SSL::SSLError, OpenSSL::SSL::Session::SessionError
114
+ tries += 1
115
+ retry if retries > 0 && tries <= retries
113
116
  end
114
117
 
115
- raise Error::Timeout if tries > retries && retries >= 0
118
+ raise Error::Timeout if retries >= 0 && tries > retries
116
119
 
117
120
  Result::API.new(http)
118
121
  end
119
122
 
123
+ def caller_version
124
+ @tddium_config["caller_version"]
125
+ end
126
+
127
+ def caller_version=(version)
128
+ @tddium_config["caller_version"] = version
129
+ end
130
+
131
+
120
132
  protected
121
133
 
134
+ def version_header
135
+ hdr = "tddium_client-#{TddiumClient::VERSION}"
136
+ hdr += ";#{caller_version}" if caller_version
137
+ hdr
138
+ end
139
+
122
140
  def tddium_uri(path)
123
141
  uri = URI.parse("")
124
142
  uri.host = tddium_config["host"]
@@ -136,9 +154,10 @@ module TddiumClient
136
154
  class Client < InternalClient
137
155
  attr_reader :environment
138
156
 
139
- def initialize(env = :development)
157
+ def initialize(env = :development, caller_version=nil)
140
158
  @all_config = YAML.load(File.read(config_path))
141
159
  self.environment = env.to_s
160
+ self.caller_version = caller_version
142
161
  end
143
162
 
144
163
  def environment=(new_environment)
@@ -268,11 +268,8 @@ describe "TddiumClient" do
268
268
  end
269
269
  end
270
270
 
271
- context "raises a timeout error" do
272
- before do
273
- HTTParty.stub(EXAMPLE_HTTP_METHOD).and_raise(Timeout::Error)
274
- end
275
-
271
+ shared_examples_for "retry on exception" do
272
+ before { HTTParty.stub(EXAMPLE_HTTP_METHOD).and_raise(raised_exception) }
276
273
  it "should retry 5 times by default to contact the API" do
277
274
  HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(6).times
278
275
  expect { tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE) }.to raise_error(TddiumClient::Error::Timeout)
@@ -284,10 +281,23 @@ describe "TddiumClient" do
284
281
  end
285
282
  end
286
283
 
284
+ context "raises a timeout error" do
285
+ it_behaves_like "retry on exception" do
286
+ let (:raised_exception) { Timeout::Error }
287
+ end
288
+ it_behaves_like "retry on exception" do
289
+ let (:raised_exception) { OpenSSL::SSL::SSLError }
290
+ end
291
+ it_behaves_like "retry on exception" do
292
+ let (:raised_exception) { OpenSSL::SSL::Session::SessionError }
293
+ end
294
+ end
295
+
287
296
  context "('#{EXAMPLE_HTTP_METHOD}', '#{EXAMPLE_TDDIUM_RESOURCE}', {}, #{EXAMPLE_API_KEY}) # with api_key" do
288
297
  it "should include #{TddiumClient::API_KEY_HEADER}=#{EXAMPLE_API_KEY} in the request headers" do
289
298
  tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, EXAMPLE_API_KEY)
290
299
  FakeWeb.last_request[TddiumClient::API_KEY_HEADER].should == EXAMPLE_API_KEY
300
+ FakeWeb.last_request[TddiumClient::CLIENT_VERSION_HEADER].should =~ /#{TddiumClient::VERSION}/
291
301
  end
292
302
  end
293
303
 
@@ -295,6 +305,17 @@ describe "TddiumClient" do
295
305
  it "should not include #{TddiumClient::API_KEY_HEADER} in the request headers" do
296
306
  tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {})
297
307
  FakeWeb.last_request[TddiumClient::API_KEY_HEADER].should be_nil
308
+ FakeWeb.last_request[TddiumClient::CLIENT_VERSION_HEADER].should =~ /#{TddiumClient::VERSION}/
309
+ end
310
+ end
311
+
312
+ context "('#{EXAMPLE_HTTP_METHOD}', '#{EXAMPLE_TDDIUM_RESOURCE}') # with caller_version" do
313
+ it "should include #{TddiumClient::CLIENT_VERSION_HEADER} in req headers with caller_version" do
314
+ ver = "tddium-preview-0.8.1"
315
+ tddium_client.caller_version = ver
316
+ tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {})
317
+ FakeWeb.last_request[TddiumClient::API_KEY_HEADER].should be_nil
318
+ FakeWeb.last_request[TddiumClient::CLIENT_VERSION_HEADER].should =~ /#{TddiumClient::VERSION};#{ver}/
298
319
  end
299
320
  end
300
321
 
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tddium_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 10
10
- version: 0.0.10
5
+ version: 0.0.12
11
6
  platform: ruby
12
7
  authors:
13
8
  - Jay Moorthi
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-08-29 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-10-05 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: httparty
@@ -26,9 +20,6 @@ dependencies:
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
23
  version: "0"
33
24
  type: :runtime
34
25
  version_requirements: *id001
@@ -40,9 +31,6 @@ dependencies:
40
31
  requirements:
41
32
  - - ">="
42
33
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
34
  version: "0"
47
35
  type: :runtime
48
36
  version_requirements: *id002
@@ -54,9 +42,6 @@ dependencies:
54
42
  requirements:
55
43
  - - ">="
56
44
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
45
  version: "0"
61
46
  type: :development
62
47
  version_requirements: *id003
@@ -68,9 +53,6 @@ dependencies:
68
53
  requirements:
69
54
  - - ">="
70
55
  - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
56
  version: "0"
75
57
  type: :development
76
58
  version_requirements: *id004
@@ -82,9 +64,6 @@ dependencies:
82
64
  requirements:
83
65
  - - ">="
84
66
  - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
67
  version: "0"
89
68
  type: :development
90
69
  version_requirements: *id005
@@ -96,9 +75,6 @@ dependencies:
96
75
  requirements:
97
76
  - - ">="
98
77
  - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
78
  version: "0"
103
79
  type: :development
104
80
  version_requirements: *id006
@@ -110,9 +86,6 @@ dependencies:
110
86
  requirements:
111
87
  - - ">="
112
88
  - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
89
  version: "0"
117
90
  type: :development
118
91
  version_requirements: *id007
@@ -124,9 +97,6 @@ dependencies:
124
97
  requirements:
125
98
  - - ">="
126
99
  - !ruby/object:Gem::Version
127
- hash: 3
128
- segments:
129
- - 0
130
100
  version: "0"
131
101
  type: :development
132
102
  version_requirements: *id008
@@ -156,7 +126,6 @@ files:
156
126
  - spec/spec_helper.rb
157
127
  - spec/tddium_client_spec.rb
158
128
  - tddium_client.gemspec
159
- has_rdoc: true
160
129
  homepage: http://www.tddium.com/
161
130
  licenses: []
162
131
 
@@ -170,23 +139,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
139
  requirements:
171
140
  - - ">="
172
141
  - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
175
- - 0
176
142
  version: "0"
177
143
  required_rubygems_version: !ruby/object:Gem::Requirement
178
144
  none: false
179
145
  requirements:
180
146
  - - ">="
181
147
  - !ruby/object:Gem::Version
182
- hash: 3
183
- segments:
184
- - 0
185
148
  version: "0"
186
149
  requirements: []
187
150
 
188
151
  rubyforge_project: tddium_client
189
- rubygems_version: 1.6.2
152
+ rubygems_version: 1.8.10
190
153
  signing_key:
191
154
  specification_version: 3
192
155
  summary: tddium Client Gem