sea_witch 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2434982a653463cae5097f00262d9f1adc88afa7
4
+ data.tar.gz: 9fdaab5a144380de3050feb6d96c842209f8023f
5
+ SHA512:
6
+ metadata.gz: 09ebfce16ea299cadbaec5c45f69f6e1a964f018eef5bf15583e930abc178d0d87406039ef66f35aaf7d52c23774e80cba57b488959856895c441899514ebebf
7
+ data.tar.gz: 1fa41c3367c3c7b058a4589728ab667186b228904a7de9b158dbf5d235bb6005959855499276e224da0f995debe5d343f117dfc57fe3cb6046e0729a413ecee9
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # Vendored gems
20
+ /vendor/ruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sea_witch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Justin Rhinesmith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SeaWitch
2
+
3
+ I often want to know the balance on my clipper card without fully logging into their site. Unfortunately, clippercard.com does not provide a usable API. This gem serves as a wrapper for their site in the attempt to provide a usable client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sea_witch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sea_witch
18
+
19
+ ## Usage
20
+
21
+ client = SeaWitch::Client.new(your_clipper_username, your_clipper_password)
22
+ puts client.balance
23
+ # => 3.04
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/sea_witch.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "sea_witch/version"
2
+ require "sea_witch/client"
@@ -0,0 +1,83 @@
1
+ require 'faraday'
2
+ require 'nokogiri'
3
+
4
+ module SeaWitch
5
+ class Client
6
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36'
7
+ BASE_URL = 'https://www.clippercard.com'
8
+ LOGIN_PATH = '/ClipperCard/loginFrame.jsf'
9
+ DASHBOARD_PATH = '/ClipperCard/dashboard.jsf'
10
+
11
+ attr_accessor :username, :password, :session_id, :logged_in
12
+
13
+ def initialize(username, password)
14
+ self.username = username
15
+ self.password = password
16
+ self.logged_in = false
17
+
18
+ self
19
+ end
20
+
21
+ def balance
22
+ @balance ||= dashboard.css('.cardInfo').children.collect(&:text).join.match(/(\$[0-9\.]+)/)[0].gsub('$', '').to_f
23
+ end
24
+
25
+ def logged_in?
26
+ !!logged_in
27
+ end
28
+
29
+ def login!
30
+ connection.headers[:user_agent] = USER_AGENT
31
+
32
+ response = connection.get(LOGIN_PATH)
33
+ login = Nokogiri::HTML(response.body)
34
+
35
+ viewstate = login.xpath('//input').select{|n| n['id'] =~ /viewstate/i}.first['value']
36
+ self.session_id = response.headers['set-cookie'].split(';').select{|c| c =~ /^JSESSIONID/i}[0]
37
+
38
+ connection.headers[:cookie] = self.session_id
39
+
40
+ login_params = self.class.default_params.merge({
41
+ 'j_idt14:username' => self.username,
42
+ 'j_idt14:password' => self.password,
43
+ 'javax.faces.ViewState' => viewstate
44
+ })
45
+
46
+ response = connection.post LOGIN_PATH, login_params
47
+
48
+ self.logged_in = true
49
+ end
50
+
51
+ def self.default_params
52
+ {
53
+ 'j_idt14' => 'j_idt14',
54
+ 'javax.faces.source' => 'j_idt14:submitLogin',
55
+ 'javax.faces.partial.event' => 'click',
56
+ 'javax.faces.partial.execute' => ':submitLogin j_idt14:username j_idt14:password',
57
+ 'javax.faces.partial.render' => 'j_idt14:err',
58
+ 'javax.faces.behavior.event' => 'action',
59
+ 'javax.faces.partial.ajax' => 'true'
60
+ }
61
+ end
62
+
63
+ private
64
+ def dashboard
65
+ @dashboard ||= Nokogiri::HTML(request_path(DASHBOARD_PATH).body)
66
+ end
67
+
68
+ def connection
69
+ @connection ||= Faraday.new(:url => BASE_URL) do |faraday|
70
+ faraday.request :url_encoded # form-encode POST params
71
+ faraday.response :logger # log requests to STDOUT
72
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
73
+ end
74
+ end
75
+
76
+ def request_path(path)
77
+ login! unless logged_in?
78
+
79
+ connection.get path
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module SeaWitch
2
+ VERSION = "0.0.1"
3
+ end
data/sea_witch.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sea_witch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sea_witch"
8
+ spec.version = SeaWitch::VERSION
9
+ spec.authors = ["jerhinesmith"]
10
+ spec.email = ["jerhinesmith@gmail.com"]
11
+ spec.summary = %q{Wraps clippercard.com to provide a usable client in the absence of a true api}
12
+ spec.description = %q{Wraps clippercard.com to provide a usable client in the absence of a true api}
13
+ spec.homepage = "https://github.com/jerhinesmith/sea_witch"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "faraday"
25
+ spec.add_runtime_dependency "nokogiri"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sea_witch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jerhinesmith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Wraps clippercard.com to provide a usable client in the absence of a
70
+ true api
71
+ email:
72
+ - jerhinesmith@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/sea_witch.rb
83
+ - lib/sea_witch/client.rb
84
+ - lib/sea_witch/version.rb
85
+ - sea_witch.gemspec
86
+ homepage: https://github.com/jerhinesmith/sea_witch
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Wraps clippercard.com to provide a usable client in the absence of a true
110
+ api
111
+ test_files: []