ocar 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78abebd948a9523d77decd1ff286a720b8478f15
4
- data.tar.gz: 53a0f484a38358c46be9a744535b5e79102107ca
3
+ metadata.gz: 9be6ad9bc114eefd69f1a9addab2252125ac2cbc
4
+ data.tar.gz: db059622eb6da421764b0dc2ce9b3ff66c99bb49
5
5
  SHA512:
6
- metadata.gz: ebf8ef1c2abb96b3c481ec2f87d3b875ff0c8ef685896031b2c26030711f823319ea5155f2d882a5c8e5ca34735f3153822e8d531e6b8ae77e218d2900ca1207
7
- data.tar.gz: a0339f8bfe83360602f84a37203180eb57e6c71a42f2acdb29860d86405acc403e4f0bfb06168e3e5cf2ec478daf2a2f73553a97490538dedcbba9944248571e
6
+ metadata.gz: a262f8fc96e8340c9b127b9de09009f54cb245f4d967c768c274189155a4b9b3e05c5fd15c0aa8a83488116e522baf84c750e242cb65b117b5ce1e21aa9c82d3
7
+ data.tar.gz: 7bb7ccaa1dc3a9b5001a1a260edc79fcb3323cd1e777494031e9e720606ed40942f7973b599e582ac0f7767a4a6f0ff1f0e9746db9fa68ec6314a1104043a04c
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Ocar
2
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/ocar`. 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
3
+ A minimal gem to get package information for the OCA service (Argentinian Courrier)
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,22 +18,39 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install ocar
22
20
 
21
+ The gem depends on the [typhoeus](https://github.com/typhoeus/typhoeus) gem.
22
+
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Please require the gem
26
+
27
+ ```ruby
28
+ require 'ocar'
29
+ ```
30
+
31
+ To get the information about a particular package.
32
+ This method will search inside all the types of packages in OCA.
26
33
 
27
- ## Development
34
+ ```ruby
35
+ Ocar.get_package 1234456
36
+ ```
28
37
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ And if the package exists, will return:
30
39
 
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).
40
+ ```ruby
41
+ @date="07/03/2015 07:22:00",
42
+ @description="Entregada",
43
+ @location="CORDOBA",
44
+ @number="0001235432",
45
+ @owner="DIAZ, Bruno",
46
+ @type="DNI">
47
+ ```
48
+ or _nil_ if package isn't found.
32
49
 
33
50
  ## Contributing
34
51
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ocar.
36
-
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lucasocon/ocar.
37
53
 
38
54
  ## License
39
55
 
40
56
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -2,52 +2,46 @@ require 'json'
2
2
  require 'typhoeus'
3
3
 
4
4
  module Ocar
5
-
6
5
  extend self
7
6
 
8
- TYPES = ["cartas", "paquetes", "dni", "partidas" ]
7
+ TYPES = %w(cartas paquetes dni partidas).freeze
9
8
  $hydra = Typhoeus::Hydra.new
10
9
 
11
- def get_package track_id
12
- requests = setup_request track_id
10
+ def get_package(track_id)
11
+ requests = setup_request(track_id)
13
12
  run_request
14
13
  get_response requests
15
14
  end
16
15
 
17
16
  private
18
- def setup_request track_id
19
- requests = TYPES.map { |type|
20
- request = Typhoeus::Request.new("http://www.oca.com.ar",
17
+
18
+ def setup_request(track_id)
19
+ # e.g. http://www.oca.com.ar/?q=package-locator&type=paquetes&number=1808200000001055400
20
+ TYPES.map do |type|
21
+ request = Typhoeus::Request.new(
22
+ 'http://www.oca.com.ar',
21
23
  method: :get,
22
- params: { q: "package-locator",
23
- type: type,
24
- number: track_id },
25
- headers: { Accept: "text/html" }
24
+ params: { q: 'package-locator',
25
+ type: type, number: track_id },
26
+ headers: {
27
+ Accept: 'application/json, text/javascript, */*; q=0.01'
28
+ }
26
29
  )
27
30
  $hydra.queue(request)
28
31
  request
29
- }
32
+ end
30
33
  end
31
34
 
32
35
  def run_request
33
36
  $hydra.run
34
37
  end
35
38
 
36
- def get_response requests
39
+ def get_response(requests)
37
40
  results = []
38
- responses = requests.map do |request|
41
+ requests.map do |request|
39
42
  parsed = JSON.parse request.response.body
40
43
  results << parsed if parsed['success'] == true
41
44
  end
42
- return check_response results
43
- end
44
-
45
-
46
- def check_response results
47
- if results.any?
48
- Ocar::Status.new(results.first)
49
- else
50
- nil
51
- end
45
+ results
52
46
  end
53
47
  end
@@ -1,3 +1,3 @@
1
1
  module Ocar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_runtime_dependency "typhoeus"
23
+
22
24
  spec.add_development_dependency "bundler", "~> 1.11"
23
25
  spec.add_development_dependency "rake", "~> 10.0"
24
26
  spec.add_development_dependency "minitest", "~> 5.0"
25
- spec.add_development_dependency "typhoeus"
26
27
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Ocon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +66,6 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '5.0'
55
- - !ruby/object:Gem::Dependency
56
- name: typhoeus
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
69
  description: This gem permit you follow your package or another(if you have the trackID
70
70
  on the OCA courries service (Argentinian Courrier)
71
71
  email:
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.4.6
110
+ rubygems_version: 2.4.5.1
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: A minimal gem to get the package information on the OCA service (Argentinian