api_resource 0.6.13 → 0.6.14

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/.rspec CHANGED
@@ -6,4 +6,5 @@
6
6
  -X
7
7
  --order random
8
8
  --drb
9
- #--debugger
9
+ --require spec_helper
10
+ --debugger
data/Gemfile.lock CHANGED
@@ -156,6 +156,9 @@ GEM
156
156
  polyglot
157
157
  polyglot (>= 0.3.1)
158
158
  tzinfo (0.3.37)
159
+ yarjuf (1.0.5)
160
+ builder
161
+ rspec (>= 2.0)
159
162
 
160
163
  PLATFORMS
161
164
  ruby
@@ -177,3 +180,4 @@ DEPENDENCIES
177
180
  simplecov
178
181
  spork
179
182
  sqlite3
183
+ yarjuf
data/Rakefile CHANGED
@@ -2,7 +2,9 @@
2
2
  require "bundler/gem_tasks"
3
3
  require 'rspec/core/rake_task'
4
4
 
5
- RSpec::Core::RakeTask.new(:spec)
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = %w[-f JUnit -o results.xml]
7
+ end
6
8
 
7
9
  task :default => :spec
8
- task :ci => %w(rspec benchmark)
10
+ task :ci => %w(rspec benchmark)
data/api_resource.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_development_dependency "rake"
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "spork"
22
+ gem.add_development_dependency "yarjuf"
22
23
  # this latest version of mocha is not compatible with the rails
23
24
  # 3.2.9
24
25
  gem.add_development_dependency "mocha", ["=0.12.7"]
@@ -11,7 +11,7 @@ module ApiResource
11
11
  # services.
12
12
  class Connection
13
13
 
14
- HTTP_FORMAT_HEADER_NAMES = {
14
+ HTTP_FORMAT_HEADER_NAMES = {
15
15
  :get => 'Accept',
16
16
  :put => 'Content-Type',
17
17
  :post => 'Content-Type',
@@ -52,7 +52,7 @@ module ApiResource
52
52
  end
53
53
 
54
54
  # make a put request
55
- # @return [String] response.body raises an
55
+ # @return [String] response.body raises an
56
56
  # ApiResource::ConnectionError if we
57
57
  # have a timeout, general exception, or
58
58
  # if result.code is not within 200..399
@@ -65,43 +65,53 @@ module ApiResource
65
65
  format.decode(request(:get, path, headers))
66
66
  end
67
67
  end
68
-
68
+
69
69
  def delete(path, headers = self.headers)
70
70
  request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path)))
71
71
  return true
72
72
  end
73
-
73
+
74
74
  def head(path, headers = self.headers)
75
75
  request(:head, path, build_request_headers(headers, :head, self.site.merge(path)))
76
76
  end
77
-
77
+
78
78
  # make a put request
79
- # @return [String] response.body raises an
79
+ # @return [String] response.body raises an
80
80
  # ApiResource::ConnectionError if we
81
81
  # have a timeout, general exception, or
82
82
  # if result.code is not within 200..399
83
83
  def put(path, body = {}, headers = self.headers)
84
- format.decode(
85
- request(
86
- :put,
87
- path,
88
- body,
89
- build_request_headers(headers, :put, self.site.merge(path))
90
- )
84
+ response = request(
85
+ :put,
86
+ path,
87
+ body,
88
+ build_request_headers(headers, :put, self.site.merge(path))
91
89
  )
90
+ # handle blank response and return true
91
+ if response.blank?
92
+ return {}
93
+ # we used to decode JSON in the response, but we don't want to
94
+ # do that anymore - we will issue a warning but keep the behavior
95
+ else
96
+ ApiResource.logger.warn(
97
+ "[DEPRECATION] Returning a response body from a PUT " +
98
+ "is deprecated. \n#{response.pretty_inspect} was returned."
99
+ )
100
+ return format.decode(response)
101
+ end
92
102
  end
93
-
103
+
94
104
  # make a post request
95
- # @return [String] response.body raises an
105
+ # @return [String] response.body raises an
96
106
  # ApiResource::ConnectionError if we
97
107
  # have a timeout, general exception, or
98
108
  # if result.code is not within 200..399
99
109
  def post(path, body = {}, headers = self.headers)
100
110
  format.decode(
101
111
  request(
102
- :post,
103
- path,
104
- body,
112
+ :post,
113
+ path,
114
+ body,
105
115
  build_request_headers(headers, :post, self.site.merge(path))
106
116
  )
107
117
  )
@@ -127,14 +137,14 @@ module ApiResource
127
137
 
128
138
  private
129
139
  # Makes a request to the remote service
130
- # @return [String] response.body raises an
140
+ # @return [String] response.body raises an
131
141
  # ApiResource::ConnectionError if we
132
142
  # have a timeout, general exception, or
133
143
  # if result.code is not within 200..399
134
144
  def request(method, path, *arguments)
135
145
  handle_response(path) do
136
146
  ActiveSupport::Notifications.instrument("request.api_resource") do |payload|
137
-
147
+
138
148
  # debug logging
139
149
  ApiResource.logger.info("#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}")
140
150
  payload[:method] = method
@@ -161,7 +171,7 @@ module ApiResource
161
171
  end
162
172
  return propogate_response_or_error(result, result.code)
163
173
  end
164
-
174
+
165
175
  def propogate_response_or_error(response, code)
166
176
  case code.to_i
167
177
  when 301,302
@@ -194,7 +204,7 @@ module ApiResource
194
204
  raise ApiResource::ConnectionError.new(response, :message => "Unknown response code: #{code}")
195
205
  end
196
206
  end
197
-
207
+
198
208
  # Creates new Net::HTTP instance for communication with the
199
209
  # remote service and resources.
200
210
  def http(path)
@@ -203,11 +213,11 @@ module ApiResource
203
213
  end
204
214
  RestClient::Resource.new("#{site.scheme}://#{site.host}:#{site.port}#{path}", {:timeout => ApiResource::Base.timeout, :open_timeout => ApiResource::Base.open_timeout})
205
215
  end
206
-
216
+
207
217
  def build_request_headers(headers, verb, uri)
208
218
  http_format_header(verb).update(headers)
209
219
  end
210
-
220
+
211
221
  def http_format_header(verb)
212
222
  {}.tap do |ret|
213
223
  ret[HTTP_FORMAT_HEADER_NAMES[verb]] = format.mime_type
@@ -18,11 +18,7 @@ module ApiResource
18
18
  end
19
19
 
20
20
  def decode(json)
21
- if json.strip.blank?
22
- return {}
23
- else
24
- JSON.parse(json)
25
- end
21
+ JSON.parse(json)
26
22
  end
27
23
  end
28
24
  end
@@ -1,3 +1,3 @@
1
1
  module ApiResource
2
- VERSION = "0.6.13"
2
+ VERSION = "0.6.14"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'spork'
3
3
  #uncomment the following line to use spork with the debugger
4
4
  #require 'spork/ext/ruby-debug'
5
+ require 'yarjuf'
5
6
 
6
7
  Spork.prefork do
7
8
  # Loading more in this block will cause your tests to run faster. However,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13
4
+ version: 0.6.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-09-24 00:00:00.000000000 Z
14
+ date: 2013-10-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -61,6 +61,22 @@ dependencies:
61
61
  - - ! '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: yarjuf
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
64
80
  - !ruby/object:Gem::Dependency
65
81
  name: mocha
66
82
  requirement: !ruby/object:Gem::Requirement