acnh_informations 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1376f9d5370f4e616af22ece0333821840a47c36b4d0af66c91583a640b90d4f
4
+ data.tar.gz: cb84e7af63bbbe7365c90cf87ab013f936c4300c121e56ab474c1c1a6abc2434
5
+ SHA512:
6
+ metadata.gz: e173270f17792509d0f426b44e3807067563c53c191f79f9f470ff260d51c84f82f388a97c80cd365328c3bf567b3b88ccf4d645870fe149f808799d7969ddb3
7
+ data.tar.gz: a39c65112399fbea6c2acea525a007875efa1aed040de713f55ddf9088481eddeed4cb8a1a0d38002e448b91da75c5ffe432c35dfb0656c7fa818ac0f94bac3f
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rest-client"
4
+ require "json"
5
+
6
+ module AcnhInformations
7
+ # Scrape informations from 'acnhapi' api
8
+ class Api
9
+ # The base URL to scrape
10
+ BASE_URL = "https://acnhapi.com"
11
+ # All available categories
12
+ CATEGORIES = %w[fish sea bugs fossils villagers icons images songs music art houseware].freeze
13
+
14
+ ##
15
+ # Verify if the object exists
16
+ #
17
+ # @param [Symbol, StringIO] category The category to find the object
18
+ # @param id [Symbol, StringIO, NilClass] The id to get
19
+ # @return [Boolean] True or False, if the wanted research exists
20
+ def self.valid?(category, id = nil)
21
+ RestClient.get("#{BASE_URL}/v1/#{category.to_s}/#{id ? id.to_s.ascii_only? ? id.to_s : "" : ""}")
22
+ true
23
+ rescue RestClient::NotFound
24
+ false
25
+ end
26
+
27
+ ##
28
+ # Scrape informations from API
29
+ #
30
+ # @param [Symbol, StringIO] category The category to find the object
31
+ # @param id [Symbol, StringIO, NilClass] The id to get
32
+ # @return [Object] The result as a Hash
33
+ # @see Api#valid?
34
+ def self.scrape(category, id = nil)
35
+ return false unless valid?(category, id)
36
+
37
+ JSON.parse(RestClient.get("#{BASE_URL}/v1/#{category.to_s}/#{id ? id.to_s : ""}"), :symbolize_names => true)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api" unless defined?(AcnhInformations::API)
4
+
5
+ module AcnhInformations
6
+ # Some tools for the project
7
+ class Api
8
+ ##
9
+ # Get a thing by an approximative name
10
+ # @param [String] category The category to get the object
11
+ # @param [String] name the approximative name
12
+ # @return [Hash, Boolean] False if the program didn't find anything, or the thing hash
13
+ def self.get_by_name(category, name)
14
+ result = false
15
+ return false unless valid?(category.to_s)
16
+
17
+ scrape(category.to_s).each do |element|
18
+ element[1][:name].each_value do |language_name|
19
+ result = element[1] if language_name.match(/#{name.to_s}/)
20
+ break if result
21
+ end
22
+ end
23
+ result
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AcnhInformations
4
+ # The current version of the gem
5
+ VERSION = "0.1.2"
6
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require_relative "acnh_informations/version"
6
+ require_relative "acnh_informations/api"
7
+ require_relative "acnh_informations/tools"
8
+
9
+ # The main module
10
+ module AcnhInformations
11
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acnh_informations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - senchuu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Get things informations from Animal Crossing New Horizons using https://acnhapi.com/.
14
+ Warning: That doesn''t get informations from players. Only included things.'
15
+ email:
16
+ - senchuuuu@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/acnh_informations.rb
22
+ - lib/acnh_informations/api.rb
23
+ - lib/acnh_informations/tools.rb
24
+ - lib/acnh_informations/version.rb
25
+ homepage: https://github.com/Senchuu/AcnhInformations
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ allowed_push_host: https://rubygems.org/
30
+ homepage_uri: https://github.com/Senchuu/AcnhInformations
31
+ source_code_uri: https://github.com/Senchuu/AcnhInformations
32
+ changelog_uri: https://github.com/Senchuu/AcnhInformations
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.2.20
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Get fish, fossiles, villagers [...] informations from Animal Crossing New
52
+ Horizons
53
+ test_files: []