socialcast 1.2.0 → 1.2.1.RC1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.3
5
5
  - ree
6
+ - 2.0.0
data/config/ldap.yml CHANGED
@@ -2,21 +2,21 @@
2
2
  # LDAP connections
3
3
  connections:
4
4
  example_connection_1:
5
- username: "cn=Directory Manager"
5
+ username: "Directory Manager"
6
6
  password: "password"
7
7
  host: ldap.yourdomain.com
8
8
  port: 389
9
9
  basedn: "ou=smallpeople,ou=qa,dc=socialcast,dc=com"
10
10
  filter: "(mail=*)"
11
11
  example_connection_2:
12
- username: "cn=Directory Manager"
12
+ username: "Directory Manager"
13
13
  password: "password"
14
14
  host: ldap.yourdomain.com
15
15
  port: 389
16
16
  basedn: "ou=tinypeople,ou=qa,dc=yourdomain,dc=com"
17
17
  filter: "(mail=*)"
18
18
  example_encrypted_connection:
19
- username: "cn=Directory Manager"
19
+ username: "Directory Manager"
20
20
  password: "password"
21
21
  host: ldap.yourdomain.com
22
22
  port: 389
@@ -59,13 +59,14 @@ permission_mappings:
59
59
  # configure LDAP field for group memberships (ex: memberof, isMemberOf, etc)
60
60
  attribute_name: memberof
61
61
  account_types:
62
- external: "cn=External,dc=example,dc=com"
62
+ external: "CN=External,OU=Groups,DC=example,DC=com"
63
63
  roles:
64
- tenant_admin: "cn=Admins,dc=example,dc=com"
65
- sbi_admin: "cn=Admins,dc=example,dc=com"
66
- reach_admin: "cn=Admins,dc=example,dc=com"
67
- town_hall_admin: "cn=Admins,dc=example,dc=com"
64
+ tenant_admin: "CN=Admins,OU=Groups,DC=example,DC=com"
65
+ sbi_admin: "CN=Admins,OU=Groups,DC=example,DC=com"
66
+ reach_admin: "CN=Admins,OU=Groups,DC=example,DC=com"
67
+ town_hall_admin: "CN=Admins,OU=Groups,DC=example,DC=com"
68
68
 
69
+ # Role search definitions need to be EXACT matches to the output from your LDAP server.
69
70
 
70
71
  # general script options
71
72
  options:
@@ -43,16 +43,16 @@ module Socialcast
43
43
  method_option :proxy, :type => :string, :desc => 'HTTP proxy options for connecting to Socialcast server'
44
44
  def authenticate
45
45
  user = options[:user] || ask('Socialcast username: ')
46
- password = options[:password] || HighLine.new.ask("Socialcast password: ") { |q| q.echo = false }
46
+ password = options[:password] || HighLine.new.ask("Socialcast password: ") { |q| q.echo = false }.to_s
47
47
  domain = options[:domain]
48
48
 
49
- url = ['https://', domain, '/api/authentication.json'].join
49
+ url = ['https://', domain, '/api/authentication'].join
50
50
  say "Authenticating #{user} to #{url}"
51
51
  params = {:email => user, :password => password }
52
52
  RestClient.log = Logger.new(STDOUT) if options[:trace]
53
53
  RestClient.proxy = options[:proxy] if options[:proxy]
54
54
  resource = RestClient::Resource.new url
55
- response = resource.post params
55
+ response = resource.post params, :accept => :json
56
56
  say "API response: #{response.body.to_s}" if options[:trace]
57
57
  communities = JSON.parse(response.body.to_s)['communities']
58
58
  domain = communities.detect {|c| c['domain'] == domain} ? domain : communities.first['domain']
@@ -73,8 +73,8 @@ module Socialcast
73
73
  options[:attachments].each do |path|
74
74
  Dir[File.expand_path(path)].each do |attachment|
75
75
  say "Uploading attachment #{attachment}..."
76
- uploader = Socialcast.resource_for_path '/api/attachments.json', {}, options[:trace]
77
- uploader.post :attachment => File.new(attachment) do |response, request, result|
76
+ uploader = Socialcast.resource_for_path '/api/attachments', {}, options[:trace]
77
+ uploader.post({:attachment => File.new(attachment)}, {:accept => :json}) do |response, request, result|
78
78
  if response.code == 201
79
79
  attachment_ids << JSON.parse(response.body)['attachment']['id']
80
80
  else
@@ -186,11 +186,15 @@ module Socialcast
186
186
  else
187
187
  say "Uploading dataset to Socialcast..."
188
188
  resource = Socialcast.resource_for_path '/api/users/provision', http_config
