brio 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,119 @@
1
- = brio
1
+ = brio - CLI power tools for appdotnet
2
2
 
3
- Describe your project here
3
+ brio is a command line application for interfacing with appdotnet social network.
4
4
 
5
- :include:brio.rdoc
5
+ == Instalation
6
+ You have to make sure that you have ruby installed. Preferably version 1.9.2 or 1.9.3 (the latest stable)
7
+
8
+ Once you've verified that Ruby is installed:
9
+
10
+ gem install brio
11
+
12
+ == Authorization
13
+ brio needs to be authorized with appdotnet to run. To proceed, type the following command at the prompt and follow the instructions:
14
+
15
+ brio authorize
16
+
17
+ This command will direct you to a URL where you can sign-in to appdotnet, authorize the application, and then enter the returned auth token back into the terminal.
18
+
19
+ == Usage Examples
20
+ Typing *brio help* will list all the available commands. You can type *brio help COMMAND* to get help for a specific command.
21
+
22
+ brio help
23
+
24
+ === Retriving your stream
25
+ brio stream
26
+ This will return your personalized stream
27
+
28
+ brio stream -g
29
+ This returns global stream
30
+
31
+ By default brio returns 20 posts. appdotnet allows up to max 200 counts. You can set a flag *-c | --count* if you want to customize the number:
32
+ brio stream -c16
33
+
34
+ You can also use them together:
35
+ brio stream -gc50
36
+
37
+ === Post Methods
38
+
39
+ ==== Create a post
40
+ brio post "Hey! I'm posting from the command line!"
41
+
42
+ ==== Reply to a post
43
+ brio post reply 12345 "hey, this is a reply!"
44
+ Note that we provided first the post id you are making a reply to, and then the message
45
+
46
+ ==== Delete a post
47
+ brio post delete 1234
48
+ You can only delete a post that you created
49
+
50
+ ==== Repost a post
51
+ brio post repost 1234
52
+
53
+ ==== Delete a repost
54
+ brio post repost --rm 1234
55
+
56
+ ==== Star a post
57
+ brio post star 1234
58
+
59
+ ==== Delete a starred post
60
+ brio post star --rm 1234
61
+
62
+ === Get user infrormation
63
+ brio whois @username
64
+ Username can be omitted and it will default to the currently authenticated user - you.
65
+
66
+ === Follow a user
67
+ brio follow @username
68
+
69
+ === Stop following a user
70
+ brio unfollow @username
71
+
72
+ === List Methods
73
+ All the *list* subcommands can take an optional *count* flag. When provided, it will return an arbitrary number of listing. By default, brio returns last 20 items.
74
+
75
+ ==== Mentions
76
+ brio list mentions
77
+ This will list the posts that mention you.
78
+
79
+ brio list mentions @username
80
+ This will list the posts that mention *username*
81
+
82
+ brio list mentions -c10 @username
83
+ List last 10 menitons for *username*
84
+
85
+ ==== Followers
86
+ brio list followers @username
87
+ This will list people that follow *username*
88
+ You can also omit *username* and brio will list your followers.
89
+
90
+ brio list followers -c50
91
+ List my last 50 followers
92
+
93
+ ==== Following
94
+ brio list following
95
+ List people I follow.
96
+
97
+ brio list following @username
98
+ List people that *username* is following.
99
+
100
+ ==== Replies
101
+ brio list replies 1234
102
+ List replies of a post with id 1234.
103
+
104
+ brio list replies 1234 -c12
105
+ List last 12 replies for a post.
106
+
107
+ ==== Posts
108
+ brio list posts @username
109
+ List posts created by *username*
110
+
111
+ brio list posts
112
+ List posts created by me (the current authenticated user).
113
+
114
+ brio list posts -c15
115
+ List my last 15 posts.
116
+
117
+ == Copyright
118
+ See LICENSE[https://github.com/klaut/brio/blob/master/LICENSE.txt] for details.
6
119
 
data/bin/brio CHANGED
@@ -10,19 +10,46 @@ program_desc 'command line client for app.net inspired by t for twitter'
10
10
 
11
11
  version Brio::VERSION
12
12
 
13
-
14
- rcfile = Brio::RCFile.instance
15
13
  client = Brio::Client.new
16
14
 
17
- # desc 'Describe some switch here'
18
- # switch [:s,:switch]
15
+ output_formats = {
16
+ 'csv' => Brio::Format::CSV.new,
17
+ 'pretty' => Brio::Format::Pretty.new
18
+ }
19
+
20
+ desc "Read Terms of Service and Privacy Policy."
21
+ skips_pre
22
+ command :tos do |c|
23
+ c.action do |global_options,options,args|
24
+ formatter = output_formats['pretty']
25
+ formatter.set_wrap
26
+ say <<END
27
+ ************* TERMS OF SERVICE ***********
28
+
29
+ By using this software you agree that in no event shall the authors or copyright holders be liable for any claim,
30
+ damages or other liability, whether in an action of contract, tort or otherwise,
31
+ arising from, out of or in connection with the software or the use or other dealings in the software.
32
+
33
+ Ok, in plain wrods this means that I am not responible for anything that happens to you while using this software.
34
+
35
+ ************* PRIVACY POLICY *************
36
+ This software does not store any infromation about you that is not essential for running it.
37
+ It creates a file called .brio.rc that stores your authorization token inside your $HOME directory. And that is it.
38
+ END
39
+ end
40
+ end
41
+
42
+
43
+ desc 'Optional. Format of the output (default: pretty for TTY, csv otherwise)'
44
+ arg_name 'csv|pretty'
45
+ flag :format
19
46
 
20
47
  desc 'authorize brio with app.net'
21
48
  skips_pre
22
49
  command :authorize do |c|
23
50
  c.action do |global_options,options,args|
24
51
 
25
- if rcfile.empty?
52
+ if client.config.empty?
26
53
  say "Welcome! Before you can use *brio* you need to authorize it with app.net"
27
54
  ask "Press [Enter] to open the app.net site."
28
55
  say ""
@@ -30,11 +57,10 @@ command :authorize do |c|
30
57
  Launchy.open client.oauth_url
31
58
  token = ask "Enter your oauth token:"
32
59
 
33
- rcfile['token'] = token
34
-
35
- say "Authorization successful."
60
+ client.config['token'] = token
61
+ say "<%= color('Authorization successful.', :green) %>"
36
62
  else
37
- say "You already authorized with app.net"
63
+ say "<%= color('You already authorized with app.net', :red) %>"
38
64
  end
39
65
 
40
66
  end
@@ -50,67 +76,202 @@ command :stream do |c|
50
76
  c.flag [:c, :count]
51
77
 
52
78
  c.action do |global_options,options,args|
53
- r = client.get_stream options[:global]
54
- r['data'].each do |post|
55
- say "#{post['id']} :: #{post['user']['username']} :: #{post['text']} :: [ #{post['created_at']} ]"
56
- say "*******************"
79
+ formatter = output_formats[global_options[:format]]
80
+ formatter.set_wrap
81
+ params = {count: options[:c].to_i, include_deleted: 0}
82
+ if options[:global]
83
+ posts = client.get_post_stream_global params
84
+ else
85
+ posts = client.get_post_stream params
57
86
  end
87
+ formatter.print_posts posts
58
88
  end
59
89
  end
60
90
 
61
- desc 'Make a new Post to app.net'
91
+ #default_desc "Post a message."
92
+ desc 'Make a new Post to appdotnet. Delete a post. Reply to a post.. see `brio help post` for more.'
62
93
  arg_name 'message'
63
94
  command :post do |c|
95
+ c.default_desc "Make a new Post to appdotnet"
64
96
  c.action do |global_options,options,args|
65
- help_now!('message is required') if args.empty?
66
- r = client.post args[0]
67
- say "Posted!"
97
+ if args.empty?
98
+ message = ask "Whats on your mind:"
99
+ else
100
+ message = args[0]
101
+ end
102
+ help_now!('message is required') if message.empty?
103
+ post = client.create_post text: message
104
+ say "<%= color('#{post.text}', :red) %>" if post.is_a? Brio::Resources::NullResource
105
+ end
106
+
107
+ c.desc 'Reply to a post'
108
+ c.arg_name 'postID message'
109
+ c.command :reply do |reply|
110
+ reply.action do |global_options,options,args|
111
+ help_now!('postID and message are both required') if args.empty?
112
+ if args.size == 1
113
+ message = ask "Your reply:"
114
+ else
115
+ message = args[1]
116
+ end
117
+ help_now!('postID and message are both required') if message.empty?
118
+ post = client.create_post reply_to: args[0], text: message
119
+ say "<%= color('#{post.text}', :red) %>" if post.is_a? Brio::Resources::NullResource
120
+ end
121
+ end
122
+
123
+ c.desc 'Delete a post (only if created by you)'
124
+ c.arg_name 'postID'
125
+ c.command :delete do |delete|
126
+ delete.action do |global_options,options,args|
127
+ help_now!('postID is required') if args.empty?
128
+ post = client.delete_post args[0]
129
+ say "<%= color('#{post.text}', :red) %>" if post.is_a? Brio::Resources::NullResource
130
+ end
131
+ end
132
+
133
+ c.desc 'Delete a starred post or a repost.'
134
+ c.switch [:rm]
135
+
136
+ c.desc 'Repost a post'
137
+ c.arg_name 'postID'
138
+ c.command :repost do |repost|
139
+ repost.action do |global_options,options,args|
140
+ help_now!('postID is required') if args.empty?
141
+ if options[:rm]
142
+ post = client.delete_post_repost args[0]
143
+ else
144
+ post = client.create_post_repost args[0]
145
+ end
146
+ say "<%= color('#{post.text}', :red) %>" if post.is_a? Brio::Resources::NullResource
147
+ end
148
+ end
149
+
150
+ c.desc 'Star a post'
151
+ c.arg_name 'postID'
152
+ c.command :star do |star|
153
+ star.action do |global_options,options,args|
154
+ help_now!('postID is required') if args.empty?
155
+ if options[:rm]
156
+ post = client.delete_post_star args[0]
157
+ else
158
+ post = client.create_post_star args[0]
159
+ end
160
+ say "<%= color('#{post.text}', :red) %>" if post.is_a? Brio::Resources::NullResource
161
+ end
68
162
  end
163
+
69
164
  end
70
165
 
71
166
  desc 'Look up a user. If no argument is provided, it defualts to the current authenticated user'
72
167
  default_value 'me'
73
- arg_name 'username'
168
+ arg_name '@username', :optional
74
169
  command :whois do |c|
75
170
  #do not forget to attach @
76
171
  c.action do |global_options,options,args|
77
- puts "whois command ran"
172
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
173
+ formatter = output_formats[global_options[:format]]
174
+ formatter.set_wrap
175
+ user = client.get_user (args[0] || 'me')
176
+ formatter.print_user user
78
177
  end
79
178
  end
80
179
 
81
- desc 'List the posts where the user is mentioned. It defualts to the current authenticated user'
82
- default_value 'me'
83
- arg_name 'username'
84
- command :mentions do |c|
85
- c.action do |global_options,options,args|
86
- puts "mentions command ran"
87
- end
88
- end
89
180
 
90
181
  desc 'Follow a user'
91
- arg_name 'username'
182
+ arg_name '@username', :multiple
92
183
  command :follow do |c|
93
184
  c.action do |global_options,options,args|
94
185
  help_now!('username is required') if args.empty?
95
- puts "follow command ran"
186
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
187
+ user = client.create_user_follow args[0]
188
+ say "<%= color('#{user.text}', :red) %>" if user.is_a? Brio::Resources::NullResource
96
189
  end
97
190
  end
98
191
 
99
- desc 'List all accounts that a user is following. It defualts to the current authenticated user'
100
- default_value 'me'
101
- arg_name 'username'
102
- command :following do |c|
192
+ desc 'Unfollow a user'
193
+ arg_name '@username', :multiple
194
+ command :unfollow do |c|
103
195
  c.action do |global_options,options,args|
104
- puts "follow command ran"
196
+ help_now!('username is required') if args.empty?
197
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
198
+ user = client.delete_user_follow args[0]
199
+ say "<%= color('#{user.text}', :red) %>" if user.is_a? Brio::Resources::NullResource
105
200
  end
106
201
  end
107
202
 
108
- desc 'list all accounts that are following a user - it defualts to the current authenticated user'
109
- default_value 'me'
110
- arg_name 'username'
111
- command :followers do |c|
112
- c.action do |global_options,options,args|
113
- puts "follow command ran"
203
+ desc 'List various resources. Followers, Mentions, .. run `brio help list` for more.'
204
+ command :list do |c|
205
+ c.desc 'The number of listings to return, up to a maximum of 200'
206
+ c.default_value '20'
207
+ c.flag [:c, :count]
208
+
209
+ c.desc 'List the posts where the user is mentioned. It defualts to the current authenticated user'
210
+ c.default_value 'me'
211
+ c.arg_name '@username', :optional
212
+ c.command :mentions do |m|
213
+ m.action do |global_options,options,args|
214
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
215
+ formatter = output_formats[global_options[:format]]
216
+ formatter.set_wrap
217
+ params = {count: options[:c].to_i, include_deleted: 0}
218
+ posts = client.get_user_mentions args[0], params
219
+ formatter.print_posts posts
220
+ end
221
+ end
222
+
223
+ c.desc 'List all accounts that a user is following. It defualts to the current authenticated user'
224
+ c.default_value 'me'
225
+ c.arg_name '@username', :optional
226
+ c.command :following do |f|
227
+ f.action do |global_options,options,args|
228
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
229
+ formatter = output_formats[global_options[:format]]
230
+ formatter.set_wrap
231
+ params = {count: options[:c].to_i}
232
+ users = client.get_user_following args[0], params
233
+ formatter.print_users users
234
+ end
235
+ end
236
+
237
+ c.desc 'list all accounts that are following a user - it defualts to the current authenticated user'
238
+ c.default_value 'me'
239
+ c.arg_name '@username', :optional
240
+ c.command :followers do |f|
241
+ f.action do |global_options,options,args|
242
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
243
+ formatter = output_formats[global_options[:format]]
244
+ formatter.set_wrap
245
+ params = {count: options[:c].to_i}
246
+ users = client.get_user_followers args[0], params
247
+ formatter.print_users users
248
+ end
249
+ end
250
+
251
+ c.desc 'list replies to a post'
252
+ c.arg_name 'postID'
253
+ c.command :replies do |f|
254
+ f.action do |global_options,options,args|
255
+ help_now!('postID is required') if args.empty?
256
+ formatter = output_formats[global_options[:format]]
257
+ formatter.set_wrap
258
+ params = {count: options[:c].to_i, include_deleted: 0}
259
+ posts = client.get_post_replies args[0], params
260
+ formatter.print_posts posts
261
+ end
262
+ end
263
+
264
+ c.desc 'list posts for a user. Defaults to the current authenticated user'
265
+ c.arg_name '@username', :optional
266
+ c.command :posts do |f|
267
+ f.action do |global_options,options,args|
268
+ exit_now!('username must start with @') if !args.empty? and !args[0].start_with?('@')
269
+ formatter = output_formats[global_options[:format]]
270
+ formatter.set_wrap
271
+ params = {count: options[:c].to_i, include_deleted: 0}
272
+ posts = client.get_user_posts args[0], params
273
+ formatter.print_posts posts
274
+ end
114
275
  end
115
276
  end
116
277
 
@@ -120,7 +281,14 @@ pre do |global,command,options,args|
120
281
  # chosen command
121
282
  # Use skips_pre before a command to skip this block
122
283
  # on that command only
123
- exit_now!('You need to authorize with app.net before using b. Run `brio authorize` to do so.') if rcfile.empty?
284
+ exit_now!('You need to authorize with app.net. Run `brio authorize` to do so.') if client.config.empty?
285
+ if global[:format].nil?
286
+ if STDOUT.tty?
287
+ global[:format] = 'pretty'
288
+ else
289
+ global[:format] = 'csv'
290
+ end
291
+ end
124
292
  true
125
293
  end
126
294
 
@@ -128,6 +296,7 @@ post do |global,command,options,args|
128
296
  # Post logic here
129
297
  # Use skips_post before a command to skip this
130
298
  # block on that command only
299
+ $terminal.wrap_at = :auto
131
300
  end
132
301
 
133
302
  on_error do |exception|
data/brio.rdoc CHANGED
@@ -1,5 +1 @@
1
1
  = brio
2
-
3
- Generate this with
4
- brio rdoc
5
- After you have described your command line interface
data/lib/brio.rb CHANGED
@@ -1,5 +1,11 @@
1
+ require 'brio/utils.rb'
1
2
  require 'brio/version.rb'
2
3
  require 'brio/rcfile.rb'
4
+ require 'brio/format/csv.rb'
5
+ require 'brio/format/pretty.rb'
6
+ require 'brio/resources/resource.rb'
7
+ require 'brio/resources/user.rb'
8
+ require 'brio/resources/post.rb'
3
9
  require 'brio/api.rb'
4
10
  require 'brio/client.rb'
5
11
 
data/lib/brio/api.rb CHANGED
@@ -8,8 +8,8 @@ module Brio
8
8
  DEFAULT_API_HOST = 'alpha-api.app.net'
9
9
  DEFAULT_PROTOCOL = 'https'
10
10
 
11
- REDIRECT_URI = 'http://heroesneverpanic.com/'
12
- SCOPE = 'stream,email,write_post,follow,messages,export'
11
+ REDIRECT_URI = 'https://brioapp.herokuapp.com/auth/callback/'
12
+ SCOPE = 'stream,email,write_post,follow,messages,update_profile,export'
13
13
  RESPONSE_TYPE = 'token'
14
14
 
15
15
 
@@ -18,16 +18,15 @@ module Brio
18
18
  "#{protocol}://#{oauth_host}/oauth/authenticate?client_id=#{CLIENT_ID}&response_type=#{RESPONSE_TYPE}&scope=#{SCOPE}&redirect_uri=#{REDIRECT_URI}"
19
19
  end
20
20
 
21
- def user_stream_url
22
- "/stream/0/posts/stream"
21
+ # POSTS
22
+ def posts_url(id ="")
23
+ id = "/#{id}" unless id.empty?
24
+ "/stream/0/posts#{id}"
23
25
  end
24
26
 
25
- def global_stream_url
26
- "/stream/0/posts/stream/global"
27
- end
28
-
29
- def posts_url
30
- "/stream/0/posts"
27
+ # USERS
28
+ def users_url( id = "me")
29
+ "/stream/0/users/#{id}"
31
30
  end
32
31
 
33
32
  private
data/lib/brio/client.rb CHANGED
@@ -1,38 +1,112 @@
1
- require 'faraday'
2
- require 'json'
1
+ require 'faraday_middleware'
2
+ #require 'json'
3
+ require 'brio/resources/post.rb'
3
4
 
4
5
  module Brio
5
6
 
6
7
  class Client
7
- include Brio::API
8
+ include API
9
+
10
+ HTTP_VERBS = {
11
+ create: 'post',
12
+ delete: 'delete',
13
+ get: 'get'
14
+ }
15
+
16
+ METHOD_PATTERNS = {
17
+ users: /(.*)_user(_?(.*))/,
18
+ posts: /(.*)_post(_?(.*))/
19
+ }
8
20
 
9
21
  def initialize
10
- @conn = Faraday.new(:url => base_api_url ) do |faraday|
11
- faraday.request :url_encoded
22
+ @conn = Faraday.new( :url => base_api_url ) do |faraday|
23
+ faraday.request :json
24
+ faraday.response :json, :content_type => /\bjson$/
12
25
  faraday.adapter Faraday.default_adapter
13
26
  end
14
- @rc = Brio::RCFile.instance
27
+ @rc = RCFile.instance
15
28
  add_oauth_header unless @rc.empty?
16
29
  end
17
30
 
18
- def get_stream( global = false )
19
- r = if global then @conn.get global_stream_url else @conn.get user_stream_url end
20
- JSON.parse(r.body)
31
+ def config
32
+ @rc
21
33
  end
22
34
 
23
- def post( text )
24
- @conn.post do |req|
25
- req.url posts_url
26
- req.headers['Content-Type'] = 'application/json'
27
- req.body = { text: "#{text}" }.to_json
28
- end
35
+ def method_missing(method_name, *args, &block)
36
+ case
37
+ when method_name.to_s =~ METHOD_PATTERNS[:users]
38
+ users HTTP_VERBS[$1.to_sym], args, $3.gsub(/_/, '/')
39
+ when method_name.to_s =~ METHOD_PATTERNS[:posts]
40
+ posts HTTP_VERBS[$1.to_sym], args, $3.gsub(/_/, '/')
41
+ else
42
+ super
43
+ end
44
+ end
45
+
46
+ def respond_to_missing?(method_name, include_private = false)
47
+ method_name.to_s =~ METHOD_PATTERNS[:users] ||
48
+ method_name.to_s =~ METHOD_PATTERNS[:posts]
29
49
  end
30
50
 
51
+
31
52
  private
32
53
  def add_oauth_header
33
- @conn.authorization :bearer, @rc['token']
54
+ @conn.authorization :bearer, config['token']
55
+ end
56
+
57
+ # USERS
58
+ def users( verb, args, to_append='')
59
+ username = get_id_from_args args
60
+ username = 'me' if username.empty?
61
+ params_hash = get_params_from_args args
62
+ r = @conn.method(verb).call do |req|
63
+ req.url "#{users_url username}/#{to_append}"
64
+ req.params = params_hash
65
+ end
66
+ case to_append
67
+ when 'mentions', 'stars', 'posts'
68
+ Resources::Post.create_from_json r.body
69
+ else
70
+ Resources::User.create_from_json r.body
71
+ end
72
+ end
73
+
74
+ #POSTS
75
+ def posts( verb, args, to_append='')
76
+ id = get_id_from_args args
77
+ params_hash = get_params_from_args args
78
+ r = @conn.method(verb).call do |req|
79
+ req.url "#{posts_url id}/#{to_append}"
80
+ if verb.to_s == 'get'
81
+ req.params = params_hash
82
+ else
83
+ req.body = params_hash
84
+ end
85
+ end
86
+ case to_append
87
+ when 'reposters', 'stars'
88
+ Resources::User.create_from_json r.body
89
+ else
90
+ Resources::Post.create_from_json r.body
91
+ end
92
+ end
93
+
94
+ def get_id_from_args( args )
95
+ if args.first && args.first.is_a?(String)
96
+ args.first
97
+ else
98
+ ""
99
+ end
100
+ end
101
+
102
+ def get_params_from_args( args )
103
+ if args.last && args.last.is_a?(Hash)
104
+ args.last
105
+ else
106
+ {}
107
+ end
34
108
  end
35
109
 
36
110
  end
37
111
 
38
- end
112
+ end
@@ -0,0 +1,44 @@
1
+ module Brio
2
+ module Format
3
+ require 'csv'
4
+ require 'time'
5
+ require 'highline/import'
6
+
7
+ class CSV
8
+ POST_HEADER = ["id", "timestampt", "username", "text", "replies"]
9
+ USER_HEADER = ["username", "name", "joined", "followers", "following"]
10
+
11
+ def print_posts( posts )
12
+ say POST_HEADER.to_csv
13
+ posts.each do |post|
14
+ print_post post
15
+ end
16
+ end
17
+
18
+ def print_post( post )
19
+ say [post.id, csv_formatted_time(post.created_at), post.user.username, post.text, post.num_replies].to_csv
20
+ end
21
+
22
+ def print_users( users )
23
+ say USER_HEADER.to_csv
24
+ users.each do |u|
25
+ print_user u
26
+ end
27
+ end
28
+
29
+ def print_user( user )
30
+ say [user.username, user.name, csv_formatted_time(user.created_at), user.counts.followers, user.counts.following].to_csv
31
+ end
32
+
33
+ def set_wrap
34
+ $terminal.wrap_at = :auto
35
+ end
36
+
37
+ private
38
+ def csv_formatted_time( timestr )
39
+ Time.parse( timestr ).utc.strftime("%Y-%m-%d %H:%M:%S %z")
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,91 @@
1
+ module Brio
2
+ module Format
3
+ require 'time'
4
+ require 'highline/import'
5
+
6
+ class Pretty
7
+ attr_accessor :wrap
8
+
9
+ HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
10
+ cs[:username] = [ :red ]
11
+ cs[:end_line] = [ :yellow] #:rgb_aaaaaa
12
+ cs[:mention] = [ :black, :on_white ]
13
+ end
14
+
15
+ def initialize
16
+ set_wrap
17
+ end
18
+
19
+
20
+ def print_posts( posts )
21
+ posts.each do |post|
22
+ print_post post
23
+ end
24
+ end
25
+
26
+ def print_post( post )
27
+ say "<%= color(\"#{post.user.username}\", :username) %>"
28
+ if post.text
29
+ say "." * @wrap
30
+ say "#{post.text.strip}"
31
+ say "." * @wrap
32
+ end
33
+ say "<%= color('<id: #{post.id} | #{pretty_format_time(post.created_at)}#{reply_status post}> <replies #{post.num_replies}>', :end_line) %>"
34
+ say "\n"
35
+ end
36
+
37
+ def print_users( users )
38
+ users.each do |u|
39
+ print_user u
40
+ end
41
+ end
42
+
43
+ def print_user( user )
44
+ say "\n"
45
+ say "<%= color(\"#{user.name}\", :username) %> [#{user.username}]"
46
+ if user.description.has_key? 'text'
47
+ say "." * @wrap
48
+ say "#{user.description.text.strip}"
49
+ say "." * @wrap
50
+ end
51
+ say "<%= color('<followers: #{user.counts.followers} | following: #{user.counts.following} | since: #{pretty_format_time(user.created_at, %{%b %e %Y})}> #{connection_stats user}', :end_line) %>"
52
+ say "\n"
53
+ end
54
+
55
+ def set_wrap
56
+ if $terminal.output_cols < 100
57
+ @wrap = $terminal.output_cols
58
+ else
59
+ @wrap = 100
60
+ end
61
+ $terminal.wrap_at = @wrap
62
+ end
63
+
64
+ def connection_stats( user )
65
+ "<follows you: #{truth_to_tick_char user.follows_you} | you follow: #{truth_to_tick_char user.you_follow}>"
66
+ end
67
+
68
+ def reply_status( post )
69
+ if post.reply_to
70
+ " | in reply to: #{post.reply_to}"
71
+ end
72
+ end
73
+
74
+ private
75
+ def pretty_format_time( timestr, format = "%b %e %H:%M" )
76
+ time = Time.parse( timestr ).utc.getlocal
77
+ time.strftime(format)
78
+ end
79
+
80
+ def truth_to_tick_char( truth_str )
81
+ if truth_str
82
+ "\u2714"
83
+ else
84
+ "\u2717"
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,9 @@
1
+ module Brio
2
+ module Resources
3
+
4
+ class Post < Resource
5
+ attr_accessor :id, :user, :created_at, :text, :num_replies, :reply_to
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ module Brio
2
+ module Resources
3
+
4
+ class Resource
5
+ def initialize( attr_hash={} )
6
+ attr_hash.map do |(k,v)|
7
+ writer_m = "#{k}="
8
+ public_send("#{k}=", v) if respond_to? writer_m
9
+ end
10
+ end
11
+
12
+ def self.create_from_json( json )
13
+ if json['data']
14
+ if json['data'].kind_of? Array
15
+ json['data'].map{ |post| self.new post }.reverse
16
+ else
17
+ self.new json['data']
18
+ end
19
+ else
20
+ NullResource.new json['meta']
21
+ end
22
+ end
23
+ end
24
+
25
+ class NullResource
26
+ attr_reader :text
27
+
28
+ def initialize( data )
29
+ @text = "#{data['code']} - #{data['error_message']}"
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Brio
2
+ module Resources
3
+
4
+ class User < Resource
5
+ attr_accessor :id, :created_at, :username, :name, :description, :counts, :follows_you, :you_follow
6
+ end
7
+
8
+ end
9
+ end
data/lib/brio/utils.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ class Hash
3
+ def method_missing(name)
4
+ return self[name] if key? name
5
+ self.each { |k,v| return v if k.to_s.to_sym == name }
6
+ super.method_missing name
7
+ end
8
+ end
data/lib/brio/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brio
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-14 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -59,22 +59,86 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: timecop
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
62
126
  - !ruby/object:Gem::Dependency
63
127
  name: gli
64
128
  requirement: !ruby/object:Gem::Requirement
65
129
  none: false
66
130
  requirements:
67
- - - '='
131
+ - - ~>
68
132
  - !ruby/object:Gem::Version
69
- version: 2.0.0
133
+ version: '2.4'
70
134
  type: :runtime
71
135
  prerelease: false
72
136
  version_requirements: !ruby/object:Gem::Requirement
73
137
  none: false
74
138
  requirements:
75
- - - '='
139
+ - - ~>
76
140
  - !ruby/object:Gem::Version
77
- version: 2.0.0
141
+ version: '2.4'
78
142
  - !ruby/object:Gem::Dependency
79
143
  name: json
80
144
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +146,7 @@ dependencies:
82
146
  requirements:
83
147
  - - ~>
84
148
  - !ruby/object:Gem::Version
85
- version: '1.6'
149
+ version: '1.7'
86
150
  type: :runtime
87
151
  prerelease: false
88
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,29 +154,29 @@ dependencies:
90
154
  requirements:
91
155
  - - ~>
92
156
  - !ruby/object:Gem::Version
93
- version: '1.6'
157
+ version: '1.7'
94
158
  - !ruby/object:Gem::Dependency
95
159
  name: launchy
96
160
  requirement: !ruby/object:Gem::Requirement
97
161
  none: false
98
162
  requirements:
99
- - - ~>
163
+ - - ! '>='
100
164
  - !ruby/object:Gem::Version
101
- version: '2.0'
165
+ version: '2.1'
102
166
  type: :runtime
103
167
  prerelease: false
104
168
  version_requirements: !ruby/object:Gem::Requirement
105
169
  none: false
106
170
  requirements:
107
- - - ~>
171
+ - - ! '>='
108
172
  - !ruby/object:Gem::Version
109
- version: '2.0'
173
+ version: '2.1'
110
174
  - !ruby/object:Gem::Dependency
111
175
  name: highline
112
176
  requirement: !ruby/object:Gem::Requirement
113
177
  none: false
114
178
  requirements:
115
- - - ~>
179
+ - - ! '>='
116
180
  - !ruby/object:Gem::Version
117
181
  version: '1.6'
118
182
  type: :runtime
@@ -120,7 +184,7 @@ dependencies:
120
184
  version_requirements: !ruby/object:Gem::Requirement
121
185
  none: false
122
186
  requirements:
123
- - - ~>
187
+ - - ! '>='
124
188
  - !ruby/object:Gem::Version
125
189
  version: '1.6'
126
190
  - !ruby/object:Gem::Dependency
@@ -128,7 +192,7 @@ dependencies:
128
192
  requirement: !ruby/object:Gem::Requirement
129
193
  none: false
130
194
  requirements:
131
- - - ~>
195
+ - - ! '>='
132
196
  - !ruby/object:Gem::Version
133
197
  version: '4.3'
134
198
  type: :runtime
@@ -136,7 +200,7 @@ dependencies:
136
200
  version_requirements: !ruby/object:Gem::Requirement
137
201
  none: false
138
202
  requirements:
139
- - - ~>
203
+ - - ! '>='
140
204
  - !ruby/object:Gem::Version
141
205
  version: '4.3'
142
206
  - !ruby/object:Gem::Dependency
@@ -146,7 +210,7 @@ dependencies:
146
210
  requirements:
147
211
  - - ! '>='
148
212
  - !ruby/object:Gem::Version
149
- version: '0'
213
+ version: '0.8'
150
214
  type: :runtime
151
215
  prerelease: false
152
216
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,8 +218,24 @@ dependencies:
154
218
  requirements:
155
219
  - - ! '>='
156
220
  - !ruby/object:Gem::Version
157
- version: '0'
158
- description: Ineract with app.net through your command line.
221
+ version: '0.8'
222
+ - !ruby/object:Gem::Dependency
223
+ name: faraday_middleware
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: 0.8.8
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: 0.8.8
238
+ description: Interact with app.net through your command line.
159
239
  email: tanja@heroesneverpanic.com
160
240
  executables:
161
241
  - brio
@@ -165,14 +245,20 @@ extra_rdoc_files:
165
245
  - brio.rdoc
166
246
  files:
167
247
  - bin/brio
248
+ - lib/brio/utils.rb
168
249
  - lib/brio/version.rb
169
250
  - lib/brio/api.rb
170
251
  - lib/brio/client.rb
171
252
  - lib/brio/rcfile.rb
253
+ - lib/brio/format/csv.rb
254
+ - lib/brio/format/pretty.rb
255
+ - lib/brio/resources/resource.rb
256
+ - lib/brio/resources/user.rb
257
+ - lib/brio/resources/post.rb
172
258
  - lib/brio.rb
173
259
  - README.rdoc
174
260
  - brio.rdoc
175
- homepage: http://heroesneverpanic.com
261
+ homepage: http://github.com/klaut/brio
176
262
  licenses: []
177
263
  post_install_message:
178
264
  rdoc_options:
@@ -201,5 +287,5 @@ rubyforge_project:
201
287
  rubygems_version: 1.8.24
202
288
  signing_key:
203
289
  specification_version: 3
204
- summary: Command line tool for app.net, inspired by t for twitter.
290
+ summary: CLI for app.net
205
291
  test_files: []