vatcheckapi 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/README.md +32 -0
- data/lib/vatcheckapi/client.rb +61 -0
- data/lib/vatcheckapi.rb +7 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7db61150097470eb862b0a2db35b82c277c357245eb5e6080c77bae329ae5fcb
|
4
|
+
data.tar.gz: dfc3eda34895bcbf7fc2b448142c3d9d8506ad97416e0e44f3be69e0fd1c4cad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36568c89fbc57010ca70e052dca8f1cb19e2f761ed1b5adc25c90ac22a8a7d45e599eab8a9bfb01d67452abccf6ef470d8b0caa297893a145f8ecd156098bbe3
|
7
|
+
data.tar.gz: 1eb3b96e25679a61359b5b65c264c95eda5237c1f39aa9abe0d7f908e6db50d29c1102231a20239568758e313916a11432946b1bf685cd6132721083da2092e3
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
### vatcheckapi-ruby
|
2
|
+
Ruby client for the `vatcheckapi.com` API.
|
3
|
+
|
4
|
+
Website: [vatcheckapi.com](https://vatcheckapi.com)
|
5
|
+
|
6
|
+
### Installation
|
7
|
+
|
8
|
+
```bash
|
9
|
+
gem install vatcheckapi
|
10
|
+
```
|
11
|
+
|
12
|
+
### Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'vatcheckapi'
|
16
|
+
|
17
|
+
client = Vatcheckapi::Client.new(api_key: ENV['VATCHECK_API_KEY'])
|
18
|
+
|
19
|
+
res = client.check(vat_number: 'DE123456789')
|
20
|
+
puts res
|
21
|
+
|
22
|
+
status = client.status
|
23
|
+
puts status
|
24
|
+
```
|
25
|
+
|
26
|
+
Authentication can be provided via `apikey` header (default) or query parameter:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = Vatcheckapi::Client.new(api_key: 'KEY', auth_in_query: true)
|
30
|
+
```
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Vatcheckapi
|
6
|
+
class Client
|
7
|
+
DEFAULT_BASE_URL = 'https://api.vatcheckapi.com/v2'
|
8
|
+
|
9
|
+
def initialize(api_key:, base_url: DEFAULT_BASE_URL, auth_in_query: false, header_name: 'apikey', timeout: 10)
|
10
|
+
raise ArgumentError, 'api_key is required' if api_key.nil? || api_key.empty?
|
11
|
+
@api_key = api_key
|
12
|
+
@base_url = base_url.gsub(%r{/$}, '')
|
13
|
+
@auth_in_query = !!auth_in_query
|
14
|
+
@header_name = header_name
|
15
|
+
@timeout = timeout
|
16
|
+
end
|
17
|
+
|
18
|
+
def status
|
19
|
+
request('status')
|
20
|
+
end
|
21
|
+
|
22
|
+
def check(params = {})
|
23
|
+
request('check', params)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def request(path, params = {})
|
29
|
+
params = (params || {}).dup
|
30
|
+
if @auth_in_query
|
31
|
+
params['apikey'] ||= @api_key
|
32
|
+
end
|
33
|
+
|
34
|
+
uri = URI.parse("#{@base_url}/#{path}")
|
35
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
36
|
+
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
http.use_ssl = (uri.scheme == 'https')
|
39
|
+
http.read_timeout = @timeout
|
40
|
+
http.open_timeout = @timeout
|
41
|
+
|
42
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
43
|
+
req['Accept'] = 'application/json'
|
44
|
+
req[@header_name] = @api_key unless @auth_in_query
|
45
|
+
|
46
|
+
res = http.request(req)
|
47
|
+
body = res.body.to_s
|
48
|
+
content_type = res['content-type'] || ''
|
49
|
+
data = content_type.include?('application/json') ? JSON.parse(body) rescue { 'raw' => body } : { 'raw' => body }
|
50
|
+
|
51
|
+
unless res.is_a?(Net::HTTPSuccess)
|
52
|
+
message = data.is_a?(Hash) ? (data['message'] || data['error']) : nil
|
53
|
+
raise StandardError, "vatcheckapi error: #{res.code} #{res.message}: #{message}"
|
54
|
+
end
|
55
|
+
|
56
|
+
data
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
data/lib/vatcheckapi.rb
ADDED
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vatcheckapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ''
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: Simple Ruby client for the VAT Check API with status and validate endpoints.
|
13
|
+
executables: []
|
14
|
+
extensions: []
|
15
|
+
extra_rdoc_files: []
|
16
|
+
files:
|
17
|
+
- README.md
|
18
|
+
- lib/vatcheckapi.rb
|
19
|
+
- lib/vatcheckapi/client.rb
|
20
|
+
homepage: https://vatcheckapi.com/
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata:
|
24
|
+
homepage_uri: https://vatcheckapi.com/
|
25
|
+
source_code_uri: https://github.com/everapihq/vatcheckapi-ruby
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.7.2
|
41
|
+
specification_version: 4
|
42
|
+
summary: Ruby client for vatcheckapi.com (status, validate)
|
43
|
+
test_files: []
|