189
- File.open(output_file, 'r') do |file|
190
- request_params = {:file => file}
191
- request_params[:skip_emails] = 'true' if (config['options']["skip_emails"] || options[:skip_emails])
192
- request_params[:test] = 'true' if (config['options']["test"] || options[:test])
193
- resource.post request_params
189
+ begin
190
+ File.open(output_file, 'r') do |file|
191
+ request_params = {:file => file}
192
+ request_params[:skip_emails] = 'true' if (config['options']["skip_emails"] || options[:skip_emails])
193
+ request_params[:test] = 'true' if (config['options']["test"] || options[:test])
194
+ resource.post request_params, :accept => :json
195
+ end
196
+ rescue RestClient::Unauthorized => e
197
+ Kernel.abort "Authenticated user either does not have administration privileges or the community is not configured to allow provisioning. Please contact Socialcast support to if you need help." if e.http_code == 401
194
198
  end
195
199
  say "Finished"
196
200
  end
@@ -217,11 +221,11 @@ module Socialcast
217
221
  end
218
222
  def current_socialcast_users(http_config)
219
223
  current_socialcast_list = Set.new
220
- request_params = {:per_page => 500, :format => 'json'}
224
+ request_params = {:per_page => 500}
221
225
  request_params[:page] = 1
222
226
  resource = create_socialcast_user_index_request(http_config, request_params)
223
227
  while true
224
- response = resource.get
228
+ response = resource.get :accept => :json
225
229
  result = JSON.parse(response)
226
230
  users = result["users"]
227
231
  break if users.blank?
@@ -234,7 +238,7 @@ module Socialcast
234
238
  current_socialcast_list
235
239
  end
236
240
  def create_socialcast_user_index_request(http_config, request_params)
237
- path_template = "/api/users.json?format=%{format}&per_page=%{per_page}&page=%{page}"
241
+ path_template = "/api/users?per_page=%{per_page}&page=%{page}"
238
242
  Socialcast.resource_for_path((path_template % request_params), http_config)
239
243
  end
240
244
  end
@@ -2,6 +2,8 @@ require 'active_resource'
2
2
 
3
3
  module Socialcast
4
4
  class Message < ActiveResource::Base
5
+ headers['Accept'] = 'application/json'
6
+
5
7
  def self.configure_from_credentials
6
8
  Socialcast::Message.site = ['https://', Socialcast.credentials[:domain], '/api'].join
7
9
  Socialcast::Message.proxy = Socialcast.credentials[:proxy] if Socialcast.credentials[:proxy]
@@ -1,3 +1,3 @@
1
1
  module Socialcast
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1.RC1"
3
3
  end
data/lib/socialcast.rb CHANGED
@@ -26,12 +26,15 @@ module Socialcast
26
26
  def basic_auth_options
27
27
  {:user => credentials[:user], :password => credentials[:password]}
28
28
  end
29
+ def default_options
30
+ basic_auth_options
31
+ end
29
32
  # configure restclient for api call
30
33
  def resource_for_path(path, options = {}, debug = true)
31
34
  RestClient.log = Logger.new(STDOUT) if debug
32
35
  RestClient.proxy = credentials[:proxy] if credentials[:proxy]
33
36
  url = ['https://', credentials[:domain], path].join
34
- RestClient::Resource.new url, options.merge(basic_auth_options)
37
+ RestClient::Resource.new url, options.merge(default_options)
35
38
  end
36
39
  end
37
40
  end
data/spec/cli_spec.rb CHANGED
@@ -9,6 +9,7 @@ describe Socialcast::CLI do
9
9
  stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
