chilexpress 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffb61bc816abc8e6ae0733dd640997e2b56f4ae1
4
+ data.tar.gz: bd125e49fdd1967d29dba0ea1dbcc85c79cc3dad
5
+ SHA512:
6
+ metadata.gz: 4f020eb6c5838494127641cd22288abe7d16831a25d3a1a71c85d3e595e6bea46e77407d5d480b507088ba357d2010d8b35dc7e6440468e06ae9ac0779ec416c
7
+ data.tar.gz: 41e167922c5b8671cad9429ee01f8fc8553259b18e9bf1d644a73a7790b560112aeb5c7a205c057d9ca767f7cd5a1dc57d4198046817e5b6c05bf6494a5701a1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chilexpress.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Pablo Orellana Mendiburú
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,71 @@
1
+ # Chilexpress
2
+
3
+ Get Chilexpress shipment information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chilexpress'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chilexpress
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # you must provide a valid Chilexpress order code
25
+ order_code = 123456
26
+
27
+ # this will take a while, Chilexpress's site response time is quite slow
28
+ result = Chilexpress.get_order(order_code)
29
+
30
+ # you can get the following shipment information
31
+ puts result.order_number
32
+ puts result.product_type
33
+ puts result.service_type
34
+ puts result.status
35
+
36
+ # if the shipment has been delivered, you can get the receiver's details
37
+ receiver = result.receiver
38
+
39
+ if receiver
40
+ puts receiver.name
41
+ puts receiver.rut
42
+ puts receiver.delivery_date
43
+ puts receiver.delivery_time
44
+ end
45
+
46
+ # you can also get the detailed tracking information
47
+ result.tracking_entries.each do |entry|
48
+ puts entry.date
49
+ puts entry.time
50
+ puts entry.activity
51
+ end
52
+ ```
53
+
54
+ ## Todo
55
+
56
+ - Write tests.
57
+ - Multi thread ```Chilexpress.get_orders(order_number_array)``` method.
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/holamendi/chilexpress/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chilexpress"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chilexpress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chilexpress"
8
+ spec.version = Chilexpress::VERSION
9
+ spec.authors = ["Pablo Orellana Mendiburú"]
10
+ spec.email = ["hola@mendi.cl"]
11
+
12
+ spec.summary = %q{Chilexpress shipment information}
13
+ spec.description = %q{Provides a simple interface to get Chilexpress's shipment information}
14
+ spec.homepage = "https://github.com/holamendi/chilexpress"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'nokogiri', '~> 1.6.6.2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,59 @@
1
+ require 'chilexpress/version'
2
+ require 'chilexpress/shipment'
3
+ require 'chilexpress/receiver'
4
+ require 'chilexpress/tracking_entry'
5
+
6
+ require 'nokogiri'
7
+ require 'open-uri'
8
+
9
+ module Chilexpress
10
+ def self.get_order(order_number)
11
+ document = get_document(order_number)
12
+ return false unless document_has_valid_order?(document)
13
+ shipment_attributes = get_shipment_info_from_document(document)
14
+ shipment_attributes[:tracking_entries] = get_tracking_entries_from_document(document)
15
+ shipment_attributes[:receiver] = get_receiver_from_document(document)
16
+ Chilexpress::Shipment.new(shipment_attributes)
17
+ end
18
+
19
+ private
20
+
21
+ def self.get_document(order_number)
22
+ Nokogiri::HTML(open("http://www.chilexpress.cl/Views/ChilexpressCL/Resultado-busqueda.aspx?DATA=#{order_number}"))
23
+ end
24
+
25
+ def self.document_has_valid_order?(document)
26
+ document.css('header.widget-header h3').any?
27
+ end
28
+
29
+ def self.get_shipment_info_from_document(document)
30
+ div = document.css('div.wigdet-content').select{ |div| div.text.include?('Orden Nº') }[0]
31
+ shipment_info = div.css('ul li ul li')
32
+ { order_number: shipment_info[0].children[1].text,
33
+ product_type: shipment_info[1].children[1].text,
34
+ service_type: shipment_info[2].children[1].text,
35
+ status: shipment_info[3].children[1].text }
36
+ end
37
+
38
+ def self.get_receiver_from_document(document)
39
+ div = document.css('div.wigdet-content').select{ |div| div.text.include?('Datos de Descarga') }[0]
40
+ return nil unless div
41
+ receiver_info = div.css('ul li ul li')
42
+ Chilexpress::Receiver.new(
43
+ rut: receiver_info[0].children[1].text.strip[1..-1],
44
+ delivery_date: receiver_info[1].children[1].text.strip[1..-1],
45
+ delivery_time: receiver_info[2].children[1].text.strip[1..-1],
46
+ name: receiver_info[3].children[1].text.strip[1..-1]
47
+ )
48
+ end
49
+
50
+ def self.get_tracking_entries_from_document(document)
51
+ document_entries = document.css('table.addresses tbody tr')
52
+ tracking_entries = []
53
+ document_entries.each do |entry|
54
+ content = entry.css('td')
55
+ tracking_entries << Chilexpress::TrackingEntry.new(date: content[0].text, time: content[1].text, activity: content[2].text)
56
+ end
57
+ tracking_entries
58
+ end
59
+ end
@@ -0,0 +1,12 @@
1
+ module Chilexpress
2
+ class Receiver
3
+ attr_reader :rut, :name, :delivery_date, :delivery_time
4
+
5
+ def initialize(attributes)
6
+ @rut = attributes[:rut]
7
+ @name = attributes[:name]
8
+ @delivery_date = attributes[:delivery_date]
9
+ @delivery_time = attributes[:delivery_time]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Chilexpress
2
+ class Shipment
3
+ attr_reader :order_number, :product_type, :service_type, :status, :receiver, :tracking_entries
4
+
5
+ def initialize(attributes)
6
+ @order_number = attributes[:order_number]
7
+ @product_type = attributes[:product_type]
8
+ @service_type = attributes[:service_type]
9
+ @status = attributes[:status]
10
+ @receiver = attributes[:receiver]
11
+ @tracking_entries = attributes[:tracking_entries] || []
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Chilexpress
2
+ class TrackingEntry
3
+ attr_reader :date, :time, :activity
4
+
5
+ def initialize(attributes)
6
+ @date = attributes[:date]
7
+ @time = attributes[:time]
8
+ @activity = attributes[:activity]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Chilexpress
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chilexpress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pablo Orellana Mendiburú
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.6.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Provides a simple interface to get Chilexpress's shipment information
56
+ email:
57
+ - hola@mendi.cl
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - chilexpress.gemspec
72
+ - lib/chilexpress.rb
73
+ - lib/chilexpress/receiver.rb
74
+ - lib/chilexpress/shipment.rb
75
+ - lib/chilexpress/tracking_entry.rb
76
+ - lib/chilexpress/version.rb
77
+ homepage: https://github.com/holamendi/chilexpress
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Chilexpress shipment information
101
+ test_files: []