chess_api 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c78e242f2753aa2589aee04b883772c7882bc1236b46ec28162f89dc5aaed645
4
- data.tar.gz: dfc8e49eacffee0287293523c52d505191d5f2aa9029ab8115820fe10fa09938
3
+ metadata.gz: 538fb045fa68b99e68f2a8aa32a020cf260a2f99cfae1161aa4cc138cdbc2953
4
+ data.tar.gz: fe22288ad461abcfd079c38702e682d08a4e776b5320508af821d242977ffca4
5
5
  SHA512:
6
- metadata.gz: 201a748355de83873a89f02f21de3212d6539d4f3180fba40c5959436a0b4a228ab8645be65fd37b11593268651569ab7bfd203e5c286e1885d7769324fe8081
7
- data.tar.gz: 191a729f1631ac462f6b572423ff704899fb275c9aef66b48aed8c0bc7e971a46a92fd00bf359d70661e5d2b57b4b04955099e7fb1ccee21562a0fd6d28420f5
6
+ metadata.gz: fd00b6c327fd240e2050741749f9c54677b0fc03cf286c854edc8488da863607e6c364d35098a8a7ca944b976fa9cb8b1b1f863ee14fa4e72e6459d9f78256da
7
+ data.tar.gz: 1ecdb2f7f4dfccfe753ffb98349f1d7cd32068645b49834570e4b0f0edbe89060d596a67456cf3f80cab7bb58871c95e701010f052eaf58f7932217d0b40dcc7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ # [0.2.1] - 2021-09-06
4
+
5
+ - Added #monthly_game_archive, returns a `Collection` of `MonthlyGameArchive` objects.
6
+ - Added daily_puzzle#retrieve and daily_puzzle#random
7
+ - Published 0.2.0 by mistake, enjoy 0.2.1 🙂
8
+
9
+ ## [0.1.1] - 2021-09-05
10
+
3
11
  - Fixed bug where #online_status returned `["online", "offline"]` for players who are online.
4
12
 
5
13
  ## [0.1.0] - 2021-08-29
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chess_api (0.1.0)
4
+ chess_api (0.2.1)
5
5
  faraday (~> 1.7)
6
6
  faraday_middleware (~> 1.1)
7
7
 
data/README.md CHANGED
@@ -99,6 +99,51 @@ irb(main):002:0> clubs.data.map { |club| [club.name, club.joined] }
99
99
  ["Fiona's Fight Club", 1616428995]]
