ygoprodeck 1.1.0 → 1.3.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: d7b8e5947a55893879f833bb1c573581a1debaacd252719387115e5e8d80c52c
4
- data.tar.gz: d5f68bbfccb2a899f822cdf4742db3bbcc3ac80651ebc9c7b56e16483de02a11
3
+ metadata.gz: d8f58d072a6210f4dec5f82b1add541ed8423a54bf2b0f6bad38ce2393d0dd78
4
+ data.tar.gz: 7667c4fba4f29d1edb23757ca053a9e2078546a051c12cf3cc97f705e3e17fcc
5
5
  SHA512:
6
- metadata.gz: 3f5ce7c3509147d7d1eb318449af73ccc5724c9445ddd91c1554d4c56d12a2eab985f318164bc32f9c560ac8846a736e11f12360a32dc6004f036513241b0311
7
- data.tar.gz: 3e3dcf4a3907d631579aaa30069fef46c0d633012c85ee89e797ad3f9726ba5d1e28d6206c73d469732702af1d6a138ad1240300c66f1e4198e3a1b745deed17
6
+ metadata.gz: f86d612102dfe91f809f1112e54b2f884d88bc0a207512ac624afb86625e965dba19223d94f6143ff0e2841248d1f9ebda5350e1ee5d0b343e59acbe03f0204a
7
+ data.tar.gz: 54a057d0ab4104da90a76ff0e5e6e1f4bfb41b12d9e0811d52790119d807670e0c70c638318360d75559c3114cbb526535c7bc8517977dd0a97ca6e77104ff36
data/.rubocop.yml CHANGED
@@ -1,4 +1,6 @@
1
- inherit_from: .rubocop_todo.yml
1
+ require:
2
+ - rubocop-performance
3
+
2
4
  AllCops:
3
5
  Include:
4
6
  - "**/*.rb"
@@ -7,4 +9,64 @@ 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
70
+
71
+ Style/NumericLiterals:
72
+ Enabled: false
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  gemspec name: 'ygoprodeck'
4
4
 
5
5
  gem 'rubocop', '1.80.0'
6
+ gem 'rubocop-performance', '1.26.0'
@@ -1,23 +1,23 @@
1
- require "ygoprodeck"
2
-
3
- # kaiba is example, you free to change card name
4
- kaiba = Ygoprodeck::Archetype.is("blue-eyes") # example I wanna search 'blue-eyes' archetype
5
-
6
- # make for looping for listing archetype
7
- kaiba_listing = [] # save listing here
8
- count = 50 # count max listing . example 50
9
- num_default = 0 # number default
10
-
11
- # looping logic
12
- for logic_search in 1..50
13
- if kaiba[num_default] == nil
14
- else
15
- kaiba_listing << kaiba[num_default]["name"]
16
- num_default += 1
17
- count -= 1
18
- end
19
- end
20
-
21
- puts "#{kaiba_listing.length} card matches for blue-eyes archetype" #length blue-eyes archetype
22
- puts "#" * 30
23
- puts "#{kaiba_listing.join(" \n")}" # each listing
1
+ require "ygoprodeck"
2
+
3
+ # kaiba is example, you free to change card name
4
+ kaiba = Ygoprodeck::Archetype.is("blue-eyes") # example I wanna search 'blue-eyes' archetype
5
+
6
+ # make for looping for listing archetype
7
+ kaiba_listing = [] # save listing here
8
+ count = 50 # count max listing . example 50
9
+ num_default = 0 # number default
10
+
11
+ # looping logic
12
+ for logic_search in 1..50
13
+ if kaiba[num_default].nil?
14
+ else
15
+ kaiba_listing << kaiba[num_default]["name"]
16
+ num_default += 1
17
+ count -= 1
18
+ end
19
+ end
20
+
21
+ puts "#{kaiba_listing.length} card matches for blue-eyes archetype" # length blue-eyes archetype
22
+ puts "#" * 30
23
+ puts "#{kaiba_listing.join(" \n")}" # each listing
data/examples/banlist.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "ygoprodeck"
2
2
 
3
3
  puts Ygoprodeck::Banlist.tcg
