sfwash 0.1.0
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.
- data/Gemfile +10 -0
- data/Gemfile.lock +18 -0
- data/README.md +61 -0
- data/bin/sfwash +23 -0
- data/lib/sfwash.rb +97 -0
- data/sfwash.gemspec +16 -0
- metadata +83 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
chronic (0.10.2)
|
5
|
+
metaclass (0.0.1)
|
6
|
+
minitest (5.0.8)
|
7
|
+
mocha (0.14.0)
|
8
|
+
metaclass (~> 0.0.1)
|
9
|
+
multipart-post (1.2.0)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
chronic
|
16
|
+
minitest
|
17
|
+
mocha
|
18
|
+
multipart-post
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
sfwash
|
2
|
+
====
|
3
|
+
|
4
|
+
A CLI for scheduling pickups on SFWash (http://sfwash.com/schedule-a-pick-up).
|
5
|
+
|
6
|
+
SFWash, unfortunately, requires you to fill in your information (address, phone
|
7
|
+
number, etc) with them every time. This script will save your details on your
|
8
|
+
machine, and reuse them every time you need to schedule a pickup. Hooray!
|
9
|
+
|
10
|
+
Note: This code may be horribly brittle because it basically just POSTs to
|
11
|
+
the SFWash website with the parameters required at the time of writing, but oh
|
12
|
+
well!
|
13
|
+
|
14
|
+
Usage
|
15
|
+
----
|
16
|
+
|
17
|
+
Install the gem:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ gem install sfwash
|
21
|
+
```
|
22
|
+
|
23
|
+
Then, to schedule a pickup (make sure you have your config file created first):
|
24
|
+
|
25
|
+
```
|
26
|
+
$ sfwash schedule
|
27
|
+
```
|
28
|
+
|
29
|
+
Or provide a day of the week:
|
30
|
+
|
31
|
+
```
|
32
|
+
$ sfwash schedule friday
|
33
|
+
```
|
34
|
+
|
35
|
+
Config file
|
36
|
+
----
|
37
|
+
|
38
|
+
At the moment, you must have a `~/.sfwash` config file to use this script.
|
39
|
+
Example config file:
|
40
|
+
|
41
|
+
```
|
42
|
+
:preferences:
|
43
|
+
:name: Amber Feng
|
44
|
+
:phone: 555-555-5555
|
45
|
+
:email: amber.feng@gmail.com
|
46
|
+
:address: 123 Main Street
|
47
|
+
:apartment: N/A
|
48
|
+
:day: Friday
|
49
|
+
:time: Anytime_Access
|
50
|
+
:instructions: OldPreferences
|
51
|
+
:detergent: Last Order
|
52
|
+
:bleach: Last Order
|
53
|
+
:softener: Last Order
|
54
|
+
```
|
55
|
+
|
56
|
+
TODOs
|
57
|
+
----
|
58
|
+
|
59
|
+
- Gem-ify
|
60
|
+
- Set date of pickup via CLI option
|
61
|
+
- Enter/update details by CLI
|
data/bin/sfwash
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require './lib/sfwash'
|
5
|
+
|
6
|
+
command = ARGV.shift
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
# If one more command line argument, it's the day to schedule the pickup
|
10
|
+
if ARGV.length == 1
|
11
|
+
options = {:day => ARGV.shift}
|
12
|
+
end
|
13
|
+
|
14
|
+
ARGV.options do |opts|
|
15
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
16
|
+
puts opts
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.parse!
|
21
|
+
end
|
22
|
+
|
23
|
+
SFWash::CLI.run(command, options)
|
data/lib/sfwash.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http/post/multipart'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module SFWash
|
5
|
+
class Client
|
6
|
+
SFWASH_URL = 'http://www.sfwash.com/schedule-a-pick-up'
|
7
|
+
TRANSFORMED_PARAMS = {
|
8
|
+
:name => 'ff_nm_Name[]',
|
9
|
+
:phone => 'ff_nm_Phone[]',
|
10
|
+
:email => 'ff_nm_email[]',
|
11
|
+
:address => 'ff_nm_bfQuickMode2392926[]',
|
12
|
+
:apartment => 'ff_nm_bfQuickMode2924333[]',
|
13
|
+
:day => 'ff_nm_day[]',
|
14
|
+
:time => 'ff_nm_Time[]',
|
15
|
+
:instructions => 'ff_nm_Instructions[]',
|
16
|
+
:detergent => 'ff_nm_detergent[]',
|
17
|
+
:bleach => 'ff_nm_Bleach[]',
|
18
|
+
:softener => 'ff_nm_Softener[]'
|
19
|
+
}
|
20
|
+
|
21
|
+
def transform_params(params)
|
22
|
+
transformed_params = {}
|
23
|
+
for key, value in params
|
24
|
+
transformed_params[TRANSFORMED_PARAMS[key]] = value
|
25
|
+
end
|
26
|
+
|
27
|
+
# Other random parameters that pretty much must be included as well
|
28
|
+
transformed_params.merge({
|
29
|
+
'ff_contentid' => 2,
|
30
|
+
'ff_applic' => nil,
|
31
|
+
'ff_module_id' => nil,
|
32
|
+
'ff_form' => 4,
|
33
|
+
'ff_task' => 'submit',
|
34
|
+
'ff_target' => 2,
|
35
|
+
'ff_align' => nil,
|
36
|
+
'option' => 'com_content',
|
37
|
+
'Itemid' => 2,
|
38
|
+
'id' => 2
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
def schedule_request(params)
|
43
|
+
url = URI.parse(SFWASH_URL)
|
44
|
+
|
45
|
+
req = Net::HTTP::Post::Multipart.new(url.path, transform_params(params))
|
46
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
47
|
+
http.request(req)
|
48
|
+
end
|
49
|
+
|
50
|
+
if res.code == '200'
|
51
|
+
puts "Successfully scheduled! You should be receiving an email from SFWash shortly."
|
52
|
+
else
|
53
|
+
puts "Blergh, something went wrong. Maybe SFWash is down? ):"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class CLI
|
59
|
+
VALID_COMMANDS = %w{schedule}
|
60
|
+
CONFIG_FILE_PATH = File.expand_path('~/.sfwash')
|
61
|
+
|
62
|
+
AVAILABLE_DAYS = %w{Monday Tuesday Wednesday Thursday Friday}
|
63
|
+
|
64
|
+
def self.run(command, options)
|
65
|
+
if command && VALID_COMMANDS.include?(command)
|
66
|
+
self.send(command, options)
|
67
|
+
elsif command
|
68
|
+
$stderr.puts("Sorry, `#{command}` is not a valid command.")
|
69
|
+
exit
|
70
|
+
else
|
71
|
+
$stderr.puts("You must specify a command! Try `sfwash help`.")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.schedule(options)
|
76
|
+
client = SFWash::Client.new
|
77
|
+
|
78
|
+
if File.exists?(CONFIG_FILE_PATH)
|
79
|
+
config = YAML.load_file(CONFIG_FILE_PATH)[:preferences]
|
80
|
+
|
81
|
+
if options[:day]
|
82
|
+
day = transform_day(options[:day])
|
83
|
+
config = config.merge(:day => day) if day
|
84
|
+
end
|
85
|
+
|
86
|
+
client.schedule_request(config)
|
87
|
+
else
|
88
|
+
puts "Oh no, you don't have a config! See the documentation at https://github.com/amfeng/sfwash."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.transform_day(day)
|
93
|
+
day = day.capitalize
|
94
|
+
day if AVAILABLE_DAYS.include?(day)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/sfwash.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'sfwash'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.summary = 'SFWash'
|
5
|
+
s.description = "CLI for scheduling SFWash (http://sfwash.com) pickups."
|
6
|
+
s.authors = ["Amber Feng"]
|
7
|
+
s.email = 'amber.feng@gmail.com'
|
8
|
+
|
9
|
+
s.add_development_dependency('minitest')
|
10
|
+
s.add_development_dependency('mocha')
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- test/test_*.rb`.split("\n")
|
14
|
+
s.executables = ['sfwash']
|
15
|
+
s.require_paths = %w[lib]
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sfwash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Amber Feng
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mocha
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: CLI for scheduling SFWash (http://sfwash.com) pickups.
|
47
|
+
email: amber.feng@gmail.com
|
48
|
+
executables:
|
49
|
+
- sfwash
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- README.md
|
56
|
+
- bin/sfwash
|
57
|
+
- lib/sfwash.rb
|
58
|
+
- sfwash.gemspec
|
59
|
+
homepage:
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: SFWash
|
83
|
+
test_files: []
|