kaspay 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3088cb7f94f5cd5b2c29a34c39a19dc233c68f9a
4
- data.tar.gz: e3248f982d6859a04cecc0b131fbeef12f79ef4b
3
+ metadata.gz: fe31038fcff900af5444f5018b64e335bce662c6
4
+ data.tar.gz: 4db5d733155f0b6e3f57d3622d16a28e1faabfd7
5
5
  SHA512:
6
- metadata.gz: fab807cd628a82bb18a1a41e090ee71f177ec1b1c0d6741453835a51c74a90c4e242a7062285048b94f51aa8e9b68ff80badf94b7115e16fff9dba279da4c4f6
7
- data.tar.gz: a615c12b5c77842dab0dea3eaf734d15b958bcf907022dcaf07bba5c94a4b6f9376bb397da21b7ff5c39cb5fb1f057d4c2be953672954ce27b8f36af8f058c8b
6
+ metadata.gz: 1701cdb520bfbbb93e12d5af8f39f1b4bfaa6fb292a675fb251310c9b21fea74d98344d9cee01baf1546ad3aaf5b446b5e369c55b7a0e82e7f0e365a37569378
7
+ data.tar.gz: b74d09a869b6a16953bc53fd88d64cca14b4411c961ecac76b2feac2bbab0bd7e864f386cf499b4d6fd8f34892569b3fd8f07dbac2a34065c695eca347064f3b
@@ -0,0 +1,35 @@
1
+ # KasPay
2
+ ## Description
3
+ A ruby library to access [KasPay](https://www.kaspay.com) with your account.
4
+
5
+ ## Installation
6
+ Install the X virtual framebuffer that we will use to run the Watir::Browser
7
+
8
+ sudo apt-get install xvfb
9
+
10
+ and then:
11
+
12
+ gem install kaspay
13
+
14
+ ## Usage
15
+ Put this code wherever you're going to use it:
16
+
17
+ require 'kaspay'
18
+
19
+ In `Gemfile`:
20
+
21
+ gem 'kaspay'
22
+
23
+ ## Examples
24
+ ###Code
25
+ ```ruby
26
+ require 'kaspay'
27
+
28
+ kaspay = KasPay.login email: "email@example.com", password: "yOurp@sSw0rD"
29
+ puts "#{kaspay.get_name}'s savings with account number #{kaspay.get_acc_num}:"
30
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
31
+ puts " Bank A balance".ljust(15) + ": " + "Rp 500,000.00".rjust(20)
32
+ puts " Bank B balance".ljust(15) + ": " + "Rp 600,000.00".rjust(20)
33
+ puts " KasPay balance".ljust(15) + ": " + kaspay.get_balance.to_s.rjust(20)
34
+ puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
35
+ ```
@@ -6,12 +6,12 @@ require 'kaspay/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "kaspay"
8
8
  spec.version = KasPay::VERSION
9
- spec.date = "2015-08-24"
9
+ spec.date = "2015-08-25"
10
10
 
11
11
  spec.authors = ["Adrian Setyadi"]
12
12
  spec.email = ["a.styd@yahoo.com"]
13
13
  spec.summary = %q{Unofficial KasPay access wrapper gem.}
14
- spec.description = %q{A gem to access KasPay web using watir-webdriver gem and X virtual framebuffer wrapped by headless gem.}
14
+ spec.description = %q{A gem to access KasPay web using watir gem and X virtual framebuffer wrapped by headless gem.}
15
15
  spec.homepage = "https://github.com/styd/kaspay"
16
16
  spec.license = "MIT"
17
17
 
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
  # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  # spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
+ spec.add_runtime_dependency 'watir', '~> 5.0', '>= 5.0.0'
23
+ spec.add_runtime_dependency 'headless', '~> 2.2', '>= 2.2.0'
22
24
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'watir-webdriver'
3
+ require 'watir'
4
4
  require 'headless'
5
5
  require_relative 'meta_stuff'
6
6
  require_relative 'kernel_patch'
@@ -36,22 +36,45 @@ class KasPay
36
36
 
37
37
  attr_accessor :browser
38
38
  attr_accessor :headless
39
+ attr_reader :email
40
+ attr_reader :password
41
+ private :headless
42
+ private :headless=
43
+ private :password
44
+
45
+ def initialize user = { email: "", password: "" }
46
+ unless user[:email] == "" || user[:password] == ""
47
+ @email = user[:email]
48
+ @password = user[:password]
49
+ login
50
+ end
51
+ end
39
52
 
40
- def initialize email, password
53
+ def login
41
54
  headless = Headless.new
42
55
  headless.start
43
56
 
44
57
  @browser = Watir::Browser.start LOGIN_URL
45
-
58
+
46
59
  browser.text_field(id: 'username').set email
47
60
  browser.text_field(id: 'password').set password
48
61
  browser.button(name: 'button').click
49
62
  end
50
-
63
+
64
+ def email= mail
65
+ @email = mail
66
+ login if user_data_complete?
67
+ end
68
+
69
+ def password= pass
70
+ @password = pass
71
+ login if user_data_complete?
72
+ end
73
+
51
74
  def current_url
52
75
  browser.url
53
76
  end
54
-
77
+
55
78
  def goto path
56
79
  url = (path[0] == "/" ? (BASE_URL + path) : path)
57
80
  browser.goto url
@@ -79,7 +102,20 @@ class KasPay
79
102
  end
80
103
 
81
104
  def logged_in?
82
- logout_link.exists?
105
+ return logout_link.exists? unless browser.nil?
106
+ return false
107
+ end
108
+
109
+ def logged_out?
110
+ return !logged_in?
111
+ end
112
+
113
+ def user_data_complete?
114
+ email != "" && password != ""
115
+ end
116
+
117
+ def inspect
118
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)} logged_in=#{logged_in?}>"
83
119
  end
84
120
 
85
121
  def method_missing(m, *args, &block)
@@ -104,7 +140,7 @@ private
104
140
  def logout_link
105
141
  logout_link = browser.a(href: "https://www.kaspay.com/account/logout")
106
142
  end
107
-
143
+
108
144
  # inner class Money
109
145
  class Money
110
146
  attr_accessor :value
@@ -130,12 +166,19 @@ private
130
166
  end
131
167
 
132
168
  def to_s
133
- "Rp " + value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse + ",-"
169
+ "Rp " + value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + ".00"
134
170
  end
135
-
171
+
172
+ def inspect
173
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)} value=#{value}>"
174
+ end
175
+
136
176
  alias_method :to_i, :value
137
177
  end
138
178
  end
139
179
 
140
180
  class LoginError < StandardError
141
181
  end
182
+
183
+ class UserDataError < StandardError
184
+ end
@@ -1,3 +1,3 @@
1
1
  class KasPay
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,16 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaspay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-24 00:00:00.000000000 Z
12
- dependencies: []
13
- description: A gem to access KasPay web using watir-webdriver gem and X virtual framebuffer
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: headless
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.2.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.2.0
53
+ description: A gem to access KasPay web using watir gem and X virtual framebuffer
14
54
  wrapped by headless gem.
15
55
  email:
16
56
  - a.styd@yahoo.com
@@ -19,6 +59,7 @@ extensions: []
19
59
  extra_rdoc_files: []
20
60
  files:
21
61
  - LICENSE.txt
62
+ - README.md
22
63
  - kaspay.gemspec
23
64
  - lib/kaspay.rb
24
65
  - lib/kaspay/version.rb
@@ -49,3 +90,4 @@ signing_key:
49
90
  specification_version: 4
50
91
  summary: Unofficial KasPay access wrapper gem.
51
92
  test_files: []
93
+ has_rdoc: