cpsn 0.5.2 → 0.6.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/README.mkd +11 -2
  2. data/VERSION +1 -1
  3. data/bin/cpsn +56 -30
  4. metadata +1 -1
data/README.mkd CHANGED
@@ -29,7 +29,10 @@ can also pass '-o' to see your offline friends as well.
29
29
  Defining Groups
30
30
  ===============
31
31
 
32
- If you find yourself looking for the status of a few friends frequently, you can define groups of users in your settings.yml file. Groups go under the ':groups:' section in the settings.yml file, and are the name you want to call them and a list of user names.
32
+ If you find yourself looking for the status of a few friends frequently, you
33
+ can define groups of users in your settings.yml file. Groups go under the
34
+ ':groups:' section in the settings.yml file, and are the name you want to call
35
+ them and a list of user names.
33
36
 
34
37
  For example:
35
38
 
@@ -39,4 +42,10 @@ For example:
39
42
 
40
43
  :groups:
41
44
  - mw2: [friend1, friend2, friend3]
42
-
45
+
46
+ You may also set a default group for cpsn to query instead of all friends when
47
+ you run the command with no arguments (you can still access all friends with
48
+ 'cpsn all'):
49
+
50
+ :groups:
51
+ - default: mw2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.6.0
data/bin/cpsn CHANGED
@@ -20,7 +20,7 @@ $json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_game
20
20
 
21
21
  class Cpsn
22
22
 
23
- attr_accessor :settings, :groups
23
+ attr_accessor :settings, :groups, :default_group
24
24
 
25
25
  def initialize(options)
26
26
  @log = Logger.new(STDERR)
@@ -28,6 +28,9 @@ class Cpsn
28
28
  if options[:debug]
29
29
  @log.level = Logger::DEBUG
30
30
  end
31
+
32
+ # may be set in load_groups
33
+ @default_group = 'all'
31
34
 
32
35
  @settings = load_settings()
33
36
  @groups = load_groups(@settings)
@@ -53,6 +56,13 @@ class Cpsn
53
56
  for group in settings[:groups].value
54
57
  name = group.value.keys[0].value
55
58
  vals = group.value[group.value.keys[0]]
59
+
60
+ if name == 'default'
61
+ @default_group = vals.value
62
+ @log.debug("Found default group #{@default_group}")
63
+ next
64
+ end
65
+
56
66
  members = []
57
67
  mem_str = ""
58
68
  for user in vals.value do
@@ -99,6 +109,37 @@ class Cpsn
99
109
  end
100
110
 
101
111
  def get_friends()
112
+ begin
113
+ return _get_friends()
114
+ rescue WWW::Mechanize::ResponseCodeError => response
115
+ puts response
116
+ if response.response_code == '403'
117
+ cpsn.get_cookie(cpsn.settings[:username].value,
118
+ cpsn.settings[:password].value)
119
+ retry
120
+ else
121
+ raise response
122
+ end
123
+ end
124
+ end
125
+
126
+ def get_friend_status(friend)
127
+ begin
128
+ return _get_friend_status(friend)
129
+ rescue WWW::Mechanize::ResponseCodeError => response
130
+ if response.response_code == '403'
131
+ cpsn.get_cookie(cpsn.settings[:username].value,
132
+ cpsn.settings[:password].value)
133
+ retry
134
+ else
135
+ raise response
136
+ end
137
+ end
138
+ end
139
+
140
+ private
141
+
142
+ def _get_friends()
102
143
  @log.debug("Getting friends list")
103
144
  page = @agent.get($friend_url)
104
145
  divs = page.search("div.slotcontent")
@@ -113,7 +154,7 @@ class Cpsn
113
154
  return friends
114
155
  end
115
156
 
116
- def get_friend_status(friend)
157
+ def _get_friend_status(friend)
117
158
  @log.debug("Loading friend status for #{friend}")
118
159
  page = @agent.get($json_url + friend)
119
160
  data = JSON.parse(page.body)
@@ -177,38 +218,23 @@ optparse.parse!
177
218
 
178
219
  cpsn = Cpsn.new(options)
179
220
 
180
- if ARGV.length >= 1 and not ARGV.include? 'all'
181
- friend_names = Set.new []
182
- args = ARGV[0..-1]
183
- for arg in args
184
- if cpsn.groups.has_key? arg
185
- friend_names.merge(cpsn.groups[arg])
186
- else
187
- friend_names.add(arg)
188
- end
189
- end
190
- else
191
- begin
192
- friend_names = cpsn.get_friends()
193
- rescue WWW::Mechanize::ResponseCodeError => response
194
- if response.response_code == '403'
195
- cpsn.get_cookie(cpsn.settings[:username].value,
196
- cpsn.settings[:password].value)
197
- retry
198
- end
221
+ if ARGV.length == 0
222
+ ARGV << cpsn.default_group
223
+ end
224
+
225
+ friend_names = Set.new []
226
+ for arg in ARGV
227
+ if arg == 'all'
228
+ friend_names.merge(cpsn.get_friends)
229
+ elsif cpsn.groups.has_key? arg
230
+ friend_names.merge(cpsn.groups[arg])
231
+ else
232
+ friend_names.add(arg)
199
233
  end
200
234
  end
201
235
 
202
236
  for friend_name in friend_names
203
- begin
204
- friend = cpsn.get_friend_status(friend_name)
205
- rescue WWW::Mechanize::ResponseCodeError => response
206
- if response.response_code == '403'
207
- cpsn.get_cookie(cpsn.settings[:username].value,
208
- cpsn.settings[:password].value)
209
- retry
210
- end
211
- end
237
+ friend = cpsn.get_friend_status(friend_name)
212
238
 
213
239
  if friend
214
240
  if friend[:status] != "offline" or options[:offline]
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bowes