Permalink
Browse files

Merge branch 'release/0.1'

  • Loading branch information...
2 parents aa889ac + 9a179df commit 8bad3e45617e57007726879512606d55fa56c61e @arielpts arielpts committed Dec 19, 2011
View
@@ -7,3 +7,4 @@ tmp/
._*
Gemfile.lock
.AppleDouble
+test/config/*.yml
View
@@ -3,11 +3,17 @@ source "http://rubygems.org"
# Example:
# gem "activesupport", ">= 2.3.5"
+gem "gibbon"
+gem "activesupport"
+gem "i18n"
+gem "rdoc"
+
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.4"
gem "rcov", ">= 0"
+ gem "pry"
end
View
@@ -42,7 +42,7 @@ end
task :default => :test
-require 'rake/rdoctask'
+require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
View
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "jung"
+ s.version = 0.1
+ s.authors = ["arielpts"]
+ s.email = ["arielpts@me.com"]
+ s.homepage = "http://www.mobvox.com.br"
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "admin_widgets"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+
+ s.add_runtime_dependency "gibbon"
+ s.add_runtime_dependency "activesupport"
+ s.add_runtime_dependency "i18n"
+ s.add_runtime_dependency "rdoc"
+end
View
@@ -1 +1,10 @@
-require 'jung/campaign.rb'
+require 'active_support/inflector'
+require 'gibbon'
+require 'pry'
+
+require 'jung/sender.rb'
+require 'jung/list.rb'
+require 'jung/campaign.rb'
+require 'jung/drivers.rb'
+require 'jung/config.rb'
+require 'jung/recipient.rb'
View
@@ -1,7 +1,17 @@
module Jung
- class Campaign
- def self.build
- new
+ class Campaign < Jung::List
+
+ attr_reader :id
+ attr_accessor :name, :sender, :subject, :message
+
+ def initialize(options)
+ @name = options[:name]
+ @subject = options[:subject]
+ @sender = options[:sender]
+ @message = options[:message]
+
+ super options
end
+
end
end
View
@@ -0,0 +1,22 @@
+module Jung
+ class Config
+
+ attr_reader :driver, :options
+
+ def self.load(file = "config/jung.yml", namespace = nil)
+ options = YAML.load_file file
+ return self.new options[namespace.to_s]
+ end
+
+ def initialize(options)
+ @driver = options["driver"]
+ @options = options["options"]
+ require 'jung/drivers/' + options["driver"].underscore + '.rb'
+ end
+
+ def driver_const
+ Jung::Drivers.const_get self.driver.camelize
+ end
+
+ end
+end
View
@@ -0,0 +1,2 @@
+module Jung::Drivers
+end
@@ -0,0 +1,15 @@
+module Jung::Drivers::Infobip
+
+ require 'jung/drivers/infobip/api.rb'
+ require 'jung/drivers/infobip/campaign.rb'
+
+ attr_reader :list_id, :api, :id
+ attr_writer :list_id, :api
+
+ def self.extended(base)
+ return if base.class != Jung::Campaign
+ base.extend Jung::Drivers::Infobip::Campaign
+ base.api = Api.new base.config
+ end
+
+end
@@ -0,0 +1,49 @@
+class Jung::Drivers::Infobip::Api
+
+ require 'net/http'
+
+ attr_reader :username, :password, :api_url, :errors, :error_messages
+ attr_writer :errors
+
+ def initialize(config)
+ @username = config.options["username"]
+ @password = config.options["password"]
+ @api_url = config.options["api_url"]
+
+ @error_messages = {
+ -2 => "Not enough credits",
+ -3 => "Network not covered",
+ -5 => "Invalid username or password",
+ -6 => "Missing destination address",
+ -7 => "Missing SMS text",
+ -8 => "Missing sender name",
+ -9 => "Invalid format of destination address",
+ -10 => "Missing username",
+ -11 => "Missing password",
+ -13 => "Invalid destination address"
+ }
+ end
+
+ def send_sms(address, message, sender)
+ do_get_request :sendsms, :GSM => address, :SMSText => message, :sender => sender, :DataCoding => '8'
+ end
+
+ private
+
+ def get_error_message id
+ error_messages[id.to_i] || 'Unknow error ID: ' + id
+ end
+
+ def do_get_request method, params
+ url = api_url + '/' + method.to_s + '/plain?user=' + username + '&password=' + password
+ url = params.reduce(url) do | url, param |
+ url + '&' + CGI.escape(param.first.to_s) + '=' + CGI.escape(param.last.to_s)
+ end
+ result = Net::HTTP.get_response(URI.parse(url)).body
+
+ self.errors ||= [] << 'url: ' + url + ' - ' + get_error_message(result)
+
+ result.to_i > 1 ? result : false
+ end
+
+end
@@ -0,0 +1,20 @@
+module Jung::Drivers::Infobip::Campaign
+
+ attr_accessor :username, :password, :api_url, :messages_ids
+
+ def deliver
+ messages_ids = recipients.map do | recipient |
+ deliver_recipient recipient.address, message
+ end
+ messages_ids.reduce(true) do | acc, value |
+ acc && value != false
+ end
+ end
+
+ protected
+
+ def deliver_recipient address, message
+ api.send_sms address, message, sender.name
+ end
+
+end
@@ -0,0 +1,18 @@
+module Jung::Drivers::Mailchimp
+
+ require 'jung/drivers/mailchimp/api.rb'
+ require 'jung/drivers/mailchimp/list.rb'
+ require 'jung/drivers/mailchimp/campaign.rb'
+
+ attr_reader :gb, :list_id, :api, :id
+ attr_writer :gb, :list_id, :api
+
+ def self.extended(base)
+ base.extend Jung::Drivers::Mailchimp::List
+ base.extend Jung::Drivers::Mailchimp::Campaign if base.class == Jung::Campaign
+
+ base.list_id = base.config.options[:list_id]
+ base.api = Api.new base.config
+ end
+
+end
Oops, something went wrong.

0 comments on commit 8bad3e4

Please sign in to comment.