cpsn 0.1.2 → 0.2.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.
Files changed (4) hide show
  1. data/TODO +2 -2
  2. data/VERSION +1 -1
  3. data/bin/cpsn +67 -17
  4. metadata +2 -2
data/TODO CHANGED
@@ -1,3 +1,3 @@
1
- save cookie jar so subsequent runs don't need to login
2
- read username/pass from a config file
3
1
  be able to define groups of users in the config file, and query them
2
+ show any status for what map ppl are in etc (like in modern warfare 2)
3
+ logging with --verbose option
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/bin/cpsn CHANGED
@@ -3,23 +3,23 @@
3
3
  require 'rubygems'
4
4
  require 'mechanize'
5
5
  require 'json'
6
-
7
- $username = ARGV[0]
8
- $password = ARGV[1]
6
+ require 'yaml'
7
+ require 'optparse'
9
8
 
10
9
  $login_url = "https://store.playstation.com/external/index.vm?returnURL=https%3a%2f%2fsecureus.playstation.com%2fRegistration%2fPSNL%2fSignInFrame.aspx"
11
10
  $friend_url = "http://profiles.us.playstation.com/playstation/psn/profile/friends"
12
11
  $json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_gamer_summary_data?id="
13
12
 
14
- def get_agent()
15
- agent = WWW::Mechanize.new
16
- agent.user_agent_alias = 'Mac FireFox'
17
- agent.redirect_ok = true
18
-
13
+ def load_settings()
14
+ settings = YAML::parse_file(File.expand_path("~/.cpsn/settings.yml"))
15
+ return settings
16
+ end
17
+
18
+ def get_cookie(agent, username, password)
19
19
  page = agent.get($login_url)
20
20
  login_form = page.forms.first
21
- login_form.loginName = $username
22
- login_form.password = $password
21
+ login_form.loginName = username
22
+ login_form.password = password
23
23
  page = agent.submit(login_form)
24
24
  link = page.links.first
25
25
 
@@ -29,7 +29,21 @@ def get_agent()
29
29
  end
30
30
 
31
31
  page = link.click
32
-
32
+
33
+ agent.cookie_jar.save_as File.expand_path("~/.cpsn/cookies.yml")
34
+ end
35
+
36
+ def get_agent(username, password)
37
+ agent = WWW::Mechanize.new
38
+ agent.user_agent_alias = 'Mac FireFox'
39
+ agent.redirect_ok = true
40
+
41
+ if File.exist? File.expand_path("~/.cpsn/cookies.yml")
42
+ agent.cookie_jar.load File.expand_path("~/.cpsn/cookies.yml")
43
+ return agent
44
+ end
45
+
46
+ get_cookie(agent, username, password)
33
47
  return agent
34
48
  end
35
49
 
@@ -66,19 +80,55 @@ def get_friend_status(agent, friend)
66
80
  return friend
67
81
  end
68
82
 
69
- agent = get_agent()
83
+ options = {}
84
+ optparse = OptionParser.new do |opts|
85
+ options[:offline] = false
86
+ opts.on('-o', '--offline', 'Show offline contacts') do
87
+ options[:offline] = true
88
+ end
70
89
 
71
- if ARGV.length >= 3
72
- friend_names = ARGV[2..-1]
90
+ opts.on(nil, '--version', 'Display version information') do
91
+ gem_dir = File.join(File.dirname(__FILE__), '..')
92
+ File.open(File.join(gem_dir, 'VERSION')) do |version_file|
93
+ print version_file.read
94
+ end
95
+ exit
96
+ end
97
+
98
+ opts.on('-h', '--help', 'Show help') do
99
+ puts opts
100
+ exit
101
+ end
102
+ end
103
+
104
+ optparse.parse!
105
+
106
+ settings = load_settings()
107
+ agent = get_agent(settings[:username].value, settings[:password].value)
108
+
109
+ if ARGV.length >= 1
110
+ friend_names = ARGV[0..-1]
73
111
  else
74
- friend_names = get_friends(agent)
112
+ begin
113
+ friend_names = get_friends(agent)
114
+ rescue WWW::Mechanize::ResponseCodeError
115
+ get_cookie(agent, settings[:username].value, settings[:password].value)
116
+ retry
117
+ end
75
118
  end
76
119
 
77
120
  for friend_name in friend_names
78
- friend = get_friend_status(agent, friend_name)
121
+ begin
122
+ friend = get_friend_status(agent, friend_name)
123
+ rescue WWW::Mechanize::ResponseCodeError
124
+ get_cookie(agent, settings[:username].value, settings[:password].value)
125
+ retry
126
+ end
79
127
 
80
128
  if friend
81
- puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing]
129
+ if friend[:status] != "offline" or options[:offline]
130
+ puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing]
131
+ end
82
132
  else
83
133
  puts "Error: no access to " + friend_name
84
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpsn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bowes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-01 00:00:00 -04:00
12
+ date: 2009-11-15 00:00:00 -05:00
13
13
  default_executable: cpsn
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency