ygoprodeck 1.1.0 → 1.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 +4 -4
- data/.rubocop.yml +60 -1
- data/Gemfile +1 -0
- data/examples/banlist.rb +1 -0
- data/examples/search.rb +1 -2
- data/examples/search_fuzzy.rb +25 -26
- data/lib/ygoprodeck/errors.rb +3 -3
- data/lib/ygoprodeck/search/all_card.rb +2 -2
- data/lib/ygoprodeck/search/archetype.rb +26 -30
- data/lib/ygoprodeck/search/banlist.rb +76 -78
- data/lib/ygoprodeck/search/card_sets.rb +21 -28
- data/lib/ygoprodeck/search/check_db_version.rb +24 -33
- data/lib/ygoprodeck/search/client/endpoint.rb +7 -8
- data/lib/ygoprodeck/search/client/image_gapis.rb +17 -16
- data/lib/ygoprodeck/search/fuzzy_name.rb +21 -20
- data/lib/ygoprodeck/search/id.rb +3 -3
- data/lib/ygoprodeck/search/list.rb +34 -47
- data/lib/ygoprodeck/search/match.rb +8 -8
- data/lib/ygoprodeck/search/name.rb +21 -22
- data/lib/ygoprodeck/search/random.rb +19 -20
- data/lib/ygoprodeck/version.rb +3 -3
- data/lib/ygoprodeck.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38c1e28c30e9912a0d3f532d69d0bb19f13496041c7aefa4722d57bb461dc3d6
|
|
4
|
+
data.tar.gz: a701b1fcfc477cfe6d4c6444efdc94d790e22ec0b45ba3079205da8e0cb557c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 585feb7a99dd8cc41a84b69132a698261ecd78a3c13dadfd1b37e9557a436b6a16703d0a9291ea11de23b4fd4dd68d0efa72a7a91dd947b659a5644c93f7bdcf
|
|
7
|
+
data.tar.gz: 8e67e92b923bf9d172175cd709b6eb1390ca9f52f67ff89a114ae8d06a14998dddac336ce15b20190810a6c4c83e369664179f1cd98512ad5f0a8154a47740c8
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
|
|
2
4
|
AllCops:
|
|
3
5
|
Include:
|
|
4
6
|
- "**/*.rb"
|
|
@@ -7,4 +9,61 @@ AllCops:
|
|
|
7
9
|
Exclude:
|
|
8
10
|
- "vendor/**/*"
|
|
9
11
|
- "db/schema.rb"
|
|
12
|
+
- Gemfile
|
|
13
|
+
- Rakefile
|
|
14
|
+
- "*.gemspec"
|
|
10
15
|
NewCops: enable
|
|
16
|
+
|
|
17
|
+
Performance:
|
|
18
|
+
Enabled: true
|
|
19
|
+
|
|
20
|
+
Layout/LineLength:
|
|
21
|
+
Enabled: false
|
|
22
|
+
|
|
23
|
+
Style/BlockDelimiters:
|
|
24
|
+
Enabled: false
|
|
25
|
+
|
|
26
|
+
Lint/AmbiguousBlockAssociation:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Metrics/BlockLength:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
Layout/HeredocIndentation:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
Metrics/ClassLength:
|
|
36
|
+
Enabled: false
|
|
37
|
+
|
|
38
|
+
Metrics/MethodLength:
|
|
39
|
+
Enabled: false
|
|
40
|
+
|
|
41
|
+
Metrics/ParameterLists:
|
|
42
|
+
Enabled: false
|
|
43
|
+
|
|
44
|
+
Metrics/AbcSize:
|
|
45
|
+
Enabled: false
|
|
46
|
+
|
|
47
|
+
Metrics/PerceivedComplexity:
|
|
48
|
+
Enabled: false
|
|
49
|
+
|
|
50
|
+
Metrics/CyclomaticComplexity:
|
|
51
|
+
Enabled: false
|
|
52
|
+
|
|
53
|
+
Style/HashEachMethods:
|
|
54
|
+
Enabled: true
|
|
55
|
+
|
|
56
|
+
Style/HashTransformKeys:
|
|
57
|
+
Enabled: false
|
|
58
|
+
|
|
59
|
+
Style/HashTransformValues:
|
|
60
|
+
Enabled: false
|
|
61
|
+
|
|
62
|
+
Style/FrozenStringLiteralComment:
|
|
63
|
+
Enabled: false
|
|
64
|
+
|
|
65
|
+
Style/Documentation:
|
|
66
|
+
Enabled: false
|
|
67
|
+
|
|
68
|
+
Style/StringLiterals:
|
|
69
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/examples/banlist.rb
CHANGED
data/examples/search.rb
CHANGED
|
@@ -3,8 +3,7 @@ require "ygoprodeck"
|
|
|
3
3
|
# yugi is example, you free to change name card
|
|
4
4
|
yugi = Ygoprodeck::Name.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
when yugi == nil
|
|
6
|
+
if yugi.nil?
|
|
8
7
|
puts "Card not found"
|
|
9
8
|
else
|
|
10
9
|
puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
|
data/examples/search_fuzzy.rb
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
require "ygoprodeck"
|
|
2
|
-
|
|
3
|
-
# yugi is example, you free to change name card
|
|
4
|
-
yugi = Ygoprodeck::Fname.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
puts yugi["
|
|
16
|
-
puts yugi["
|
|
17
|
-
puts yugi["
|
|
18
|
-
puts yugi["
|
|
19
|
-
puts yugi["
|
|
20
|
-
puts yugi["
|
|
21
|
-
puts yugi["
|
|
22
|
-
puts yugi["
|
|
23
|
-
puts yugi["
|
|
24
|
-
puts Ygoprodeck::
|
|
25
|
-
|
|
26
|
-
end
|
|
1
|
+
require "ygoprodeck"
|
|
2
|
+
|
|
3
|
+
# yugi is example, you free to change name card
|
|
4
|
+
yugi = Ygoprodeck::Fname.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
|
|
5
|
+
|
|
6
|
+
if yugi.nil?
|
|
7
|
+
puts "Card not found"
|
|
8
|
+
else
|
|
9
|
+
puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
|
|
10
|
+
|
|
11
|
+
puts "#" * 10
|
|
12
|
+
|
|
13
|
+
# => get specific information of dark magician
|
|
14
|
+
puts yugi["id"]
|
|
15
|
+
puts yugi["name"]
|
|
16
|
+
puts yugi["attribute"]
|
|
17
|
+
puts yugi["type"]
|
|
18
|
+
puts yugi["race"]
|
|
19
|
+
puts yugi["level"]
|
|
20
|
+
puts yugi["desc"]
|
|
21
|
+
puts yugi["atk"]
|
|
22
|
+
puts yugi["def"]
|
|
23
|
+
puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
|
|
24
|
+
puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
|
|
25
|
+
end
|
data/lib/ygoprodeck/errors.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Error < StandardError; end
|
|
3
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Error < StandardError; end
|
|
3
|
+
end
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#
|
|
2
|
-
# sorry I did't created get all card, because you need 2 days to get all card
|
|
1
|
+
#
|
|
2
|
+
# sorry I did't created get all card, because you need 2 days to get all card
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Archetype
|
|
3
|
-
attr_reader :archetype
|
|
4
|
-
|
|
5
|
-
def self.is(archetype)
|
|
6
|
-
url =
|
|
7
|
-
"#{Ygoprodeck::Endpoint.is}cardinfo.php?archetype=#{URI.encode_www_form_component(archetype)}"
|
|
8
|
-
uri = URI(url)
|
|
9
|
-
|
|
10
|
-
begin
|
|
11
|
-
response = Net::HTTP.get(uri)
|
|
12
|
-
load = JSON.parse(response)
|
|
13
|
-
|
|
14
|
-
if load["data"].nil? || load["data"].empty?
|
|
15
|
-
{
|
|
16
|
-
"error" => "No card matching your query was found in the database."
|
|
17
|
-
}
|
|
18
|
-
else
|
|
19
|
-
load["data"]
|
|
20
|
-
end
|
|
21
|
-
rescue
|
|
22
|
-
{ "error" => "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Archetype
|
|
3
|
+
attr_reader :archetype
|
|
4
|
+
|
|
5
|
+
def self.is(archetype)
|
|
6
|
+
url =
|
|
7
|
+
"#{Ygoprodeck::Endpoint.is}cardinfo.php?archetype=#{URI.encode_www_form_component(archetype)}&format=genesys&misc=yes"
|
|
8
|
+
uri = URI(url)
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
response = Net::HTTP.get(uri)
|
|
12
|
+
load = JSON.parse(response)
|
|
13
|
+
|
|
14
|
+
if load["data"].nil? || load["data"].empty?
|
|
15
|
+
{
|
|
16
|
+
"error" => "No card matching your query was found in the database."
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
load["data"]
|
|
20
|
+
end
|
|
21
|
+
rescue StandardError
|
|
22
|
+
{ "error" => "Something went wrong" }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,78 +1,76 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require 'json'
|
|
3
|
-
require 'uri'
|
|
4
|
-
|
|
5
|
-
module Ygoprodeck
|
|
6
|
-
class Banlist
|
|
7
|
-
API_BASE = 'https://ygoprodeck.com/api/banlist'
|
|
8
|
-
|
|
9
|
-
def self.fetch_banlist(format)
|
|
10
|
-
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?banlist=#{format}"
|
|
11
|
-
uri = URI(url)
|
|
12
|
-
|
|
13
|
-
begin
|
|
14
|
-
response = Net::HTTP.get(uri)
|
|
15
|
-
load = JSON.parse(response)
|
|
16
|
-
|
|
17
|
-
if load.has_key?('error')
|
|
18
|
-
{ 'error' => load['error'] }
|
|
19
|
-
else
|
|
20
|
-
load
|
|
21
|
-
end
|
|
22
|
-
rescue JSON::ParserError
|
|
23
|
-
{ 'error' => 'Failed to parse JSON response' }
|
|
24
|
-
rescue SocketError
|
|
25
|
-
{ 'error' => 'Network connection error' }
|
|
26
|
-
rescue StandardError => e
|
|
27
|
-
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def self.tcg
|
|
32
|
-
fetch_banlist('tcg')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.ocg
|
|
36
|
-
fetch_banlist('ocg')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def self.goat
|
|
40
|
-
fetch_banlist('goat')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.md
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
req =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
end
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Ygoprodeck
|
|
6
|
+
class Banlist
|
|
7
|
+
API_BASE = 'https://ygoprodeck.com/api/banlist'.freeze
|
|
8
|
+
|
|
9
|
+
def self.fetch_banlist(format)
|
|
10
|
+
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?banlist=#{format}"
|
|
11
|
+
uri = URI(url)
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
response = Net::HTTP.get(uri)
|
|
15
|
+
load = JSON.parse(response)
|
|
16
|
+
|
|
17
|
+
if load.has_key?('error')
|
|
18
|
+
{ 'error' => load['error'] }
|
|
19
|
+
else
|
|
20
|
+
load
|
|
21
|
+
end
|
|
22
|
+
rescue JSON::ParserError
|
|
23
|
+
{ 'error' => 'Failed to parse JSON response' }
|
|
24
|
+
rescue SocketError
|
|
25
|
+
{ 'error' => 'Network connection error' }
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.tcg
|
|
32
|
+
fetch_banlist('tcg')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.ocg
|
|
36
|
+
fetch_banlist('ocg')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.goat
|
|
40
|
+
fetch_banlist('goat')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.md
|
|
44
|
+
dates_uri = URI("#{API_BASE}/getBanListDates.php")
|
|
45
|
+
dates_res = Net::HTTP.get(dates_uri)
|
|
46
|
+
dates = JSON.parse(dates_res)
|
|
47
|
+
|
|
48
|
+
master_duel_dates = dates.select { |d| d['type'] == 'Master Duel' }
|
|
49
|
+
return { 'error' => 'No Master Duel dates found' } if master_duel_dates.empty?
|
|
50
|
+
|
|
51
|
+
latest_date = master_duel_dates.map { |d| d['date'] }.max
|
|
52
|
+
|
|
53
|
+
list_uri = URI("#{API_BASE}/getBanList.php?list=Master%20Duel&date=#{latest_date}")
|
|
54
|
+
req = Net::HTTP::Get.new(list_uri)
|
|
55
|
+
req['User-Agent'] = 'Mozilla/5.0'
|
|
56
|
+
|
|
57
|
+
res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
|
|
58
|
+
http.request(req)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
load = JSON.parse(res.body)
|
|
62
|
+
|
|
63
|
+
if load.is_a?(Hash) && load.key?('error')
|
|
64
|
+
{ 'error' => load['error'] }
|
|
65
|
+
else
|
|
66
|
+
load
|
|
67
|
+
end
|
|
68
|
+
rescue JSON::ParserError
|
|
69
|
+
{ 'error' => 'Failed to parse JSON response' }
|
|
70
|
+
rescue SocketError
|
|
71
|
+
{ 'error' => 'Network connection error' }
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Card
|
|
3
|
-
def self.sets
|
|
4
|
-
url = "https://db.ygoprodeck.com/api/v7/cardsets.php"
|
|
5
|
-
uri = URI(url)
|
|
6
|
-
|
|
7
|
-
begin
|
|
8
|
-
response = Net::HTTP.get(uri)
|
|
9
|
-
load = JSON.parse(response)
|
|
10
|
-
|
|
11
|
-
if load.is_a?(Hash) && load.has_key?('error')
|
|
12
|
-
{ 'error' => load['error'] }
|
|
13
|
-
else
|
|
14
|
-
load
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{ 'error' => 'Request timed out' }
|
|
23
|
-
rescue StandardError => e
|
|
24
|
-
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Card
|
|
3
|
+
def self.sets
|
|
4
|
+
url = "https://db.ygoprodeck.com/api/v7/cardsets.php"
|
|
5
|
+
uri = URI(url)
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
response = Net::HTTP.get(uri)
|
|
9
|
+
load = JSON.parse(response)
|
|
10
|
+
|
|
11
|
+
if load.is_a?(Hash) && load.has_key?('error')
|
|
12
|
+
{ 'error' => load['error'] }
|
|
13
|
+
else
|
|
14
|
+
load
|
|
15
|
+
end
|
|
16
|
+
rescue StandardError => e
|
|
17
|
+
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class CheckDbVer
|
|
3
|
-
def self.info
|
|
4
|
-
url = "https://db.ygoprodeck.com/api/v7/checkDBVer.php"
|
|
5
|
-
uri = URI(url)
|
|
6
|
-
|
|
7
|
-
begin
|
|
8
|
-
response = Net::HTTP.get_response(uri)
|
|
9
|
-
|
|
10
|
-
unless response.is_a?(Net::HTTPSuccess)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
load
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{ 'error' => 'Network connection error' }
|
|
26
|
-
rescue Net::ReadTimeout => e
|
|
27
|
-
{ 'error' => 'Request timed out' }
|
|
28
|
-
rescue StandardError => e
|
|
29
|
-
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class CheckDbVer
|
|
3
|
+
def self.info
|
|
4
|
+
url = "https://db.ygoprodeck.com/api/v7/checkDBVer.php"
|
|
5
|
+
uri = URI(url)
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
response = Net::HTTP.get_response(uri)
|
|
9
|
+
|
|
10
|
+
return { 'error' => "HTTP request failed with status code: #{response.code}" } unless response.is_a?(Net::HTTPSuccess)
|
|
11
|
+
|
|
12
|
+
load = JSON.parse(response.body)
|
|
13
|
+
|
|
14
|
+
if load.is_a?(Hash) && load.has_key?('error')
|
|
15
|
+
{ 'error' => load['error'] }
|
|
16
|
+
else
|
|
17
|
+
load
|
|
18
|
+
end
|
|
19
|
+
rescue StandardError => e
|
|
20
|
+
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Endpoint
|
|
3
|
+
def self.is
|
|
4
|
+
"https://db.ygoprodeck.com/api/v7/"
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Image
|
|
3
|
+
attr_reader :image_by_id
|
|
4
|
+
|
|
5
|
+
def self.is(image_by_id)
|
|
6
|
+
"https://images.ygoprodeck.com/images/cards/#{image_by_id}.jpg"
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class Image_small
|
|
11
|
+
attr_reader :image_small_by_id
|
|
12
|
+
|
|
13
|
+
def self.is(image_small_by_id)
|
|
14
|
+
"https://images.ygoprodeck.com/images/cards_cropped/#{image_small_by_id}.jpg"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Fname
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
load["data"][
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Fname
|
|
3
|
+
attr_reader :f_name
|
|
4
|
+
|
|
5
|
+
def self.is(f_name)
|
|
6
|
+
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(f_name)}&format=genesys&misc=yes"
|
|
7
|
+
uri = URI(url)
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
response = Net::HTTP.get(uri)
|
|
11
|
+
load = JSON.parse(response)
|
|
12
|
+
|
|
13
|
+
return nil if load["data"].nil? || load["data"].empty?
|
|
14
|
+
|
|
15
|
+
load["data"][0]
|
|
16
|
+
rescue StandardError
|
|
17
|
+
{ "error" => "Something went wrong" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/ygoprodeck/search/id.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Ygoprodeck
|
|
2
2
|
class ID
|
|
3
3
|
def self.is(id)
|
|
4
|
-
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?id=#{
|
|
4
|
+
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?id=#{id}"
|
|
5
5
|
uri = URI(url)
|
|
6
6
|
|
|
7
7
|
begin
|
|
@@ -11,8 +11,8 @@ module Ygoprodeck
|
|
|
11
11
|
return nil if load["data"].nil? || load["data"].empty?
|
|
12
12
|
|
|
13
13
|
load["data"][0]
|
|
14
|
-
rescue
|
|
15
|
-
|
|
14
|
+
rescue StandardError
|
|
15
|
+
{ "error" => "Something went wrong" }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -1,47 +1,34 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class List
|
|
3
|
-
attr_reader :list
|
|
4
|
-
|
|
5
|
-
def self.is(list)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{ 'error' => 'Failed to parse JSON response' }
|
|
36
|
-
rescue Net::OpenTimeout => e
|
|
37
|
-
{ 'error' => 'Connection timed out' }
|
|
38
|
-
rescue Net::ReadTimeout => e
|
|
39
|
-
{ 'error' => 'Request timed out' }
|
|
40
|
-
rescue SocketError => e
|
|
41
|
-
{ 'error' => 'Network connection error' }
|
|
42
|
-
rescue StandardError => e
|
|
43
|
-
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class List
|
|
3
|
+
attr_reader :list
|
|
4
|
+
|
|
5
|
+
def self.is(list)
|
|
6
|
+
# Encode query parameter to handle special characters properly
|
|
7
|
+
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(list)}&format=genesys&misc=yes"
|
|
8
|
+
uri = URI(url)
|
|
9
|
+
|
|
10
|
+
# Use timeout to prevent hanging on slow connections
|
|
11
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: 10, read_timeout: 10) do |http|
|
|
12
|
+
http.get(uri.request_uri)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Check HTTP status code first
|
|
16
|
+
case response
|
|
17
|
+
when Net::HTTPSuccess
|
|
18
|
+
load = JSON.parse(response.body)
|
|
19
|
+
|
|
20
|
+
if load.has_key?('error')
|
|
21
|
+
{ 'error' => load['error'] }
|
|
22
|
+
elsif load['data'].nil? || load['data'].empty?
|
|
23
|
+
{ 'error' => 'No card matching your query was found in the database.' }
|
|
24
|
+
else
|
|
25
|
+
load['data']
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
{ 'error' => "HTTP request failed with status code: #{response.code}" }
|
|
29
|
+
end
|
|
30
|
+
rescue StandardError => e
|
|
31
|
+
{ 'error' => "An unexpected error occurred: #{e.message}" }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Ygoprodeck
|
|
2
2
|
class Match
|
|
3
3
|
def self.normalize(text)
|
|
4
|
-
text.downcase.gsub(/[^a-z0-9\s
|
|
4
|
+
text.downcase.gsub(/[^a-z0-9\s-]/, '').strip
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def self.is(name_card)
|
|
@@ -13,23 +13,23 @@ module Ygoprodeck
|
|
|
13
13
|
|
|
14
14
|
substring_matches = names.select { |name| normalize(name).include?(normalized_input) }
|
|
15
15
|
|
|
16
|
-
if
|
|
17
|
-
best_match = substring_matches.min_by { |name| normalize(name).length }
|
|
18
|
-
else
|
|
16
|
+
if substring_matches.empty?
|
|
19
17
|
word_matches = names.select do |name|
|
|
20
18
|
name_words = normalize(name).split
|
|
21
19
|
input_words.all? { |word| name_words.any? { |nw| nw.include?(word) } }
|
|
22
20
|
end
|
|
23
21
|
|
|
24
|
-
if
|
|
25
|
-
best_match = word_matches.min_by { |name| normalize(name).length }
|
|
26
|
-
else
|
|
22
|
+
if word_matches.empty?
|
|
27
23
|
matcher = Levenshtein.new(normalized_input)
|
|
28
24
|
best_match = names.min_by { |name| matcher.match(normalize(name)) }
|
|
25
|
+
else
|
|
26
|
+
best_match = word_matches.min_by { |name| normalize(name).length }
|
|
29
27
|
end
|
|
28
|
+
else
|
|
29
|
+
best_match = substring_matches.min_by { |name| normalize(name).length }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
best_match
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
end
|
|
35
|
+
end
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Name
|
|
3
|
-
attr_reader :name
|
|
4
|
-
|
|
5
|
-
def self.is(name)
|
|
6
|
-
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?name=#{URI.encode_www_form_component(name)}"
|
|
7
|
-
uri = URI(url)
|
|
8
|
-
|
|
9
|
-
begin
|
|
10
|
-
response = Net::HTTP.get(uri)
|
|
11
|
-
load = JSON.parse(response)
|
|
12
|
-
|
|
13
|
-
return nil if load["data"].nil? || load["data"].empty?
|
|
14
|
-
|
|
15
|
-
load["data"][0]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Name
|
|
3
|
+
attr_reader :name
|
|
4
|
+
|
|
5
|
+
def self.is(name)
|
|
6
|
+
url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?name=#{URI.encode_www_form_component(name)}&format=genesys&misc=yes"
|
|
7
|
+
uri = URI(url)
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
response = Net::HTTP.get(uri)
|
|
11
|
+
load = JSON.parse(response)
|
|
12
|
+
|
|
13
|
+
return nil if load["data"].nil? || load["data"].empty?
|
|
14
|
+
|
|
15
|
+
load["data"][0]
|
|
16
|
+
rescue StandardError
|
|
17
|
+
{ "error" => "Something went wrong" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
class Card
|
|
3
|
-
def self.random
|
|
4
|
-
url = "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust"
|
|
5
|
-
uri = URI(url)
|
|
6
|
-
|
|
7
|
-
begin
|
|
8
|
-
response = Net::HTTP.get(uri)
|
|
9
|
-
load = JSON.parse(response)
|
|
10
|
-
|
|
11
|
-
return nil if load["data"].nil? || load["data"].empty?
|
|
12
|
-
|
|
13
|
-
load["data"][0]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
class Card
|
|
3
|
+
def self.random
|
|
4
|
+
url = "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust&format=genesys&misc=yes"
|
|
5
|
+
uri = URI(url)
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
response = Net::HTTP.get(uri)
|
|
9
|
+
load = JSON.parse(response)
|
|
10
|
+
|
|
11
|
+
return nil if load["data"].nil? || load["data"].empty?
|
|
12
|
+
|
|
13
|
+
load["data"][0]
|
|
14
|
+
rescue StandardError
|
|
15
|
+
{ "error" => "Something went wrong" }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/ygoprodeck/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module Ygoprodeck
|
|
2
|
-
VERSION = "1.1.
|
|
3
|
-
end
|
|
1
|
+
module Ygoprodeck
|
|
2
|
+
VERSION = "1.2.1".freeze
|
|
3
|
+
end
|
data/lib/ygoprodeck.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require "open-uri"
|
|
2
|
-
require "net/http"
|
|
3
|
-
require "json"
|
|
4
|
-
require "amatch"
|
|
5
|
-
include Amatch
|
|
6
|
-
|
|
7
|
-
Dir[File.join(__dir__, "ygoprodeck/**/*.rb")].sort.each { |f| require f }
|
|
8
|
-
|
|
9
|
-
module Ygoprodeck
|
|
10
|
-
end
|
|
1
|
+
require "open-uri"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "json"
|
|
4
|
+
require "amatch"
|
|
5
|
+
include Amatch
|
|
6
|
+
|
|
7
|
+
Dir[File.join(__dir__, "ygoprodeck/**/*.rb")].sort.each { |f| require f }
|
|
8
|
+
|
|
9
|
+
module Ygoprodeck
|
|
10
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ygoprodeck
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rokhimin Wahid
|
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
171
171
|
- !ruby/object:Gem::Version
|
|
172
172
|
version: '0'
|
|
173
173
|
requirements: []
|
|
174
|
-
rubygems_version:
|
|
174
|
+
rubygems_version: 4.0.1
|
|
175
175
|
specification_version: 4
|
|
176
176
|
summary: ygoprodeck API wrapper for search yugioh's card
|
|
177
177
|
test_files: []
|