tenios-api 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f8f391faf118141ffe8aa25f8b03268fe17a042725743f38b01b54a3cf7e6fd7
4
+ data.tar.gz: 52ff37ed16b3d624c7e5bc637890dd15581f8d0fb38360f0c314e5b05f9f25e8
5
+ SHA512:
6
+ metadata.gz: fb2864919b8829eae4b1ef6af31e1aa01f25803a2d1e3db1145bf08a7767cf0b3b80ba685322382e6f7d6fc4792e99becb0069470755777e9b7a9ddd816df3a3
7
+ data.tar.gz: 64dfb553c6c1c830748b5033054b11feaee46388266ae1827e08e054755988811e07f2a84402d516d4d3dda3e7cd793e1e184038e5b3f9d1e4d9a4df04262c27
@@ -0,0 +1,54 @@
1
+ ruby: &ruby
2
+ image: carwow/ruby-ci:2.5.3
3
+
4
+ version: 2
5
+
6
+ jobs:
7
+ bundle:
8
+ working_directory: ~/tenios-api
9
+ docker:
10
+ - *ruby
11
+ steps:
12
+ - checkout
13
+ - restore_cache:
14
+ keys:
15
+ - bundle-{{ checksum "Gemfile.lock" }}
16
+ - bundle-
17
+ - run: |
18
+ bundle config --local path vendor/bundle &&
19
+ bundle check || bundle install --jobs=4 --retry=3
20
+ - save_cache:
21
+ key: bundle-{{ checksum "Gemfile.lock" }}
22
+ paths: [~/tenios-api/vendor/bundle]
23
+ - persist_to_workspace:
24
+ root: '~'
25
+ paths: [tenios-api]
26
+
27
+ rubocop:
28
+ working_directory: ~/tenios-api
29
+ docker:
30
+ - *ruby
31
+ steps:
32
+ - attach_workspace:
33
+ at: '~'
34
+ - run: bundle exec rubocop
35
+
36
+ tests:
37
+ working_directory: ~/tenios-api
38
+ docker:
39
+ - *ruby
40
+ steps:
41
+ - attach_workspace:
42
+ at: '~'
43
+ - run: |
44
+ bundle exec rspec
45
+
46
+ workflows:
47
+ version: 2
48
+ build:
49
+ jobs:
50
+ - bundle
51
+ - rubocop:
52
+ requires: [bundle]
53
+ - tests:
54
+ requires: [bundle]
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_gem:
2
+ carwow_rubocop:
3
+ - default.yml
4
+
5
+ Naming/FileName:
6
+ Exclude:
7
+ - lib/tenios-api.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tenios-api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tenios-api (0.1.0)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ carwow_rubocop (2.1.1)
13
+ rubocop (~> 0.58)
14
+ rubocop-rspec (~> 1.28)
15
+ diff-lcs (1.3)
16
+ faraday (0.15.4)
17
+ multipart-post (>= 1.2, < 3)
18
+ faraday_middleware (0.13.1)
19
+ faraday (>= 0.7.4, < 1.0)
20
+ jaro_winkler (1.5.2)
21
+ multipart-post (2.0.0)
22
+ parallel (1.13.0)
23
+ parser (2.6.0.0)
24
+ ast (~> 2.4.0)
25
+ powerpack (0.1.2)
26
+ psych (3.1.0)
27
+ rainbow (3.0.0)
28
+ rake (12.3.2)
29
+ rspec (3.8.0)
30
+ rspec-core (~> 3.8.0)
31
+ rspec-expectations (~> 3.8.0)
32
+ rspec-mocks (~> 3.8.0)
33
+ rspec-core (3.8.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-expectations (3.8.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-mocks (3.8.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.8.0)
41
+ rspec-support (3.8.0)
42
+ rubocop (0.65.0)
43
+ jaro_winkler (~> 1.5.1)
44
+ parallel (~> 1.10)
45
+ parser (>= 2.5, != 2.5.1.1)
46
+ powerpack (~> 0.1)
47
+ psych (>= 3.1.0)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (~> 1.4.0)
51
+ rubocop-rspec (1.32.0)
52
+ rubocop (>= 0.60.0)
53
+ ruby-progressbar (1.10.0)
54
+ unicode-display_width (1.4.1)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler
61
+ carwow_rubocop
62
+ rake
63
+ rspec
64
+ tenios-api!
65
+
66
+ BUNDLED WITH
67
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Pedro Chambino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Tenios API Client ☎️
2
+
3
+ Get Call Detail Records (CDRs) from [Tenios API].
4
+
5
+ [Tenios API]: https://www.tenios.de/en/doc/api-cdr-request
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tenios-api'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require 'tenios-api'
19
+
20
+ client = Tenios::API::Client.new(access_key: ENV['TENIOS_ACCESS_KEY'])
21
+
22
+ client.cdrs(Time.new(2019, 2, 1)..Time.new(2019, 2, 2))
23
+ # returns lazy Enumerator with the records
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/tenios-api-ruby.
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,64 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Tenios
6
+ module API
7
+ class Client
8
+ def initialize(access_key:)
9
+ @access_key = access_key
10
+ end
11
+
12
+ def http_client
13
+ @http_client ||= Faraday.new(url: 'https://api.tevox.com') do |c|
14
+ c.request :json
15
+ c.response :json
16
+ c.response :raise_error
17
+ c.use :gzip
18
+
19
+ c.adapter Faraday.default_adapter
20
+ end
21
+ end
22
+
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
30
+
31
+ private
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)'
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
+ end
48
+
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
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Tenios
2
+ module API
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
data/lib/tenios/api.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Tenios
2
+ module API
3
+ autoload :Version, 'tenios/api/version'
4
+ autoload :Client, 'tenios/api/client'
5
+ end
6
+ end
data/lib/tenios-api.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tenios/api'
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'tenios/api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'tenios-api'
7
+ spec.version = Tenios::API::VERSION
8
+ spec.authors = ['carwow Developers']
9
+ spec.email = ['developers@carwow.co.uk']
10
+ spec.summary = 'Tenios API Client ☎️'
11
+ spec.description = 'Get Call Detail Records (CDRs) from Tenios API.'
12
+ spec.homepage = 'https://github.com/carwow/tenios-api-ruby'
13
+ spec.license = 'MIT'
14
+
15
+ if spec.respond_to?(:metadata)
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+ else
18
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
19
+ 'public gem pushes.'
20
+ end
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'faraday'
28
+ spec.add_dependency 'faraday_middleware'
29
+
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'carwow_rubocop'
32
+ spec.add_development_dependency 'rake'
33
+ spec.add_development_dependency 'rspec'
34
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tenios-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - carwow Developers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: carwow_rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Get Call Detail Records (CDRs) from Tenios API.
98
+ email:
99
+ - developers@carwow.co.uk
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".circleci/config.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/tenios-api.rb
114
+ - lib/tenios/api.rb
115
+ - lib/tenios/api/client.rb
116
+ - lib/tenios/api/version.rb
117
+ - tenios-api.gemspec
118
+ homepage: https://github.com/carwow/tenios-api-ruby
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ allowed_push_host: https://rubygems.org
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Tenios API Client ☎️
142
+ test_files: []