tmoney 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d045f351f71f8ce98cb40fd3c2c998ef2fc9652d
4
+ data.tar.gz: 2822634461bfebbc1fbd0181bd2973450ba0d6cb
5
+ SHA512:
6
+ metadata.gz: d42aa8dbd65995d57a056a06d51a002c6532b2aec1e3b2b714094d71383985d1b0e023d66b09490aac7e63607fef39cb5d1001f6302025522a9ade003dda08b6
7
+ data.tar.gz: bbceb543b326e2dddcbdd9260bf2cd489a865678532d08c3726f2ffff6309dd0aabdcfb0fabb04ac1c835b570bb39f047f8bcbf15f9d3730fc43dafd1f884528
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "nokogiri"
4
+ gem "rest-client"
5
+ gem "rspec"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 buo
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.
@@ -0,0 +1,26 @@
1
+ # tmoney
2
+
3
+ A simple client for [T-money](https://www.t-money.co.kr/).
4
+
5
+ ## How to use
6
+
7
+ The following is the example which demonstrates how to use T-money client. To test this code, you need to change `<USERNAME>` and `<PASSWORD>` to your own username and password.
8
+ ```ruby
9
+ require 'tmoney'
10
+
11
+ client = Tmoney::Client.new
12
+ client.connect('<USERNAME>', '<PASSWORD>')
13
+ cards = client.cards
14
+ puts '== My Cards', cards
15
+ puts '== Transactions', cards[0].transactions
16
+ ```
17
+
18
+ It will produce the following output:
19
+ ```
20
+ == My Cards
21
+ 티머니 0000-0000-0000-0000 2015-09-15
22
+ == Transactions
23
+ 2015-09-13 19:25:39 지하철 서울메트로(2호선) 1050
24
+ 2015-09-13 20:51:06 택시 택시 3400
25
+ 2015-09-15 21:44:55 충전 1호선 서울역 50000
26
+ ```
@@ -0,0 +1,77 @@
1
+ require 'tmoney/card'
2
+ require 'tmoney/version'
3
+
4
+ require 'rest-client'
5
+ require 'nokogiri'
6
+
7
+ # Set timezone
8
+ ENV['TZ'] = 'Asia/Seoul'
9
+
10
+ module Tmoney
11
+ class Client
12
+ def request(method, url, params = nil)
13
+ begin
14
+ headers = {}
15
+ unless @cookies.nil? or @cookies.empty?
16
+ headers[:Cookie] = @cookies
17
+ end
18
+ url = "https://www.t-money.co.kr#{url}"
19
+ resp = RestClient::Request.execute(:method => method, :url => url, :payload => params, :headers => headers)
20
+ rescue RestClient::ExceptionWithResponse => err
21
+ case err.response.code
22
+ when 200
23
+ resp = err.response
24
+ else
25
+ raise err
26
+ end
27
+ end
28
+ resp
29
+ end
30
+
31
+ # 로그인
32
+ def connect(username, password)
33
+ params = {
34
+ :logOut => 'N',
35
+ :indlMbrsId => username,
36
+ :mbrsPwd => password
37
+ }
38
+ resp = request(:post, '/ncs/pct/lgncent/ReadMbrsLgn.dev', params)
39
+
40
+ # A string for use in the Cookie header, like “name1=value2; name2=value2”.
41
+ @cookies = resp.cookie_jar.cookies.join('; ')
42
+ end
43
+
44
+ # 등록된 카드 현황
45
+ def cards
46
+ resp = request(:get, '/ncs/pct/mtmn/ReadRgtCardPrcn.dev?logOut=N')
47
+ doc = Nokogiri::HTML(resp.body)
48
+ results = []
49
+ doc.css('.tb_mylist table tbody tr').each do |tr|
50
+ card = Card.new
51
+ card.client = self
52
+
53
+ # 카드 구분
54
+ card.type = tr.css('td:nth-child(1)').text.strip
55
+
56
+ # 카드 번호. `####-####-####-####` 형태.
57
+ card.no = tr.css('td:nth-child(2)').text.strip
58
+
59
+ # 카드 등록일. `YYYY-MM-DD` 형태.
60
+ card.regdate = tr.css('td:nth-child(3)').text.strip
61
+
62
+ # 등록 서비스
63
+ # `어`: 어린이 요금 적용
64
+ # `청`: 청소년 요금 적용
65
+ # `소`: 소득공제
66
+ # `현`: 현금영수증
67
+ # `마`: 마일리지
68
+ # `분`: 분실/도난
69
+ card.services = tr.css('td:nth-child(4) span').text.strip.split(//)
70
+
71
+ results << card
72
+ end
73
+
74
+ results
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,75 @@
1
+ require 'tmoney/transaction'
2
+
3
+ module Tmoney
4
+ class Card
5
+ attr_accessor :type, :no, :regdate, :services
6
+
7
+ def client=(client)
8
+ @client = client
9
+ end
10
+
11
+ # 사용 내역 조회
12
+ # - 조회기간은 조회신청일(0일) 기준 D-367일 부터 D-2일 까지 가능합니다.
13
+ # - 사용내역 조회는 홈페이지에 등록된 카드만 제공되며, 카드 등록 이후 내역부터 조회 가능합니다.
14
+ # - 유패스카드 전환 회원의 사용내역은 2014년 10월 15일 이후부터 조회가 가능합니다.
15
+ # - 티머니 카드가 아닌 신용카드 및 타사 선불카드의 이용내역은 제공되지 않습니다.
16
+ # - 회원가입 이전의 사용내역을 원하시는 경우 [사용내역 신청]메뉴를 이용하시기 바랍니다.
17
+ # - 회원가입 이전에 할인 등록된 카드는 조회하실 수 없으니 새로 등록을 하시기 바랍니다.
18
+ def transactions
19
+ params = {
20
+ # 분류
21
+ # 분류에 따라 결과 페이지 형식이 달라지므로 변경하지 않는다.
22
+ # `ALL`: 전체
23
+ # `USE`: 사용
24
+ # `CHG`: 충전
25
+ # `RY` : 환불
26
+ :inqrDvs => 'ALL',
27
+
28
+ # 거래내역 조회 본인 동의 여부
29
+ # 본인은 조회 하고자 하는 해당 카드가 본인의 소유임을 확인하며, 조회된 거래내역 및 기록이
30
+ # 제 3자 에게 유출됨으로 인하여 발생하게 되는 모든 문제에 대하여는 그 책임이 본인에게 있음을
31
+ # 확인 합니다.
32
+ :agrmYn => 'Y',
33
+
34
+ # 카드 번호
35
+ :srcPrcrNo => @no.gsub(/-/, ''),
36
+
37
+ # 조회 기간
38
+ # `1`: 최근 1주
39
+ # `2`: 최근 1개월
40
+ # `3`: 최근 3개월
41
+ # `4`: 최근 6개월
42
+ # `5`: 최근 1년
43
+ :srcChcDiv => 5,
44
+
45
+ # 조회 시작 일자. `YYYY-MM-DD` 형태
46
+ :srcSttDt => @regdate,
47
+
48
+ # 조회 종료 일자. `YYYY-MM-DD` 형태
49
+ :srcEdDt => Time.new.strftime('%Y-%m-%d')
50
+ }
51
+ resp = @client.request(:post, '/ncs/pct/mtmn/ReadTrprInqr.dev', params)
52
+
53
+ doc = Nokogiri::HTML(resp.body)
54
+
55
+ results = []
56
+ doc.css('#protable tbody tr').each do |tr|
57
+ t = Transaction.new
58
+
59
+ t.datetime = Time.parse(tr.css('td:nth-child(1)').text.strip)
60
+ t.category = tr.css('td:nth-child(2)').text.strip
61
+ t.payee = tr.css('td:nth-child(3)').text.strip
62
+ t.amount = tr.css('td:nth-child(4)').text.gsub(/[,원]/, '').strip.to_i
63
+
64
+ results << t
65
+ end
66
+
67
+ # Sort transactions in ascending order (old to new).
68
+ results.reverse
69
+ end
70
+
71
+ def to_s
72
+ "#{@type} #{@no} #{@regdate} #{@services.join(',')}"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ module Tmoney
2
+ class Transaction
3
+ attr_accessor :datetime, :category, :payee, :amount
4
+
5
+ def to_s
6
+ "#{@datetime.strftime('%Y-%m-%d %H:%M:%S')} #{@category} #{@payee} #{@amount}"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Tmoney
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ RSpec.configure do |config|
2
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require 'tmoney'
3
+
4
+ describe Tmoney::Client do
5
+ end
@@ -0,0 +1,17 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'tmoney/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'tmoney'
7
+ gem.version = Tmoney::VERSION
8
+ gem.authors = ['buo']
9
+ gem.email = ['buo@users.noreply.github.com']
10
+ gem.summary = 'A simple client for T-Money'
11
+ gem.description = 'A simple client for T-Money (https://www.t-money.co.kr/)'
12
+ gem.homepage = 'https://github.com/buo/tmoney'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.require_paths = ['lib']
17
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmoney
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - buo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple client for T-Money (https://www.t-money.co.kr/)
14
+ email:
15
+ - buo@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - .rspec
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - lib/tmoney.rb
26
+ - lib/tmoney/card.rb
27
+ - lib/tmoney/transaction.rb
28
+ - lib/tmoney/version.rb
29
+ - spec/spec_helper.rb
30
+ - spec/tmoney_spec.rb
31
+ - tmoney.gemspec
32
+ homepage: https://github.com/buo/tmoney
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.0.14
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: A simple client for T-Money
56
+ test_files: []