greip 1.0.0 → 1.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: ebdb7873c4bbcf7cd5fc3a8b0cdaf8f51b828cfa28caf4c30dea54fae600ad7b
4
- data.tar.gz: 10884b2aa0fa86d1f1e186e657c7de2ffedb47c45900a41535d9b5872689e561
3
+ metadata.gz: 4bbddd021eaf8e658594c1f357074319d34322d82c25b4e9492b8f2ec9a51f15
4
+ data.tar.gz: a3ca4eee13821dbc872069fb0b39ccc2ff2d32c041a2abe2c56e22262ec8eb21
5
5
  SHA512:
6
- metadata.gz: f73126699d34c56599a945b2183a6d054a9e8950988aae0177053adbe07b6bb4cfde48caa7426692ce2fbb3f9d102e446ef2761331087854806c31c7d015a3b2
7
- data.tar.gz: 71a209235dbb27ac64809e9adf0405a4b573b430894cad98271a38641423a4bcbbe667a672d5489fdb61c0eea522e89f8e86184a833590dbae887f61b3ea7700
6
+ metadata.gz: 8ca0eb6afe3fd0a4d78c8fed60dad90c833d1f255169c778ad5d9851a0910c9389ed20a2fdcd710c40720013a0be691ef91251cd0f34f5f3370b1f528b800dc5
7
+ data.tar.gz: 22b2b21d15bd94da949bb22bff9c2ef8192e1f7e0d155456c33bd7c10c7af932e6381fa668b546c787af2c329d85c426d3ee100372997505b9cc2587905b6705
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ - Trolling, insulting or derogatory comments, and personal or political attacks
24
+ - Public or private harassment
25
+ - Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ - Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at info@greip.io. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/README.md CHANGED
@@ -49,7 +49,7 @@ Here's how you use the methods:
49
49
  require 'greip'
50
50
 
51
51
  access_token = 'your-api-key-goes-here'
52
- handler = greip::create(access_token)
52
+ handler = Greip.create(access_token)
53
53
  data = handler.lookup({ ip: "1.1.1.1", params: ["security", "timezone", "currency"], lang: "EN", mode: "live" })
54
54
 
55
55
  puts data
@@ -58,215 +58,168 @@ puts data
58
58
 
59
59
  ### 2. Bulk IP Lookup Method
60
60
 
61
- ```javascript
62
- const { Greip } = require("greip-node");
63
-
64
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
65
-
66
- greip
67
- .BulkLookup({
68
- ips: ["1.1.1.1", "2.2.2.2"],
69
- })
70
- .then((res: any) => {
71
- console.log(res.data); // Log Response
72
- })
73
- .catch((error: any) => {
74
- console.log(error);
75
- });
61
+ ```ruby
62
+ require 'greip'
63
+
64
+ access_token = 'your-api-key-goes-here'
65
+ handler = Greip.create(access_token)
66
+
67
+ data = handler.bulk_lookup({ ips: ["1.1.1.1", "2.2.2.2"], params: ["security", "timezone", "currency"], lang: "EN", mode: "live" })
68
+
69
+ puts data
76
70
  ```
77
71
 
78
72
  ### 3. ASN Lookup Method
79
73
 
80
- ```javascript
81
- const { Greip } = require("greip-node");
82
-
83
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
84
-
85
- greip
86
- .ASN({
87
- asn: "AS01",
88
- })
89
- .then((res: any) => {
90
- console.log(res.data); // Log Response
91
- })
92
- .catch((error: any) => {
93
- console.log(error);
94
- });
74
+ ```ruby
75
+ require 'greip'
76
+
77
+ access_token = 'your-api-key-goes-here'
78
+ handler = Greip.create(access_token)
79
+
80
+ data = handler.asn({ asn: "AS01", mode: "live" })
81
+
82
+ puts data
95
83
  ```
96
84
 
97
85
  ### 4. Profanity Detection Method
98
86
 
