LVS-JSONService 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{LVS-JSONService}
5
- s.version = "0.5.3"
5
+ s.version = "0.5.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["LVS", "andyjeffries", "mooktakim"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -114,17 +114,23 @@ module LVS
114
114
  options[:required].each do |key|
115
115
  raise LVS::JsonService::Error.new("Required field #{key} wasn't supplied", internal_service, '0', method_params) if method_params[key].blank?
116
116
  end
117
+ url = @site + prefix + internal_service
118
+ if options[:interpolate_url]
119
+ method_params.each do |key, value|
120
+ url.gsub!(":#{key.to_s}", value.to_s)
121
+ end
122
+ end
117
123
  if block
118
- self.run_remote_request(@site + prefix + internal_service, method_params, options) do |result|
119
- if flags && flags[:raw]
124
+ self.run_remote_request(url, method_params, options) do |result|
125
+ if (flags && flags[:raw]) || options[:raw]
120
126
  yield(result)
121
127
  else
122
128
  block.call(self.parse_result(result))
123
129
  end
124
130
  end
125
131
  else
126
- result = self.run_remote_request(@site + prefix + internal_service, method_params, options)
127
- if flags && flags[:raw]
132
+ result = self.run_remote_request(url, method_params, options)
133
+ if (flags && flags[:raw]) || options[:raw]
128
134
  result
129
135
  else
130
136
  self.parse_result(result)
@@ -19,12 +19,20 @@ module LVS
19
19
  def http_standard_request_with_timeout(service, args, options)
20
20
  uri = URI.parse(service)
21
21
 
22
- req = Net::HTTP::Post.new(uri.path)
22
+ Rails.logger.debug("Options are #{options.inspect}")
23
+ if options[:http_method] == :get
24
+ path = uri.path
25
+ path += "?#{uri.query}" unless uri.query.blank?
26
+ req = Net::HTTP::Get.new(path)
27
+ Rails.logger.debug("Getting '#{path}'")
28
+ else
29
+ req = Net::HTTP::Post.new(uri.path)
30
+ req.form_data = { "object_request" => args.to_json }
31
+ Rails.logger.debug("Posting to #{uri.path}")
32
+ end
23
33
  req.basic_auth(uri.user, uri.password) unless uri.user.to_s == ""
24
34
  req.add_field("X-LVS-Request-ID", options[:request_id])
25
35
 
26
- req.form_data = { "object_request" => args.to_json }
27
-
28
36
  options[:encrypted] ||= require_ssl?
29
37
  retries = options[:retries] || 0
30
38
  hard_retries = 1 # For persistent connection failures
@@ -36,6 +44,8 @@ module LVS
36
44
  http.open_timeout = options[:timeout] || 1
37
45
  http.read_timeout = options[:timeout] || 1
38
46
  response = http.request(req)
47
+ Rails.logger.debug("Request is #{req.inspect}")
48
+ Rails.logger.debug("Response is #{response.body.inspect}")
39
49
 
40
50
  rescue Errno::EPIPE, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED
41
51
  hard_retries -= 1
@@ -97,7 +107,11 @@ module LVS
97
107
  verify_request_id(response["X-LVS-Request-ID"], options[:request_id])
98
108
  net_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
99
109
  start = Time.now
100
- result = JSON.parse(response.body)
110
+ if options[:raw]
111
+ result = response.body.force_encoding("UTF-8")
112
+ else
113
+ result = JSON.parse(response.body.force_encoding("UTF-8"))
114
+ end
101
115
  parse_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
102
116
  timing = "Net: #{net_timing}, Parse: #{parse_timing}"
103
117
  if options[:cached_for]
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LVS-JSONService
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 5
8
- - 3
9
- version: 0.5.3
4
+ prerelease:
5
+ version: 0.5.4
10
6
  platform: ruby
11
7
  authors:
12
8
  - LVS
@@ -27,10 +23,6 @@ dependencies:
27
23
  requirements:
28
24
  - - ">="
29
25
  - !ruby/object:Gem::Version
30
- segments:
31
- - 3
32
- - 0
33
- - 3
34
26
  version: 3.0.3
35
27
  type: :runtime
36
28
  version_requirements: *id001
@@ -82,21 +74,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
74
  requirements:
83
75
  - - ">="
84
76
  - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
77
  version: "0"
88
78
  required_rubygems_version: !ruby/object:Gem::Requirement
89
79
  none: false
90
80
  requirements:
91
81
  - - ">="
92
82
  - !ruby/object:Gem::Version
93
- segments:
94
- - 0
95
83
  version: "0"
96
84
  requirements: []
97
85
 
98
86
  rubyforge_project:
99
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.6.1
100
88
  signing_key:
101
89
  specification_version: 3
102
90
  summary: A Ruby library for interacting with external JSON services