vatzen 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf7ea76e8d953d583636d45d28109ffc74401159192c9bae22e1661f224777c3
4
+ data.tar.gz: 5e8170d0c916aa7c9745feac6b63edcc21358503e922b7ccd88fa5c481d623f5
5
+ SHA512:
6
+ metadata.gz: 841c31c2467a176da557fbd71006d86e0df02543d32b30febda8c36387710c1e2e757efb27186cd1ffd9418e0531bcf755e79327cc043c736c33b44af931d575
7
+ data.tar.gz: 22cf74c67b6e94c760c00b4eef0cad18e9c4530f9328a56719ad3c1be2f5adff532b39317b31019a06337da6bb30707d6a88927617afca9e6eb43567844b20e0
@@ -0,0 +1,23 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ class Api
5
+ def initialize(api_key)
6
+ @api_endpoint = 'https://api.vatzen.com/v1/'
7
+ @headers = {
8
+ 'x-api-key' => api_key,
9
+ 'Content-Type' => 'application/json',
10
+ 'Accept' => 'application/json'
11
+ }
12
+ end
13
+
14
+ def api_get(path, query = {})
15
+ response = HTTParty.get(@api_endpoint + path, :query => query, :headers => @headers)
16
+ response.parsed_response
17
+ end
18
+
19
+ def api_post(path, body = {}, query = {})
20
+ response = HTTParty.post(@api_endpoint + path, :body => body.to_json, :query => query, :headers => @headers)
21
+ response.parsed_response
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'api'
2
+
3
+ class Prices < Api
4
+ def initialize(api_key)
5
+ super(api_key)
6
+ end
7
+
8
+ def get_prices(limit: 100, page: 1)
9
+ self.api_get('prices', {
10
+ 'limit' => limit,
11
+ 'page' => page,
12
+ })
13
+ end
14
+
15
+ def create_price_calculation(amount: nil, vat_included: false, category: nil, country_code: nil, country_name: nil, ip_address: nil, use_client_ip: nil)
16
+ raise "amount is required" if !amount
17
+
18
+ self.api_post('prices', {}, {
19
+ 'amount' => amount,
20
+ 'vat_included' => vat_included,
21
+ 'category' => category,
22
+ 'country_code' => country_code,
23
+ 'country_name' => country_name,
24
+ 'ip_address' => ip_address,
25
+ 'use_client_ip' => use_client_ip,
26
+ })
27
+ end
28
+
29
+ def calculate(amount: nil, vat_included: false, category: nil, country_code: nil, country_name: nil, ip_address: nil, use_client_ip: nil)
30
+ raise "amount is required" if !amount
31
+
32
+ self.api_get('price', {
33
+ 'amount' => amount,
34
+ 'vat_included' => vat_included,
35
+ 'category' => category,
36
+ 'country_code' => country_code,
37
+ 'country_name' => country_name,
38
+ 'ip_address' => ip_address,
39
+ 'use_client_ip' => use_client_ip,
40
+ })
41
+ end
42
+
43
+ def get_calculation_by_id(id)
44
+ self.api_get('prices/' + id)
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'api'
2
+
3
+ class Rates < Api
4
+ def initialize(api_key)
5
+ super(api_key)
6
+ end
7
+
8
+ def get_rate(country_code: nil, country_name: nil, ip_address: nil, use_client_ip: nil)
9
+ self.api_get('rate', {
10
+ 'country_code' => country_code,
11
+ 'country_name' => country_name,
12
+ 'ip_address' => ip_address,
13
+ 'use_client_ip' => use_client_ip,
14
+ })
15
+ end
16
+
17
+ def get_rates(limit: 100, page: 1, member_state: false)
18
+ self.api_get('rates', {
19
+ 'limit' => limit,
20
+ 'page' => page,
21
+ 'member_state' => member_state
22
+ })
23
+ end
24
+
25
+ def get_rate_by_country_code(country_code)
26
+ self.api_get('rate/' + country_code)
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'api'
2
+
3
+ class Validation < Api
4
+ def initialize(api_key)
5
+ super(api_key)
6
+ end
7
+
8
+ def validate(vat_number)
9
+ self.api_get('validate/' + vat_number)
10
+ end
11
+
12
+ def create_validation(vat_number: nil)
13
+ raise 'vat_number is required' if !vat_number
14
+
15
+ self.api_port('validate', {}, { 'vat_number' => vat_number })
16
+ end
17
+
18
+ def get_validations(limit: 100, page: 1)
19
+ self.api_get('validations', {
20
+ 'limit' => limit,
21
+ 'page' => page,
22
+ })
23
+ end
24
+
25
+ def get_validation_by_id(id)
26
+ self.api_get('validations/' + id)
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'rates'
2
+ require_relative 'validation'
3
+ require_relative 'prices'
4
+
5
+ class Vatzen
6
+ def initialize(api_key)
7
+ @rates = Rates.new(api_key)
8
+ @validation = Validation.new(api_key)
9
+ @prices = Prices.new(api_key)
10
+ end
11
+
12
+ attr_accessor :rates, :validation, :prices
13
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vatzen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Kulgavy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby gem for connecting with VatZen API
14
+ email: i.kulgavy@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/api.rb
20
+ - lib/prices.rb
21
+ - lib/rates.rb
22
+ - lib/validation.rb
23
+ - lib/vatzen.rb
24
+ homepage: https://rubygems.org/gems/vatzen
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
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: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.7
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Vatzen
48
+ test_files: []