squash_matrix 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +17 -3
- data/lib/squash_matrix/client.rb +17 -2
- data/lib/squash_matrix/constants.rb +2 -1
- data/lib/squash_matrix/nokogiri-parser.rb +27 -1
- data/lib/squash_matrix/version.rb +1 -1
- data/squash_matrix.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f3c73a85e406636213cedf77e71fbce5d4c76c7
|
4
|
+
data.tar.gz: 24f57ca32dcb19c25d4effa0b248279770c42ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24be0f0f3c6cbd4df937c61861a0990666a16812ee84bfbd51564db31bbaa28f4daa0cc8b60edf935a85a680e39adc04642298ec6162dd547cc31fcf60692b65
|
7
|
+
data.tar.gz: 73dd1e9747fb354bdc84344099c6a87bbe7b23f27222a7768b89b0a72629616fae6b150a9fde531f55438d7b74fa49d84b14fc050ef7b87ce8b8b12599182c4d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
Ruby SDK for www.squashmatrix.com
|
4
4
|
|
5
|
-
The generated client interacts with www.squashmatrix.com by retrieving player and club information and performing search requests.
|
6
|
-
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
@@ -25,7 +23,23 @@ Or install it yourself as:
|
|
25
23
|
```ruby
|
26
24
|
client = SquashMatrix::Client.new # initialize client
|
27
25
|
=> SquashMatrix::Client
|
28
|
-
client.player_info(42547) # retrieve player
|
26
|
+
client.player_info(42547) # retrieve player results for joshua wilkosz #42547
|
27
|
+
=> {
|
28
|
+
:rating=>"250.202",
|
29
|
+
:clubs=>[
|
30
|
+
{
|
31
|
+
:name=>"Melbourne University (2011-2017)",
|
32
|
+
:id=>336
|
33
|
+
}
|
34
|
+
],
|
35
|
+
:teams=>[
|
36
|
+
{
|
37
|
+
:name=>"Melbourne University (2) (2017)",
|
38
|
+
:id=>72831
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
client.player_results(42547) # retrieve player results for joshua wilkosz #42547
|
29
43
|
=> [
|
30
44
|
{
|
31
45
|
:event=>"2017 Melbourne Autumn State Open Pennant",
|
data/lib/squash_matrix/client.rb
CHANGED
@@ -50,6 +50,22 @@ module SquashMatrix
|
|
50
50
|
handle_http_request(uri, success_proc)
|
51
51
|
end
|
52
52
|
|
53
|
+
# Returns player results.
|
54
|
+
# @note If suppress_errors == false SquashMatrix Errors will be raised upon HttpNotFound, HttpConflict, Timeout::Error, etc...
|
55
|
+
# @param id [Fixnum] played id found on squash matrix
|
56
|
+
# @return [Array<Hash>] Array of player match results
|
57
|
+
|
58
|
+
def player_results(id=nil)
|
59
|
+
return if id.nil?
|
60
|
+
uri = URI::HTTP.build({
|
61
|
+
host: SquashMatrix::Constants::SQUASH_MATRIX_URL,
|
62
|
+
path: SquashMatrix::Constants::PLAYER_RESULTS_PATH.gsub(':id', id.to_s),
|
63
|
+
query: SquashMatrix::Constants::PLAYER_RSULTS_QUERY
|
64
|
+
})
|
65
|
+
success_proc = lambda {|res| SquashMatrix::NokogiriParser.player_results(res.body)}
|
66
|
+
handle_http_request(uri, success_proc)
|
67
|
+
end
|
68
|
+
|
53
69
|
# Returns player info.
|
54
70
|
# @note If suppress_errors == false SquashMatrix Errors will be raised upon HttpNotFound, HttpConflict, Timeout::Error, etc...
|
55
71
|
# @param id [Fixnum] played id found on squash matrix
|
@@ -59,8 +75,7 @@ module SquashMatrix
|
|
59
75
|
return if id.nil?
|
60
76
|
uri = URI::HTTP.build({
|
61
77
|
host: SquashMatrix::Constants::SQUASH_MATRIX_URL,
|
62
|
-
path: SquashMatrix::Constants::
|
63
|
-
query: SquashMatrix::Constants::PLAYER_RSULTS_QUERY
|
78
|
+
path: SquashMatrix::Constants::PLAYER_HOME_PATH.gsub(':id', id.to_s)
|
64
79
|
})
|
65
80
|
success_proc = lambda {|res| SquashMatrix::NokogiriParser.player_info(res.body)}
|
66
81
|
handle_http_request(uri, success_proc)
|
@@ -3,7 +3,8 @@ module SquashMatrix
|
|
3
3
|
module Constants
|
4
4
|
SQUASH_MATRIX_URL = "www.squashmatrix.com"
|
5
5
|
LOGIN_PATH = "/Account/LogOn"
|
6
|
-
|
6
|
+
PLAYER_RESULTS_PATH = "/Home/PlayerResults/:id"
|
7
|
+
PLAYER_HOME_PATH = "/Home/Player/:id"
|
7
8
|
CLUB_PATH = "/Home/Club/:id"
|
8
9
|
SEARCH_PATH = "/Home/Search"
|
9
10
|
PLAYER_RSULTS_QUERY = "max=0&X-Requested-With=XMLHttpRequest"
|
@@ -4,7 +4,7 @@ require_relative 'constants'
|
|
4
4
|
module SquashMatrix
|
5
5
|
class NokogiriParser
|
6
6
|
class << self
|
7
|
-
def
|
7
|
+
def player_rsults(body)
|
8
8
|
Nokogiri::HTML(body)&.xpath('//table[@id="results"]//tbody//tr')&.map do |r|
|
9
9
|
date = r.at_css('td[1]')&.content
|
10
10
|
opponent_id = r.at_css('td[10]//a')&.attribute('href')&.content
|
@@ -28,6 +28,32 @@ module SquashMatrix
|
|
28
28
|
end.compact
|
29
29
|
end
|
30
30
|
|
31
|
+
def player_info(body)
|
32
|
+
rows = Nokogiri::HTML(body)&.xpath('//table[@id="profile"]//tbody//tr')
|
33
|
+
rating = rows[1]&.css('td[2]')&.text
|
34
|
+
clubs = rows[2]&.css('td[2]')&.css('ul//li')&.map do |c|
|
35
|
+
id = c&.css('a')&.attribute('href')&.text
|
36
|
+
rtn = {
|
37
|
+
name: c&.text
|
38
|
+
}
|
39
|
+
rtn[:id] = SquashMatrix::Constants::CLUB_FROM_PATH_REGEX.match(id)[1].to_i if id
|
40
|
+
rtn
|
41
|
+
end
|
42
|
+
teams = rows[3]&.css('td[2]')&.css('ul//li')&.map do |c|
|
43
|
+
id = c&.css('a')&.attribute('href')&.text
|
44
|
+
rtn = {
|
45
|
+
name: c&.text
|
46
|
+
}
|
47
|
+
rtn[:id] = SquashMatrix::Constants::TEAM_FROM_PATH_REGEX.match(id)[1].to_i if id
|
48
|
+
rtn
|
49
|
+
end
|
50
|
+
{
|
51
|
+
rating: rating,
|
52
|
+
clubs: clubs,
|
53
|
+
teams: teams
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
31
57
|
def club_info(body)
|
32
58
|
html = Nokogiri::HTML(body)
|
33
59
|
name = SquashMatrix::Constants::CLUB_FROM_TITLE_REGEX.match(html.css('title').text)[1]
|
data/squash_matrix.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["joshua@wilkosz.com.au"]
|
11
11
|
|
12
12
|
spec.summary = %q{Ruby SDK for www.squashmatrix.com}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{Ruby SDK for www.squashmatrix.com}
|
14
14
|
spec.homepage = "https://github.com/wilkosz/squash_matrix"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squash_matrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Wilkosz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,8 +120,7 @@ dependencies:
|
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: 1.8.4
|
123
|
-
description:
|
124
|
-
player and club information and performing search requests
|
123
|
+
description: Ruby SDK for www.squashmatrix.com
|
125
124
|
email:
|
126
125
|
- joshua@wilkosz.com.au
|
127
126
|
executables: []
|