99
- ```javascript
100
- const { Greip } = require("greip-node");
101
-
102
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
103
-
104
- greip
105
- .Profanity({
106
- text: "This is just normal sample text.",
107
- })
108
- .then((res: any) => {
109
- console.log(res.data); // Log Response
110
- })
111
- .catch((error: any) => {
112
- console.log(error);
113
- });
87
+ ```ruby
88
+ require 'greip'
89
+
90
+ access_token = 'your-api-key-goes-here'
91
+ handler = Greip.create(access_token)
92
+
93
+ data = handler.profanity({ text: "This is just a normal text", lang: "EN", mode: "live" })
94
+
95
+ puts data
114
96
  ```
115
97
 
116
98
  ### 5. Country Lookup Method
117
99
 
118
- ```javascript
119
- const { Greip } = require("greip-node");
120
-
121
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
122
-
123
- greip
124
- .Country({
125
- countryCode: "SA",
126
- })
127
- .then((res: any) => {
128
- console.log(res.data); // Log Response
129
- })
130
- .catch((error: any) => {
131
- console.log(error);
132
- });
100
+ ```ruby
101
+ require 'greip'
102
+
103
+ access_token = 'your-api-key-goes-here'
104
+ handler = Greip.create(access_token)
105
+
106
+ data = handler.country({ countryCode: "PS", params: ["timezone", "currency"], lang: "EN", mode: "live" })
107
+
108
+ puts data
133
109
  ```
134
110
 
135
111
  ### 6. Email Validation Method
136
112
 
137
- ```javascript
138
- const { Greip } = require("greip-node");
139
-
140
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
141
-
142
- greip
143
- .EmailValidation({
144
- email: "name@domain.com",
145
- })
146
- .then((res: any) => {
147
- console.log(res.data); // Log Response
148
- })
149
- .catch((error: any) => {
150
- console.log(error);
151
- });
113
+ ```ruby
114
+ require 'greip'
115
+
116
+ access_token = 'your-api-key-goes-here'
117
+ handler = Greip.create(access_token)
118
+
119
+ data = handler.email_validation({ email: "name@domain.com", mode: "live" })
120
+
121
+ puts data
152
122
  ```
153
123
 
154
124
  ### 7. Phone Validation Method
155
125
 
156
- ```javascript
157
- const { Greip } = require("greip-node");
158
-
159
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
160
-
161
- greip
162
- .PhoneValidation({
163
- phone: "123123123",
164
- countryCode: "US",
165
- })
166
- .then((res: any) => {
167
- console.log(res.data); // Log Response
168
- })
169
- .catch((error: any) => {
170
- console.log(error);
171
- });
126
+ ```ruby
127
+ require 'greip'
128
+
129
+ access_token = 'your-api-key-goes-here'
130
+ handler = Greip.create(access_token)
131
+
132
+ data = handler.phone_validation({ phone: "1234567890", countryCode: "TR", mode: "live" })
133
+
134
+ puts data
172
135
  ```
173
136
 
174
137
  ### 8. Payment Fraud Prevention Method
175
138
 
