social-bee 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .idea
5
+ .idea
@@ -28,9 +28,31 @@ module SocialBee
28
28
 
29
29
  end
30
30
 
31
+ def client( token )
32
+ Koala::Facebook::API.new( token )
33
+ end
34
+
31
35
 
32
36
  def say_public( message, token )
33
- Koala::Facebook::GraphAPI.new( token ).put_wall_post( message )
37
+ client( token ).put_wall_post( message )
38
+ end
39
+
40
+ def say_private( to, message, token )
41
+ client( token ).put_object( to, 'inbox', :message => message )
42
+ end
43
+
44
+ def say_friends( message, token )
45
+ get_friends( token ).each do |itm|
46
+ say_private( itm, message, token )
47
+ end
48
+ end
49
+
50
+ def get_friends( token )
51
+ arr = []
52
+ client( token ).get_connections('me', 'friends').each do |itm|
53
+ arr.push itm['id']
54
+ end
55
+ arr
34
56
  end
35
57
 
36
58
 
@@ -7,18 +7,37 @@ module SocialBee
7
7
 
8
8
 
9
9
  def initialize(p={})
10
- raise 'Undefined config file' unless @config = YAML.load_file(Rails.root + p[:config])[Rails.env]
11
- end
12
10
 
11
+ raise 'Undefined config file' unless @config = YAML.load_file(Rails.root + p[:config])[Rails.env]
13
12
 
14
- def say_public( message, token, secret )
15
13
  Twitter.configure do |config|
16
14
  raise 'Undefined consumer key' unless config.consumer_key = @config['app_key']
17
15
  raise 'Undefined consumer secret' unless config.consumer_secret = @config['app_secret']
18
- raise 'Undefined user token' unless config.oauth_token = token
19
- raise 'Undefined user secret' unless config.oauth_token_secret = secret
20
16
  end
21
- Twitter.update( message )
17
+
18
+ end
19
+
20
+ def client( token, secret )
21
+ Twitter::Client.new( :oauth_token => token, :oauth_token_secret => secret )
22
+ end
23
+
24
+
25
+ def say_public( message, token, secret )
26
+ client( token, secret ).update( message )
27
+ end
28
+
29
+ def say_private( to, message, token, secret )
30
+ client( token, secret ).direct_message_create( to, message )
31
+ end
32
+
33
+ def say_friends( message, token, secret )
34
+ get_friends( token, secret ).each do |itm|
35
+ say_private( itm, message, token, secret )
36
+ end
37
+ end
38
+
39
+ def get_friends( token, secret )
40
+ client( token, secret ).follower_ids.ids
22
41
  end
23
42
 
24
43
 
@@ -1,3 +1,3 @@
1
1
  module SocialBee
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -16,10 +16,28 @@ module SocialBee
16
16
 
17
17
  end
18
18
 
19
+ def client( token )
20
+ @app.access_token = token
21
+ @app
22
+ end
23
+
19
24
 
20
25
  def say_public( message, token )
21
- @app.access_token = token
22
- @app.wall.post( :message => CGI::escape(message) )
26
+ client( token ).wall.post( :message => CGI::escape(message) )
27
+ end
28
+
29
+ def say_private( to, message, token )
30
+ client( token ).messages.send( :uid => to, :message => message )
31
+ end
32
+
33
+ def say_friends( message, token )
34
+ get_friends(token).each do |itm|
35
+ say_private( itm, message, token )
36
+ end
37
+ end
38
+
39
+ def get_friends( token )
40
+ client( token ).friends.get
23
41
  end
24
42
 
25
43
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social-bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000 Z
12
+ date: 2011-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twitter
16
- requirement: &70237501277600 !ruby/object:Gem::Requirement
16
+ requirement: &70206097759580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70237501277600
24
+ version_requirements: *70206097759580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: koala
27
- requirement: &70237501277180 !ruby/object:Gem::Requirement
27
+ requirement: &70206097756100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70237501277180
35
+ version_requirements: *70206097756100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vk-ruby
38
- requirement: &70237501276620 !ruby/object:Gem::Requirement
38
+ requirement: &70206097755440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70237501276620
46
+ version_requirements: *70206097755440
47
47
  description: Simple messaging wrapper for Facebook, Twitter, Vkontakte
48
48
  email:
49
49
  - atimofeev@reactant.ru