unitfyi 0.1.0 → 0.1.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: d09f3b838597fa616f5b18376b64e95822671c201b186ddb16982395bb08e85e
4
- data.tar.gz: 7f4f978371a8232817a9842d1c51199fcc71cd920e7833038020cc27ceff1ecb
3
+ metadata.gz: eb1cefdfbccf745bf68af0d82e4893d4686c120fcfc62ea7b387afcc39cb01ec
4
+ data.tar.gz: dcaa3aa7c12b40ee400800fc326471e29324ed25445a8fee5fce19ef46a245c6
5
5
  SHA512:
6
- metadata.gz: de2457e348e07bbe8606caa620cf57ad3ef0abbd55ce674fae731d8db6c5dc8e0c587f39d14ef2a2ac2590a5b926bf215a2e03714593902e23f14e5488f34dad
7
- data.tar.gz: d698a999ea9fa2d1d63504c58c673723eec646bb6bf88ad73ed0070e7616306f4c6aab58ddbe1ac1b2e0062b357bcdf7ab60051722a09fa827d736fb92868397
6
+ metadata.gz: e64104b67951666c10e6e59574f0fa10918d315cd1a02a2b42aaad3e39fc937f914ca45250d83f7b87e32ffc23eca1efbb96d17563cf3b138621f1572057d6b7
7
+ data.tar.gz: 2c704ed3e3b954efd0c1c0fd4dbfdeb660ee488681436b4438c467baf32b9e9170593a1f7fca5615d9ae5cc94daabd855db5cc43fca7e3484ad48782c82b4267
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module UnitFYI
8
+ class Client
9
+ DEFAULT_BASE_URL = "https://unitfyi.com/api"
10
+
11
+ def initialize(base_url: DEFAULT_BASE_URL)
12
+ @base_url = base_url
13
+ end
14
+
15
+ def search(query)
16
+ get("/search/", q: query)
17
+ end
18
+
19
+ def entity(slug)
20
+ get("/unit/#{slug}/")
21
+ end
22
+
23
+ def glossary_term(slug)
24
+ get("/glossary/#{slug}/")
25
+ end
26
+
27
+ def random
28
+ get("/random/")
29
+ end
30
+
31
+ private
32
+
33
+ def get(path, params = {})
34
+ uri = URI("#{@base_url}#{path}")
35
+ uri.query = URI.encode_www_form(params) unless params.empty?
36
+
37
+ response = Net::HTTP.get_response(uri)
38
+
39
+ unless response.is_a?(Net::HTTPSuccess)
40
+ raise Error, "HTTP #{response.code}: #{response.body}"
41
+ end
42
+
43
+ JSON.parse(response.body, symbolize_names: true)
44
+ end
45
+ end
46
+
47
+ class Error < StandardError; end
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnitFYI
4
+ VERSION = "0.1.1"
5
+ end
data/lib/unitfyi.rb CHANGED
@@ -1,71 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "json"
5
- require "uri"
6
-
7
- # Ruby client for UnitFYI REST API (unitfyi.com).
8
- #
9
- # client = UnitFYI::Client.new
10
- # result = client.search("query")
11
- #
12
- module UnitFYI
13
- class Client
14
- BASE_URL = "https://unitfyi.com"
15
-
16
- def initialize(base_url: BASE_URL)
17
- @base_url = base_url
18
- end
19
-
20
- def search(query)
21
- get("/api/v1/search/", q: query)
22
- end
23
-
24
- # List all blog/categories.
25
- def list_blog/categories
26
- get("/api/v1/blog/categories/")
27
- end
28
-
29
- # Get blog/category by slug.
30
- def get_blog/category(slug)
31
- get("/api/v1/blog/categories/#{slug}/")
32
- end
33
- # List all blog/posts.
34
- def list_blog/posts
35
- get("/api/v1/blog/posts/")
36
- end
37
-
38
- # Get blog/post by slug.
39
- def get_blog/post(slug)
40
- get("/api/v1/blog/posts/#{slug}/")
41
- end
42
- # List all faqs.
43
- def list_faqs
44
- get("/api/v1/faqs/")
45
- end
46
-
47
- # Get faq by slug.
48
- def get_faq(slug)
49
- get("/api/v1/faqs/#{slug}/")
50
- end
51
- # List all glossary.
52
- def list_glossary
53
- get("/api/v1/glossary/")
54
- end
55
-
56
- # Get term by slug.
57
- def get_term(slug)
58
- get("/api/v1/glossary/#{slug}/")
59
- end
60
-
61
- private
62
-
63
- def get(path, **params)
64
- uri = URI.join(@base_url, path)
65
- uri.query = URI.encode_www_form(params) unless params.empty?
66
- response = Net::HTTP.get_response(uri)
67
- raise "HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
68
- JSON.parse(response.body)
69
- end
70
- end
71
- end
3
+ require_relative "unitfyi/version"
4
+ require_relative "unitfyi/client"
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitfyi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - FYIPedia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-21 00:00:00.000000000 Z
11
+ date: 2026-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Ruby client for the UnitFYI REST API at unitfyi.com. Zero external dependencies.
14
- email: dev@fyipedia.com
13
+ description: API client for unitfyi.com. Unit conversion across 220 units and 20 categories.
14
+ Zero dependencies.
15
+ email:
16
+ - hello@fyipedia.com
15
17
  executables: []
16
18
  extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
19
21
  - lib/unitfyi.rb
22
+ - lib/unitfyi/client.rb
23
+ - lib/unitfyi/version.rb
20
24
  homepage: https://unitfyi.com
21
25
  licenses:
22
26
  - MIT
23
27
  metadata:
24
- source_code_uri: https://github.com/fyipedia/unitfyi-rb
25
- documentation_uri: https://unitfyi.com/api/v1/schema/
26
28
  homepage_uri: https://unitfyi.com
29
+ source_code_uri: https://github.com/fyipedia/unitfyi-rb
30
+ changelog_uri: https://github.com/fyipedia/unitfyi-rb/blob/main/CHANGELOG.md
31
+ documentation_uri: https://unitfyi.com/developers/
32
+ bug_tracker_uri: https://github.com/fyipedia/unitfyi-rb/issues
27
33
  post_install_message:
28
34
  rdoc_options: []
29
35
  require_paths:
@@ -42,5 +48,5 @@ requirements: []
42
48
  rubygems_version: 3.0.3.1
43
49
  signing_key:
44
50
  specification_version: 4
45
- summary: Ruby client for UnitFYI API
51
+ summary: Unit conversion across 220 units and 20 categories
46
52
  test_files: []