invoice_count 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: 65a5e412933c686518a7f64da20bfc41792a6578f73db4501f22d489c27c8cb6
4
+ data.tar.gz: 30aaef35d882791bafde23a2b3bcb771f253fd9867ce13145c0ecd2bad1a7416
5
+ SHA512:
6
+ metadata.gz: 158ebe61b16f18cb501eff15b3ecd319d4a5dbf30e4a67db2d449d5051773ff2329dee3ca03f77a943dc17226c9d75820c52443bea98f290a263500905e45293
7
+ data.tar.gz: abadca02ea8bfb26416c74df557c2669ec0117622ad377d6d246a5ee2515c9574b4ce955a24bb4db73610025c406df5f4d31c9b408b084ea0aa68d33ea972de6
data/.dockerignore ADDED
File without changes
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = false
8
+ indent_style = space
9
+ indent_size = 2
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/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.0
6
+ before_install: gem install bundler -v 1.16.1
7
+ script: bundle exec rspec
data/Dockerfile ADDED
@@ -0,0 +1,21 @@
1
+ # build:
2
+ # docker build -t babasbot/invoice_count .
3
+ # run:
4
+ # docker run --rm -it babasbot/invoice_count count \
5
+ # ID \
6
+ # --init=INIT_DATE \
7
+ # --term=TERM_DATE
8
+
9
+ FROM ruby:2.5.1-alpine
10
+
11
+ RUN apk --update --upgrade add git
12
+
13
+ RUN mkdir -p /opt/invoice_count
14
+ WORKDIR /opt/invoice_count
15
+
16
+ COPY . /opt/invoice_count
17
+
18
+ RUN bundle install
19
+ RUN bundle exec rake install
20
+
21
+ ENTRYPOINT ["bundle", "exec", "invoice_count"]
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ invoice_count (0.1.0)
5
+ faraday (~> 0.15.2)
6
+ thor (~> 0.19.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ coveralls (0.8.22)
14
+ json (>= 1.8, < 3)
15
+ simplecov (~> 0.16.1)
16
+ term-ansicolor (~> 1.3)
17
+ thor (~> 0.19.4)
18
+ tins (~> 1.6)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ docile (1.3.1)
23
+ faraday (0.15.2)
24
+ multipart-post (>= 1.2, < 3)
25
+ hashdiff (0.3.7)
26
+ json (2.1.0)
27
+ multipart-post (2.0.0)
28
+ public_suffix (3.0.2)
29
+ rake (11.3.0)
30
+ rspec (3.7.0)
31
+ rspec-core (~> 3.7.0)
32
+ rspec-expectations (~> 3.7.0)
33
+ rspec-mocks (~> 3.7.0)
34
+ rspec-core (3.7.1)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-expectations (3.7.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.7.0)
39
+ rspec-mocks (3.7.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-support (3.7.1)
43
+ safe_yaml (1.0.4)
44
+ simplecov (0.16.1)
45
+ docile (~> 1.1)
46
+ json (>= 1.8, < 3)
47
+ simplecov-html (~> 0.10.0)
48
+ simplecov-html (0.10.2)
49
+ term-ansicolor (1.6.0)
50
+ tins (~> 1.0)
51
+ thor (0.19.4)
52
+ tins (1.16.3)
53
+ vcr (3.0.3)
54
+ webmock (3.4.2)
55
+ addressable (>= 2.3.6)
56
+ crack (>= 0.3.2)
57
+ hashdiff
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.11, >= 1.11.2)
64
+ coveralls (~> 0.8.15)
65
+ invoice_count!
66
+ rake (~> 11.2, >= 11.2.2)
67
+ rspec (~> 3.0)
68
+ vcr (~> 3.0, >= 3.0.3)
69
+ webmock (~> 3.4, >= 3.4.2)
70
+
71
+ BUNDLED WITH
72
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # InvoiceCount
2
+ [![Build Status](https://travis-ci.org/babasbot/invoice_count.svg?branch=master)](https://travis-ci.org/babasbot/invoice_count)
3
+ [![Coverage Status](https://coveralls.io/repos/github/babasbot/invoice_count/badge.svg?branch=master)](https://coveralls.io/github/babasbot/invoice_count?branch=master)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a3e84d623817a96f948d/maintainability)](https://codeclimate.com/github/babasbot/invoice_count/maintainability)
5
+
6
+ A CLI tool that counts emmited invoices in a given period.
7
+
8
+ ## Installation
9
+
10
+
11
+ ```ruby
12
+ gem 'invoice_count'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install invoice_count
22
+
23
+ ## Usage
24
+
25
+ Usage:
26
+ $ invoice_count count ID --init=INIT_DATE --term=TERM_DATE
27
+
28
+ Options:
29
+ --init=INIT_DATE
30
+ --term=TERM_DATE
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/babasbot/invoice_count.
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
data/bin/invoice_count ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'invoice_count'
4
+
5
+ InvoiceCount::CLI.start(ARGV)
@@ -0,0 +1,9 @@
1
+ version: '3'
2
+ services:
3
+ invoice_count:
4
+ build: '.'
5
+ command:
6
+ - "count"
7
+ - "1f1bcc03-5fa9-4e73-a150-79a569f912d9"
8
+ - "--init=2017-01-01"
9
+ - "--term=2017-12-31"
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'invoice_count/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'invoice_count'
8
+ spec.version = InvoiceCount::VERSION
9
+ spec.authors = ['Luis Alfredo Lorenzo']
10
+ spec.email = ['babasbot@gmail.com']
11
+
12
+ spec.summary = 'A CLI tool that counts emmited invoices'
13
+ spec.homepage = 'https://github.com/babasbot/invoice_count'
14
+ spec.description = <<~DESCRIPTION
15
+ A CLI tool that counts the emmited invoices in a given period.
16
+ DESCRIPTION
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
19
+ file.match(%r{^(test|spec|features)/})
20
+ end
21
+
22
+ spec.bindir = 'bin'
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
28
+ spec.add_development_dependency 'webmock', '~> 3.4', '>= 3.4.2'
29
+ spec.add_development_dependency 'rake', '~> 11.2', '>= 11.2.2'
30
+ spec.add_development_dependency 'bundler', '~> 1.11', '>= 1.11.2'
31
+ spec.add_development_dependency 'coveralls', '~> 0.8.15'
32
+
33
+ spec.add_runtime_dependency 'faraday', '~> 0.15.2'
34
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'invoice_count/version'
2
+ require 'invoice_count/error'
3
+ require 'invoice_count/connection'
4
+ require 'invoice_count/invoice'
5
+ require 'invoice_count/count_command'
6
+ require 'thor'
7
+ require 'date'
8
+
9
+ module InvoiceCount
10
+ class CLI < Thor
11
+ desc 'count ID', 'counts emmited invoices for the given client'
12
+
13
+ method_option :init, required: true, desc: 'initial date', banner: 'INIT_DATE'
14
+ method_option :term, required: true, desc: 'ending date', banner: 'TERM_DATE'
15
+
16
+ def count(id)
17
+ starting_date = Date.parse(options[:init])
18
+ ending_date = Date.parse(options[:term])
19
+
20
+ puts InvoiceCount::CountCommand.new(id, starting_date, ending_date).execute
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+ require 'singleton'
3
+
4
+ module InvoiceCount
5
+ class Connection < SimpleDelegator
6
+ include Singleton
7
+
8
+ def initialize
9
+ connection = Faraday.new(url: 'http://34.209.24.195/')
10
+
11
+ connection.headers['Content-Type'] = 'application/json'
12
+ connection.headers['Accept'] = 'application/json'
13
+ connection.headers['User-Agent'] = "InvoiceCount/#{InvoiceCount::VERSION}"
14
+
15
+ super(connection)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ module InvoiceCount
2
+ class CountCommand
3
+ def initialize(id, starting_date, ending_date)
4
+ @id = id
5
+ @starting_date = starting_date
6
+ @ending_date = ending_date
7
+ @current_step = (ending_date - starting_date).to_i
8
+ @count = 0
9
+ end
10
+
11
+ def execute
12
+ date_range.step(current_step).each_cons(2) do |slice|
13
+ self.current_slice = slice
14
+
15
+ @count += current_slice_invoice_count
16
+ end
17
+
18
+ if current_slice_term_date < @ending_date
19
+ params = [@id, current_slice_term_date + 1, @ending_date]
20
+ @count += InvoiceCount::Invoice.count(*params).to_i
21
+ end
22
+
23
+ @count
24
+ rescue InvoiceCount::Error::TooManyResults
25
+ @current_step /= 2 and retry
26
+ end
27
+
28
+ private
29
+
30
+ attr_accessor :current_slice, :current_step
31
+
32
+ def date_range
33
+ (current_slice_init_date || @starting_date)..(@ending_date + 1)
34
+ end
35
+
36
+ def current_slice_invoice_count
37
+ params = [@id, current_slice_init_date, current_slice_term_date]
38
+ InvoiceCount::Invoice.count(*params).to_i
39
+ end
40
+
41
+ def current_slice_init_date
42
+ current_slice&.first
43
+ end
44
+
45
+ def current_slice_term_date
46
+ current_slice.last - 1
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ module InvoiceCount
2
+ class Error < StandardError
3
+ class BadRequest < Error
4
+ def initialize
5
+ super('The request could not be understood by the server due to malformed syntax or missing parameters')
6
+ end
7
+ end
8
+
9
+ class TooManyResults < Error
10
+ def initialize
11
+ super('too many invoices in the given period')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module InvoiceCount
2
+ class Invoice
3
+ def self.count(id, starting_date, ending_date)
4
+ response = InvoiceCount::Connection.instance.get do |request|
5
+ request.url('/facturas')
6
+
7
+ request.params['id'] = id
8
+ request.params['start'] = starting_date
9
+ request.params['finish'] = ending_date
10
+ end
11
+
12
+ # server responds with an ASCII-8BIT string
13
+ body = response.body.force_encoding('utf-8').encode
14
+
15
+ case body
16
+ when /Hay más de 100 resultados/
17
+ raise InvoiceCount::Error::TooManyResults
18
+ when /Te faltan parámetros/
19
+ raise InvoiceCount::Error::BadRequest
20
+ end
21
+
22
+ body.to_i
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module InvoiceCount
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: invoice_count
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luis Alfredo Lorenzo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.3
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: webmock
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.4'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.4.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.4'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.4.2
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '11.2'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 11.2.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '11.2'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 11.2.2
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.11'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.11.2
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.11'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.11.2
107
+ - !ruby/object:Gem::Dependency
108
+ name: coveralls
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: 0.8.15
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: 0.8.15
121
+ - !ruby/object:Gem::Dependency
122
+ name: faraday
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: 0.15.2
128
+ type: :runtime
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: 0.15.2
135
+ - !ruby/object:Gem::Dependency
136
+ name: thor
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: 0.19.1
142
+ type: :runtime
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: 0.19.1
149
+ description: 'A CLI tool that counts the emmited invoices in a given period.
150
+
151
+ '
152
+ email:
153
+ - babasbot@gmail.com
154
+ executables:
155
+ - invoice_count
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - ".dockerignore"
160
+ - ".editorconfig"
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".travis.yml"
164
+ - Dockerfile
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - README.md
168
+ - Rakefile
169
+ - bin/invoice_count
170
+ - docker-compose.yml
171
+ - invoice_count.gemspec
172
+ - lib/invoice_count.rb
173
+ - lib/invoice_count/connection.rb
174
+ - lib/invoice_count/count_command.rb
175
+ - lib/invoice_count/error.rb
176
+ - lib/invoice_count/invoice.rb
177
+ - lib/invoice_count/version.rb
178
+ homepage: https://github.com/babasbot/invoice_count
179
+ licenses: []
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.7.3
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: A CLI tool that counts emmited invoices
201
+ test_files: []