100
100
  ```
101
101
 
102
+ ### Fetching the monthly game archive links for a player on Chess.com
103
+ ```ruby
104
+ irb(main):001:0> result = client.monthly_game_archive.list(username: "ryanjcaldwell")
105
+ =>
106
+ #<ChessApi::Collection:0x0000000153351480
107
+ ...
108
+
109
+ irb(main):002:0> result.data.first.url
110
+ => "https://api.chess.com/pub/player/ryanjcaldwell/games/2019/03"
111
+ ```
112
+
113
+ ### Fetching the Daily Puzzle from Chess.com
114
+ ```ruby
115
+ irb(main):001:0> daily_puzzle = client.daily_puzzle.retrieve
116
+ =>
117
+ #<ChessApi::DailyPuzzle:0x000000012d98b218
118
+ ...
119
+
120
+ irb(main):002:0> daily_puzzle.title
121
+ => "Disconnecting Connection"
122
+
123
+ irb(main):003:0> daily_puzzle.pgn
124
+ => "[Result \"*\"]\r\n[FEN \"3rb3/5pk1/2n1pn1p/rp3Pp1/6P1/1P2B2P/2R3BK/R3N3 w - - 0 1\"]\r\n\r\n1.Rxa5 Nxa5 2.Bb6 Rd1 3.Bxa5 *"
125
+
126
+ irb(main):004:0> daily_puzzle.image
127
+ => "https://www.chess.com/dynboard?fen=3rb3/5pk1/2n1pn1p/rp3Pp1/6P1/1P2B2P/2R3BK/R3N3%20w%20-%20-%200%201&size=2"
128
+ ```
129
+
130
+ ### Fetching a random Daily Puzzle from Chess.com
131
+ ```ruby
132
+ irb(main):001:0> random_daily_puzzle = client.daily_puzzle.random
133
+ =>
134
+ #<ChessApi::DailyPuzzle:0x000000014740e5a0
135
+ ...
136
+
137
+ irb(main):002:0> random_daily_puzzle.publish_time
138
+ => 1306047600
139
+
140
+ irb(main):003:0> random_daily_puzzle.pgn
141
+ => "[Date \"????.??.??\"]\r\n[Result \"*\"]\r\n[FEN \"1B6/1p4Rp/p4kp1/8/8/8/Pr4PP/6K1 b - - 0 1\"]\r\n\r\n1...Rb1+ 2. Kf2 Kxg7\r\n*"
142
+
143
+ irb(main):004:0> random_daily_puzzle.url
144
+ => "https://www.chess.com/forum/view/daily-puzzles/5222011---eluding-danger"
145
+ ```
146
+
102
147
  ## Development
103
148
 
104
149
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -19,6 +19,14 @@ module ChessApi
19
19
  TitledPlayerResource.new(self)
20
20
  end
21
21
 
22
+ def monthly_game_archive
23
+ MonthlyGameArchiveResource.new(self)
24
+ end
25
+
26
+ def daily_puzzle
27
+ DailyPuzzleResource.new(self)
28
+ end
29
+
22
30
  def connection
23
31
  @connection ||= Faraday.new do |conn|
24
32
  conn.url_prefix = BASE_URL
@@ -0,0 +1,11 @@
1
+ module ChessApi
2
+ module InputHelpers
3
+ def downcased_username
4
+ @username&.downcase
5
+ end
6
+
7
+ def upcased_title_abbreviation
8
+ @title_abbreviation&.upcase
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module ChessApi
2
+ class DailyPuzzle < Object
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module ChessApi
2
+ class MonthlyGameArchive < Object
3
+ def initialize(archive_url)
4
+ super({url: archive_url})
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module ChessApi
2
+ class DailyPuzzleResource < Resource
3
+ def retrieve
4
+ ChessApi::DailyPuzzle.new(
5
+ get_request("puzzle").body
6
+ )
7
+ end
8
+
9
+ def random
10
+ ChessApi::DailyPuzzle.new(
11
+ get_request("puzzle/random").body
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module ChessApi
2
+ class MonthlyGameArchiveResource < Resource
3
+ include InputHelpers
4
+
5
+ def list(username:)
6
+ @username = username
7
+ result = get_request("player/#{downcased_username}/games/archives")
8
+
9
+ Collection.from_response(
10
+ result,
11
+ key: "archives",
12
+ type: ChessApi::MonthlyGameArchive
13
+ )
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,6 @@
1
1
  module ChessApi
2
2
  class PlayerResource < Resource
3
+ include InputHelpers
3
4
 
4
5
  module OnlineStatus
5
6
  ONLINE = "online"
@@ -30,11 +31,5 @@ module ChessApi
30
31
  type: ChessApi::Club
31
32
  )
32
33
  end
33
-
34
- private
35
-
36
- def downcased_username
37
- @username&.downcase
38
- end
39
34
  end
40
35
  end
@@ -1,8 +1,12 @@
1
1
  module ChessApi
2
2
  class TitledPlayerResource < Resource
3
+ include InputHelpers
4
+
3
5
  def with_title(title_abbreviation:)
6
+ @title_abbreviation = title_abbreviation
7
+
4
8
  Collection.from_response(
5
- get_request("titled/#{title_abbreviation&.upcase}"),
9
+ get_request("titled/#{upcased_title_abbreviation}"),
6
10
  key: "players",
7
11
  type: ChessApi::TitledPlayer
8
12
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChessApi
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/chess_api.rb CHANGED
@@ -4,22 +4,22 @@ require_relative 'chess_api/version'
4
4
 
5
5
  module ChessApi
6
6
  autoload :Client, 'chess_api/client'
7
- autoload :Resource, 'chess_api/resource'
8
- autoload :Object, 'chess_api/object'
9
7
  autoload :Collection, 'chess_api/collection'
10
8
  autoload :Error, 'chess_api/error'
9
+ autoload :InputHelpers, 'chess_api/input_helpers'
10
+ autoload :Object, 'chess_api/object'
11
+ autoload :Resource, 'chess_api/resource'
11
12
 
12
13
  # Objects
14
+ autoload :Club, 'chess_api/objects/club'
15
+ autoload :DailyPuzzle, 'chess_api/objects/daily_puzzle'
16
+ autoload :MonthlyGameArchive, 'chess_api/objects/monthly_game_archive'
13
17
  autoload :Player, 'chess_api/objects/player'
14
18
  autoload :TitledPlayer, 'chess_api/objects/titled_player'
15
- autoload :Club, 'chess_api/objects/club'
16
19
 
17
20
  # Resources
21
+ autoload :DailyPuzzleResource, 'chess_api/resources/daily_puzzles'
22
+ autoload :MonthlyGameArchiveResource, 'chess_api/resources/monthly_game_archives'
18
23
  autoload :PlayerResource, 'chess_api/resources/players'
19
24
  autoload :TitledPlayerResource, 'chess_api/resources/titled_players'
20
-
21
- def self.build_object(data, klass)
22
- return data unless data.is_a?(Hash)
23
- klass.new(data)
24
- end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chess_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Caldwell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-05 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -58,11 +58,16 @@ files:
58
58
  - lib/chess_api/client.rb
59
59
  - lib/chess_api/collection.rb
60
60
  - lib/chess_api/error.rb
61
+ - lib/chess_api/input_helpers.rb
61
62
  - lib/chess_api/object.rb
62
63
  - lib/chess_api/objects/club.rb
64
+ - lib/chess_api/objects/daily_puzzle.rb
65
+ - lib/chess_api/objects/monthly_game_archive.rb
63
66
  - lib/chess_api/objects/player.rb
64
67
  - lib/chess_api/objects/titled_player.rb
65
68
  - lib/chess_api/resource.rb
69
+ - lib/chess_api/resources/daily_puzzles.rb
70
+ - lib/chess_api/resources/monthly_game_archives.rb
66
71
  - lib/chess_api/resources/players.rb
67
72
  - lib/chess_api/resources/titled_players.rb
68
73
  - lib/chess_api/version.rb