4
- #puts Ygoprodeck::Banlist.ocg
5
- #puts Ygoprodeck::Banlist.goat
4
+ # puts Ygoprodeck::Banlist.ocg
5
+ # puts Ygoprodeck::Banlist.goat
6
+ # puts Ygoprodeck::Banlist.md
data/examples/search.rb CHANGED
@@ -1,26 +1,26 @@
1
- require "ygoprodeck"
2
-
3
- # yugi is example, you free to change name card
4
- yugi = Ygoprodeck::Name.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
5
-
6
- case
7
- when yugi == nil
8
- puts "Card not found"
9
- else
10
- puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
11
-
12
- puts "#" * 10
13
-
14
- # => get specific information of dark magician
15
- puts yugi["id"]
16
- puts yugi["name"]
17
- puts yugi["attribute"]
18
- puts yugi["type"]
19
- puts yugi["race"]
20
- puts yugi["level"]
21
- puts yugi["desc"]
22
- puts yugi["atk"]
23
- puts yugi["def"]
24
- puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
25
- puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
26
- end
1
+ require "ygoprodeck"
2
+
3
+ # match name card exactly
4
+ matching = Ygoprodeck::Match.is('dark magician')
5
+ yugi = Ygoprodeck::Fname.is(matching)
6
+
7
+ if yugi.nil?
8
+ puts "Card not found"
9
+ else
10
+ puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
11
+
12
+ puts "#" * 10
13
+
14
+ # => get specific information of dark magician
15
+ puts yugi["id"]
16
+ puts yugi["name"]
17
+ puts yugi["attribute"]
18
+ puts yugi["type"]
19
+ puts yugi["race"]
20
+ puts yugi["level"]
21
+ puts yugi["desc"]
22
+ puts yugi["atk"]
23
+ puts yugi["def"]
24
+ puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
25
+ puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
26
+ end
@@ -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 JSON::ParserError => e
22
- { "error" => "Failed to parse JSON response" }
23
- rescue SocketError => e
24
- { "error" => "Network connection error" }
25
- rescue StandardError => e
26
- { "error" => "An unexpected error occurred: #{e.message}" }
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,134 @@
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
- dates_uri = URI("#{API_BASE}/getBanListDates.php")
46
- dates_res = Net::HTTP.get(dates_uri)
47
- dates = JSON.parse(dates_res)
48
-
49
- master_duel_dates = dates.select { |d| d['type'] == 'Master Duel' }
50
- return { 'error' => 'No Master Duel dates found' } if master_duel_dates.empty?
51
-
52
- latest_date = master_duel_dates.map { |d| d['date'] }.max
53
-
54
- list_uri = URI("#{API_BASE}/getBanList.php?list=Master%20Duel&date=#{latest_date}")
55
- req = Net::HTTP::Get.new(list_uri)
56
- req['User-Agent'] = 'Mozilla/5.0'
57
-
58
- res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
59
- http.request(req)
60
- end
61
-
62
- load = JSON.parse(res.body)
63
-
64
- if load.is_a?(Hash) && load.key?('error')
65
- { 'error' => load['error'] }
66
- else
67
- load
68
- end
69
- rescue JSON::ParserError
70
- { 'error' => 'Failed to parse JSON response' }
71
- rescue SocketError
72
- { 'error' => 'Network connection error' }
73
- rescue StandardError => e
74
- { 'error' => "An unexpected error occurred: #{e.message}" }
75
-
76
- end
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
+ dates_uri = URI("#{API_BASE}/getBanListDates.php")
33
+ dates_res = Net::HTTP.get(dates_uri)
34
+ dates = JSON.parse(dates_res)
35
+
36
+ tcg_dates = dates.select { |d| d['type'] == 'TCG' }
37
+ return { 'error' => 'No TCG dates found' } if tcg_dates.empty?
38
+
39
+ latest_date = tcg_dates.map { |d| d['date'] }.max
40
+
41
+ list_uri = URI("#{API_BASE}/getBanList.php?list=TCG&date=#{latest_date}")
42
+ req = Net::HTTP::Get.new(list_uri)
43
+ req['User-Agent'] = 'Mozilla/5.0'
44
+
45
+ res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
46
+ http.request(req)
47
+ end
48
+
49
+ load = JSON.parse(res.body)
50
+
51
+ if load.is_a?(Hash) && load.key?('error')
52
+ { 'error' => load['error'] }
53
+ else
54
+ load
55
+ end
56
+ rescue JSON::ParserError
57
+ { 'error' => 'Failed to parse JSON response' }
58
+ rescue SocketError
59
+ { 'error' => 'Network connection error' }
60
+ rescue StandardError => e
61
+ { 'error' => "An unexpected error occurred: #{e.message}" }
62
+ end
63
+
64
+ def self.ocg
65
+ dates_uri = URI("#{API_BASE}/getBanListDates.php")
66
+ dates_res = Net::HTTP.get(dates_uri)
67
+ dates = JSON.parse(dates_res)
68
+
69
+ ocg_dates = dates.select { |d| d['type'] == 'OCG' }
70
+ return { 'error' => 'No OCG dates found' } if ocg_dates.empty?
71
+
72
+ latest_date = ocg_dates.map { |d| d['date'] }.max
73
+
74
+ list_uri = URI("#{API_BASE}/getBanList.php?list=OCG&date=#{latest_date}")
75
+ req = Net::HTTP::Get.new(list_uri)
76
+ req['User-Agent'] = 'Mozilla/5.0'
77
+
78
+ res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
79
+ http.request(req)
80
+ end
81
+
82
+ load = JSON.parse(res.body)
83
+
84
+ if load.is_a?(Hash) && load.key?('error')
85
+ { 'error' => load['error'] }
86
+ else
87
+ load
88
+ end
89
+ rescue JSON::ParserError
90
+ { 'error' => 'Failed to parse JSON response' }
91
+ rescue SocketError
92
+ { 'error' => 'Network connection error' }
93
+ rescue StandardError => e
94
+ { 'error' => "An unexpected error occurred: #{e.message}" }
95
+ end
96
+
97
+ def self.goat
98
+ fetch_banlist('goat')
99
+ end
100
+
101
+ def self.md
102
+ dates_uri = URI("#{API_BASE}/getBanListDates.php")
103
+ dates_res = Net::HTTP.get(dates_uri)
104
+ dates = JSON.parse(dates_res)
105
+
106
+ master_duel_dates = dates.select { |d| d['type'] == 'Master Duel' }
107
+ return { 'error' => 'No Master Duel dates found' } if master_duel_dates.empty?
108
+
109
+ latest_date = master_duel_dates.map { |d| d['date'] }.max
110
+
111
+ list_uri = URI("#{API_BASE}/getBanList.php?list=Master%20Duel&date=#{latest_date}")
112
+ req = Net::HTTP::Get.new(list_uri)
113
+ req['User-Agent'] = 'Mozilla/5.0'
114
+
115
+ res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
116
+ http.request(req)
117
+ end
118
+
119
+ load = JSON.parse(res.body)
120
+
121
+ if load.is_a?(Hash) && load.key?('error')
122
+ { 'error' => load['error'] }
123
+ else
124
+ load
125
+ end
126
+ rescue JSON::ParserError
127
+ { 'error' => 'Failed to parse JSON response' }
128
+ rescue SocketError
129
+ { 'error' => 'Network connection error' }
130
+ rescue StandardError => e
131
+ { 'error' => "An unexpected error occurred: #{e.message}" }
132
+ end
133
+ end
134
+ 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
- rescue JSON::ParserError => e
18
- { 'error' => 'Failed to parse JSON response' }
19
- rescue SocketError => e
20
- { 'error' => 'Network connection error' }
21
- rescue Timeout::Error => e
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
- return { 'error' => "HTTP request failed with status code: #{response.code}" }
12
- end
13
-
14
- load = JSON.parse(response.body)
15
-
16
- if load.is_a?(Hash) && load.has_key?('error')
17
- { 'error' => load['error'] }
18
- else
19
- load
20
- end
21
-
22
- rescue JSON::ParserError => e
23
- { 'error' => 'Failed to parse JSON response' }
24
- rescue SocketError => e
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
- module Ygoprodeck
3
- class Endpoint
4
- def self.is
5
- "https://db.ygoprodeck.com/api/v7/"
6
- end
7
- end
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
- module Ygoprodeck
3
- class Image
4
- attr_reader :image_by_id
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
- def self.is(image_small_by_id)
13
- "https://images.ygoprodeck.com/images/cards_cropped/#{image_small_by_id}.jpg"
14
- end
15
- end
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
- def self.is(f_name)
4
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(f_name)}"
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
- rescue JSON::ParserError, SocketError, StandardError => e
16
- nil
17
- end
18
- end
19
- end
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
@@ -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=#{(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 JSON::ParserError, SocketError, StandardError => e
15
- nil
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
- begin
7
- # Encode query parameter to handle special characters properly
8
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(list)}"
9
- uri = URI(url)
10
-
11
- # Use timeout to prevent hanging on slow connections
12
- response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: 10, read_timeout: 10) do |http|
13
- http.get(uri.request_uri)
14
- end
15
-
16
- # Check HTTP status code first
17
- case response
18
- when Net::HTTPSuccess
19
- load = JSON.parse(response.body)
20
-
21
- if load.has_key?('error')
22
- return { 'error' => load['error'] }
23
- elsif load['data'].nil? || load['data'].empty?
24
- return { 'error' => 'No card matching your query was found in the database.' }
25
- else
26
- return load['data']
27
- end
28
- else
29
- return { 'error' => "HTTP request failed with status code: #{response.code}" }
30
- end
31
-
32
- rescue URI::InvalidURIError => e
33
- { 'error' => 'Invalid URL or search term' }
34
- rescue JSON::ParserError => e
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\-]/, '').strip
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 !substring_matches.empty?
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 !word_matches.empty?
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
- rescue JSON::ParserError, SocketError, StandardError => e
18
- nil
19
- end
20
- end
21
- end
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
- rescue JSON::ParserError, SocketError, StandardError => e
16
- nil
17
- end
18
- end
19
- end
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
@@ -1,3 +1,3 @@
1
- module Ygoprodeck
2
- VERSION = "1.1.0"
3
- end
1
+ module Ygoprodeck
2
+ VERSION = "1.3.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
@@ -4,7 +4,7 @@ RSpec.describe Ygoprodeck do
4
4
  end