176
- ```javascript
177
- const { Greip } = require("greip-node");
178
-
179
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
180
-
181
- greip
182
- .PaymentFraud({
183
- data: {
184
- action: "purchase",
185
- website_domain: "",
186
- website_name: "",
187
- merchant_id: 21,
188
- shipment_id: 1,
189
- transaction_id: 100,
190
- transaction_amount: 1000000,
191
- transaction_currency: "GBP",
192
- cart_items: {
193
- item_id: 1,
194
- item_name: "Product name",
195
- item_quantity: 1,
196
- item_price: "1100.55",
197
- item_category_id: 1,
198
- },
199
- isDigitalProducts: true,
200
- coupon: "ASDF",
201
- customer_id: 1,
202
- customer_firstname: "First",
203
- customer_lastname: "Last",
204
- customer_pob: "London",
205
- customer_ip: "1.1.1.1",
206
- customer_country: "GB",
207
- customer_region: "London",
208
- customer_city: "London",
209
- customer_zip: "NW10 7PQ",
210
- customer_street: "7 Coronation Road",
211
- customer_street2: "",
212
- customer_latitude: 0.123,
213
- customer_longitude: 0.123,
214
- customer_device_id: "UNIQUE_DEVICE_ID",
215
- customer_phone: "000000000",
216
- customer_registration_date: 1677554670,
217
- customer_balance: "1000.00",
218
- customer_dob: "1997-19-05",
219
- customer_email: "name@domain.com",
220
- customer_2fa: true,
221
- customer_useragent: "Mozill almaden sdfwer",
222
- shipping_country: "GB",
223
- shipping_region: "London",
224
- shipping_city: "London",
225
- shipping_zip: "NW10 7PQ",
226
- shipping_street: "7 Coronation Road",
227
- shipping_street2: "",
228
- shipping_latitude: 0.123,
229
- shipping_longitude: 0.123,
230
- billing_country: "GB",
231
- billing_region: "London",
232
- billing_city: "London",
233
- billing_zip: "NW10 7PQ",
234
- billing_street: "7 Coronation Road",
235
- billing_street2: "",
236
- billing_latitude: 0.123,
237
- billing_longitude: 0.123,
238
- payment_type: "applepay",
239
- card_name: "First Last",
240
- card_number: "1234XXXXXXXX1234",
241
- card_expiry: "29/05",
242
- cvv_result: true,
243
- },
244
- })
245
- .then((res: any) => {
246
- console.log(res.data); // Log Response
247
- })
248
- .catch((error: any) => {
249
- console.log(error);
250
- });
139
+ ```ruby
140
+ require 'greip'
141
+
142
+ access_token = 'your-api-key-goes-here'
143
+ handler = Greip.create(access_token)
144
+
145
+ payload = {
146
+ action: "purchase",
147
+ website_domain: "",
148
+ website_name: "",
149
+ merchant_id: 21,
150
+ shipment_id: 1,
151
+ transaction_id: 100,
152
+ transaction_amount: 1000000,
153
+ transaction_currency: "GBP",
154
+ cart_items: {
155
+ item_id: 1,
156
+ item_name: "Product name",
157
+ item_quantity: 1,
158
+ item_price: "1100.55",
159
+ item_category_id: 1,
160
+ },
161
+ isDigitalProducts: true,
162
+ coupon: "ASDF",
163
+ customer_id: 1,
164
+ customer_firstname: "First",
165
+ customer_lastname: "Last",
166
+ customer_pob: "London",
167
+ customer_ip: "1.1.1.1",
168
+ customer_country: "GB",
169
+ customer_region: "London",
170
+ customer_city: "London",
171
+ customer_zip: "NW10 7PQ",
172
+ customer_street: "7 Coronation Road",
173
+ customer_street2: "",
174
+ customer_latitude: 0.123,
175
+ customer_longitude: 0.123,
176
+ customer_device_id: "UNIQUE_DEVICE_ID",
177
+ customer_phone: "000000000",
178
+ customer_registration_date: 1677554670,
179
+ customer_balance: "1000.00",
180
+ customer_dob: "1997-19-05",
181
+ customer_email: "name@domain.com",
182
+ customer_2fa: true,
183
+ customer_useragent: "Mozill almaden sdfwer",
184
+ shipping_country: "GB",
185
+ shipping_region: "London",
186
+ shipping_city: "London",
187
+ shipping_zip: "NW10 7PQ",
188
+ shipping_street: "7 Coronation Road",
189
+ shipping_street2: "",
190
+ shipping_latitude: 0.123,
191
+ shipping_longitude: 0.123,
192
+ billing_country: "GB",
193
+ billing_region: "London",
194
+ billing_city: "London",
195
+ billing_zip: "NW10 7PQ",
196
+ billing_street: "7 Coronation Road",
197
+ billing_street2: "",
198
+ billing_latitude: 0.123,
199
+ billing_longitude: 0.123,
200
+ payment_type: "applepay",
201
+ card_name: "First Last",
202
+ card_number: "1234XXXXXXXX1234",
203
+ card_expiry: "29/05",
204
+ cvv_result: true,
205
+ }
206
+
207
+ data = handler.payment_fraud({ data: payload })
208
+
209
+ puts data
251
210
  ```
252
211
 
253
212
  ### 9. IBAN Validation Method
254
213
 
255
- ```javascript
256
- const { Greip } = require("greip-node");
257
-
258
- let greip = new Greip(process.env.YOUR_GREIP_TOKEN);
259
-
260
- greip
261
- .IBANValidation({
262
- iban: "BY86AKBB10100000002966000000",
263
- })
264
- .then((res: any) => {
265
- console.log(res); // Log Response
266
- })
267
- .catch((error: any) => {
268
- console.log(error);
269
- });
214
+ ```ruby
215
+ require 'greip'
216
+
217
+ access_token = 'your-api-key-goes-here'
218
+ handler = Greip.create(access_token)
219
+
220
+ data = handler.iban_validation({ iban: "BY86AKBB10100000002966000000" })
221
+
222
+ puts data
270
223
  ```
