socialcast 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/socialcast +39 -12
- data/lib/socialcast.rb +20 -0
- data/socialcast.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/socialcast
CHANGED
@@ -3,32 +3,59 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'commander/import'
|
5
5
|
require 'rest_client'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'json'
|
8
|
+
require 'lib/socialcast'
|
9
|
+
include Socialcast
|
6
10
|
|
7
11
|
program :version, File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
8
12
|
program :description, 'command line interface to the socialcast api'
|
9
13
|
|
14
|
+
command :authenticate do |c|
|
15
|
+
c.syntax = 'socialcast authenticate [options]'
|
16
|
+
c.summary = 'authenticate your Socialcast credentials'
|
17
|
+
c.description = 'verify that your credentials are valid'
|
18
|
+
c.example 'socialcast authenticate -u emily@socialcast.com', 'default usage'
|
19
|
+
c.option '-u', '--user STRING', String, 'Socialcast account username/email'
|
20
|
+
c.option '--domain STRING', String, 'Socialcast community domain'
|
21
|
+
c.action do |args, options|
|
22
|
+
options.default :domain => 'api.socialcast.com'
|
23
|
+
|
24
|
+
options.user = ask('Socialcast username: ') unless options.user
|
25
|
+
options.password = password
|
26
|
+
|
27
|
+
say "Authenticating #{options.user}"
|
28
|
+
url = ['https://', options.domain, '/api/authentication.json'].join
|
29
|
+
params = {:email => options.user, :password => options.password }
|
30
|
+
resource = RestClient::Resource.new url
|
31
|
+
resource.post params do |response|
|
32
|
+
say "API response:" if options.trace
|
33
|
+
puts response.body.to_s if options.trace
|
34
|
+
communities = JSON.parse(response.body.to_s)['communities']
|
35
|
+
options.domain = communities.detect {|c| c['domain'] == options.domain} ? options.domain : communities.first['domain']
|
36
|
+
end
|
37
|
+
|
38
|
+
save_credentials :user => options.user, :password => options.password, :domain => options.domain
|
39
|
+
say "Authentication successful for #{options.domain}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
10
44
|
command :share do |c|
|
11
45
|
c.syntax = 'socialcast share <message> [options]'
|
12
46
|
c.summary = 'share a message'
|
13
47
|
c.description = 'post a message into your socialcast stream'
|
14
|
-
c.example '
|
15
|
-
c.option '-u', '--user STRING', String, 'Socialcast account username'
|
16
|
-
c.option '--domain STRING', String, 'Socialcast community domain'
|
48
|
+
c.example 'socialcast share "some text"', 'basic usage'
|
17
49
|
c.action do |args, options|
|
18
50
|
message = args.first
|
19
|
-
options.user = ask('Socialcast username: ') unless options.user
|
20
|
-
options.password = password
|
21
|
-
options.domain = ask('Socialcast domain: ') unless options.domain
|
22
|
-
|
23
|
-
# options.default :domain => 'demo.socialcast.local', :user => user, :password => password
|
24
51
|
|
25
|
-
url = ['https://',
|
26
|
-
say "Posting message to: #{url}"
|
27
|
-
resource = RestClient::Resource.new url, :user =>
|
52
|
+
url = ['https://', credentials[:domain], '/api/messages.json'].join
|
53
|
+
say "Posting message from #{credentials[:user]} to: #{url}"
|
54
|
+
resource = RestClient::Resource.new url, :user => credentials[:user], :password => credentials[:password]
|
28
55
|
params = {:message => {:body => message}}
|
29
56
|
resource.post params do |response|
|
30
57
|
say "API response:" if options.trace
|
31
|
-
|
58
|
+
say response.body.to_s if options.trace
|
32
59
|
end
|
33
60
|
say "Message has been shared" #FIXME: use notify_ok to show growl
|
34
61
|
end
|
data/lib/socialcast.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Socialcast
|
2
|
+
def config_dir
|
3
|
+
config_dir = File.expand_path '~/.socialcast'
|
4
|
+
FileUtils.mkdir config_dir, :mode => 0700 unless File.exist?(config_dir)
|
5
|
+
config_dir
|
6
|
+
end
|
7
|
+
def credentials_file
|
8
|
+
File.join config_dir, 'credentials.yml'
|
9
|
+
end
|
10
|
+
def save_credentials(options)
|
11
|
+
File.open(credentials_file, "w") do |f|
|
12
|
+
f.write(options.to_yaml)
|
13
|
+
end
|
14
|
+
File.chmod 0600, credentials_file
|
15
|
+
end
|
16
|
+
def credentials
|
17
|
+
raise 'Unknown Socialcast credentials. Run `socialcast authenticate` to initialize' unless File.exist?(credentials_file)
|
18
|
+
YAML.load_file(credentials_file)
|
19
|
+
end
|
20
|
+
end
|
data/socialcast.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{socialcast}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Sonnek"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-14}
|
13
13
|
s.default_executable = %q{socialcast}
|
14
14
|
s.description = %q{publish messages to your stream from a command line interface}
|
15
15
|
s.email = %q{ryan@socialcast.com}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-14 00:00:00 -06:00
|
19
19
|
default_executable: socialcast
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|