tenios-api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +9 -3
- data/README.md +19 -3
- data/lib/tenios/api/call_detail_records.rb +56 -0
- data/lib/tenios/api/client.rb +16 -34
- data/lib/tenios/api/number.rb +39 -0
- data/lib/tenios/api/verification.rb +73 -0
- data/lib/tenios/api/version.rb +3 -1
- data/lib/tenios/api.rb +4 -1
- data/lib/tenios-api.rb +2 -0
- data/tenios-api.gemspec +3 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 432dc3d9f0e7fc555722bad490b36d2f7d4be866df5c3458af6c9044ef6b57eb
|
4
|
+
data.tar.gz: 37128cbd40ba9000eb72429c1c2b3eaab39e9418a7bf775f6c8f7c609eb58edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0841faadf6ad05340b1eaa6a3c523fb7bfb4b4f242bc387405a3be241b43b9dfbf4efc5696110564640892e9853b391309a4f7f202c2e3a1f8567713fd2c7b2
|
7
|
+
data.tar.gz: 2485adec0b7a8ae0a43cafca6aeb4d7267e59557973ff497827853a499a734d53e656f59bb0e6bc129e08d475836a39dfbc620fda3f9b552aec0e13ac789c6de
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tenios-api (0.
|
4
|
+
tenios-api (0.2.0)
|
5
5
|
faraday
|
6
6
|
faraday_middleware
|
7
7
|
|
@@ -12,17 +12,22 @@ GEM
|
|
12
12
|
carwow_rubocop (2.1.1)
|
13
13
|
rubocop (~> 0.58)
|
14
14
|
rubocop-rspec (~> 1.28)
|
15
|
+
coderay (1.1.2)
|
15
16
|
diff-lcs (1.3)
|
16
17
|
faraday (0.15.4)
|
17
18
|
multipart-post (>= 1.2, < 3)
|
18
19
|
faraday_middleware (0.13.1)
|
19
20
|
faraday (>= 0.7.4, < 1.0)
|
20
21
|
jaro_winkler (1.5.2)
|
21
|
-
|
22
|
+
method_source (0.9.2)
|
23
|
+
multipart-post (2.1.1)
|
22
24
|
parallel (1.13.0)
|
23
25
|
parser (2.6.0.0)
|
24
26
|
ast (~> 2.4.0)
|
25
27
|
powerpack (0.1.2)
|
28
|
+
pry (0.12.2)
|
29
|
+
coderay (~> 1.1.0)
|
30
|
+
method_source (~> 0.9.0)
|
26
31
|
psych (3.1.0)
|
27
32
|
rainbow (3.0.0)
|
28
33
|
rake (12.3.2)
|
@@ -59,9 +64,10 @@ PLATFORMS
|
|
59
64
|
DEPENDENCIES
|
60
65
|
bundler
|
61
66
|
carwow_rubocop
|
67
|
+
pry
|
62
68
|
rake
|
63
69
|
rspec
|
64
70
|
tenios-api!
|
65
71
|
|
66
72
|
BUNDLED WITH
|
67
|
-
|
73
|
+
2.0.2
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Tenios API Client ☎️
|
2
2
|
|
3
|
-
|
3
|
+
HTTP client for [Tenios API].
|
4
4
|
|
5
|
-
[Tenios API]: https://www.tenios.de/
|
5
|
+
[Tenios API]: https://www.tenios.de/doc-topic/voice-api
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -18,11 +18,27 @@ gem 'tenios-api'
|
|
18
18
|
require 'tenios-api'
|
19
19
|
|
20
20
|
client = Tenios::API::Client.new(access_key: ENV['TENIOS_ACCESS_KEY'])
|
21
|
+
```
|
22
|
+
|
23
|
+
### Call Detail Records
|
24
|
+
|
25
|
+
[Tenios documentation](https://www.tenios.de/en/doc/api-cdr-request)
|
21
26
|
|
22
|
-
|
27
|
+
```ruby
|
28
|
+
client.cdrs.retrieve(Time.utc(2019, 2, 1)..Time.utc(2019, 2, 2))
|
23
29
|
# returns lazy Enumerator with the records
|
24
30
|
```
|
25
31
|
|
32
|
+
### Number Order
|
33
|
+
|
34
|
+
[Tenios documentation](https://www.tenios.de/en/doc/api-number-order)
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# check Tenios documentation for verification options
|
38
|
+
verification_id = client.verification.create(options)['verification_id']
|
39
|
+
order_id = client.number.order(verification_id: verification_id)['order_id']
|
40
|
+
```
|
41
|
+
|
26
42
|
## Contributing
|
27
43
|
|
28
44
|
Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/tenios-api-ruby.
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tenios
|
4
|
+
module API
|
5
|
+
class CallDetailRecords
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrieve(date_range, page_size: 100)
|
13
|
+
stream do |page|
|
14
|
+
payload = build_payload(date_range, page: page, page_size: page_size)
|
15
|
+
client.http_client.post('/cdrs/retrieve', payload).body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_payload(date_range, page:, page_size:)
|
22
|
+
expect_date_range! date_range
|
23
|
+
|
24
|
+
{
|
25
|
+
access_key: client.access_key,
|
26
|
+
start_date_from: format_datetime(date_range.begin),
|
27
|
+
start_date_to: format_datetime(date_range.end),
|
28
|
+
page: page,
|
29
|
+
page_size: page_size
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def expect_date_range!(date_range)
|
34
|
+
return if %i[begin end].all? { |method| date_range.respond_to? method }
|
35
|
+
|
36
|
+
raise TypeError, <<~ERR.strip
|
37
|
+
Expect date_range to be Range-like (respond_to methods #begin and #end), but was: #{date_range.class}
|
38
|
+
ERR
|
39
|
+
end
|
40
|
+
|
41
|
+
def format_datetime(time)
|
42
|
+
time.utc.strftime('%FT%H:%M:%S.0Z')
|
43
|
+
end
|
44
|
+
|
45
|
+
def stream
|
46
|
+
Enumerator.new do |records|
|
47
|
+
(1..Float::INFINITY).each do |page|
|
48
|
+
res = yield page
|
49
|
+
res['items'].each { |item| records << item }
|
50
|
+
break if res['total_items'] <= page * res['page_size']
|
51
|
+
end
|
52
|
+
end.lazy
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/tenios/api/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'faraday'
|
3
5
|
require 'faraday_middleware'
|
@@ -5,6 +7,8 @@ require 'faraday_middleware'
|
|
5
7
|
module Tenios
|
6
8
|
module API
|
7
9
|
class Client
|
10
|
+
attr_reader :access_key
|
11
|
+
|
8
12
|
def initialize(access_key:)
|
9
13
|
@access_key = access_key
|
10
14
|
end
|
@@ -20,45 +24,23 @@ module Tenios
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
payload = payload_for_cdrs(start_date, page: page, page_size: page_size)
|
26
|
-
http_client.post('/cdrs/retrieve', payload).body
|
27
|
-
end
|
28
|
-
end
|
29
|
-
alias cdrs call_detail_records
|
27
|
+
class <<self
|
28
|
+
private
|
30
29
|
|
31
|
-
|
30
|
+
def endpoint(name, klass)
|
31
|
+
API.autoload klass, "tenios/api/#{name}"
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
34
|
+
def #{name}
|
35
|
+
@#{name} ||= #{klass}.new(self)
|
36
|
+
end
|
37
|
+
RUBY
|
38
38
|
end
|
39
|
-
|
40
|
-
{
|
41
|
-
access_key: access_key,
|
42
|
-
start_date_from: format_datetime(start_date.begin),
|
43
|
-
start_date_to: format_datetime(start_date.end),
|
44
|
-
page: page,
|
45
|
-
page_size: page_size
|
46
|
-
}.to_json
|
47
39
|
end
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def stream
|
54
|
-
Enumerator.new do |records|
|
55
|
-
(1..Float::INFINITY).each do |page|
|
56
|
-
res = yield page
|
57
|
-
res['items'].each { |item| records << item }
|
58
|
-
break if res['total_items'] <= page * res['page_size']
|
59
|
-
end
|
60
|
-
end.lazy
|
61
|
-
end
|
41
|
+
endpoint :call_detail_records, :CallDetailRecords
|
42
|
+
endpoint :verification, :Verification
|
43
|
+
endpoint :number, :Number
|
62
44
|
end
|
63
45
|
end
|
64
46
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tenios
|
4
|
+
module API
|
5
|
+
class Number
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
NUMBER_TYPES = [
|
13
|
+
GEOGRAPHICAL = 'GEOGRAPHICAL'
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def order(verification_id:, number_type: GEOGRAPHICAL, **options)
|
17
|
+
payload = build_payload(verification_id: verification_id, number_type: number_type, **options)
|
18
|
+
client.http_client.post('/number/order', payload).body
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
OPTIONS = %i[
|
24
|
+
link_to_number
|
25
|
+
number_type
|
26
|
+
push_secret
|
27
|
+
push_url
|
28
|
+
verification_id
|
29
|
+
].freeze
|
30
|
+
private_constant :OPTIONS
|
31
|
+
|
32
|
+
def build_payload(**options)
|
33
|
+
options
|
34
|
+
.slice(*OPTIONS)
|
35
|
+
.merge(access_key: client.access_key)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Tenios
|
6
|
+
module API
|
7
|
+
class Verification
|
8
|
+
attr_reader :client
|
9
|
+
|
10
|
+
def initialize(client)
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
DOCUMENT_TYPES = %w[
|
15
|
+
ALLOCATION_NOTICE
|
16
|
+
IDENTITY_CARD
|
17
|
+
BUSINESS_LICENSE
|
18
|
+
IDENTITY_CARD_AND_BUSINESS_LICENSE
|
19
|
+
CERTIFICATE_OF_REGISTRATION
|
20
|
+
CONTRACT
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def create(options)
|
24
|
+
payload = build_payload(options)
|
25
|
+
client.http_client.post('/verification/create', payload).body
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
OPTIONS = %i[
|
31
|
+
area_code
|
32
|
+
city
|
33
|
+
country
|
34
|
+
document_data
|
35
|
+
document_type
|
36
|
+
house_number
|
37
|
+
street
|
38
|
+
].freeze
|
39
|
+
private_constant :OPTIONS
|
40
|
+
|
41
|
+
def build_payload(options)
|
42
|
+
to_option = build_option(options)
|
43
|
+
|
44
|
+
OPTIONS.map(&to_option).to_h
|
45
|
+
.merge(access_key: client.access_key)
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_option(options)
|
49
|
+
lambda do |name|
|
50
|
+
value = options.fetch(name)
|
51
|
+
validate = :"validate_#{name}!"
|
52
|
+
send validate, value if respond_to? validate, true
|
53
|
+
[name, value]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def validate_document_type!(type)
|
58
|
+
return if DOCUMENT_TYPES.include? type
|
59
|
+
|
60
|
+
raise ArgumentError, "invalid document_type: #{type}"
|
61
|
+
end
|
62
|
+
|
63
|
+
PDF_FILE_SIGNATURE = Base64.encode64('%PDF-')[0..6].freeze
|
64
|
+
private_constant :PDF_FILE_SIGNATURE
|
65
|
+
|
66
|
+
def validate_document_data!(data)
|
67
|
+
return if data.start_with? PDF_FILE_SIGNATURE
|
68
|
+
|
69
|
+
raise ArgumentError, 'invalid document_data: should be a base64 encoded pdf file'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/tenios/api/version.rb
CHANGED
data/lib/tenios/api.rb
CHANGED
data/lib/tenios-api.rb
CHANGED
data/tenios-api.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'tenios/api/version'
|
@@ -29,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
29
31
|
|
30
32
|
spec.add_development_dependency 'bundler'
|
31
33
|
spec.add_development_dependency 'carwow_rubocop'
|
34
|
+
spec.add_development_dependency 'pry'
|
32
35
|
spec.add_development_dependency 'rake'
|
33
36
|
spec.add_development_dependency 'rspec'
|
34
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tenios-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +126,10 @@ files:
|
|
112
126
|
- Rakefile
|
113
127
|
- lib/tenios-api.rb
|
114
128
|
- lib/tenios/api.rb
|
129
|
+
- lib/tenios/api/call_detail_records.rb
|
115
130
|
- lib/tenios/api/client.rb
|
131
|
+
- lib/tenios/api/number.rb
|
132
|
+
- lib/tenios/api/verification.rb
|
116
133
|
- lib/tenios/api/version.rb
|
117
134
|
- tenios-api.gemspec
|
118
135
|
homepage: https://github.com/carwow/tenios-api-ruby
|
@@ -135,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
152
|
- !ruby/object:Gem::Version
|
136
153
|
version: '0'
|
137
154
|
requirements: []
|
138
|
-
rubygems_version: 3.0.
|
155
|
+
rubygems_version: 3.0.3
|
139
156
|
signing_key:
|
140
157
|
specification_version: 4
|
141
158
|
summary: Tenios API Client ☎️
|