web_invoice 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'mechanize'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.3.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ mechanize (1.0.0)
11
+ nokogiri (>= 1.2.1)
12
+ nokogiri (1.4.4)
13
+ rake (0.8.7)
14
+ rcov (0.9.9)
15
+ rspec (2.3.0)
16
+ rspec-core (~> 2.3.0)
17
+ rspec-expectations (~> 2.3.0)
18
+ rspec-mocks (~> 2.3.0)
19
+ rspec-core (2.3.1)
20
+ rspec-expectations (2.3.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.3.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ jeweler (~> 1.5.2)
30
+ mechanize
31
+ rcov
32
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 CHIKURA Shinsaku
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = web_invoice
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to web_invoice
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 CHIKURA Shinsaku. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "web_invoice"
16
+ gem.homepage = "http://github.com/chsh/web_invoice"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Web Invoice Downloader}
19
+ gem.description = %Q{Simple Web Invoice Downloader}
20
+ gem.email = "chsh@thinq.jp"
21
+ gem.authors = ["CHIKURA Shinsaku"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'mechanize'
25
+ gem.add_development_dependency 'rspec'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "web_invoice #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/webinvoice ADDED
@@ -0,0 +1,4 @@
1
+ #!/this/will/be/overritten/or/wrapped/anyways/do/not/warry/ruby
2
+ # -*- encoding: UTF-8 -*-
3
+
4
+ require 'web_invoice/cli'
@@ -0,0 +1,57 @@
1
+
2
+ require 'optparse'
3
+ require 'web_invoice'
4
+
5
+ class WebInvoice::CLI
6
+ class Params
7
+ def initialize(args)
8
+ opt = OptionParser.new
9
+ opt.on('-c config-file', 'default: ~/.webinvoicerc') { |v| @config = YAML.load_file(v) }
10
+ opt.on('-d download-dir','default: .' ) { |v| @download_to = v }
11
+ opt.on('-s service', 'default: saison_card') { |v| @service_name = v }
12
+ opt.on('-u user') { |v| @user = v }
13
+ opt.on('-p password') { |v| @password = v }
14
+ opt.parse! args
15
+ @config ||= YAML.load_file(File.join(ENV['HOME'], '.webinvoicerc'))
16
+ @service_name = lookup_master_service
17
+ @service_config = symbolize_keys(@config['services'][@service_name])
18
+ @service_config[:download_to] = @download_to if @download_to
19
+ @service_config[:user] = @user if @user
20
+ @service_config[:password] = @password if @password
21
+ end
22
+ attr_reader :service_name, :service_config
23
+ def service_class
24
+ begin
25
+ eval "WebInvoice::#{service_name.split(/_/).map { |w| w.capitalize }.join('')}"
26
+ rescue
27
+ nil
28
+ end
29
+ end
30
+ private
31
+ def lookup_master_service
32
+ @config['services'].each do |key, value|
33
+ return key if value['default']
34
+ end
35
+ nil
36
+ end
37
+ def symbolize_keys(hash)
38
+ return nil unless hash
39
+ h = {}
40
+ hash.each do |key, value|
41
+ h[key.to_s.to_sym] = value
42
+ end
43
+ h
44
+ end
45
+ end
46
+ def self.run(args)
47
+ WebInvoice::CLI.new.run(args)
48
+ end
49
+ def run(args)
50
+ params = Params.new(args)
51
+ sc = params.service_class
52
+ raise "service_class not found." unless sc
53
+ sc.execute params.service_config
54
+ end
55
+ end
56
+
57
+ WebInvoice::CLI.run(ARGV)
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'mechanize'
5
+
6
+ class WebInvoice::SaisonCard
7
+ def initialize(opts = {})
8
+ @agent = Mechanize.new
9
+ @user_id = opts[:user]
10
+ @user_password = opts[:password]
11
+ @download_to = opts[:download_to] || '.'
12
+ end
13
+ def self.execute(opts)
14
+ wi = new opts
15
+ wi.login
16
+ wi.download
17
+ end
18
+ def login
19
+ do_login unless @login
20
+ end
21
+ def download(folder = nil)
22
+ login
23
+ folder ||= @download_to
24
+ pwd = `pwd`.chomp
25
+ if folder
26
+ Dir.chdir folder
27
+ end
28
+ @agent.page.link_with(text: '利用明細確認').click
29
+ csv_link = @agent.page.link_with(text: 'CSVダウンロード')
30
+ pdf_link = @agent.page.link_with(text: 'Web明細ダウンロード')
31
+ csv_link.click
32
+ @agent.page.save
33
+ pdf_link.click
34
+ @agent.page.save
35
+ if folder
36
+ Dir.chdir pwd
37
+ end
38
+ end
39
+ private
40
+ def do_login
41
+ @agent.get 'https://netanswerplus.saisoncard.co.jp/WebPc/welcomeSCR.do'
42
+ f = @agent.page.forms[0]
43
+ f.inputId = @user_id
44
+ f.inputPassword = @user_password
45
+ f.submit
46
+ @login = true
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module WebInvoice
3
+ end
4
+
5
+ require 'web_invoice/saison_card'
6
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'web_invoice'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "WebInvoice" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{web_invoice}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["CHIKURA Shinsaku"]
12
+ s.date = %q{2011-03-13}
13
+ s.description = %q{Simple Web Invoice Downloader}
14
+ s.email = %q{chsh@thinq.jp}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/web_invoice.rb",
28
+ "spec/spec_helper.rb",
29
+ "spec/web_invoice_spec.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/chsh/web_invoice}
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.5.2}
35
+ s.summary = %q{Web Invoice Downloader}
36
+ s.test_files = [
37
+ "spec/spec_helper.rb",
38
+ "spec/web_invoice_spec.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<mechanize>, [">= 0"])
54
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<mechanize>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<mechanize>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<mechanize>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, [">= 0"])
69
+ end
70
+ end
71
+
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_invoice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - CHIKURA Shinsaku
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-13 00:00:00 +09:00
14
+ default_executable: webinvoice
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: mechanize
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.5.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: mechanize
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ description: Simple Web Invoice Downloader
94
+ email: chsh@thinq.jp
95
+ executables:
96
+ - webinvoice
97
+ extensions: []
98
+
99
+ extra_rdoc_files:
100
+ - LICENSE.txt
101
+ - README.rdoc
102
+ files:
103
+ - .document
104
+ - .rspec
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ - Rakefile
110
+ - VERSION
111
+ - bin/webinvoice
112
+ - lib/web_invoice.rb
113
+ - lib/web_invoice/cli.rb
114
+ - lib/web_invoice/saison_card.rb
115
+ - spec/spec_helper.rb
116
+ - spec/web_invoice_spec.rb
117
+ - web_invoice.gemspec
118
+ has_rdoc: true
119
+ homepage: http://github.com/chsh/web_invoice
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: -1311712060282417750
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ requirements: []
143
+
144
+ rubyforge_project:
145
+ rubygems_version: 1.5.2
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Web Invoice Downloader
149
+ test_files:
150
+ - spec/spec_helper.rb
151
+ - spec/web_invoice_spec.rb