Class: Twilip::Client
- Inherits:
-
Object
- Object
- Twilip::Client
- Defined in:
- lib/twilip.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
"twilip.yml"
- USER_AGENT =
"Twilip - ruby api wrapper for microblogs - #{Twilip::VERSION}"
Instance Method Summary collapse
- #config ⇒ Object
- #deliver(message, tags = nil) ⇒ Object
-
#initialize(config_file_url = nil) ⇒ Client
constructor
A new instance of Client.
- #load_adapters ⇒ Object
- #preprocess_message(message) ⇒ Object
Constructor Details
#initialize(config_file_url = nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/twilip.rb', line 12 def initialize(config_file_url = nil) @config_file = config_file_url ? config_file_url : DEFAULT_CONFIG_FILE load_adapters end |
Instance Method Details
#config ⇒ Object
24 25 26 |
# File 'lib/twilip.rb', line 24 def config YAML.load_file @config_file end |
#deliver(message, tags = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/twilip.rb', line 28 def deliver(, =nil) if @tags = .split(",").map {|m| m.strip } else @tags = [] end = () config["adapters"].each do |adapter| adapter_class = "#{adapter.capitalize}Adapter" adapter_class = Twilip.const_get(adapter_class) a_class = adapter_class.new config[adapter.to_s] a_class.deliver(, @tags) end end |
#load_adapters ⇒ Object
18 19 20 21 22 |
# File 'lib/twilip.rb', line 18 def load_adapters lib_dir = File.dirname(__FILE__) full_pattern = File.join(lib_dir, 'adapters', '*.rb') Dir.glob(full_pattern).each { |file| require file } end |
#preprocess_message(message) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/twilip.rb', line 47 def () # find urls :) url_regexp = /http[s]?:\/\/\w/ url = .split.grep(url_regexp).to_s short = Googl.shorten url .gsub!(url, short.short_url) end |