infostrada 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 056a9814b1582d72d2e88e5dc3aa2c9bef44350c
4
- data.tar.gz: 7395f9bc6a499fee10d1eab7c41cb35b4ba1fb53
3
+ metadata.gz: 0400ee91f7d81abbcb4e4497725a576da61c80fe
4
+ data.tar.gz: a1365e64e78f37720d3d2e3342e50c17d5cba1f4
5
5
  SHA512:
6
- metadata.gz: c2734d1c0810f909cbcea929cdf5f58c3e6c9bbb6a1969371346913b57ae746273d5ff0d4dddcc06334b3936ab8eedc03ce0d3f1bd2892fb4e6b9479f6e13cfc
7
- data.tar.gz: 0f0db14a2daeb806e6ec73fbed8d634178f28d76af9dde9c8c0ce31a0567ec8daffe10bf1ee535f5171fcb9edc646f974791748b9efdded54f9b668d2f5db1f9
6
+ metadata.gz: cbd07f6433f35d2127380ef0146388add157c878c4e3b893e1f0feb13f64eac037832b42eaf72198f2da5ef17d7621dd8a5da1a6b114f6e09c1f0ba416c07adc
7
+ data.tar.gz: c18b1bf31061cf68423209d9845af9e54825054adc935899d3b9b7c860e7755d7d963188a6acd80420ccfd7f207c5c38c26a826159ef9d63e8a09b8214a8aa23
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.pstore
data/Gemfile.lock CHANGED
@@ -3,9 +3,9 @@ PATH
3
3
  specs:
4
4
  infostrada (0.1.0)
5
5
  colored (~> 1.2)
6
- eventmachine (~> 1.0.3)
7
- httparty (~> 0.13.0)
8
- tzinfo (~> 1.1.0)
6
+ eventmachine (~> 1.0, >= 1.0.3)
7
+ httparty (~> 0.13, >= 0.13.0)
8
+ tzinfo (~> 0.3.37)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -49,9 +49,7 @@ GEM
49
49
  sexp_processor (~> 4.1)
50
50
  sexp_processor (4.4.3)
51
51
  slop (3.5.0)
52
- thread_safe (0.3.3)
53
- tzinfo (1.1.0)
54
- thread_safe (~> 0.1)
52
+ tzinfo (0.3.39)
55
53
 
56
54
  PLATFORMS
57
55
  ruby
@@ -59,7 +57,7 @@ PLATFORMS
59
57
  DEPENDENCIES
60
58
  bundler (~> 1.5)
61
59
  infostrada!
62
- pry (~> 0.9.12)
63
- rake (~> 10.2.2)
64
- reek (~> 1.3.7)
65
- rubocop (~> 0.20.1)
60
+ pry (~> 0.9, >= 0.9.12)
61
+ rake (~> 10.2, >= 10.2.2)
62
+ reek (~> 1.3, >= 1.3.7)
63
+ rubocop (~> 0.20, >= 0.20.1)
data/infostrada.gemspec CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.0'
28
28
  spec.add_dependency 'colored', '~> 1.2'
29
- spec.add_dependency 'tzinfo', '~> 1.1', '>= 1.1.0'
29
+ spec.add_dependency 'tzinfo', '~> 0.3', '>= 0.3.37'
30
30
  spec.add_dependency 'eventmachine', '~> 1.0', '>= 1.0.3'
31
31
  end
@@ -1,29 +1,54 @@
1
1
  require 'eventmachine'
2
2
 
3
3
  module Infostrada
4
+ # This is the base class that you should subclass to make a new endpoints poller. You should also
5
+ # call the EndpointsPoller.set_frequency and EndpointsPoller.listen_to and define a
6
+ # process_endpoints(endpoints) that will be called when there are updates on the list of endpoints
7
+ # defined via listen_to. EndpointsPoller will use CallRefresh behind the scenes to fetch the
8
+ # updated endpoints.
9
+ #
10
+ # Example of a minimal poller:
11
+ #
12
+ # module Infostrada
13
+ # class GamesPoller < EndpointsPoller
14
+ # # What's the request frequency, in seconds.
15
+ # set_frequency 15
16
+ #
17
+ # # What are the endpoints that we're interested in?
18
+ # listen_to %w(GetMatchActionList_All)
19
+ #
20
+ # def process_endpoints(endpoints)
21
+ # end
22
+ # end
23
+ # end
4
24
  class EndpointsPoller
5
25
  class << self
6
26
  attr_accessor :polling_frequency, :endpoints
7
27
 
28
+ # Called on the sublcasses to set what's the interval (in seconds) for the requests.
8
29
  def set_frequency(frequency)
9
30
  @polling_frequency = frequency
10
31
  end
11
32
 
33
+ # Also called on the cubclasses to set what are the endpoints that we will parse.
12
34
  def listen_to(endpoints)
