LVS-JSONService 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{LVS-JSONService}
5
- s.version = "0.4.8"
5
+ s.version = "0.4.9"
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"]
9
- s.date = %q{2010-01-20}
9
+ s.date = %q{2010-12-16}
10
10
  s.email = %q{info@lvs.co.uk}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -50,9 +50,7 @@ Gem::Specification.new do |s|
50
50
  "spec/lvs/json_service/request_spec.rb",
51
51
  "spec/spec_helper.rb"
52
52
  ]
53
- s.add_dependency('activesupport', '>= 3.0.1')
54
- s.add_dependency('eventmachine', '>= 0.12.10')
55
- s.add_dependency('em-http-request', '>= 0.2.6')
53
+ s.add_dependency('activesupport', '>= 3.0.3')
56
54
 
57
55
  if s.respond_to? :specification_version then
58
56
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "JSONService"
8
- gem.summary = %Q{TODO}
8
+ gem.summary = %Q{This is a JSON Service for interacting with an ABP backend server from LVS}
9
9
  gem.email = "info@lvs.co.uk"
10
10
  gem.homepage = "http://github.com/lvs/JSONService"
11
11
  gem.authors = ["LVS", "andyjeffries"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
data/lib/json_service.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'rubygems'
2
2
  require 'active_support'
3
- require 'eventmachine'
4
- require 'em-http'
5
3
  require 'lvs/json_service/base'
6
4
  require 'lvs/json_service/logger'
@@ -21,7 +21,6 @@ module LVS
21
21
  @auth_cert = ""
22
22
  @auth_key = ""
23
23
  @auth_key_pass = ""
24
- @eventmachine_async = false
25
24
 
26
25
  def encrypted=(value)
27
26
  @encrypted = value
@@ -56,10 +55,6 @@ module LVS
56
55
  @field_prefix = value
57
56
  end
58
57
 
59
- def is_eventmachine_async!
60
- @eventmachine_async = true
61
- end
62
-
63
58
  def site=(value)
64
59
  # value is containing AGP_LOCATION already sometimes:
65
60
  value.gsub!(/^#{AGP_LOCATION}/, '') if defined?(AGP_LOCATION) && value.match(/#{AGP_LOCATION}/)
@@ -98,7 +93,6 @@ module LVS
98
93
  end
99
94
 
100
95
  options[:encrypted] = @encrypted if @encrypted
101
- options[:eventmachine_async] = @eventmachine_async if @eventmachine_async
102
96
  options[:auth_cert] = @auth_cert if @auth_cert
103
97
  options[:auth_key] = @auth_key if @auth_key
104
98
  options[:auth_key_pass] = @auth_key_pass if @auth_key_pass
@@ -79,30 +79,6 @@ module LVS
79
79
  yield(response)
80
80
  end
81
81
 
82
- def http_eventmachine_request_with_timeout(service, args, options)
83
- http_options = {}
84
- http_options[:timeout] = options[:timeout] || 1
85
- http_options[:head] = {"X-LVS-Request-ID" => options[:request_id]}
86
- http_options[:body] = {"object_request" => args.to_json}
87
-
88
- http = EventMachine::HttpRequest.new(service).post(http_options)
89
- http.callback {
90
- response = OpenStruct.new(:request_id => http.response_header["X-LVS-Request-ID"], :body => http.response)
91
- yield(response)
92
- }
93
- http.errback {
94
- if (http.response_header.status == 404)
95
- yield(LVS::JsonService::NotFoundError.new("404 Found for the service #{service}", 404, service, args))
96
- elsif (http.response_header.status == 304)
97
- yield(LVS::JsonService::NotModified.new("304 Data hasn't changed", 304, service, args))
98
- elsif (http.response_header.status == 0)
99
- yield(LVS::JsonService::BackendUnavailableError.new("Backend unavailable (in time)", 500, service, args))
100
- else
101
- yield(LVS::JsonService::Error.new("Unknown error (#{http.response_header.inspect})", 500, service, args))
102
- end
103
- }
104
- end
105
-
106
82
  def run_remote_request(service, args, options = {})
107
83
  LVS::JsonService::Logger.debug "Requesting '#{service}' with #{args.to_json}"
108
84
 
@@ -116,44 +92,21 @@ module LVS
116
92
  end
117
93
  if response.nil?
118
94
  start = Time.now
119
- if options[:eventmachine_async]
120
- http_eventmachine_request_with_timeout(service, args, options) do |response|
121
- if response.is_a?(LVS::JsonService::Error)
122
- result = response
123
- else
124
- verify_request_id(response.request_id, options[:request_id])
125
- net_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
126
- start = Time.now
127
- result = JSON.parse(response.body)
128
- parse_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
129
- timing = "Net: #{net_timing}, Parse: #{parse_timing}"
130
- if options[:cached_for]
131
- Rails.cache.write([service, args].cache_key, [response, result], :expires_in => options[:cached_for])
132
- end
133
- log_response(timing, response.body, options)
134
- if result.is_a?(Hash) && result.has_key?("PCode")
135
- result = LVS::JsonService::Error.new(result["message"], result["PCode"], service, args, result)
136
- end
137
- end
138
- yield(result) if block_given?
95
+ http_standard_request_with_timeout(service, args, options) do |response|
96
+ verify_request_id(response["X-LVS-Request-ID"], options[:request_id])
97
+ net_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
98
+ start = Time.now
99
+ result = JSON.parse(response.body)
100
+ parse_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
101
+ timing = "Net: #{net_timing}, Parse: #{parse_timing}"
102
+ if options[:cached_for]
103
+ Rails.cache.write([service, args].cache_key, [response, result], :expires_in => options[:cached_for])
139
104
  end
140
- else
141
- http_standard_request_with_timeout(service, args, options) do |response|
142
- verify_request_id(response["X-LVS-Request-ID"], options[:request_id])
143
- net_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
144
- start = Time.now
145
- result = JSON.parse(response.body)
146
- parse_timing = ("%.1f" % ((Time.now - start) * 1000)) + "ms"
147
- timing = "Net: #{net_timing}, Parse: #{parse_timing}"
148
- if options[:cached_for]
149
- Rails.cache.write([service, args].cache_key, [response, result], :expires_in => options[:cached_for])
150
- end
151
- log_response(timing, response.body, options)
152
- if result.is_a?(Hash) && result.has_key?("PCode")
153
- raise LVS::JsonService::Error.new(result["message"], result["PCode"], service, args, result)
154
- end
155
- yield(result) if block_given?
105
+ log_response(timing, response.body, options)
106
+ if result.is_a?(Hash) && result.has_key?("PCode")
107
+ raise LVS::JsonService::Error.new(result["message"], result["PCode"], service, args, result)
156
108
  end
109
+ yield(result) if block_given?
157
110
  end
158
111
  else
159
112
  log_response(timing, response.body, options)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 8
9
- version: 0.4.8
8
+ - 9
9
+ version: 0.4.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - LVS
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-01-20 00:00:00 +00:00
18
+ date: 2010-12-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,40 +29,10 @@ dependencies:
29
29
  segments:
30
30
  - 3
31
31
  - 0
32
- - 1
33
- version: 3.0.1
32
+ - 3
33
+ version: 3.0.3
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: eventmachine
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
- - 12
47
- - 10
48
- version: 0.12.10
49
- type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: em-http-request
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- segments:
60
- - 0
61
- - 2
62
- - 6
63
- version: 0.2.6
64
- type: :runtime
65
- version_requirements: *id003
66
36
  description:
67
37
  email: info@lvs.co.uk
68
38
  executables: []