business-br-shipping 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47a459bc58842eabb4be31648e8b3ad94479c65ea47d36fda900c6c9491b2a62
4
+ data.tar.gz: 4bbce150dea1ed866f987caff38c34a4a7e5ba9d6a19a9105c57119482730b25
5
+ SHA512:
6
+ metadata.gz: e9598a6cf5cc147e390da962e05f3fe3668e31d82e815ba6e03b7cc0fcf4ef69fdfdab70c4b25b2e4a43100ffb246447c36dc3b5ba68292a85515cdfc3fb8837
7
+ data.tar.gz: 36cad5a83293787c60d0b218361f9a17c0d61102bbe34256edb1f77952df1917f79fa9cfa06f4f887e5d963ab76e71ffadfa404f8d4a169b35ce8a981952d3a3
@@ -0,0 +1,88 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,vim
3
+ # Edit at https://www.gitignore.io/?templates=ruby,vim
4
+
5
+ ### Ruby ###
6
+ *.gem
7
+ *.rbc
8
+ /.config
9
+ /coverage/
10
+ /InstalledFiles
11
+ /pkg/
12
+ /spec/reports/
13
+ /spec/examples.txt
14
+ /test/tmp/
15
+ /test/version_tmp/
16
+ /tmp/
17
+
18
+ # Used by dotenv library to load environment variables.
19
+ # .env
20
+
21
+ # Ignore Byebug command history file.
22
+ .byebug_history
23
+
24
+ ## Specific to RubyMotion:
25
+ .dat*
26
+ .repl_history
27
+ build/
28
+ *.bridgesupport
29
+ build-iPhoneOS/
30
+ build-iPhoneSimulator/
31
+
32
+ ## Specific to RubyMotion (use of CocoaPods):
33
+ #
34
+ # We recommend against adding the Pods directory to your .gitignore. However
35
+ # you should judge for yourself, the pros and cons are mentioned at:
36
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
37
+ # vendor/Pods/
38
+
39
+ ## Documentation cache and generated files:
40
+ /.yardoc/
41
+ /_yardoc/
42
+ /doc/
43
+ /rdoc/
44
+
45
+ ## Environment normalization:
46
+ /.bundle/
47
+ /vendor/bundle
48
+ /lib/bundler/man/
49
+
50
+ # for a library or gem, you might want to ignore these files since the code is
51
+ # intended to run in multiple environments; otherwise, check them in:
52
+ # Gemfile.lock
53
+ # .ruby-version
54
+ # .ruby-gemset
55
+
56
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
57
+ .rvmrc
58
+
59
+ ### Ruby Patch ###
60
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
61
+ # .rubocop-https?--*
62
+
63
+ ### Vim ###
64
+ # Swap
65
+ [._]*.s[a-v][a-z]
66
+ [._]*.sw[a-p]
67
+ [._]s[a-rt-v][a-z]
68
+ [._]ss[a-gi-z]
69
+ [._]sw[a-p]
70
+
71
+ # Session
72
+ Session.vim
73
+ Sessionx.vim
74
+
75
+ # Temporary
76
+ .netrwhist
77
+ *~
78
+
79
+ # Auto-generated tag files
80
+ tags
81
+
82
+ # Persistent undo
83
+ [._]*.un~
84
+
85
+ # Coc configuration directory
86
+ .vim
87
+
88
+ # End of https://www.gitignore.io/api/ruby,vim
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in business-br-shipping.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ business-br-shipping (0.1.0)
5
+ http (~> 4.4.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ diff-lcs (1.3)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ ffi (1.12.2)
16
+ ffi-compiler (1.0.1)
17
+ ffi (>= 1.0.0)
18
+ rake
19
+ http (4.4.1)
20
+ addressable (~> 2.3)
21
+ http-cookie (~> 1.0)
22
+ http-form_data (~> 2.2)
23
+ http-parser (~> 1.2.0)
24
+ http-cookie (1.0.3)
25
+ domain_name (~> 0.5)
26
+ http-form_data (2.3.0)
27
+ http-parser (1.2.1)
28
+ ffi-compiler (>= 1.0, < 2.0)
29
+ public_suffix (4.0.4)
30
+ rake (12.3.3)
31
+ rspec (3.9.0)
32
+ rspec-core (~> 3.9.0)
33
+ rspec-expectations (~> 3.9.0)
34
+ rspec-mocks (~> 3.9.0)
35
+ rspec-core (3.9.1)
36
+ rspec-support (~> 3.9.1)
37
+ rspec-expectations (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-mocks (3.9.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-support (3.9.2)
44
+ unf (0.1.4)
45
+ unf_ext
46
+ unf_ext (0.0.7.7)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ business-br-shipping!
53
+ rake (~> 12.0)
54
+ rspec (~> 3.0)
55
+
56
+ BUNDLED WITH
57
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Daniel Vinciguerra
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.
@@ -0,0 +1,40 @@
1
+ # Business::Br::Shipping
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/business/br/shipping`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'business-br-shipping'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install business-br-shipping
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dvinciguerra/business-br-shipping.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "business/br/shipping"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/business-br/shipping/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'business-br-shipping'
7
+ spec.version = Business::BR::Shipping::VERSION
8
+ spec.authors = ['Daniel Vinciguerra']
9
+ spec.email = ['daniel.vinciguerra@bivee.com.br']
10
+
11
+ spec.summary =
12
+ 'Shipping info lib that provide API integrations with brazilian companies.'
13
+ spec.description =
14
+ 'Shipping info lib that provide API integrations with brazilian companies.'
15
+ spec.homepage = 'https://github.com/dvinciguerra/business-br-shipping'
16
+ spec.license = 'MIT'
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+ # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ # spec.add_dependency '', ''
35
+ spec.add_dependency 'http', '~>4.4.1'
36
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'json'
5
+
6
+ require 'business-br/shipping/version'
7
+
8
+ module Business
9
+ module BR
10
+ module Shipping
11
+ class << self
12
+ API_HOST = ENV['API_HOST'] || 'https://api.postmon.com.br/v1/rastreio/'
13
+ API_PROVIDER = ENV['API_PROVIDER'] || 'ect'
14
+
15
+ def tracking(shipping_code)
16
+ return nil unless shipping_code
17
+
18
+ response = HTTP.get("#{API_HOST}/#{API_PROVIDER}/#{shipping_code}")
19
+ payload = JSON.parse(response.body.to_s)
20
+
21
+ code, provider, activities = payload.values_at('codigo', 'servico', 'historico')
22
+
23
+ {
24
+ code: code,
25
+ provider: provider,
26
+ activities: activities_serializer(activities)
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def activities_serializer(activities)
33
+ activities.map do |activity|
34
+ location, date, status, description = activity.values_at(
35
+ 'local', 'data', 'situacao', 'detalhes'
36
+ )
37
+
38
+ { location: location, date: date, status: status, description: description }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module Business
2
+ module BR
3
+ module Shipping
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
data/play.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('.', 'lib'))
5
+
6
+ require 'business-br/shipping'
7
+
8
+ shipping_code = ENV['TRACKING_CODE'] || 'YOUR_TRACKING_CODE'
9
+
10
+ tracking_info = Business::BR::Shipping.tracking(shipping_code)
11
+
12
+ pp tracking_info
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: business-br-shipping
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Vinciguerra
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.4.1
27
+ description: Shipping info lib that provide API integrations with brazilian companies.
28
+ email:
29
+ - daniel.vinciguerra@bivee.com.br
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - business-br-shipping.gemspec
45
+ - lib/business-br/shipping.rb
46
+ - lib/business-br/shipping/version.rb
47
+ - play.rb
48
+ homepage: https://github.com/dvinciguerra/business-br-shipping
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/dvinciguerra/business-br-shipping
53
+ source_code_uri: https://github.com/dvinciguerra/business-br-shipping
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.7.6
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Shipping info lib that provide API integrations with brazilian companies.
74
+ test_files: []