LVS-JSONService 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LVS-JSONService
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  require_paths:
6
6
  - lib
7
7
  platform: ruby
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{LVS-JSONService}
5
- s.version = "0.4.6"
5
+ s.version = "0.4.7"
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"]
@@ -10,14 +10,14 @@ Gem::Specification.new do |s|
10
10
  s.email = %q{info@lvs.co.uk}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
13
- "README.rdoc"
13
+ "README.textile"
14
14
  ]
15
15
  s.files = [
16
16
  ".gitignore",
17
17
  ".specification",
18
18
  "LVS-JSONService.gemspec",
19
19
  "LICENSE",
20
- "README.rdoc",
20
+ "README.textile",
21
21
  "Rakefile",
22
22
  "VERSION",
23
23
  "lib/json_service.rb",
@@ -0,0 +1,97 @@
1
+ h2. Purpose
2
+
3
+ This gem is an internal LVS project for communicating with an AGP (Advanced Gaming Platform) backend server.
4
+
5
+ h2. History
6
+
7
+ In the old days there was the WebApi classes which used XML-RPC. Then there was the 'new' ABP::API::JSN class (why JSON is abbreviated to JSN is unknown) which has all the JSON API calls in one class.
8
+
9
+ This felt very un-Railsy, so Andy Jeffries wrote the new JsonService parent class, so we can treat each group of JSON services like a model. This is similar to the way ActiveResource works (but we can't use ActiveResource as our models aren't really resources).
10
+
11
+ h2. Example
12
+
13
+ As a simple example of how to create a new model based JSON API class:
14
+
15
+ <pre><code>require 'json_service'
16
+
17
+ class Event < LVS::JsonService::Base
18
+ self.site = AGP_LOCATION + '/jsonservices/'
19
+ self.service_prefix = 'com.lvsint.abp.client.json.commands.'
20
+ self.field_prefix = 'event_'
21
+
22
+ define_service :special, 'DoSomethingSpecial.json',
23
+ :defaults => {:n => 5}, :required => [:n, :locale]
24
+
25
+ define_service :details, 'ListAllEvents.json',
26
+ :defaults => {:searchType => Event::SEARCH_TYPE_IDS},
27
+ :required => [:searchType, :searchIds],
28
+ :optional => [:locale, :period, :includeEventInfoYN]
29
+
30
+ end</code></pre>
31
+
32
+ You then use it just like an ActiveRecord model (at the moment it's read only - we'll add write capabilities to it in an ActiveRecord style when we need them):
33
+
34
+ <pre><code>events = Event.special :locale => "en-gb"
35
+ events.each do |event|
36
+ puts "#{event.id} #{event.title}"
37
+ end</code></pre>
38
+
39
+ The field names come from the JSON return field names after the field_prefix is stripped off (if present).
40
+
41
+ There is also a bit of magic that converts fields ending in 'date' to be a Time value, and fields starting with has_ such as has_bets to return a boolean (and create a bets? method too).
42
+
43
+ h2. Combined results
44
+
45
+ The first version of json_service only worked if the result was an array of hashes. The latest version will now accept a hash as the result and make any elements that have arrays as the values an array of objects. For example, given the JSON as follows:
46
+
47
+ <pre><code>{
48
+ 'event_id': 132,
49
+ 'event_location': 'Anfield, Liverpool, England',
50
+ 'teams': [
51
+ {
52
+ 'name': 'Liverpool',
53
+ 'colour': 'Red'
54
+ },
55
+ {
56
+ 'name': 'Everton',
57
+ 'colour': 'Blue'
58
+ }
59
+ ]
60
+ }</code></pre>
61
+
62
+ You could then use the class in this way:
63
+
64
+ <pre><code>event = Event.my_combined_call :locale => "en-gb"
65
+ puts "ID: " + event.id
66
+ puts "Location: " + event.location
67
+ events.teams.each do |team|
68
+ puts "#{team.name}(#{event.colour})"
69
+ end</code></pre>
70
+
71
+ h2. Faking calls
72
+
73
+ There are times when you're ready to develop on the Rails side but the Web API isn't ready. You can create a fake service that just parses a hard-coded JSON string in the same way as it would if it had come back from the Web API.
74
+
75
+ <pre><code>class Event < LVS::JsonService::Base
76
+ self.site = AGP_LOCATION + '/jsonservices/'
77
+ self.service_prefix = 'com.lvsint.abp.client.json.commands.'
78
+ self.field_prefix = 'event_'
79
+
80
+ fake_service :special, '{"status":"OK", "count":2}'
81
+ end</code></pre>
82
+
83
+ h2. Communication Resiliancy
84
+
85
+ The AGP backend doesn't always reliably allow a connection and prompt response. Therefore there is now the facility to define a timeout for a connection (and response) and an amount of retries rather than immediately failing.
86
+
87
+ The new parameters are defined as per the following example:
88
+
89
+ <pre><code> define_service :last_minute, 'FDJListLastMinuteEventsService.json',
90
+ :defaults => {:n => 5}, :required => [:n, :locale], :timeout => 3, :retries => 3</code></pre>
91
+
92
+ The default values are 1 second timeout (note: this is actually 1 second connection timeout and 1 second read timeout, so 2 seconds total) and 0 retries.
93
+
94
+ If it fails to connect or times out, it retries <code>:retries</code> times with timeout set to <code>:timeout</code> + 50%.
95
+
96
+
97
+ Copyright (C) 2009-2010 LVS Ltd.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.6
1
+ 0.4.7
@@ -17,7 +17,7 @@ module LVS
17
17
  key = create_key(host, port)
18
18
  begin
19
19
  LVS::JsonService::Logger.debug "Disconnecting from #{host}:#{port}"
20
- @@connections[key].finish
20
+ @@connections[key].finish if @@connections[key]
21
21
  rescue IOError
22
22
  # Do nothing
23
23
  end
@@ -29,7 +29,7 @@ module LVS
29
29
  @@connections.each do |key, connection|
30
30
  begin
31
31
  LVS::JsonService::Logger.debug "Disconnecting from #{host}:#{port}"
32
- connection.finish
32
+ connection.finish if connection
33
33
  rescue IOError
34
34
  # Do nothing
35
35
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LVS-JSONService
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 7
9
+ version: 0.4.7
5
10
  platform: ruby
6
11
  authors:
7
12
  - LVS
@@ -10,39 +15,51 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-01-20 00:00:00 +01:00
18
+ date: 2010-01-20 00:00:00 +00:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activesupport
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 5
24
32
  version: 2.3.5
25
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  - !ruby/object:Gem::Dependency
27
36
  name: eventmachine
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
31
39
  requirements:
32
40
  - - ">="
33
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 12
45
+ - 10
34
46
  version: 0.12.10
35
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
36
49
  - !ruby/object:Gem::Dependency
37
50
  name: em-http-request
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
41
53
  requirements:
42
54
  - - ">="
43
55
  - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ - 2
59
+ - 6
44
60
  version: 0.2.6
45
- version:
61
+ type: :runtime
62
+ version_requirements: *id003
46
63
  description:
47
64
  email: info@lvs.co.uk
48
65
  executables: []
@@ -51,13 +68,13 @@ extensions: []
51
68
 
52
69
  extra_rdoc_files:
53
70
  - LICENSE
54
- - README.rdoc
71
+ - README.textile
55
72
  files:
56
73
  - .gitignore
57
74
  - .specification
58
75
  - LVS-JSONService.gemspec
59
76
  - LICENSE
60
- - README.rdoc
77
+ - README.textile
61
78
  - Rakefile
62
79
  - VERSION
63
80
  - lib/json_service.rb
@@ -90,18 +107,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
107
  requirements:
91
108
  - - ">="
92
109
  - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
93
112
  version: "0"
94
- version:
95
113
  required_rubygems_version: !ruby/object:Gem::Requirement
96
114
  requirements:
97
115
  - - ">="
98
116
  - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
99
119
  version: "0"
100
- version:
101
120
  requirements: []
102
121
 
103
122
  rubyforge_project:
104
- rubygems_version: 1.3.5
123
+ rubygems_version: 1.3.6
105
124
  signing_key:
106
125
  specification_version: 3
107
126
  summary: A Ruby library for interacting with external JSON services
@@ -1,7 +0,0 @@
1
- = JSONService
2
-
3
- Description goes here.
4
-
5
- == Copyright
6
-
7
- Copyright (c) 2009 LVS. See LICENSE for details.