social_media 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +46 -0
- data/Rakefile +26 -0
- data/lib/social_media/engine.rb +5 -0
- data/lib/social_media/errors.rb +19 -0
- data/lib/social_media/service/base.rb +28 -0
- data/lib/social_media/service/facebook.rb +7 -0
- data/lib/social_media/service/linkedin.rb +7 -0
- data/lib/social_media/service/twitter.rb +58 -0
- data/lib/social_media/service.rb +27 -0
- data/lib/social_media/version.rb +3 -0
- data/lib/social_media.rb +4 -0
- data/lib/tasks/social_media_tasks.rake +4 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0ab5e277bfddb91ea1d30fa0964344bb7a94a43
|
4
|
+
data.tar.gz: b9ec1d354846101171f776a386ad8033d23eb091
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f00ffe6626443899f23b7d839a6ec43e276f2dc62ca5fa4f87ed91c95fcd2cf24e8124ec592f891420857c6c01a2d68c23a1f493d616595ecb67fcb494e1c7bc
|
7
|
+
data.tar.gz: 7ea5a155be68519d3134349b146e6a25eef47eb16cb12be975125db598904eeda0b931a5c5eb1f1cb9bff467e54d2316366d8b5acd1f8dcfab99970bc811f48a
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 mwlang
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# SocialMedia
|
2
|
+
|
3
|
+
Facebook: 1,712,000,000 users
|
4
|
+
WhatsApp 1,000,000,000 users
|
5
|
+
Facebook Messenger: 1,000,000,000 users
|
6
|
+
QQ: 899,000,000 users
|
7
|
+
WeChat: 806,000,000 users
|
8
|
+
QZone: 652,000,000 users
|
9
|
+
Tumblr: 555,000,000 users
|
10
|
+
Instagram: 500,000,000 users
|
11
|
+
Twitter: 313,000,000 users
|
12
|
+
Baidu Tieba: 300,000,000 users
|
13
|
+
Skype: 300,000,000 users
|
14
|
+
Sina Weibo: 282,000,000 users
|
15
|
+
Viber: 249,000,000 users
|
16
|
+
Line: 218,000,000 users
|
17
|
+
Snapchat: 200,000,000 users
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
The idea is to treat social media sites like databases. With that in mind, we'll have adapters for each each social media service
|
21
|
+
that we connect, passing the appropriate connection strings to. Once connected, we can then query and publish to the connection using
|
22
|
+
the same method calls and parameters across the various social media services. Of course some services will have more functionality
|
23
|
+
than others. The library can be configured to silently ignore limited functionality or to explicitly raise errors.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'social_media'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
```bash
|
34
|
+
$ bundle
|
35
|
+
```
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
```bash
|
39
|
+
$ gem install social_media
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
Contribution directions go here.
|
44
|
+
|
45
|
+
## License
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
require 'rspec/core'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'SocialMedia'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.rdoc')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
22
|
+
|
23
|
+
task :default => :spec
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
# require 'bundler/gem_tasks'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SocialMedia
|
2
|
+
|
3
|
+
def self.convert_exception_class exception, klass
|
4
|
+
return exception if exception.is_a?(klass)
|
5
|
+
e = klass.new("#{exception.class}: #{exception.message}")
|
6
|
+
e.wrapped_exception = exception
|
7
|
+
e.set_backtrace(exception.backtrace)
|
8
|
+
e
|
9
|
+
end
|
10
|
+
|
11
|
+
class Error < ::StandardError
|
12
|
+
# If this exception wraps an underlying exception, the underlying
|
13
|
+
# exception is held here.
|
14
|
+
attr_accessor :wrapped_exception
|
15
|
+
end
|
16
|
+
|
17
|
+
Unauthorized = Class.new(Error)
|
18
|
+
Error::Unauthorized = Unauthorized
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SocialMedia
|
2
|
+
module Service
|
3
|
+
class Base
|
4
|
+
def self.name
|
5
|
+
raise NotImplementedError.new "#{self.to_s}::name not implemented"
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :connection_params
|
9
|
+
|
10
|
+
def initialize connection_params
|
11
|
+
@connection_params = connection_params
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast_error error
|
15
|
+
return Error
|
16
|
+
end
|
17
|
+
|
18
|
+
def handle_error &block
|
19
|
+
begin
|
20
|
+
yield
|
21
|
+
rescue Exception => error
|
22
|
+
wrapped_error = SocialMedia::convert_exception_class(error, cast_error(error) || Error)
|
23
|
+
raise wrapped_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SocialMedia::Service
|
2
|
+
require 'twitter'
|
3
|
+
|
4
|
+
class Twitter < Base
|
5
|
+
def self.name
|
6
|
+
:twitter
|
7
|
+
end
|
8
|
+
|
9
|
+
def cast_error error
|
10
|
+
return ::SocialMedia::Error::Unauthorized if error.is_a? ::Twitter::Error::Unauthorized
|
11
|
+
end
|
12
|
+
|
13
|
+
def client
|
14
|
+
@client ||= ::Twitter::REST::Client.new do |config|
|
15
|
+
config.consumer_key = connection_params[:consumer_key]
|
16
|
+
config.consumer_secret = connection_params[:consumer_secret]
|
17
|
+
config.access_token = connection_params[:access_token]
|
18
|
+
config.access_token_secret = connection_params[:access_token_secret]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def send_message message, options={}
|
23
|
+
return send_text_message(message, options) unless options.has_key? :filenames
|
24
|
+
send_multipart_message message, options
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_message message_id
|
28
|
+
result = client.destroy_status message_id
|
29
|
+
result.first.id
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_profile_background filename
|
33
|
+
client.update_profile_banner(open filename)
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_profile_image filename
|
37
|
+
result = client.update_profile_image(open filename)
|
38
|
+
result.id
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def send_text_message message, options
|
44
|
+
handle_error do
|
45
|
+
result = client.update(message, options)
|
46
|
+
result.id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_multipart_message message, options
|
51
|
+
media = Array(options.delete(:filenames)).map{ |fn| File.new(fn) }
|
52
|
+
handle_error do
|
53
|
+
result = client.update_with_media(message, media, options)
|
54
|
+
result.id
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'service/base'
|
2
|
+
require_relative 'service/facebook'
|
3
|
+
require_relative 'service/twitter'
|
4
|
+
require_relative 'service/linkedin'
|
5
|
+
|
6
|
+
module SocialMedia::Service
|
7
|
+
def self.service_classes
|
8
|
+
ObjectSpace.each_object(Class).select { |klass| klass < SocialMedia::Service::Base }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.services
|
12
|
+
service_classes.map(&:name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.service name
|
16
|
+
service_classes.detect{ |d| d.name == name.to_sym }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.method_missing method_sym, *arguments
|
20
|
+
if service_by_name = service(method_sym)
|
21
|
+
return service_by_name if arguments.empty?
|
22
|
+
service_by_name.new *arguments
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/social_media.rb
ADDED
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: social_media
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mwlang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: twitter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: koala
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: google-api-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.5.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.5.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.9.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.9.3
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.21.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.21.0
|
167
|
+
description: Social Media allows publishing to any number of social media services
|
168
|
+
using one common API.
|
169
|
+
email:
|
170
|
+
- mwlang@cybrains.net
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- MIT-LICENSE
|
176
|
+
- README.md
|
177
|
+
- Rakefile
|
178
|
+
- lib/social_media.rb
|
179
|
+
- lib/social_media/engine.rb
|
180
|
+
- lib/social_media/errors.rb
|
181
|
+
- lib/social_media/service.rb
|
182
|
+
- lib/social_media/service/base.rb
|
183
|
+
- lib/social_media/service/facebook.rb
|
184
|
+
- lib/social_media/service/linkedin.rb
|
185
|
+
- lib/social_media/service/twitter.rb
|
186
|
+
- lib/social_media/version.rb
|
187
|
+
- lib/tasks/social_media_tasks.rake
|
188
|
+
homepage: https://github.com/mwlang/social_media
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata: {}
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 2.5.1
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: Social Media allows publishing to any number of social media services using
|
212
|
+
one common API.
|
213
|
+
test_files: []
|