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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8f391faf118141ffe8aa25f8b03268fe17a042725743f38b01b54a3cf7e6fd7
4
- data.tar.gz: 52ff37ed16b3d624c7e5bc637890dd15581f8d0fb38360f0c314e5b05f9f25e8
3
+ metadata.gz: 432dc3d9f0e7fc555722bad490b36d2f7d4be866df5c3458af6c9044ef6b57eb
4
+ data.tar.gz: 37128cbd40ba9000eb72429c1c2b3eaab39e9418a7bf775f6c8f7c609eb58edc
5
5
  SHA512:
6
- metadata.gz: fb2864919b8829eae4b1ef6af31e1aa01f25803a2d1e3db1145bf08a7767cf0b3b80ba685322382e6f7d6fc4792e99becb0069470755777e9b7a9ddd816df3a3
7
- data.tar.gz: 64dfb553c6c1c830748b5033054b11feaee46388266ae1827e08e054755988811e07f2a84402d516d4d3dda3e7cd793e1e184038e5b3f9d1e4d9a4df04262c27
6
+ metadata.gz: b0841faadf6ad05340b1eaa6a3c523fb7bfb4b4f242bc387405a3be241b43b9dfbf4efc5696110564640892e9853b391309a4f7f202c2e3a1f8567713fd2c7b2
7
+ data.tar.gz: 2485adec0b7a8ae0a43cafca6aeb4d7267e59557973ff497827853a499a734d53e656f59bb0e6bc129e08d475836a39dfbc620fda3f9b552aec0e13ac789c6de
data/.circleci/config.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ruby: &ruby
2
- image: carwow/ruby-ci:2.5.3
2
+ image: carwow/ruby-ci:2.6
3
3
 
4
4
  version: 2
5
5
 
data/.rubocop.yml CHANGED
@@ -5,3 +5,9 @@ inherit_gem:
5
5
  Naming/FileName:
6
6
  Exclude:
7
7
  - lib/tenios-api.rb
8
+
9
+ RSpec/VerifiedDoubles:
10
+ Enabled: false
11
+
12
+ Style/FrozenStringLiteralComment:
13
+ Enabled: true
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in tenios-api.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tenios-api (0.1.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
- multipart-post (2.0.0)
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
- 1.17.3
73
+ 2.0.2
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Tenios API Client ☎️
2
2
 
3
- Get Call Detail Records (CDRs) from [Tenios API].
3
+ HTTP client for [Tenios API].
4
4
 
5
- [Tenios API]: https://www.tenios.de/en/doc/api-cdr-request
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
- client.cdrs(Time.new(2019, 2, 1)..Time.new(2019, 2, 2))
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
@@ -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
- def call_detail_records(start_date, page_size: 100)
24
- stream do |page|
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
- private
30
+ def endpoint(name, klass)
31
+ API.autoload klass, "tenios/api/#{name}"
32
32
 
33
- attr_reader :access_key
34
-
35
- def payload_for_cdrs(start_date, page:, page_size:)
36
- unless %i[begin end].all? { |method| start_date.respond_to? method }
37
- raise TypeError, 'Expect start_date to be Range-like (respond_to methods #begin and #end)'
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
- def format_datetime(time)
50
- time.utc.strftime('%FT%H:%M:%S.0Z')
51
- end
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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tenios
2
4
  module API
3
- VERSION = '0.1.0'.freeze
5
+ VERSION = '0.2.0'
4
6
  end
5
7
  end
data/lib/tenios/api.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tenios/api/client'
4
+
1
5
  module Tenios
2
6
  module API
3
7
  autoload :Version, 'tenios/api/version'
4
- autoload :Client, 'tenios/api/client'
5
8
  end
6
9
  end
data/lib/tenios-api.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tenios/api'
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.1.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-02-21 00:00:00.000000000 Z
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.2
155
+ rubygems_version: 3.0.3
139
156
  signing_key:
140
157
  specification_version: 4
141
158
  summary: Tenios API Client ☎️