13
35
  @endpoints = endpoints
14
36
  end
15
37
  end
16
38
 
39
+ # Main cycle that calls EM.run and will then use the EndpointsPoller#process_endpoints method
40
+ # to process the updated endpoints.
17
41
  def run
18
- EM.run {
42
+ EM.run do
19
43
  EM.add_periodic_timer(self.class.polling_frequency) do
20
44
  puts "[#{Time.now}] Refresh since #{CallRefresh.last_update}"
21
45
 
22
- endpoints = EndpointChecker.new
46
+ endpoints = EndpointChecker.new(self.class.endpoints)
47
+
23
48
  endpoints.callback { |endpoints| process_endpoints(endpoints) }
24
49
  endpoints.errback { |error| puts "ERROR: #{error}" }
25
50
  end
26
- }
51
+ end
27
52
  end
28
53
 
29
54
  def process_endpoints(endpoints)
@@ -31,13 +56,15 @@ module Infostrada
31
56
  end
32
57
  end
33
58
 
59
+ # EndpointChecker is an helper class that will call CallRefresh.get_latest to check which updates
60
+ # were made since the last request. It will then call .succeed or .fail asynchronously.
34
61
  class EndpointChecker
35
62
  include EM::Deferrable
36
63
 
37
- def initialize
64
+ def initialize(endpoints_whitelist)
38
65
  begin
39
66
  updated = Infostrada::CallRefresh.get_latest
40
- updated = updated.select { |endpoint| self.class.endpoints.include?(endpoint.method) }
67
+ updated = updated.select { |endpoint| endpoints_whitelist.include?(endpoint.method) }
41
68
 
42
69
  self.succeed(updated)
43
70
  rescue => e
@@ -4,7 +4,7 @@ module Infostrada
4
4
  class TeamInfo < Infostrada::BaseRequest
5
5
  attr_accessor :official_name, :official_short_name, :public_name, :public_short_name, :nickname
6
6
  attr_accessor :foundation_date, :official_stadium_name, :stadium_name, :stadium_capacity
7
- attr_accessor :url, :city
7
+ attr_accessor :url, :city, :country, :country_short_name
8
8
 
9
9
  URL = '/GetTeamInfo'
10
10
 
@@ -15,17 +15,19 @@ module Infostrada
15
15
  end
16
16
 
17
17
  def initialize(hash)
18
- @official_name = hash['c_OfficialName']
19
- @official_short_name = hash['c_OfficialNameSort']
20
- @public_name = hash['c_PublicName']
21
- @public_short_name = hash['c_PublicNameSort']
22
- @nickname = hash['c_Nickname']
23
- @foundation_date = hash['d_FoundationDate']
24
- @official_stadium_name = hash['c_StadiumOfficialName']
25
- @stadium_name = hash['c_Stadium']
26
- @stadium_capacity = hash['n_StadiumCapacity']
27
- @url = hash['c_URL']
28
- @city = hash['c_City']
18
+ @official_name = hash['c_OfficialName']
19
+ @official_short_name = hash['c_OfficialNameSort']
20
+ @public_name = hash['c_PublicName']
21
+ @public_short_name = hash['c_PublicNameSort']
22
+ @nickname = hash['c_Nickname']
23
+ @foundation_date = hash['d_FoundationDate']
24
+ @official_stadium_name = hash['c_StadiumOfficialName']
25
+ @stadium_name = hash['c_Stadium']
26
+ @stadium_capacity = hash['n_StadiumCapacity']
27
+ @url = hash['c_URL']
28
+ @city = hash['c_City']
29
+ @country = hash['c_Country']
30
+ @country_short_name = hash['c_CountryShort']
29
31
 
30
32
  self
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Infostrada
2
- VERSION = '0.1.0'
3
- end
2
+ VERSION = '0.1.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infostrada
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
@@ -144,20 +144,20 @@ dependencies:
144
144
  requirements:
145
145
  - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: '1.1'
147
+ version: '0.3'
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
- version: 1.1.0
150
+ version: 0.3.37
151
151
  type: :runtime
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: '1.1'
157
+ version: '0.3'
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- version: 1.1.0
160
+ version: 0.3.37
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: eventmachine
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -186,12 +186,12 @@ executables:
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
189
+ - ".gitignore"
189
190
  - Gemfile
190
191
  - Gemfile.lock
191
192
  - README.md
192
193
  - bin/strada
193
194
  - infostrada.gemspec
194
- - infostrada.pstore
195
195
  - lib/infostrada.rb
196
196
  - lib/infostrada/base_request.rb
197
197
  - lib/infostrada/call_refresh.rb
data/infostrada.pstore DELETED
@@ -1 +0,0 @@
1
- {:last_updateIu: Time