ptax 0.2.beta → 0.3.beta

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ptax.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'ruby-debug19', :require => 'ruby-debug'
8
+ gem 'wirble'
9
+ gem 'hirb'
10
+ end
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ptax (0.1.beta)
5
+ nokogiri (>= 1.5.0)
6
+ rest-client (>= 1.6.7)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ archive-tar-minitar (0.5.2)
12
+ columnize (0.3.4)
13
+ hirb (0.5.0)
14
+ linecache19 (0.5.12)
15
+ ruby_core_source (>= 0.1.4)
16
+ mime-types (1.16)
17
+ nokogiri (1.5.0)
18
+ rest-client (1.6.7)
19
+ mime-types (>= 1.16)
20
+ ruby-debug-base19 (0.11.25)
21
+ columnize (>= 0.3.1)
22
+ linecache19 (>= 0.5.11)
23
+ ruby_core_source (>= 0.1.4)
24
+ ruby-debug19 (0.11.6)
25
+ columnize (>= 0.3.1)
26
+ linecache19 (>= 0.5.11)
27
+ ruby-debug-base19 (>= 0.11.19)
28
+ ruby_core_source (0.1.5)
29
+ archive-tar-minitar (>= 0.5.2)
30
+ wirble (0.1.3)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ hirb
37
+ ptax!
38
+ ruby-debug19
39
+ wirble
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Fernando Ultremare
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = ptax
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ptax
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Fernando Ultremare. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,43 @@
1
+ module Helpers
2
+ module RestHelper
3
+ def get(url, params = {})
4
+ RestClient.get(url, :params => split_params(params)) do |response, request, result|
5
+ case response.code
6
+ when 200
7
+ response.body
8
+ else
9
+ raise "PTAX API Error(code=#{response.code}): #{response.body}"
10
+ end
11
+ end
12
+ end
13
+
14
+ def post(url, params)
15
+ RestClient.post(url, params) do |response, request, result|
16
+ case response.code
17
+ when 200
18
+ response.body
19
+ else
20
+ raise "PTAX API Error(code=#{response.code}): #{response.body}"
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+ def parse_html(response)
27
+ Nokogiri::HTML(response)
28
+ end
29
+
30
+ def split_params(params)
31
+ params.inject(Hash.new) do |new_params, (k,v)|
32
+ if v.kind_of? Hash
33
+ v.each { |(k2, v2)| new_params["#{k}[#{k2}]"] = v2 }
34
+ else
35
+ new_params[k] = v
36
+ end
37
+ new_params
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+
@@ -0,0 +1,12 @@
1
+ require 'rest-client'
2
+ require 'nokogiri'
3
+
4
+ module Helpers
5
+ autoload :RestHelper, "helpers/rest_helper"
6
+ end
7
+
8
+ module Ptax
9
+ autoload :Client, "ptax/client"
10
+ end
11
+
12
+
@@ -0,0 +1,21 @@
1
+ module Ptax
2
+ class Client
3
+ include Helpers::RestHelper
4
+
5
+ def download_ptax_csv(params = {})
6
+ csv_link = find_daily_ptax_csv_link(:date => params[:date])
7
+ File.open(params[:path], 'w') { |f| f.write(get csv_link) }
8
+ end
9
+
10
+
11
+ def find_daily_ptax_csv_link(params = {})
12
+ doc = parse_html(post "http://www4.bcb.gov.br/pec/taxas/port/PtaxRPesq.asp",
13
+ :RadOpcao => '2',
14
+ :DATAINI => params[:date],
15
+ :ChkMoeda => '220',
16
+ :OPCAO => '2')
17
+
18
+ doc.css('.conteudo a').first.attributes["href"].value
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ version = '0.3.beta'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.platform = Gem::Platform::RUBY
5
+ s.name = 'ptax'
6
+ s.version = version
7
+ s.summary = 'Ruby API Wrapper for public data avaiable at Brazilian Central Bank web site'
8
+ s.description = 'Ruby API Wrapper for public data avaiable at Brazilian Central Bank web site'
9
+
10
+ s.required_ruby_version = '>= 1.8.7'
11
+ s.required_rubygems_version = ">= 1.3.6"
12
+
13
+ s.author = 'Fernando Ultremare'
14
+ s.email = 'feroult@gmail.com'
15
+ s.homepage = ''
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('rest-client', '>= 1.6.7')
23
+ s.add_dependency('nokogiri', '>= 1.5.0')
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+ require 'fileutils'
3
+
4
+ class TestClient < Test::Unit::TestCase
5
+
6
+ def test_sanity
7
+ client = Ptax::Client.new
8
+ end
9
+
10
+ def test_find_daily_ptax_csv_link
11
+ client = Ptax::Client.new
12
+ link = client.find_daily_ptax_csv_link(:date => '13/10/2011')
13
+ assert_not_nil link
14
+ end
15
+
16
+ def test_download_ptax_csv
17
+ client = Ptax::Client.new
18
+
19
+ FileUtils.rm_rf('/tmp/ptax.csv')
20
+
21
+ client.download_ptax_csv(:date => '13/10/2011', :path => '/tmp/ptax.csv')
22
+ assert File.exists?('/tmp/ptax.csv')
23
+
24
+ FileUtils.rm_rf('/tmp/ptax.csv')
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ # helper file
2
+ require 'test/unit'
3
+ require 'ruby-debug'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+
8
+ require 'ptax'
9
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.beta
4
+ version: 0.3.beta
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &79634860 !ruby/object:Gem::Requirement
16
+ requirement: &73979870 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *79634860
24
+ version_requirements: *73979870
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &79634610 !ruby/object:Gem::Requirement
27
+ requirement: &73979490 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,14 +32,24 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *79634610
35
+ version_requirements: *73979490
36
36
  description: Ruby API Wrapper for public data avaiable at Brazilian Central Bank web
37
37
  site
38
38
  email: feroult@gmail.com
39
39
  executables: []
40
40
  extensions: []
41
41
  extra_rdoc_files: []
42
- files: []
42
+ files:
43
+ - Gemfile
44
+ - Gemfile.lock
45
+ - LICENSE.txt
46
+ - README.rdoc
47
+ - lib/helpers/rest_helper.rb
48
+ - lib/ptax.rb
49
+ - lib/ptax/client.rb
50
+ - ptax.gemspec
51
+ - test/functional/test_client.rb
52
+ - test/helper.rb
43
53
  homepage: ''
44
54
  licenses: []
45
55
  post_install_message: