brio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = brio
2
+
3
+ Describe your project here
4
+
5
+ :include:brio.rdoc
6
+
data/bin/brio ADDED
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'highline/import'
4
+ require 'launchy'
5
+ require 'brio'
6
+
7
+ include GLI::App
8
+
9
+ program_desc 'command line client for app.net inspired by t for twitter'
10
+
11
+ version Brio::VERSION
12
+
13
+
14
+ rcfile = Brio::RCFile.instance
15
+ client = Brio::Client.new
16
+
17
+ # desc 'Describe some switch here'
18
+ # switch [:s,:switch]
19
+
20
+ desc 'authorize brio with app.net'
21
+ skips_pre
22
+ command :authorize do |c|
23
+ c.action do |global_options,options,args|
24
+
25
+ if rcfile.empty?
26
+ say "Welcome! Before you can use *brio* you need to authorize it with app.net"
27
+ ask "Press [Enter] to open the app.net site."
28
+ say ""
29
+
30
+ Launchy.open client.oauth_url
31
+ token = ask "Enter your oauth token:"
32
+
33
+ rcfile['token'] = token
34
+
35
+ say "Authorization successful."
36
+ else
37
+ say "You already authorized with app.net"
38
+ end
39
+
40
+ end
41
+ end
42
+
43
+ desc "Retrives Posts in the stream. Defaults to user's stream"
44
+ command :stream do |c|
45
+ c.desc 'Retrives Posts from the global stream.'
46
+ c.switch [:g, :global]
47
+
48
+ c.desc 'The number of latest Posts to return, up to a maximum of 200'
49
+ c.default_value '20'
50
+ c.flag [:c, :count]
51
+
52
+ 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 "*******************"
57
+ end
58
+ end
59
+ end
60
+
61
+ desc 'Make a new Post to app.net'
62
+ arg_name 'message'
63
+ command :post do |c|
64
+ 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!"
68
+ end
69
+ end
70
+
71
+ desc 'Look up a user. If no argument is provided, it defualts to the current authenticated user'
72
+ default_value 'me'
73
+ arg_name 'username'
74
+ command :whois do |c|
75
+ #do not forget to attach @
76
+ c.action do |global_options,options,args|
77
+ puts "whois command ran"
78
+ end
79
+ end
80
+
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
+
90
+ desc 'Follow a user'
91
+ arg_name 'username'
92
+ command :follow do |c|
93
+ c.action do |global_options,options,args|
94
+ help_now!('username is required') if args.empty?
95
+ puts "follow command ran"
96
+ end
97
+ end
98
+
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|
103
+ c.action do |global_options,options,args|
104
+ puts "follow command ran"
105
+ end
106
+ end
107
+
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"
114
+ end
115
+ end
116
+
117
+ pre do |global,command,options,args|
118
+ # Pre logic here
119
+ # Return true to proceed; false to abourt and not call the
120
+ # chosen command
121
+ # Use skips_pre before a command to skip this block
122
+ # 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?
124
+ true
125
+ end
126
+
127
+ post do |global,command,options,args|
128
+ # Post logic here
129
+ # Use skips_post before a command to skip this
130
+ # block on that command only
131
+ end
132
+
133
+ on_error do |exception|
134
+ # Error logic here
135
+ # return false to skip default error handling
136
+ true
137
+ end
138
+
139
+ exit run(ARGV)
data/brio.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = brio
2
+
3
+ Generate this with
4
+ brio rdoc
5
+ After you have described your command line interface
data/lib/brio.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'brio/version.rb'
2
+ require 'brio/rcfile.rb'
3
+ require 'brio/api.rb'
4
+ require 'brio/client.rb'
5
+
6
+ # Add requires for other files you add to your project here, so
7
+ # you just need to require this one file in your bin file
data/lib/brio/api.rb ADDED
@@ -0,0 +1,52 @@
1
+ module Brio
2
+
3
+ module API
4
+
5
+ CLIENT_ID = '9JnCd6aS5VGNjd7p5Cx6EA7qd6Xz7eEs'
6
+
7
+ DEFAULT_OAUTH_HOST = 'alpha.app.net'
8
+ DEFAULT_API_HOST = 'alpha-api.app.net'
9
+ DEFAULT_PROTOCOL = 'https'
10
+
11
+ REDIRECT_URI = 'http://heroesneverpanic.com/'
12
+ SCOPE = 'stream,email,write_post,follow,messages,export'
13
+ RESPONSE_TYPE = 'token'
14
+
15
+
16
+
17
+ def oauth_url
18
+ "#{protocol}://#{oauth_host}/oauth/authenticate?client_id=#{CLIENT_ID}&response_type=#{RESPONSE_TYPE}&scope=#{SCOPE}&redirect_uri=#{REDIRECT_URI}"
19
+ end
20
+
21
+ def user_stream_url
22
+ "/stream/0/posts/stream"
23
+ end
24
+
25
+ def global_stream_url
26
+ "/stream/0/posts/stream/global"
27
+ end
28
+
29
+ def posts_url
30
+ "/stream/0/posts"
31
+ end
32
+
33
+ private
34
+ def base_api_url
35
+ "#{protocol}://#{api_host}"
36
+ end
37
+
38
+ def oauth_host
39
+ DEFAULT_OAUTH_HOST
40
+ end
41
+
42
+ def api_host
43
+ DEFAULT_API_HOST
44
+ end
45
+
46
+ def protocol
47
+ DEFAULT_PROTOCOL
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,38 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Brio
5
+
6
+ class Client
7
+ include Brio::API
8
+
9
+ def initialize
10
+ @conn = Faraday.new(:url => base_api_url ) do |faraday|
11
+ faraday.request :url_encoded
12
+ faraday.adapter Faraday.default_adapter
13
+ end
14
+ @rc = Brio::RCFile.instance
15
+ add_oauth_header unless @rc.empty?
16
+ end
17
+
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)
21
+ end
22
+
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
29
+ end
30
+
31
+ private
32
+ def add_oauth_header
33
+ @conn.authorization :bearer, @rc['token']
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,54 @@
1
+ require 'singleton'
2
+
3
+ module Brio
4
+
5
+ class RCFile
6
+ include Singleton
7
+
8
+ FILE_NAME = ".brio.rc"
9
+
10
+ def initialize
11
+ @path = File.join( ENV['HOME'], FILE_NAME )
12
+ @data = load_data
13
+ end
14
+
15
+ def []=(param, val)
16
+ config[param] = val
17
+ save_data
18
+ end
19
+
20
+ def [](param)
21
+ config[param]
22
+ end
23
+
24
+ def config
25
+ @data['config']
26
+ end
27
+
28
+ def empty?
29
+ @data == default_config
30
+ end
31
+
32
+
33
+ private
34
+ def default_config
35
+ {'config' => {}}
36
+ end
37
+
38
+ def load_data
39
+ require 'yaml'
40
+ YAML.load_file(@path)
41
+ rescue Errno::ENOENT
42
+ default_config
43
+ end
44
+
45
+ def save_data
46
+ require 'yaml'
47
+ File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |rcfile|
48
+ rcfile.write @data.to_yaml
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,3 @@
1
+ module Brio
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tanja Pislar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
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: rdoc
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
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: gli
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.6'
94
+ - !ruby/object:Gem::Dependency
95
+ name: launchy
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: highline
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.6'
126
+ - !ruby/object:Gem::Dependency
127
+ name: htmlentities
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: '4.3'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '4.3'
142
+ - !ruby/object:Gem::Dependency
143
+ name: faraday
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Ineract with app.net through your command line.
159
+ email: tanja@heroesneverpanic.com
160
+ executables:
161
+ - brio
162
+ extensions: []
163
+ extra_rdoc_files:
164
+ - README.rdoc
165
+ - brio.rdoc
166
+ files:
167
+ - bin/brio
168
+ - lib/brio/version.rb
169
+ - lib/brio/api.rb
170
+ - lib/brio/client.rb
171
+ - lib/brio/rcfile.rb
172
+ - lib/brio.rb
173
+ - README.rdoc
174
+ - brio.rdoc
175
+ homepage: http://heroesneverpanic.com
176
+ licenses: []
177
+ post_install_message:
178
+ rdoc_options:
179
+ - --title
180
+ - brio
181
+ - --main
182
+ - README.rdoc
183
+ - -ri
184
+ require_paths:
185
+ - lib
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ! '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 1.8.24
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: Command line tool for app.net, inspired by t for twitter.
205
+ test_files: []