bigdatacloud 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 788fbb2ae51c6e2253342f4df3845af0f8b6d8663362315bfdd569598519d70c
4
+ data.tar.gz: 220e7a0a41738e2eeb45ba7313fc21b47ef7c7bc7fdf81bdb7fd9d8e5df27ce7
5
+ SHA512:
6
+ metadata.gz: 8dfbecf1b39da4aaae11645bcac43ff00ca0aa213be216539b8c5912e9b21b9d8e40e0dcb6834e955e1aea4fdc9b5f2583a72b6a0d57382b09f2825fa4170280
7
+ data.tar.gz: c9021ebaa92728d4b745b922791071015eca9a831b66254912d0263887780d87198af386520a3e905a8265cfa9ae5c391c6beacba304a63f9989473b947fa31d
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `bigdatacloud` Ruby gem will be documented here.
4
+
5
+ This project follows [Semantic Versioning](https://semver.org/).
6
+
7
+ ---
8
+
9
+ ## [1.0.0] - 2026-04-11
10
+
11
+ ### Initial Release
12
+ - Full typed client with 4 API groups: IP Geolocation, Reverse Geocoding, Verification, Network Engineering
13
+ - All 13 IP Geolocation endpoints covered
14
+ - All 3 Reverse Geocoding endpoints covered
15
+ - All 3 Verification endpoints covered (phone + email)
16
+ - All 7 Network Engineering endpoints covered
17
+ - `BigDataCloud::ConfidenceArea.split_into_polygons()` for multi-polygon confidence areas
18
+ - `BigDataCloud::Client.from_environment` factory reading `BIGDATACLOUD_API_KEY`
19
+ - `validate_phone` and `validate_phone_by_ip` require explicit country/IP — never silently uses server IP
20
+ - Ruby 3.0+ required; tested on Ruby 4.0
21
+ - Zero external dependencies — stdlib `net/http` + `json` only
22
+ - 4 sample scripts verified against live API
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BigDataCloud Pty Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE OF ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # BigDataCloud Ruby SDK
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/bigdatacloud)](https://rubygems.org/gems/bigdatacloud)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+ [![Ruby](https://img.shields.io/badge/Ruby-3.0%2B-red)](https://www.ruby-lang.org)
6
+
7
+ Official Ruby SDK for [BigDataCloud](https://www.bigdatacloud.com) APIs. Strongly-typed client for IP Geolocation, Reverse Geocoding, Phone & Email Verification, and Network Engineering.
8
+
9
+ Zero external dependencies — stdlib `net/http` and `json` only.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ gem install bigdatacloud
15
+ ```
16
+
17
+ Or add to your `Gemfile`:
18
+
19
+ ```ruby
20
+ gem "bigdatacloud"
21
+ ```
22
+
23
+ ## API Key
24
+
25
+ Get a free API key at [bigdatacloud.com/login](https://www.bigdatacloud.com/login). No credit card required.
26
+
27
+ ```bash
28
+ export BIGDATACLOUD_API_KEY=your-key-here
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ```ruby
34
+ require "bigdatacloud"
35
+
36
+ # Reads BIGDATACLOUD_API_KEY from environment
37
+ client = BigDataCloud::Client.from_environment
38
+
39
+ # Or pass the key directly
40
+ # client = BigDataCloud::Client.new("your-key-here")
41
+
42
+ # IP Geolocation
43
+ geo = client.ip_geolocation.get(ip: "1.1.1.1")
44
+ puts "#{geo.location.city}, #{geo.country.name}"
45
+
46
+ # Reverse Geocoding
47
+ place = client.reverse_geocoding.reverse_geocode(-33.87, 151.21)
48
+ puts "#{place.city}, #{place.country_name}"
49
+
50
+ # Phone Validation — country_code is required
51
+ phone = client.verification.validate_phone("+61412345678", "AU")
52
+ puts "Valid: #{phone.is_valid}, Type: #{phone.line_type}"
53
+
54
+ # Email Verification
55
+ email = client.verification.verify_email("user@example.com")
56
+ puts "Valid: #{email.is_valid}, Disposable: #{email.is_disposable}"
57
+ ```
58
+
59
+ ## Confidence Area
60
+
61
+ The `confidence_area` field may encode multiple polygons. Use the helper:
62
+
63
+ ```ruby
64
+ geo = client.ip_geolocation.get_with_confidence_area(ip: "1.1.1.1")
65
+ polygons = BigDataCloud::ConfidenceArea.split_into_polygons(geo.confidence_area)
66
+ polygons.each_with_index do |ring, i|
67
+ puts "Ring #{i + 1}: #{ring.size} points"
68
+ end
69
+ ```
70
+
71
+ ## Available APIs
72
+
73
+ | Client | Methods |
74
+ |--------|---------|
75
+ | `client.ip_geolocation` | `get`, `get_with_confidence_area`, `get_full`, `get_country_by_ip`, `get_country_info`, `get_all_countries`, `get_hazard_report`, `get_user_risk`, `get_asn_info`, `get_network_by_ip`, `get_timezone_by_iana_id`, `get_timezone_by_ip`, `parse_user_agent` |
76
+ | `client.reverse_geocoding` | `reverse_geocode`, `reverse_geocode_with_timezone`, `get_timezone_by_location` |
77
+ | `client.verification` | `validate_phone`, `validate_phone_by_ip`, `verify_email` |
78
+ | `client.network_engineering` | `get_asn_info_full`, `get_receiving_from`, `get_transit_to`, `get_bgp_prefixes`, `get_networks_by_cidr`, `get_asn_rank_list`, `get_tor_exit_nodes` |
79
+
80
+ ## Phone Validation
81
+
82
+ Both methods require explicit country context — never uses server IP silently:
83
+
84
+ ```ruby
85
+ # You know the country
86
+ phone = client.verification.validate_phone("+61412345678", "AU")
87
+
88
+ # You know the end user's IP (pass their IP, not your server's)
89
+ phone = client.verification.validate_phone_by_ip("0412345678", user_ip)
90
+ ```
91
+
92
+ ## Error Handling
93
+
94
+ ```ruby
95
+ begin
96
+ geo = client.ip_geolocation.get(ip: "1.1.1.1")
97
+ rescue BigDataCloud::Error => e
98
+ puts "API error #{e.status_code}: #{e.message}"
99
+ end
100
+ ```
101
+
102
+ ## Samples
103
+
104
+ ```bash
105
+ export BIGDATACLOUD_API_KEY=your-key-here
106
+ ruby samples/ip_geolocation.rb
107
+ ruby samples/reverse_geocoding.rb
108
+ ruby samples/verification.rb
109
+ ruby samples/network_engineering.rb
110
+ ```
111
+
112
+ ## License
113
+
114
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,94 @@
1
+ module BigDataCloud
2
+ module Api
3
+ # IP Geolocation package — 13 endpoints.
4
+ class IpGeolocation
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ # Returns geolocation data for an IP address. Pass nil to use the caller's IP.
10
+ def get(ip: nil, locality_language: "en")
11
+ Models::IpGeolocationResponse.new(
12
+ @http.get("ip-geolocation", { ip: ip, localityLanguage: locality_language })
13
+ )
14
+ end
15
+
16
+ # Returns geolocation including confidence area polygon(s).
17
+ def get_with_confidence_area(ip: nil, locality_language: "en")
18
+ Models::IpGeolocationWithConfidenceAreaResponse.new(
19
+ @http.get("ip-geolocation-with-confidence", { ip: ip, localityLanguage: locality_language })
20
+ )
21
+ end
22
+
23
+ # Returns full geolocation including confidence area and hazard report.
24
+ def get_full(ip: nil, locality_language: "en")
25
+ Models::IpGeolocationFullResponse.new(
26
+ @http.get("ip-geolocation-full", { ip: ip, localityLanguage: locality_language })
27
+ )
28
+ end
29
+
30
+ # Returns country information for an IP address.
31
+ def get_country_by_ip(ip: nil, locality_language: "en")
32
+ data = @http.get("country-by-ip", { ip: ip, localityLanguage: locality_language })
33
+ Models::CountryInfo.new(data["country"] || data)
34
+ end
35
+
36
+ # Returns detailed information about a country by ISO code.
37
+ def get_country_info(country_code, locality_language: "en")
38
+ Models::CountryInfo.new(
39
+ @http.get("country-info", { code: country_code, localityLanguage: locality_language })
40
+ )
41
+ end
42
+
43
+ # Returns a list of all countries with full details.
44
+ def get_all_countries(locality_language: "en")
45
+ data = @http.get("countries", { localityLanguage: locality_language })
46
+ Array(data).map { |c| Models::CountryInfo.new(c) }
47
+ end
48
+
49
+ # Returns a detailed hazard and threat report for an IP address.
50
+ def get_hazard_report(ip: nil)
51
+ Models::HazardReport.new(@http.get("hazard-report", { ip: ip }))
52
+ end
53
+
54
+ # Returns a risk assessment suitable for e-commerce and sign-up flows.
55
+ def get_user_risk(ip: nil)
56
+ Models::UserRisk.new(@http.get("user-risk", { ip: ip }))
57
+ end
58
+
59
+ # Returns short ASN information (no peers/transit lists).
60
+ def get_asn_info(asn, locality_language: "en")
61
+ Models::AsnInfoResponse.new(
62
+ @http.get("asn-info", { asn: asn, localityLanguage: locality_language })
63
+ )
64
+ end
65
+
66
+ # Returns detailed network information for an IP address.
67
+ def get_network_by_ip(ip, locality_language: "en")
68
+ Models::NetworkByIpResponse.new(
69
+ @http.get("network-by-ip", { ip: ip, localityLanguage: locality_language })
70
+ )
71
+ end
72
+
73
+ # Returns timezone information for an IANA timezone ID (e.g. "Australia/Sydney").
74
+ def get_timezone_by_iana_id(iana_time_zone_id)
75
+ Models::TimezoneResponse.new(
76
+ @http.get("timezone-info", { timeZoneId: iana_time_zone_id })
77
+ )
78
+ end
79
+
80
+ # Returns timezone information for an IP address.
81
+ def get_timezone_by_ip(ip: nil)
82
+ Models::TimezoneResponse.new(@http.get("timezone-by-ip", { ip: ip }))
83
+ end
84
+
85
+ # Parses a User-Agent string into device, OS and browser info.
86
+ def parse_user_agent(user_agent_string)
87
+ raise ArgumentError, "user_agent_string must not be empty" if user_agent_string.to_s.strip.empty?
88
+ Models::UserAgentResponse.new(
89
+ @http.get("user-agent-info", { userAgentRaw: user_agent_string })
90
+ )
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,59 @@
1
+ module BigDataCloud
2
+ module Api
3
+ # Network Engineering package — 7 endpoints.
4
+ class NetworkEngineering
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ # Returns extended ASN info including peers, transit, prefix counts, and service area.
10
+ def get_asn_info_full(asn, locality_language: "en")
11
+ Models::AsnInfoFullResponse.new(
12
+ @http.get("asn-info-full", { asn: asn, localityLanguage: locality_language })
13
+ )
14
+ end
15
+
16
+ # Returns paginated upstream providers (ASNs this ASN receives traffic from).
17
+ def get_receiving_from(asn, batch_size: 25, offset: 0, locality_language: "en")
18
+ Models::AsnInfoFullResponse.new(
19
+ @http.get("asn-info-receiving-from", { asn: asn, batchSize: batch_size, offset: offset, localityLanguage: locality_language })
20
+ )
21
+ end
22
+
23
+ # Returns paginated downstream peers (ASNs this ASN provides transit to).
24
+ def get_transit_to(asn, batch_size: 25, offset: 0, locality_language: "en")
25
+ Models::AsnInfoFullResponse.new(
26
+ @http.get("asn-info-transit-to", { asn: asn, batchSize: batch_size, offset: offset, localityLanguage: locality_language })
27
+ )
28
+ end
29
+
30
+ # Returns paginated active BGP prefixes for an ASN. Set +ipv4: false+ for IPv6.
31
+ def get_bgp_prefixes(asn, ipv4: true, batch_size: 25, offset: 0)
32
+ Models::PrefixesListResponse.new(
33
+ @http.get("prefixes-list", { asn: asn, isv4: ipv4 ? "true" : "false", batchSize: batch_size, offset: offset })
34
+ )
35
+ end
36
+
37
+ # Returns all networks announced on BGP within a CIDR range.
38
+ def get_networks_by_cidr(cidr, locality_language: "en")
39
+ Models::NetworkByCidrResponse.new(
40
+ @http.get("network-by-cidr", { cidr: cidr, localityLanguage: locality_language })
41
+ )
42
+ end
43
+
44
+ # Returns a paginated ranked list of all ASNs by IPv4 address space.
45
+ def get_asn_rank_list(batch_size: 15, offset: 0)
46
+ Models::AsnRankListResponse.new(
47
+ @http.get("asn-rank-list", { batchSize: batch_size, offset: offset })
48
+ )
49
+ end
50
+
51
+ # Returns a paginated list of active Tor exit nodes.
52
+ def get_tor_exit_nodes(batch_size: 25, offset: 0)
53
+ Models::TorExitNodesResponse.new(
54
+ @http.get("tor-exit-nodes-list", { batchSize: batch_size, offset: offset })
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ module BigDataCloud
2
+ module Api
3
+ # Reverse Geocoding package — 3 endpoints.
4
+ class ReverseGeocoding
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ # Converts GPS coordinates to city, locality, subdivision, and country.
10
+ def reverse_geocode(latitude, longitude, locality_language: "en")
11
+ Models::ReverseGeocodeResponse.new(
12
+ @http.get("reverse-geocode", { latitude: latitude, longitude: longitude, localityLanguage: locality_language })
13
+ )
14
+ end
15
+
16
+ # Converts GPS coordinates to locality and timezone in a single call.
17
+ def reverse_geocode_with_timezone(latitude, longitude, locality_language: "en")
18
+ Models::ReverseGeocodeWithTimezoneResponse.new(
19
+ @http.get("reverse-geocode-with-timezone", { latitude: latitude, longitude: longitude, localityLanguage: locality_language })
20
+ )
21
+ end
22
+
23
+ # Returns timezone information for GPS coordinates.
24
+ def get_timezone_by_location(latitude, longitude)
25
+ Models::TimezoneResponse.new(
26
+ @http.get("timezone-by-location", { latitude: latitude, longitude: longitude })
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ module BigDataCloud
2
+ module Api
3
+ # Phone & Email Verification package — 3 endpoints.
4
+ class Verification
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ # Validates a phone number. +country_code+ (e.g. "AU") is required.
10
+ # If you know the caller's IP but not their country, use #validate_phone_by_ip instead.
11
+ def validate_phone(phone_number, country_code)
12
+ raise ArgumentError, "phone_number must not be empty" if phone_number.to_s.strip.empty?
13
+ raise ArgumentError,
14
+ 'country_code is required for validate_phone (e.g. "AU"). ' \
15
+ "If you know the caller's IP, use validate_phone_by_ip instead." if country_code.to_s.strip.empty?
16
+ Models::PhoneValidationResponse.new(
17
+ @http.get("phone-number-validate", { number: phone_number, countryCode: country_code })
18
+ )
19
+ end
20
+
21
+ # Validates a phone number using +ip+ for country detection.
22
+ # +ip+ must be the end user's IP address — never the server's.
23
+ def validate_phone_by_ip(phone_number, ip)
24
+ raise ArgumentError, "phone_number must not be empty" if phone_number.to_s.strip.empty?
25
+ raise ArgumentError,
26
+ "ip is required for validate_phone_by_ip — pass the end user's IP. " \
27
+ "If you know the country, use validate_phone instead." if ip.to_s.strip.empty?
28
+ Models::PhoneValidationResponse.new(
29
+ @http.get("phone-number-validate-by-ip", { number: phone_number, ip: ip })
30
+ )
31
+ end
32
+
33
+ # Verifies an email address — checks syntax, mail server, and disposable status.
34
+ def verify_email(email_address)
35
+ raise ArgumentError, "email_address must not be empty" if email_address.to_s.strip.empty?
36
+ Models::EmailVerificationResponse.new(
37
+ @http.get("email-verify", { emailAddress: email_address })
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ module BigDataCloud
2
+ # Official Ruby client for BigDataCloud APIs.
3
+ #
4
+ # Thread-safe — create once and reuse across your application.
5
+ #
6
+ # @example
7
+ # client = BigDataCloud::Client.from_environment
8
+ # geo = client.ip_geolocation.get(ip: "1.1.1.1")
9
+ # puts "#{geo.location.city}, #{geo.country.name}"
10
+ class Client
11
+ attr_reader :ip_geolocation, :reverse_geocoding, :verification, :network_engineering
12
+
13
+ def initialize(api_key, timeout: 30)
14
+ raise ArgumentError, "api_key must not be empty" if api_key.to_s.strip.empty?
15
+ http = HttpClient.new(api_key)
16
+ @ip_geolocation = Api::IpGeolocation.new(http)
17
+ @reverse_geocoding = Api::ReverseGeocoding.new(http)
18
+ @verification = Api::Verification.new(http)
19
+ @network_engineering = Api::NetworkEngineering.new(http)
20
+ end
21
+
22
+ # Creates a client reading the API key from the +BIGDATACLOUD_API_KEY+ environment variable.
23
+ #
24
+ # @raise [RuntimeError] if the environment variable is not set.
25
+ def self.from_environment
26
+ key = ENV["BIGDATACLOUD_API_KEY"]
27
+ raise "BIGDATACLOUD_API_KEY environment variable is not set. " \
28
+ "Set it with: export BIGDATACLOUD_API_KEY=your-key-here" if key.to_s.strip.empty?
29
+ new(key)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,57 @@
1
+ module BigDataCloud
2
+ # Helper for working with confidence area point arrays.
3
+ #
4
+ # The +confidence_area+ field may encode multiple polygons in a flat array.
5
+ # Do NOT treat the entire array as a single polygon ring.
6
+ #
7
+ # @example
8
+ # geo = client.ip_geolocation.get_with_confidence_area("1.1.1.1")
9
+ # polygons = BigDataCloud::ConfidenceArea.split_into_polygons(geo.confidence_area)
10
+ # polygons.each_with_index do |ring, i|
11
+ # puts "Ring #{i + 1}: #{ring.size} points"
12
+ # end
13
+ module ConfidenceArea
14
+ # Splits a flat confidence area point list into individual closed polygon rings.
15
+ #
16
+ # @param points [Array<Models::GeoPoint>] Raw confidence_area from the API.
17
+ # @return [Array<Array<Models::GeoPoint>>] Array of closed polygon rings.
18
+ def self.split_into_polygons(points)
19
+ return [] if points.nil? || points.empty?
20
+
21
+ polygons = []
22
+ current = []
23
+
24
+ points.each do |point|
25
+ if current.any?
26
+ first = current.first
27
+ if approx_equal(first.latitude, point.latitude) &&
28
+ approx_equal(first.longitude, point.longitude)
29
+ current << point
30
+ polygons << current.dup if current.size >= 4
31
+ current = []
32
+ next
33
+ end
34
+ end
35
+ current << point
36
+ end
37
+
38
+ # Handle unclosed trailing polygon
39
+ if current.size >= 3
40
+ current << current.first
41
+ polygons << current
42
+ end
43
+
44
+ polygons
45
+ end
46
+
47
+ # Returns true when the confidence area encodes more than one polygon.
48
+ def self.multi_polygon?(points)
49
+ split_into_polygons(points).size > 1
50
+ end
51
+
52
+ def self.approx_equal(a, b)
53
+ (a - b).abs < 1e-5
54
+ end
55
+ private_class_method :approx_equal
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ module BigDataCloud
2
+ # Raised when the BigDataCloud API returns an error response.
3
+ class Error < StandardError
4
+ attr_reader :status_code, :response_body
5
+
6
+ def initialize(message, status_code: 0, response_body: "")
7
+ super(message)
8
+ @status_code = status_code
9
+ @response_body = response_body
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "uri"
4
+
5
+ module BigDataCloud
6
+ # Lightweight Net::HTTP wrapper. Thread-safe — each request opens its own connection.
7
+ class HttpClient
8
+ BASE_URL = "https://api-bdc.net/data/"
9
+ TIMEOUT = 30
10
+
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ end
14
+
15
+ def get(endpoint, params = {})
16
+ params = params.merge(key: @api_key).reject { |_, v| v.nil? || v.to_s.empty? }
17
+ uri = URI("#{BASE_URL}#{endpoint}")
18
+ uri.query = URI.encode_www_form(params)
19
+
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ http.use_ssl = true
22
+ http.read_timeout = TIMEOUT
23
+ http.open_timeout = TIMEOUT
24
+
25
+ request = Net::HTTP::Get.new(uri)
26
+ request["Accept"] = "application/json"
27
+
28
+ response = http.request(request)
29
+
30
+ unless response.is_a?(Net::HTTPSuccess)
31
+ raise BigDataCloud::Error.new(
32
+ "BigDataCloud API error #{response.code} on '#{endpoint}'.",
33
+ status_code: response.code.to_i,
34
+ response_body: response.body.to_s
35
+ )
36
+ end
37
+
38
+ JSON.parse(response.body)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ module BigDataCloud
2
+ module Models
3
+ # Base model — converts a JSON hash into an object with accessor methods.
4
+ # Uses snake_case accessors mapped from camelCase JSON keys.
5
+ class Base
6
+ def initialize(data = {})
7
+ return unless data.is_a?(Hash)
8
+ data.each do |key, value|
9
+ setter = :"#{snake_case(key)}="
10
+ send(setter, value) if respond_to?(setter, true)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def snake_case(str)
17
+ str.to_s
18
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
19
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
20
+ .downcase
21
+ end
22
+
23
+ def self.attr_model(name, klass)
24
+ define_method(name) { instance_variable_get(:"@#{name}") }
25
+ define_method(:"#{name}=") do |val|
26
+ instance_variable_set(:"@#{name}", val.is_a?(Hash) ? klass.new(val) : val)
27
+ end
28
+ end
29
+
30
+ def self.attr_model_array(name, klass)
31
+ define_method(name) { instance_variable_get(:"@#{name}") || [] }
32
+ define_method(:"#{name}=") do |val|
33
+ arr = Array(val).map { |v| v.is_a?(Hash) ? klass.new(v) : v }
34
+ instance_variable_set(:"@#{name}", arr)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ module BigDataCloud
2
+ module Models
3
+ class GeoPoint < Base
4
+ attr_accessor :latitude, :longitude
5
+ end
6
+
7
+ class Currency < Base
8
+ attr_accessor :numeric_code, :code, :name, :iso_name
9
+ end
10
+
11
+ class WBClassification < Base
12
+ attr_accessor :id, :value
13
+ end
14
+
15
+ class CountryInfo < Base
16
+ attr_accessor :iso_alpha2, :iso_alpha3, :m49_code, :name, :iso_name,
17
+ :iso_name_full, :un_region, :calling_code, :country_flag_emoji
18
+ attr_model :currency, Currency
19
+ attr_model :wb_region, WBClassification
20
+ attr_model :wb_income_level, WBClassification
21
+ end
22
+
23
+ class Location < Base
24
+ attr_accessor :continent, :continent_code, :is_european_union, :city,
25
+ :postcode, :plus_code, :principal_subdivision,
26
+ :principal_subdivision_code, :country_name, :country_code
27
+
28
+ def locality_name=(val); @locality = val; end
29
+ def locality; @locality; end
30
+ end
31
+
32
+ class AdministrativeArea < Base
33
+ attr_accessor :name, :description, :iso_name, :iso_code, :admin_level, :order
34
+ end
35
+
36
+ class LocalityInfo < Base
37
+ attr_model_array :administrative, AdministrativeArea
38
+ attr_model_array :informative, AdministrativeArea
39
+ end
40
+
41
+ class Carrier < Base
42
+ attr_accessor :asn, :asn_numeric, :organisation
43
+ end
44
+
45
+ class Network < Base
46
+ attr_accessor :registry, :registry_status, :registered_country,
47
+ :registered_country_name, :organisation, :bgp_prefix,
48
+ :asn, :is_bogon
49
+ attr_model_array :carriers, Carrier
50
+ end
51
+
52
+ class TimezoneResponse < Base
53
+ attr_accessor :iana_time_id, :display_name, :utc_offset,
54
+ :utc_offset_seconds, :is_daylight_saving_time, :local_time
55
+ end
56
+
57
+ class UserRisk < Base
58
+ attr_accessor :risk, :description
59
+ end
60
+
61
+ class HazardReport < Base
62
+ attr_accessor :is_known_as_tor_server, :is_known_as_vpn, :is_known_as_proxy,
63
+ :is_known_as_datacenter, :is_known_as_bot, :is_spamhaus_drop,
64
+ :is_spamhaus_edrop, :is_spamhaus_asn_drop, :is_blacklisted_uceprotect,
65
+ :is_blacklisted_blocklist_de, :is_blacklisted_aa_tools,
66
+ :hosting_likelihood, :is_hosting_asn, :is_cellular, :security_threat
67
+ attr_model :user_risk, UserRisk
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,32 @@
1
+ module BigDataCloud
2
+ module Models
3
+ class IpGeolocationResponse < Base
4
+ attr_accessor :ip, :last_updated
5
+ attr_model :country, CountryInfo
6
+ attr_model :location, Location
7
+ attr_model :network, Network
8
+ end
9
+
10
+ class IpGeolocationWithConfidenceAreaResponse < Base
11
+ attr_accessor :ip, :confidence, :last_updated
12
+ attr_model :country, CountryInfo
13
+ attr_model :location, Location
14
+ attr_model :network, Network
15
+ attr_model_array :confidence_area, GeoPoint
16
+ end
17
+
18
+ class IpGeolocationFullResponse < Base
19
+ attr_accessor :ip, :confidence, :security_threat, :last_updated
20
+ attr_model :country, CountryInfo
21
+ attr_model :location, Location
22
+ attr_model :network, Network
23
+ attr_model :hazard_report, HazardReport
24
+ attr_model_array :confidence_area, GeoPoint
25
+ end
26
+
27
+ class UserAgentResponse < Base
28
+ attr_accessor :user_agent_raw, :user_agent_display, :user_agent,
29
+ :device, :os, :is_mobile, :is_spider
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,66 @@
1
+ module BigDataCloud
2
+ module Models
3
+ class AsnInfoResponse < Base
4
+ attr_accessor :asn, :asn_numeric, :organisation, :name, :registry,
5
+ :registered_country, :rank, :rank_text,
6
+ :total_ipv4_addresses, :total_ipv4_prefixes, :total_ipv6_prefixes
7
+ end
8
+
9
+ class AsnPeer < Base
10
+ attr_accessor :asn, :asn_numeric, :organisation, :registered_country,
11
+ :rank, :rank_text
12
+ end
13
+
14
+ class AsnInfoFullResponse < Base
15
+ attr_accessor :asn, :asn_numeric, :organisation, :name, :registry,
16
+ :registered_country, :rank, :rank_text,
17
+ :total_ipv4_addresses, :total_ipv4_prefixes, :total_ipv6_prefixes,
18
+ :total_receiving_from, :total_transit_to
19
+ attr_model_array :receiving_from, AsnPeer
20
+ attr_model_array :transit_to, AsnPeer
21
+ attr_model_array :confidence_area, GeoPoint
22
+ end
23
+
24
+ class NetworkByIpResponse < Base
25
+ attr_accessor :ip, :registry, :registry_status, :registered_country,
26
+ :registered_country_name, :organisation, :is_reachable_globally,
27
+ :is_bogon, :bgp_prefix, :bgp_prefix_network_address,
28
+ :bgp_prefix_last_address, :total_addresses
29
+ attr_model_array :carriers, Carrier
30
+ end
31
+
32
+ class BgpPrefix < Base
33
+ attr_accessor :bgp_prefix, :bgp_prefix_network_address, :bgp_prefix_last_address,
34
+ :total_addresses, :allocation_date, :is_bogon
35
+ end
36
+
37
+ class PrefixesListResponse < Base
38
+ attr_accessor :asn, :total
39
+ attr_model_array :prefixes, BgpPrefix
40
+ end
41
+
42
+ class NetworkByCidrResponse < Base
43
+ attr_accessor :cidr, :parent
44
+ attr_model :network, Network
45
+ end
46
+
47
+ class AsnRankEntry < Base
48
+ attr_accessor :asn, :asn_numeric, :organisation, :registered_country,
49
+ :rank, :rank_text, :total_ipv4_addresses
50
+ end
51
+
52
+ class AsnRankListResponse < Base
53
+ attr_accessor :total
54
+ attr_model_array :asns, AsnRankEntry
55
+ end
56
+
57
+ class TorExitNode < Base
58
+ attr_accessor :ip, :country_code, :country_name, :asn, :organisation
59
+ end
60
+
61
+ class TorExitNodesResponse < Base
62
+ attr_accessor :total
63
+ attr_model_array :nodes, TorExitNode
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ module BigDataCloud
2
+ module Models
3
+ class ReverseGeocodeResponse < Base
4
+ attr_accessor :latitude, :longitude, :plus_code, :city, :postcode,
5
+ :principal_subdivision, :principal_subdivision_code,
6
+ :country_name, :country_code, :continent, :continent_code,
7
+ :is_european_union
8
+ attr_model :locality_info, LocalityInfo
9
+
10
+ def locality_name=(val); @locality = val; end
11
+ def locality; @locality; end
12
+ end
13
+
14
+ class ReverseGeocodeWithTimezoneResponse < Base
15
+ attr_accessor :latitude, :longitude, :plus_code, :city, :postcode,
16
+ :principal_subdivision, :principal_subdivision_code,
17
+ :country_name, :country_code, :continent, :continent_code,
18
+ :is_european_union
19
+ attr_model :locality_info, LocalityInfo
20
+ attr_model :time_zone, TimezoneResponse
21
+
22
+ def locality_name=(val); @locality = val; end
23
+ def locality; @locality; end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module BigDataCloud
2
+ module Models
3
+ class PhoneValidationResponse < Base
4
+ attr_accessor :is_valid, :e164_format, :international_format,
5
+ :national_format, :line_type, :location
6
+ attr_model :country, CountryInfo
7
+ end
8
+
9
+ class EmailVerificationResponse < Base
10
+ attr_accessor :input_data, :is_valid, :is_syntax_valid,
11
+ :is_mail_server_defined, :is_known_spammer_domain,
12
+ :is_disposable, :is_valid_for_receiving
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module BigDataCloud
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "bigdatacloud/version"
2
+ require_relative "bigdatacloud/error"
3
+ require_relative "bigdatacloud/http_client"
4
+ require_relative "bigdatacloud/confidence_area"
5
+ require_relative "bigdatacloud/models/base"
6
+ require_relative "bigdatacloud/models/common"
7
+ require_relative "bigdatacloud/models/ip_geolocation"
8
+ require_relative "bigdatacloud/models/reverse_geocoding"
9
+ require_relative "bigdatacloud/models/verification"
10
+ require_relative "bigdatacloud/models/network"
11
+ require_relative "bigdatacloud/api/ip_geolocation"
12
+ require_relative "bigdatacloud/api/reverse_geocoding"
13
+ require_relative "bigdatacloud/api/verification"
14
+ require_relative "bigdatacloud/api/network_engineering"
15
+ require_relative "bigdatacloud/client"
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigdatacloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - BigDataCloud Pty Ltd
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Official Ruby SDK for BigDataCloud APIs — IP Geolocation, Reverse Geocoding,
13
+ Phone & Email Verification, Network Engineering
14
+ email:
15
+ - support@bigdatacloud.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE
22
+ - README.md
23
+ - lib/bigdatacloud.rb
24
+ - lib/bigdatacloud/api/ip_geolocation.rb
25
+ - lib/bigdatacloud/api/network_engineering.rb
26
+ - lib/bigdatacloud/api/reverse_geocoding.rb
27
+ - lib/bigdatacloud/api/verification.rb
28
+ - lib/bigdatacloud/client.rb
29
+ - lib/bigdatacloud/confidence_area.rb
30
+ - lib/bigdatacloud/error.rb
31
+ - lib/bigdatacloud/http_client.rb
32
+ - lib/bigdatacloud/models/base.rb
33
+ - lib/bigdatacloud/models/common.rb
34
+ - lib/bigdatacloud/models/ip_geolocation.rb
35
+ - lib/bigdatacloud/models/network.rb
36
+ - lib/bigdatacloud/models/reverse_geocoding.rb
37
+ - lib/bigdatacloud/models/verification.rb
38
+ - lib/bigdatacloud/version.rb
39
+ homepage: https://www.bigdatacloud.com
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://www.bigdatacloud.com
44
+ source_code_uri: https://github.com/bigdatacloudapi/bigdatacloud-ruby
45
+ documentation_uri: https://www.bigdatacloud.com/docs/sdks
46
+ changelog_uri: https://github.com/bigdatacloudapi/bigdatacloud-ruby/blob/main/CHANGELOG.md
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 4.0.8
62
+ specification_version: 4
63
+ summary: Official Ruby SDK for BigDataCloud APIs
64
+ test_files: []