10
10
  with(:body => /message\_type\"\:null/).
11
11
  with(:body => /testing/).
12
+ with(:headers => {'Accept' => 'application/json'}).
12
13
  to_return(:status => 200, :body => "", :headers => {})
13
14
 
14
15
  Socialcast::CLI.start ['share', 'testing']
@@ -24,6 +25,7 @@ describe Socialcast::CLI do
24
25
  stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
25
26
  with(:body => /message\_type\"\:review\_request/).
26
27
  with(:body => /please\sreview/).
28
+ with(:headers => {'Accept' => 'application/json'}).
27
29
  to_return(:status => 200, :body => "", :headers => {})
28
30
 
29
31
  Socialcast::CLI.start ['share', 'please review', '--message_type=review_request']
@@ -37,6 +39,7 @@ describe Socialcast::CLI do
37
39
  Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
38
40
  stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
39
41
  with(:body => /group\_id\"\:123/).
42
+ with(:headers => {'Accept' => 'application/json'}).
40
43
  to_return(:status => 200, :body => "", :headers => {})
41
44
 
42
45
  Socialcast::CLI.start ['share', 'hi', '--group_id=123']
@@ -51,6 +54,7 @@ describe Socialcast::CLI do
51
54
  stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
52
55
  with(:body => /message\_type\"\:null/).
53
56
  with(:body => /testing/).
57
+ with(:headers => {'Accept' => 'application/json'}).
54
58
  to_return(:status => 200, :body => "", :headers => {})
55
59
 
56
60
  Socialcast::CLI.start ['share', 'testing']
@@ -105,6 +109,26 @@ describe Socialcast::CLI do
105
109
  end
106
110
  it 'does post to Socialcast and does not call Kernel.abort' do end # see expectations
107
111
  end
112
+ context 'with socialcast returning 401' do
113
+ before do
114
+ Net::LDAP.any_instance.stub(:search).and_return(nil)
115
+
116
+ @result = ''
117
+ Zlib::GzipWriter.stub(:open).and_yield(@result)
118
+ Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
119
+ Socialcast::CLI.any_instance.should_receive(:load_configuration).with('/my/path/to/ldap.yml').and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml')))
120
+ File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true)
121
+
122
+ File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
123
+ rest_client_resource = double(:rest_client_resource)
124
+ rest_client_resource.stub(:post).and_raise(RestClient::Unauthorized.new(mock('Unauthorized HTTP Response', :code => '401')))
125
+ Socialcast.stub(:resource_for_path).and_return(rest_client_resource)
126
+ Kernel.should_receive(:abort).with("Authenticated user either does not have administration privileges or the community is not configured to allow provisioning. Please contact Socialcast support to if you need help.").once
127
+
128
+ Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml', '-f']
129
+ end
130
+ it "raises Kernel abort" do end # see expectations
131
+ end
108
132
  context 'with absolute path to ldap.yml file' do
109
133
  before do
110
134
  @entry = Net::LDAP::Entry.new("dc=example,dc=com")
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
5
- prerelease:
4
+ version: 1.2.1.RC1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Sonnek
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-24 00:00:00.000000000 Z
13
+ date: 2013-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &2159242780 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 1.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2159242780
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.4.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: json
28
- requirement: &2159241780 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 1.4.6
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *2159241780
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.4.6
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: thor
39
- requirement: &2159241300 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 0.14.6
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *2159241300
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.14.6
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: highline
50
- requirement: &2159240840 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: 1.6.2
56
71
  type: :runtime
57
72
  prerelease: false
58
- version_requirements: *2159240840
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.6.2
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: socialcast-net-ldap
61
- requirement: &2159240200 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: 0.1.6
67
87
  type: :runtime
68
88
  prerelease: false
69
- version_requirements: *2159240200
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 0.1.6
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: activeresource
72
- requirement: &2159239520 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: 2.3.11
78
103
  type: :runtime
79
104
  prerelease: false
80
- version_requirements: *2159239520
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.3.11
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: rspec
83
- requirement: &2159238860 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ! '>='
@@ -88,10 +118,15 @@ dependencies:
88
118
  version: 2.11.0
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *2159238860
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: 2.11.0
92
127
  - !ruby/object:Gem::Dependency
93
128
  name: webmock
94
- requirement: &2159238400 !ruby/object:Gem::Requirement
129
+ requirement: !ruby/object:Gem::Requirement
95
130
  none: false
96
131
  requirements:
97
132
  - - ! '>='
@@ -99,18 +134,28 @@ dependencies:
99
134
  version: 1.7.7
100
135
  type: :development
101
136
  prerelease: false
102
- version_requirements: *2159238400
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.7.7
103
143
  - !ruby/object:Gem::Dependency
104
144
  name: rake
105
- requirement: &2159237940 !ruby/object:Gem::Requirement
145
+ requirement: !ruby/object:Gem::Requirement
106
146
  none: false
107
147
  requirements:
108
- - - =
148
+ - - '='
109
149
  - !ruby/object:Gem::Version
110
150
  version: 0.9.2.2
111
151
  type: :development
112
152
  prerelease: false
113
- version_requirements: *2159237940
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - '='
157
+ - !ruby/object:Gem::Version
158
+ version: 0.9.2.2
114
159
  description: publish messages to your stream from a command line interface
115
160
  email:
116
161
  - ryan@socialcast.com
@@ -162,15 +207,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
207
  - - ! '>='
163
208
  - !ruby/object:Gem::Version
164
209
  version: '0'
210
+ segments:
211
+ - 0
212
+ hash: -357253051264046673
165
213
  required_rubygems_version: !ruby/object:Gem::Requirement
166
214
  none: false
167
215
  requirements:
168
- - - ! '>='
216
+ - - ! '>'
169
217
  - !ruby/object:Gem::Version
170
- version: '0'
218
+ version: 1.3.1
171
219
  requirements: []
172
220
  rubyforge_project: socialcast
173
- rubygems_version: 1.8.10
221
+ rubygems_version: 1.8.25
174
222
  signing_key:
175
223
  specification_version: 3
176
224
  summary: command line interface to socialcast api