trainfyi 0.1.0
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 +7 -0
- data/lib/trainfyi.rb +80 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: aaeb166b22e0157fa6b1d3255b1fc87e3f65939951c20ca2704665dc2b8c61b4
|
|
4
|
+
data.tar.gz: f687ba940cecb544741ee54859b49ad8ff2bab56365c8d4ed61fad6466a1d5c7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '019ccd19854b844492c9c72755a9e3f9a3448ae7d6729bbcfc990f2c8f1fbb822fb041faae193041ce8637a2079bb4a90a61b6578fa0b718a6f7020479730fd1'
|
|
7
|
+
data.tar.gz: 1d74bf250cd50bb19e1e3ccad718ff23bba0ff57c271ad35ed0178e89bd207416f6faef7284670b241a2077f3ee01251022bab61b292e36d3d820afb6fa65da3
|
data/lib/trainfyi.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "json"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
# Ruby client for TrainFYI REST API (trainfyi.com).
|
|
8
|
+
#
|
|
9
|
+
# client = TrainFYI::Client.new
|
|
10
|
+
# result = client.search("query")
|
|
11
|
+
#
|
|
12
|
+
module TrainFYI
|
|
13
|
+
class Client
|
|
14
|
+
BASE_URL = "https://trainfyi.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 countries.
|
|
25
|
+
def list_countries
|
|
26
|
+
get("/api/v1/countries/")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Get country by slug.
|
|
30
|
+
def get_country(slug)
|
|
31
|
+
get("/api/v1/countries/#{slug}/")
|
|
32
|
+
end
|
|
33
|
+
# List all faqs.
|
|
34
|
+
def list_faqs
|
|
35
|
+
get("/api/v1/faqs/")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Get faq by slug.
|
|
39
|
+
def get_faq(slug)
|
|
40
|
+
get("/api/v1/faqs/#{slug}/")
|
|
41
|
+
end
|
|
42
|
+
# List all operators.
|
|
43
|
+
def list_operators
|
|
44
|
+
get("/api/v1/operators/")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Get operator by slug.
|
|
48
|
+
def get_operator(slug)
|
|
49
|
+
get("/api/v1/operators/#{slug}/")
|
|
50
|
+
end
|
|
51
|
+
# List all route pairs.
|
|
52
|
+
def list_route_pairs
|
|
53
|
+
get("/api/v1/route-pairs/")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Get route pair by slug.
|
|
57
|
+
def get_route_pair(slug)
|
|
58
|
+
get("/api/v1/route-pairs/#{slug}/")
|
|
59
|
+
end
|
|
60
|
+
# List all stations.
|
|
61
|
+
def list_stations
|
|
62
|
+
get("/api/v1/stations/")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Get station by slug.
|
|
66
|
+
def get_station(slug)
|
|
67
|
+
get("/api/v1/stations/#{slug}/")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def get(path, **params)
|
|
73
|
+
uri = URI.join(@base_url, path)
|
|
74
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
|
75
|
+
response = Net::HTTP.get_response(uri)
|
|
76
|
+
raise "HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
|
77
|
+
JSON.parse(response.body)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: trainfyi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- FYIPedia
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for the TrainFYI REST API at trainfyi.com. Zero external
|
|
14
|
+
dependencies.
|
|
15
|
+
email: dev@fyipedia.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/trainfyi.rb
|
|
21
|
+
homepage: https://trainfyi.com
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata:
|
|
25
|
+
source_code_uri: https://github.com/fyipedia/trainfyi-rb
|
|
26
|
+
documentation_uri: https://trainfyi.com/api/v1/schema/
|
|
27
|
+
homepage_uri: https://trainfyi.com
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '3.0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubygems_version: 3.0.3.1
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: Ruby client for TrainFYI API
|
|
47
|
+
test_files: []
|