271
224
 
272
225
  ## Options, Methods and More
@@ -277,4 +230,4 @@ You can find the full guide of this package by visiting our
277
230
  ## Credits
278
231
 
279
232
  - [Greip Developers](https://greip.io)
280
- - [All Contributors](https://github.com/Greipio/node/graphs/contributors)
233
+ - [All Contributors](https://github.com/Greipio/ruby/graphs/contributors)
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Layout/LineLength
4
+
5
+ require "bundler/gem_tasks"
6
+ require "rake/testtask"
7
+
8
+ # Define the test tasks
9
+ task_names = %w[lookup bulk_lookup country profanity asn email_validation phone_validation iban_validation payment_fraud]
10
+ task_names.each do |task_name|
11
+ Rake::TestTask.new(task_name) do |t|
12
+ t.libs << "test"
13
+ t.pattern = "test/#{task_name}_test.rb"
14
+ t.verbose = true
15
+ end
16
+ end
17
+
18
+ desc "Run all tests"
19
+ task :test do
20
+ task_names.each { |task_name| Rake::Task[task_name].invoke }
21
+ end
22
+
23
+ desc "Default task"
24
+ task default: :test
25
+
26
+ # rubocop:enable Layout/LineLength
data/env.example ADDED
@@ -0,0 +1 @@
1
+ TOKEN="your-greip-api-key"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Greip
4
+ BASE_URL = "https://gregeoip.com"
5
+
6
+ AVAILABLE_LANGUAGES = %w[EN AR DE FR ES JA ZH RU].freeze
7
+ AVAILABLE_GEOIP_PARAMS = %w[location security timezone currency device].freeze
8
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErrorMessages
4
+ MODE = "The `mode` option value you specified is unknown.\n" \
5
+ "You can use: `live` or `test`.\nRead more at: " \
6
+ "https://docs.greip.io/api-reference/endpoint/payment-fraud/payment-fraud-prevention"
7
+
8
+ DATA = "You should pass the `data` parameter."
9
+
10
+ COUNTRY_CODE_PHONE = "You should pass both `phone` and `countryCode` parameters."
11
+
12
+ IP = "You should pass the `ip` parameter."
13
+
14
+ IPS = "You should pass the `ips` parameter."
15
+
16
+ VALID_IPS = "You should pass a valid IP Addresses in the `ips` parameter."
17
+
18
+ LANG = "The `lang` option value you specified is unknown.\n" \
19
+ "You can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, or `RU`."
20
+
21
+ TEXT = "You should pass the `text` parameter."
22
+
23
+ ASN = "You should pass the `asn` parameter."
24
+
25
+ EMAIL = "You should pass the `email` parameter."
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Greip
4
+ VERSION = "1.1.1"
5
+ end
data/lib/greip.rb ADDED
@@ -0,0 +1,350 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/AbcSize
4
+ # rubocop:disable Metrics/ClassLength
5
+ # rubocop:disable Metrics/CyclomaticComplexity
6
+ # rubocop:disable Metrics/MethodLength
7
+ # rubocop:disable Metrics/PerceivedComplexity
8
+ # rubocop:disable Style/NegatedIf
9
+
10
+ require_relative "greip/version"
11
+ require_relative "greip/constants"
12
+ require_relative "greip/error_messages"
13
+
14
+ require "json"
15
+ require "net/http"
16
+ require "uri"
17
+
18
+ # Greip module
19
+ module Greip
20
+ class Error < StandardError; end
21
+
22
+ # GreipHandler class
23
+ class GreipHandler
24
+ def initialize(token)
25
+ @token = token
26
+ end
27
+
28
+ def lookup(options)
29
+ ip = options[:ip] || ""
30
+ params = options[:params] || []
31
+ lang = (options[:lang] || "EN").upcase
32
+ mode = (options[:mode] || "live").downcase
33
+
34
+ # Validate the ip variable
35
+ raise StandardError, ErrorMessages::IP unless ip.length > 5
36
+
37
+ # Validate the params variable items
38
+ params.each do |per_param|
39
+ if !per_param.empty? && !AVAILABLE_GEOIP_PARAMS.include?(per_param)
40
+ raise StandardError, "The '#{per_param}' module you used is unknown.\n" \
41
+ "You can use: `location`, `security`, `timezone`, `currency`, and/or `device`."
42
+ end
43
+ end
44
+
45
+ # Validate the lang variable
46
+ !AVAILABLE_LANGUAGES.include?(lang) && (raise StandardError, ErrorMessages::LANG)
47
+
48
+ # Validate the mode variable
49
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
50
+
51
+ url = URI(BASE_URL + "/IPLookup?ip=#{ip}&params=#{params.join(",")}&lang=#{lang}&mode=#{mode}&source=Ruby-Gem")
52
+
53
+ http = Net::HTTP.new(url.host, url.port)
54
+ http.use_ssl = (url.scheme == "https")
55
+
56
+ request = Net::HTTP::Get.new(url)
57
+ request["Authorization"] = "Bearer #{@token}"
58
+
59
+ response = http.request(request)
60
+
61
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
62
+
63
+ parsed_response = JSON.parse(response.body)
64
+
65
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
66
+
67
+ parsed_response["data"]
68
+ end
69
+
70
+ def bulk_lookup(options)
71
+ ips = options[:ips] || []
72
+ params = options[:params] || []
73
+ lang = (options[:lang] || "EN").upcase
74
+ mode = (options[:mode] || "live").downcase
75
+
76
+ ips = [] unless ips.is_a?(Array)
77
+
78
+ # Validate the ips variable
79
+ raise StandardError, ErrorMessages::IPS if ips.empty?
80
+
81
+ ips.each do |ip|
82
+ raise StandardError, ErrorMessages::VALID_IPS if ip.length < 7
83
+ end
84
+
85
+ # Validate the params variable items
86
+ params.each do |param|
87
+ if !param.empty? && !AVAILABLE_GEOIP_PARAMS.include?(param)
88
+ raise StandardError, "The '#{param}' module you used is unknown.\n" \
89
+ "You can use: `location`, `security`, `timezone`, `currency`, and/or `device`."
90
+ end
91
+ end
92
+
93
+ # Validate the lang variable
94
+ !AVAILABLE_LANGUAGES.include?(lang) && (raise StandardError, ErrorMessages::LANG)
95
+
96
+ # Validate the mode variable
97
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
98
+
99
+ url = URI("#{BASE_URL}/BulkLookup?ips=#{ips.join(",")}&params=#{params.join(",")}&lang=#{lang}&mode=#{mode}")
100
+
101
+ http = Net::HTTP.new(url.host, url.port)
102
+ http.use_ssl = (url.scheme == "https")
103
+
104
+ request = Net::HTTP::Get.new(url)
105
+ request["Authorization"] = "Bearer #{@token}"
106
+
107
+ response = http.request(request)
108
+
109
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
110
+
111
+ parsed_response = JSON.parse(response.body)
112
+
113
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
114
+
115
+ parsed_response["data"]
116
+ end
117
+
118
+ def country(options)
119
+ country_code = options[:countryCode] || ""
120
+ params = options[:params] || []
121
+ lang = (options[:lang] || "EN").upcase
122
+ mode = (options[:mode] || "live").downcase
123
+
124
+ # Validate the params variable items
125
+ params.each do |param|
126
+ next unless param.empty? || !AVAILABLE_COUNTRY_PARAMS.include?(param)
127
+
128
+ raise StandardError, "The '#{param}' module you used is unknown.\n" \
129
+ "You can use: `language`, `flag`, `currency`, and/or `timezone`.\n" \
130
+ "Read more at: https://docs.greip.io/api-reference/endpoint/other-services/country-data"
131
+ end
132
+
133
+ # Validate the lang variable
134
+ raise StandardError, ErrorMessages::LANG if !AVAILABLE_LANGUAGES.include?(lang)
135
+
136
+ # Validate the mode variable
137
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
138
+
139
+ url = URI("#{BASE_URL}/Country?CountryCode=#{country_code}&params=#{params.join(",")}&lang=#{lang}&mode=#{mode}")
140
+
141
+ http = Net::HTTP.new(url.host, url.port)
142
+ http.use_ssl = (url.scheme == "https")
143
+
144
+ request = Net::HTTP::Get.new(url)
145
+ request["Authorization"] = "Bearer #{@token}"
146
+
147
+ response = http.request(request)
148
+
149
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
150
+
151
+ parsed_response = JSON.parse(response.body)
152
+
153
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
154
+
155
+ parsed_response["data"]
156
+ end
157
+
158
+ def profanity(options)
159
+ text = options[:text] || ""
160
+ params = options[:params] || []
161
+ lang = (options[:lang] || "EN").upcase
162
+ mode = (options[:mode] || "live").downcase
163
+
164
+ # Validate the text variable
165
+ raise StandardError, ErrorMessages::TEXT if text.empty?
166
+
167
+ # Validate the lang variable
168
+ raise StandardError, ErrorMessages::LANG if !AVAILABLE_LANGUAGES.include?(lang)
169
+
170
+ # Validate the mode variable
171
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
172
+
173
+ url = URI("#{BASE_URL}/badWords?text=#{text}&params=#{params.join(",")}&format=JSON&lang=#{lang}&mode=#{mode}")
174
+
175
+ http = Net::HTTP.new(url.host, url.port)
176
+ http.use_ssl = (url.scheme == "https")
177
+
178
+ request = Net::HTTP::Get.new(url)
179
+ request["Authorization"] = "Bearer #{@token}"
180
+
181
+ response = http.request(request)
182
+
183
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
184
+
185
+ parsed_response = JSON.parse(response.body)
186
+
187
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
188
+
189
+ parsed_response["data"]
190
+ end
191
+
192
+ def asn(options)
193
+ asn = (options[:asn] || "").upcase
194
+ mode = (options[:mode] || "live").downcase
195
+
196
+ # Validate the asn variable
197
+ raise StandardError, ErrorMessages::ASN if asn.empty?
198
+
199
+ # Validate the mode variable
200
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
201
+
202
+ url = URI("#{BASE_URL}/ASNLookup?asn=#{asn}&mode=#{mode}")
203
+
204
+ http = Net::HTTP.new(url.host, url.port)
205
+ http.use_ssl = (url.scheme == "https")
206
+
207
+ request = Net::HTTP::Get.new(url)
208
+ request["Authorization"] = "Bearer #{@token}"
209
+
210
+ response = http.request(request)
211
+
212
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
213
+
214
+ parsed_response = JSON.parse(response.body)
215
+
216
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
217
+
218
+ parsed_response["data"]
219
+ end
220
+
221
+ def email_validation(options)
222
+ email = (options[:email] || "").downcase
223
+ mode = (options[:mode] || "live").downcase
224
+
225
+ # Validate the email variable
226
+ raise StandardError, ErrorMessages::EMAIL if email.empty?
227
+
228
+ # Validate the mode variable
229
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
230
+
231
+ url = URI("#{BASE_URL}/validateEmail?email=#{email}&mode=#{mode}")
232
+
233
+ http = Net::HTTP.new(url.host, url.port)
234
+ http.use_ssl = (url.scheme == "https")
235
+
236
+ request = Net::HTTP::Get.new(url)
237
+ request["Authorization"] = "Bearer #{@token}"
238
+
239
+ response = http.request(request)
240
+
241
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
242
+
243
+ parsed_response = JSON.parse(response.body)
244
+
245
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
246
+
247
+ parsed_response["data"]
248
+ end
249
+
250
+ def phone_validation(options)
251
+ phone = options[:phone] || ""
252
+ country_code = (options[:countryCode] || "").upcase
253
+ mode = (options[:mode] || "live").downcase
254
+
255
+ # Validate the phone and countryCode variables
256
+ (phone.empty? || country_code.empty?) && (raise StandardError, ErrorMessages::COUNTRY_CODE_PHONE)
257
+
258
+ # Validate the mode variable
259
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
260
+
261
+ url = URI("#{BASE_URL}/validatePhone?phone=#{phone}&countryCode=#{country_code}&mode=#{mode}")
262
+
263
+ http = Net::HTTP.new(url.host, url.port)
264
+ http.use_ssl = (url.scheme == "https")
265
+
266
+ request = Net::HTTP::Get.new(url)
267
+ request["Authorization"] = "Bearer #{@token}"
268
+
269
+ response = http.request(request)
270
+
271
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
272
+
273
+ parsed_response = JSON.parse(response.body)
274
+
275
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
276
+
277
+ parsed_response["data"]
278
+ end
279
+
280
+ def iban_validation(options)
281
+ iban = (options[:iban] || "").upcase
282
+ mode = (options[:mode] || "live").downcase
283
+
284
+ # Validate the iban variable
285
+ raise StandardError, "You should pass the `iban` parameter." if iban.empty?
286
+
287
+ # Validate the mode variable
288
+ mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)
289
+
290
+ url = URI("#{BASE_URL}/validateIBAN?iban=#{iban}&mode=#{mode}")
291
+
292
+ http = Net::HTTP.new(url.host, url.port)
293
+ http.use_ssl = (url.scheme == "https")
294
+
295
+ request = Net::HTTP::Get.new(url)
296
+ request["Authorization"] = "Bearer #{@token}"
297
+
298
+ response = http.request(request)
299
+
300
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
301
+
302
+ parsed_response = JSON.parse(response.body)
303
+
304
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
305
+
306
+ parsed_response["data"]
307
+ end
308
+
309
+ def payment_fraud(options)
310
+ data = options[:data] || []
311
+ mode = (options[:mode] || "live").downcase
312
+
313
+ # Validate the mode variable
314
+ raise StandardError, ErrorMessages::MODE unless %w[live test].include?(mode)
315
+
316
+ # Validate the data variable
317
+ raise StandardError, ErrorMessages::DATA unless data.is_a?(Hash) && !data.empty?
318
+
319
+ url = URI("#{BASE_URL}/paymentFraud")
320
+
321
+ http = Net::HTTP.new(url.host, url.port)
322
+ http.use_ssl = (url.scheme == "https")
323
+
324
+ request = Net::HTTP::Post.new(url)
325
+ request["Content-Type"] = "application/json"
326
+ request["Authorization"] = "Bearer #{@token}"
327
+ request.body = data.to_json
328
+
329
+ response = http.request(request)
330
+
331
+ raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"
332
+
333
+ parsed_response = JSON.parse(response.body)
334
+ raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"
335
+
336
+ parsed_response["data"]
337
+ end
338
+ end
339
+
340
+ def self.create(token)
341
+ GreipHandler.new(token)
342
+ end
343
+ end
344
+
345
+ # rubocop:enable Style/NegatedIf
346
+ # rubocop:enable Metrics/PerceivedComplexity
347
+ # rubocop:enable Metrics/MethodLength
348
+ # rubocop:enable Metrics/CyclomaticComplexity
349
+ # rubocop:enable Metrics/ClassLength
350
+ # rubocop:enable Metrics/AbcSize
data/sig/greip.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Greip
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greip Team
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-08 00:00:00.000000000 Z
11
+ date: 2024-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,19 +38,86 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- description: The official Gem of Greip for Ruby on Rails
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.37'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.37'
97
+ description: The official Gem of Greip for Ruby.
42
98
  email:
43
99
  - info@greip.io
44
100
  executables: []
45
101
  extensions: []
46
- extra_rdoc_files:
47
- - README.md
102
+ extra_rdoc_files: []
48
103
  files:
104
+ - ".rubocop.yml"
105
+ - CODE_OF_CONDUCT.md
49
106
  - README.md
107
+ - Rakefile
108
+ - env.example
109
+ - lib/greip.rb
110
+ - lib/greip/constants.rb
111
+ - lib/greip/error_messages.rb
112
+ - lib/greip/version.rb
113
+ - sig/greip.rbs
50
114
  homepage: https://greip.io/
51
115
  licenses:
52
116
  - Apache-2.0
53
- metadata: {}
117
+ metadata:
118
+ homepage_uri: https://greip.io/
119
+ source_code_uri: https://github.com/Greipio/ruby
120
+ changelog_uri: https://changelog.greip.io/
54
121
  post_install_message:
55
122
  rdoc_options: []
56
123
  require_paths:
@@ -59,15 +126,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
126
  requirements:
60
127
  - - ">="
61
128
  - !ruby/object:Gem::Version
62
- version: 2.5.0
129
+ version: 3.0.0
63
130
  required_rubygems_version: !ruby/object:Gem::Requirement
64
131
  requirements:
65
132
  - - ">="
66
133
  - !ruby/object:Gem::Version
67
134
  version: '0'
68
135
  requirements: []
69
- rubygems_version: 3.2.3
136
+ rubygems_version: 3.5.6
70
137
  signing_key:
71
138
  specification_version: 4
72
- summary: Greip services for Ruby on Rails
139
+ summary: Greip services for Ruby.
73
140
  test_files: []