cpsn 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/TODO +0 -2
  2. data/VERSION +1 -1
  3. data/bin/cpsn +23 -2
  4. metadata +1 -1
data/TODO CHANGED
@@ -1,3 +1 @@
1
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.2.0
1
+ 0.3.0
data/bin/cpsn CHANGED
@@ -5,17 +5,24 @@ require 'mechanize'
5
5
  require 'json'
6
6
  require 'yaml'
7
7
  require 'optparse'
8
+ require 'logger'
8
9
 
9
10
  $login_url = "https://store.playstation.com/external/index.vm?returnURL=https%3a%2f%2fsecureus.playstation.com%2fRegistration%2fPSNL%2fSignInFrame.aspx"
10
11
  $friend_url = "http://profiles.us.playstation.com/playstation/psn/profile/friends"
11
12
  $json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_gamer_summary_data?id="
12
13
 
14
+
15
+ $log = Logger.new(STDERR)
16
+ $log.level = Logger::WARN
17
+
13
18
  def load_settings()
19
+ $log.debug("Loading settings")
14
20
  settings = YAML::parse_file(File.expand_path("~/.cpsn/settings.yml"))
15
21
  return settings
16
22
  end
17
23
 
18
24
  def get_cookie(agent, username, password)
25
+ $log.debug("Signing in for new cookie")
19
26
  page = agent.get($login_url)
20
27
  login_form = page.forms.first
21
28
  login_form.loginName = username
@@ -34,6 +41,7 @@ def get_cookie(agent, username, password)
34
41
  end
35
42
 
36
43
  def get_agent(username, password)
44
+ $log.debug("Creating new user agent")
37
45
  agent = WWW::Mechanize.new
38
46
  agent.user_agent_alias = 'Mac FireFox'
39
47
  agent.redirect_ok = true
@@ -48,21 +56,27 @@ def get_agent(username, password)
48
56
  end
49
57
 
50
58
  def get_friends(agent)
59
+ $log.debug("Getting friends list")
51
60
  page = agent.get($friend_url)
52
61
  divs = page.search("div.slotcontent")
53
62
 
54
63
  friends = []
55
64
  for div in divs
56
- friends << div.attributes["id"]
65
+ friend = div.attributes["id"]
66
+ friends << friend
67
+ $log.debug("Found friend #{friend}")
57
68
  end
58
69
 
59
70
  return friends
60
71
  end
61
72
 
62
73
  def get_friend_status(agent, friend)
74
+ $log.debug("Loading friend status for #{friend}")
63
75
  page = agent.get($json_url + friend)
64
76
  data = JSON.parse(page.body)
65
77
 
78
+ $log.debug(data)
79
+
66
80
  friend = {:name => data["userName"]}
67
81
 
68
82
  if data["onlineStatus"] == nil
@@ -72,9 +86,11 @@ def get_friend_status(agent, friend)
72
86
  if data["onlineStatus"]["extensionStatus"] != nil
73
87
  friend[:status] = 'online'
74
88
  friend[:playing] = data["onlineStatus"]["extensionStatus"]["title"]
89
+ friend[:game_status] = data["onlineStatus"]["extensionStatus"]["status"]
75
90
  else
76
91
  friend[:status] = 'offline'
77
92
  friend[:playing] = ""
93
+ friend[:game_status] = ""
78
94
  end
79
95
 
80
96
  return friend
@@ -87,6 +103,11 @@ optparse = OptionParser.new do |opts|
87
103
  options[:offline] = true
88
104
  end
89
105
 
106
+ opts.on('-d', '--debug', 'Show debugging information') do
107
+ $log.level = Logger::DEBUG
108
+ end
109
+
110
+
90
111
  opts.on(nil, '--version', 'Display version information') do
91
112
  gem_dir = File.join(File.dirname(__FILE__), '..')
92
113
  File.open(File.join(gem_dir, 'VERSION')) do |version_file|
@@ -127,7 +148,7 @@ for friend_name in friend_names
127
148
 
128
149
  if friend
129
150
  if friend[:status] != "offline" or options[:offline]
130
- puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing]
151
+ puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing] + "\t" + friend[:game_status]
131
152
  end
132
153
  else
133
154
  puts "Error: no access to " + friend_name
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bowes