twilip 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/adapters/.gitkeep +0 -0
- data/lib/adapters/base_adapter.rb +51 -0
- data/lib/adapters/blip.rb +10 -0
- data/lib/adapters/flaker.rb +12 -0
- data/lib/adapters/pinger.rb +12 -0
- data/lib/adapters/twitter.rb +24 -0
- data/lib/test/.gitkeep +0 -0
- data/lib/twilip.rb +57 -0
- data/lib/twilip.yml.example +23 -0
- data/lib/twilip/version.rb +4 -0
- data/twilip.gemspec +24 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
class BaseAdapter
|
5
|
+
attr_writer :headers
|
6
|
+
def headers
|
7
|
+
@headers ||= default_headers_map
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_headers_map
|
11
|
+
headers = []
|
12
|
+
headers << ["User-Agent", Twilip::Client::USER_AGENT]
|
13
|
+
headers << ["Accept", "application/json"]
|
14
|
+
headers << ["Pragma", "no-cache"]
|
15
|
+
headers
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_headers(request)
|
19
|
+
|
20
|
+
headers.each do |header|
|
21
|
+
request.add_field(header[0], headers[1])
|
22
|
+
end
|
23
|
+
request
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(config = {})
|
27
|
+
@login = config["login"]
|
28
|
+
@password = config["password"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_tags(message, tags)
|
32
|
+
@message = message.strip
|
33
|
+
|
34
|
+
unless tags.empty?
|
35
|
+
tags.each do |tag|
|
36
|
+
@message << " ##{tag.strip}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@message
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_deliver(api_url, *form_data)
|
43
|
+
url = URI.parse(api_url)
|
44
|
+
request = Net::HTTP::Post.new(url.path)
|
45
|
+
request.basic_auth @login, @password
|
46
|
+
request.set_form_data(*form_data)
|
47
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(add_headers(request)) }
|
48
|
+
JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'base_adapter' )
|
2
|
+
|
3
|
+
class PingerAdapter < BaseAdapter
|
4
|
+
URL = "http://a.pinger.pl/auth_add_message.json"
|
5
|
+
|
6
|
+
def deliver(message, tags = [])
|
7
|
+
message = add_tags(message, tags)
|
8
|
+
process_deliver(URL, {"text" => message}, "&")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "twitter"
|
3
|
+
|
4
|
+
class TwitterAdapter < BaseAdapter
|
5
|
+
|
6
|
+
def initialize(conf = {})
|
7
|
+
|
8
|
+
Twitter.configure do |config|
|
9
|
+
config.consumer_key = conf["consumer_key"]
|
10
|
+
config.consumer_secret = conf["consumer_secret"]
|
11
|
+
config.oauth_token = conf["oauth_token"]
|
12
|
+
config.oauth_token_secret = conf["oauth_token_secret"]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver(message, tags = [])
|
18
|
+
message = add_tags(message, tags)
|
19
|
+
|
20
|
+
Twitter.update(message[0,140])
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/test/.gitkeep
ADDED
File without changes
|
data/lib/twilip.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'googl'
|
4
|
+
require 'twilip/version'
|
5
|
+
|
6
|
+
module Twilip
|
7
|
+
class Client
|
8
|
+
|
9
|
+
DEFAULT_CONFIG_FILE = "twilip.yml"
|
10
|
+
USER_AGENT = "Twilip - ruby api wrapper for microblogs - #{Twilip::VERSION}"
|
11
|
+
|
12
|
+
def initialize(config_file_url = nil)
|
13
|
+
@config_file = config_file_url ? config_file_url : DEFAULT_CONFIG_FILE
|
14
|
+
|
15
|
+
load_adapters
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_adapters
|
19
|
+
lib_dir = File.dirname(__FILE__)
|
20
|
+
full_pattern = File.join(lib_dir, 'adapters', '*.rb')
|
21
|
+
Dir.glob(full_pattern).each { |file| require file }
|
22
|
+
end
|
23
|
+
|
24
|
+
def config
|
25
|
+
YAML.load_file @config_file
|
26
|
+
end
|
27
|
+
|
28
|
+
def deliver(message, tags=nil)
|
29
|
+
|
30
|
+
if tags
|
31
|
+
@tags = tags.split(",").map {|m| m.strip }
|
32
|
+
else
|
33
|
+
@tags = []
|
34
|
+
end
|
35
|
+
|
36
|
+
preprocessed_message = preprocess_message(message)
|
37
|
+
|
38
|
+
config["adapters"].each do |adapter|
|
39
|
+
adapter_class = "#{adapter.capitalize}Adapter"
|
40
|
+
adapter_class = Twilip.const_get(adapter_class)
|
41
|
+
a_class = adapter_class.new config[adapter.to_s]
|
42
|
+
a_class.deliver(preprocessed_message, @tags)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def preprocess_message(message)
|
48
|
+
# find urls :)
|
49
|
+
url_regexp = /http[s]?:\/\/\w/
|
50
|
+
url = message.split.grep(url_regexp).to_s
|
51
|
+
|
52
|
+
short = Googl.shorten url
|
53
|
+
message.gsub!(url, short.short_url)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
adapters:
|
2
|
+
- blip
|
3
|
+
|
4
|
+
blip:
|
5
|
+
login: blip_user
|
6
|
+
password: blip_password
|
7
|
+
|
8
|
+
twitter:
|
9
|
+
consumer_key: 6adjf;lkas;d
|
10
|
+
consumer_secret: 4lajdhfuwefj
|
11
|
+
oauth_token: 256645873-asldjfhauwehf
|
12
|
+
oauth_token_secret: uQasdljfhoauw
|
13
|
+
|
14
|
+
flaker:
|
15
|
+
login: username_flaker
|
16
|
+
password: pass_flaker
|
17
|
+
|
18
|
+
pinger:
|
19
|
+
login: pinger-login
|
20
|
+
password: pinger_password
|
21
|
+
|
22
|
+
|
23
|
+
|
data/twilip.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "twilip/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "twilip"
|
7
|
+
s.version = Twilip::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Mariusz Nosinski"]
|
10
|
+
s.email = ["marioosh@5dots.pl"]
|
11
|
+
s.homepage = "http://marioosh.5dots.pl"
|
12
|
+
s.summary = %q{Twilip is ruby wrapper for popular microblogs, like Twitter, Blip, Flaker and Pinger}
|
13
|
+
s.description = %q{With twilip you can deliver one message to how many microblogs you want. All you need is another adapter and credentials in config file.}
|
14
|
+
|
15
|
+
s.add_dependency('googl')
|
16
|
+
s.add_dependency('twitter')
|
17
|
+
|
18
|
+
# s.rubyforge_project = "twilip"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twilip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mariusz Nosinski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-24 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: googl
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: twitter
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: With twilip you can deliver one message to how many microblogs you want. All you need is another adapter and credentials in config file.
|
50
|
+
email:
|
51
|
+
- marioosh@5dots.pl
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- Rakefile
|
62
|
+
- lib/adapters/.gitkeep
|
63
|
+
- lib/adapters/base_adapter.rb
|
64
|
+
- lib/adapters/blip.rb
|
65
|
+
- lib/adapters/flaker.rb
|
66
|
+
- lib/adapters/pinger.rb
|
67
|
+
- lib/adapters/twitter.rb
|
68
|
+
- lib/test/.gitkeep
|
69
|
+
- lib/twilip.rb
|
70
|
+
- lib/twilip.yml.example
|
71
|
+
- lib/twilip/version.rb
|
72
|
+
- twilip.gemspec
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://marioosh.5dots.pl
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.5.0
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Twilip is ruby wrapper for popular microblogs, like Twitter, Blip, Flaker and Pinger
|
107
|
+
test_files: []
|
108
|
+
|