5
5
 
6
6
  it "check search by fuzzy name spesific" do
7
- spec_name = Ygoprodeck::Fname.is('dark magician')
8
- expect(spec_name['id']).to eq(46986414)
9
- end
7
+ spec_name = Ygoprodeck::Fname.is('dark magician')
8
+ expect(spec_name['id']).to eq(46986421)
9
+ end
10
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.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rokhimin Wahid
@@ -114,12 +114,9 @@ files:
114
114
  - examples/archetype.rb
115
115
  - examples/banlist.rb
116
116
  - examples/check_db.rb
117
- - examples/id.rb
118
- - examples/list.rb
119
117
  - examples/match.rb
120
118
  - examples/random.rb
121
119
  - examples/search.rb
122
- - examples/search_fuzzy.rb
123
120
  - examples/set.rb
124
121
  - lib/ygoprodeck.rb
125
122
  - lib/ygoprodeck/errors.rb
@@ -171,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
168
  - !ruby/object:Gem::Version
172
169
  version: '0'
173
170
  requirements: []
174
- rubygems_version: 3.7.1
171
+ rubygems_version: 4.0.1
175
172
  specification_version: 4
176
173
  summary: ygoprodeck API wrapper for search yugioh's card
177
174
  test_files: []
data/examples/id.rb DELETED
@@ -1,25 +0,0 @@
1
- require "ygoprodeck"
2
-
3
- yugi = Ygoprodeck::ID.is("46986414")
4
-
5
- case
6
- when 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/examples/list.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'ygoprodeck'
2
-
3
- puts Ygoprodeck::List.is('dark magician')
@@ -1,26 +0,0 @@
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
- case
7
- when yugi == nil
8
- puts "Card not found"
9
- else
10
- puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
11
-
12
- puts "#" * 10
13
-
14
- # => get specific information of dark magician
15
- puts yugi["id"]
16
- puts yugi["name"]
17
- puts yugi["attribute"]
18
- puts yugi["type"]
19
- puts yugi["race"]
20
- puts yugi["level"]
21
- puts yugi["desc"]
22
- puts yugi["atk"]
23
- puts yugi["def"]
24
- puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
25
- puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
26
- end