uc_card 0.0.3

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2012 kimoto
@@ -0,0 +1,31 @@
1
+ = uc_card
2
+ UCカード(www.uccard.co.jp)の取引履歴に簡易にアクセスするためのライブラリです。
3
+
4
+ = Require
5
+ Ruby1.9
6
+
7
+ = Install
8
+ $ gem install uc_card
9
+
10
+ = Usage
11
+ インストールするとuc_cardコマンドが使えるようになりますので、ライブラリとして使わなくてもコマンドとして簡単に使うことができます。
12
+ このコマンドは未払いのクレジットカード取引を一覧して表示してくれるコマンドです。(オプションは一切ない)
13
+ $ uc_card
14
+ 2012/01/28: ****** 500 1回払い 1回
15
+ 2012/01/26: ****** 5940 1回払い 1回
16
+ 2012/01/22: ****** 3357 1回払い 1回
17
+ 2012/01/22: ****** 85 1回払い 1回
18
+ 2012/01/21: ****** 1340 1回払い 1回
19
+ 2012/01/21: ****** 250 1回払い 1回
20
+ 2012/01/14: ****** 250 1回払い 1回
21
+ Total: 11722
22
+
23
+ ライブラリとして使うときは
24
+ require 'uc_card'
25
+ UCCard.start_with_pit("uccard.co.jp") do |card|
26
+ puts card
27
+ end
28
+
29
+ == Copyright
30
+ Copyright (c) 2012 kimoto. See LICENSE for details.
31
+
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "uc_card"
8
+ gem.summary = %Q{www.uccard.co.jp Ruby Interface}
9
+ gem.description = %Q{www.uccard.co.jp Ruby Interface}
10
+ gem.email = "sub+peerler@gmail.com"
11
+ gem.homepage = "http://github.com/kimoto/uc_card"
12
+ gem.authors = ["kimoto"]
13
+ gem.executables = ["uc_card"]
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ gem.add_dependency 'mechanize'
16
+ gem.add_dependency 'pit'
17
+ gem.add_dependency 'nokogiri'
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ if File.exist?('VERSION')
51
+ version = File.read('VERSION')
52
+ else
53
+ version = ""
54
+ end
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "uc_card #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Author: kimoto
4
+ require 'uc_card'
5
+ UCCard.start_with_pit("uccard.co.jp") do |card|
6
+ puts card
7
+ end
8
+
@@ -0,0 +1,8 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ # Author: kimoto
4
+ require 'uc_card'
5
+ UCCard.start_with_pit("uccard.co.jp") do |card|
6
+ puts card
7
+ end
8
+
@@ -0,0 +1,117 @@
1
+ require 'nokogiri'
2
+ require 'mechanize'
3
+ require 'logger'
4
+ require 'pit'
5
+
6
+ class UCCard
7
+ attr_reader :recent_shoppings
8
+
9
+ def self.start(options={})
10
+ instance=self.new(options)
11
+ begin
12
+ instance.login
13
+ instance.go_recent
14
+ yield instance
15
+ ensure
16
+ instance.logout
17
+ end
18
+ end
19
+
20
+ def self.start_with_pit(pit_key, &block)
21
+ config = Pit.get(pit_key, :require => {
22
+ :user => 'your name',
23
+ :password => 'your password'
24
+ })
25
+ self.start(:user => config[:user], :password => config[:password], &block)
26
+ end
27
+
28
+ def initialize(options={})
29
+ @user = options[:user] or raise ArgumentError('user')
30
+ @password = options[:password] or raise ArgumentError('password')
31
+
32
+ ## data
33
+ @recent_shoppings = []
34
+
35
+ create_agent
36
+ end
37
+
38
+ ### login / logout
39
+ def login
40
+ @agent.get("https://atunet.uccard.co.jp/UCPc/welcomeSCR.do")
41
+ @agent.page.form_with(:name => '_USA01Form'){ |f|
42
+ f.field_with(:name => 'inputId').value = @user
43
+ f.field_with(:name => 'inputPassword').value = @password
44
+ f.click_button
45
+ }
46
+ end
47
+
48
+ def logout
49
+ @agent.get('https://atunet.uccard.co.jp/UCPc/USL0100BLC01.do?r=8400550016797730123')
50
+ end
51
+
52
+ def go_recent
53
+ @agent.get("https://atunet.uccard.co.jp/UCPc/USC0101BLC01NOW.do?r=7005820039568205309")
54
+ @recent_shoppings = []
55
+ Nokogiri(@agent.page.body).search("#mainWrap > table > tbody > tr")[2..-1].each{ |record|
56
+ (date, klass, name, value, usecase, times, note, payment) = record.search("td").map{|e| e.text.strip}
57
+ @recent_shoppings << ShoppingData.new(
58
+ :date => date, :klass => klass, :name => name,
59
+ :value => value, :usecase => usecase, :times => times,
60
+ :note => note, :payment => payment)
61
+ }
62
+ end
63
+
64
+ ### api
65
+ def reserved_payment
66
+ recent_shoppings.inject(0) {|total, record|
67
+ total += record.money
68
+ }.to_i
69
+ end
70
+
71
+ def reserved_payment_this_month
72
+ end
73
+
74
+ def to_s
75
+ recent_data = recent_shoppings.map(&:to_s).join($/)
76
+ return <<-EOT
77
+ #{recent_data}
78
+ Total: #{reserved_payment}
79
+ EOT
80
+ end
81
+
82
+ private
83
+ def create_agent
84
+ unless @agent
85
+ @agent = Mechanize.new{ |agent|
86
+ agent.user_agent_alias = "Windows IE 7"
87
+ }
88
+ end
89
+ end
90
+ end
91
+
92
+ class UCCard::ShoppingData
93
+ attr_accessor :date
94
+ attr_accessor :klass
95
+ attr_accessor :name
96
+ attr_accessor :value
97
+ attr_accessor :usecase
98
+ attr_accessor :times
99
+ attr_accessor :note
100
+ attr_accessor :payment
101
+
102
+ def initialize(options={})
103
+ options.each{ |k,v|
104
+ self.send("#{k.to_s}=", v)
105
+ }
106
+ end
107
+
108
+ def money
109
+ @value.gsub(/\D/, '').to_i
110
+ end
111
+
112
+ def to_s
113
+ #"#{date}: " + [@date, @klass, @name, @value, @usecase, @times, @note, @payment].join(',')
114
+ "#{@date}: #{@name} #{money} #{@usecase} #{@times}"
115
+ end
116
+ end
117
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'uc_card'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UcCardTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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{uc_card}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kimoto"]
12
+ s.date = %q{2012-02-10}
13
+ s.default_executable = %q{uc_card}
14
+ s.description = %q{www.uccard.co.jp Ruby Interface}
15
+ s.email = %q{sub+peerler@gmail.com}
16
+ s.executables = ["uc_card"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/uc_card",
29
+ "examples/uc_card.rb",
30
+ "lib/uc_card.rb",
31
+ "test/test_helper.rb",
32
+ "test/uc_card_test.rb",
33
+ "uc_card.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/kimoto/uc_card}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{www.uccard.co.jp Ruby Interface}
40
+ s.test_files = [
41
+ "test/test_helper.rb",
42
+ "test/uc_card_test.rb",
43
+ "examples/uc_card.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
53
+ s.add_runtime_dependency(%q<pit>, [">= 0"])
54
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ s.add_dependency(%q<mechanize>, [">= 0"])
58
+ s.add_dependency(%q<pit>, [">= 0"])
59
+ s.add_dependency(%q<nokogiri>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
63
+ s.add_dependency(%q<mechanize>, [">= 0"])
64
+ s.add_dependency(%q<pit>, [">= 0"])
65
+ s.add_dependency(%q<nokogiri>, [">= 0"])
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uc_card
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - kimoto
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-10 00:00:00 +09:00
18
+ default_executable: uc_card
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: mechanize
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: pit
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: nokogiri
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :runtime
71
+ version_requirements: *id004
72
+ description: www.uccard.co.jp Ruby Interface
73
+ email: sub+peerler@gmail.com
74
+ executables:
75
+ - uc_card
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - LICENSE
80
+ - README.rdoc
81
+ files:
82
+ - .document
83
+ - .gitignore
84
+ - LICENSE
85
+ - README.rdoc
86
+ - Rakefile
87
+ - VERSION
88
+ - bin/uc_card
89
+ - examples/uc_card.rb
90
+ - lib/uc_card.rb
91
+ - test/test_helper.rb
92
+ - test/uc_card_test.rb
93
+ - uc_card.gemspec
94
+ has_rdoc: true
95
+ homepage: http://github.com/kimoto/uc_card
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --charset=UTF-8
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.7
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: www.uccard.co.jp Ruby Interface
126
+ test_files:
127
+ - test/test_helper.rb
128
+ - test/uc_card_test.rb
129
+ - examples/uc_card.rb