Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/0.4.0'

  • Loading branch information...
commit 574e3959526186f48d78bbb866dcf0e7209f3ed9 2 parents 13d9fd8 + 00f51fb
@danxexe danxexe authored
View
2  VERSION
@@ -1 +1 @@
-0.3.0
+0.4.0
View
4 lib/jung/drivers/infobip.rb
@@ -12,4 +12,8 @@ def self.extended(base)
base.api = Api.new base.config
end
+ def errors
+ api.errors
+ end
+
end
View
15 lib/jung/drivers/infobip/api.rb
@@ -2,13 +2,14 @@ class Jung::Drivers::Infobip::Api
require 'net/http'
- attr_reader :username, :password, :api_url, :errors, :error_messages
- attr_writer :errors
+ attr_reader :username, :password, :api_url, :error_messages
+ attr_accessor :errors
def initialize(config)
@username = config.options["username"]
@password = config.options["password"]
@api_url = config.options["api_url"]
+ @errors = []
@error_messages = {
-2 => "Not enough credits",
@@ -28,14 +29,10 @@ def send_sms(address, message, sender, options = {})
do_get_request :sendsms, { :GSM => address, :SMSText => message, :sender => sender, :DataCoding => '8' }.merge(options)
end
- def schedule_sms(address, message, sender, from_now, options = {})
- send_sms address, message, sender, { :sendDateTime => from_now }.merge(options)
- end
-
private
def get_error_message id
- error_messages[id.to_i] || 'Unknow error ID: ' + id
+ error_messages[id.to_i] || "Unknow error ID: #{id}"
end
def do_get_request method, params
@@ -44,8 +41,8 @@ def do_get_request method, params
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)
+
+ self.errors << get_error_message(result)
result.to_i > 1 ? result : false
end
View
71 lib/jung/drivers/infobip/campaign.rb
@@ -1,6 +1,43 @@
module Jung::Drivers::Infobip::Campaign
attr_accessor :username, :password, :api_url, :messages_ids
+ attr_accessor :app_id # Warning: Infobip limitation: app_id should not be more than 30 chars
+ attr_accessor :webhook
+
+ attr_reader :deliver_at
+ def deliver_at=(val)
+ @deliver_in = nil
+ @deliver_at = val
+ end
+
+ def deliver_in
+ return @deliver_in = nil unless deliver_at.respond_to?(:to_time)
+
+ @deliver_in ||= begin
+
+ time = deliver_at.to_time
+ seconds_from_now = (Time.now - time) * -1
+
+ unless seconds_from_now < 0
+ minutes_from_now, seconds_from_now = seconds_from_now.divmod(60)
+ hours_from_now, minutes_from_now = minutes_from_now.divmod(60)
+ days_from_now, hours_from_now = hours_from_now.divmod(24)
+ seconds_from_now = seconds_from_now.to_i
+
+ time_from_now = {
+ :d => days_from_now,
+ :h => hours_from_now,
+ :m => minutes_from_now,
+ :s => seconds_from_now
+ }.reject { |k,v| v == 0 }.map { |(k,v)| "#{v}#{k}" }.join
+ else
+ time_from_now = nil
+ end
+
+ time_from_now
+ end
+ end
+
def deliver(recipients = self.recipients)
messages_ids = recipients.map do | recipient |
@@ -15,39 +52,19 @@ def deliver_test(recipients)
end
def schedule time
- seconds_from_now = (Time.now - time) * -1
-
- unless seconds_from_now < 0
- minutes_from_now, seconds_from_now = seconds_from_now.divmod(60)
- hours_from_now, minutes_from_now = minutes_from_now.divmod(60)
- days_from_now, hours_from_now = hours_from_now.divmod(24)
- seconds_from_now = seconds_from_now.to_i
-
- time_from_now = {
- :d => days_from_now,
- :h => hours_from_now,
- :m => minutes_from_now,
- :s => seconds_from_now
- }.reject { |k,v| v == 0 }.map { |(k,v)| "#{v}#{k}" }.join
- else
- time_from_now = nil
- end
-
- messages_ids = recipients.map do | recipient |
- address = recipient.is_a?(Jung::Recipient) ? recipient.address : recipient
- schedule_recipient address, message, time_from_now
- end
- delivery_success? messages_ids
+ self.deliver_at = time
+ deliver
end
+
protected
- def deliver_recipient address, message
- api.send_sms address, message, sender.name
+ def delivery_options
+ { :appid => app_id, :pushurl => webhook, :sendDateTime => deliver_in }.reject{ |k,v| v.nil? }
end
- def schedule_recipient address, message, time_from_now = nil
- api.schedule_sms address, message, sender.name, time_from_now
+ def deliver_recipient address, message
+ api.send_sms address, message, sender.name, delivery_options
end
def delivery_success?(messages_ids)
View
4 lib/jung/drivers/mailchimp.rb
@@ -15,4 +15,8 @@ def self.extended(base)
base.api = Api.new base.config
end
+ def errors
+ api.errors
+ end
+
end
View
5 lib/jung/drivers/mailchimp/api.rb
@@ -1,12 +1,13 @@
class Jung::Drivers::Mailchimp::Api
- attr_reader :config, :gb, :list_id, :errors
- attr_writer :errors
+ attr_reader :config, :gb, :list_id
+ attr_accessor :errors
def initialize(config)
@config = config
@gb = Gibbon.new config.options["api_key"]
@list_id = config.options["list_id"]
+ @errors = []
end
# List Related
View
3  lib/jung/drivers/mailchimp/list.rb
@@ -10,9 +10,6 @@ def all
list_members
end
- def errors
- api.errors
- end
protected
Please sign in to comment.
Something went wrong with that request. Please try again.