danest-sailthru-client 1.16 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/sailthru.rb +35 -22
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 837599b172f021e53746c666ee63ba91b3356caa
4
- data.tar.gz: 79ca81519104cb8c4eb6b8c1087c3647a657dbf4
3
+ metadata.gz: 22e99cd96c83b06498bd6bdb4e872178927fb480
4
+ data.tar.gz: f96e18491e65d1f290b24705e129599f0ce6b6c5
5
5
  SHA512:
6
- metadata.gz: 7e30c5cbc539336514f506e02451c5af3fd15563b1183df4192fd8e75ed326b5a66fb74d2879996b1ea8b89c50a1c45798cca1132991aa0b083472cf4bf8bb86
7
- data.tar.gz: ed06a75b6eabd368501eaf9c7becb34d4d37772e0ed12afa0c9f0d064006b04777bb678107d573b895c475011dbd06fe868033144e7166be1f2a3b2559f4f26f
6
+ metadata.gz: db9bddf036e7faf8ae917a812ca24d57689723825bf7572c9ba7d1322c4d4e2a5cd02e828b4060bbe8a35e8c882591237e165d23057a4d9cb8fe7e49bca7be99
7
+ data.tar.gz: f00b3c0aad2636a4be59d5d3f20e287f4191507a6e6d297f5cbe65d466594fc505fa71d92a449f2dcc33eba35b3bbd0820d3ccd544d65a9f2e6b46570af02481
data/README.md CHANGED
@@ -6,7 +6,7 @@ sailthru-ruby-client
6
6
  For installation instructions, documentation, and examples please visit:
7
7
  [http://getstarted.sailthru.com/developers/api-libraries/ruby](http://getstarted.sailthru.com/developers/api-libraries/ruby)
8
8
 
9
- A simple client library to remotely access the `Sailthru REST API` as per [http://getstarted.sailthru.com/developers/api](http://getstarted.sailthru.com/developers/api)
9
+ A simple client library to remotely access the `Sailthru REST API` as per [http://getstarted.sailthru.com/api](http://getstarted.sailthru.com/developers/api)
10
10
 
11
11
  By default, it will make request in `JSON` format.
12
12
 
data/lib/sailthru.rb CHANGED
@@ -9,11 +9,14 @@ require 'net/http/post/multipart'
9
9
 
10
10
  module Sailthru
11
11
 
12
- Version = VERSION = '1.15'
12
+ Version = VERSION = '2.0.0'
13
13
 
14
14
  class SailthruClientException < Exception
15
15
  end
16
16
 
17
+ class SailthruUnavailableException < Exception
18
+ end
19
+
17
20
  module Helpers
18
21
  # params:
19
22
  # params, Hash
@@ -102,13 +105,14 @@ module Sailthru
102
105
  # api_uri, String
103
106
  #
104
107
  # Instantiate a new client; constructor optionally takes overrides for key/secret/uri and proxy server settings.
105
- def initialize(api_key, secret, api_uri=nil, proxy_host=nil, proxy_port=nil)
108
+ def initialize(api_key, secret, api_uri=nil, proxy_host=nil, proxy_port=nil, opts={})
106
109
  @api_key = api_key
107
110
  @secret = secret
108
111
  @api_uri = if api_uri.nil? then 'https://api.sailthru.com' else api_uri end
109
112
  @proxy_host = proxy_host
110
113
  @proxy_port = proxy_port
111
114
  @verify_ssl = true
115
+ @opts = opts
112
116
  end
113
117
 
114
118
  # params:
@@ -126,7 +130,7 @@ module Sailthru
126
130
  # http://docs.sailthru.com/api/send
127
131
  def send(template_name, email, vars={}, options = {}, schedule_time = nil)
128
132
  warn "[DEPRECATION] `send` is deprecated. Please use `send_email` instead."
129
- send_email(template_name, email, vars={}, options = {}, schedule_time = nil)
133
+ send_email(template_name, email, vars, options, schedule_time)
130
134
  end
131
135
 
132
136
  # params:
@@ -321,7 +325,7 @@ module Sailthru
321
325
  data[:templates] = templates unless templates.empty?
322
326
  self.api_post(:email, data)
323
327
  end
324
-
328
+
325
329
  # params:
326
330
  # new_email, String
327
331
  # old_email, String
@@ -336,7 +340,7 @@ module Sailthru
336
340
  data[:change_email] = old_email
337
341
  self.api_post(:email, data)
338
342
  end
339
-
343
+
340
344
  # params:
341
345
  # template_name, String
342
346
  # returns:
@@ -384,6 +388,7 @@ module Sailthru
384
388
  return false unless params[:action] == :verify
385
389
 
386
390
  sig = params.delete(:sig)
391
+ sig = sig.delete_if {|key, value| key == :controller}
387
392
  return false unless sig == get_signature_hash(params, @secret)
388
393
 
389
394
  _send = self.get_send(params[:send_id])
@@ -406,16 +411,17 @@ module Sailthru
406
411
  if request.post?
407
412
  [:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
408
413
 
409
- return false unless params[:action] == :optout
414
+ return false unless params[:action] == 'optout'
410
415
 
411
416
  sig = params.delete(:sig)
417
+ sig = sig.delete_if {|key, value| key == :controller}
412
418
  return false unless sig == get_signature_hash(params, @secret)
413
419
  return true
414
420
  else
415
421
  return false
416
422
  end
417
423
  end
418
-
424
+
419
425
  # params:
420
426
  # params, Hash
421
427
  # request, String
@@ -425,9 +431,10 @@ module Sailthru
425
431
  if request.post?
426
432
  [:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
427
433
 
428
- return false unless params[:action] == :hardbounce
434
+ return false unless params[:action] == 'hardbounce'
429
435
 
430
436
  sig = params.delete(:sig)
437
+ sig = sig.delete_if {|key, value| key == :controller}
431
438
  return false unless sig == get_signature_hash(params, @secret)
432
439
  return true
433
440
  else
@@ -586,14 +593,14 @@ module Sailthru
586
593
  # params
587
594
  # list, String
588
595
  #
589
- # Get information about a list.
596
+ # Get information about a list.
590
597
  def get_list(list)
591
598
  return api_get(:list, {:list => list})
592
599
  end
593
600
 
594
601
  # params
595
602
  #
596
- # Get information about all lists
603
+ # Get information about all lists
597
604
  def get_lists()
598
605
  return api_get(:list, {})
599
606
  end
@@ -680,42 +687,42 @@ module Sailthru
680
687
  end
681
688
  api_post(:job, data, binary_key)
682
689
  end
683
-
690
+
684
691
  # params
685
692
  # emails, String | Array
686
- # implementation for import_job
687
- def process_import_job(list, emails, report_email = nil, postback_url = nil)
688
- data = {}
693
+ # implementation for import_job
694
+ def process_import_job(list, emails, report_email = nil, postback_url = nil, options = {})
695
+ data = options
689
696
  data['list'] = list
690
697
  data['emails'] = Array(emails).join(',')
691
698
  process_job(:import, data, report_email, postback_url)
692
699
  end
693
700
 
694
701
  # implementation for import job using file upload
695
- def process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil)
696
- data = {}
702
+ def process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil, options = {})
703
+ data = options
697
704
  data['list'] = list
698
705
  data['file'] = file_path
699
706
  process_job(:import, data, report_email, postback_url, 'file')
700
707
  end
701
708
 
702
709
  # implementation for update job using file upload
703
- def process_update_job_from_file(file_path, report_email = nil, postback_url = nil)
704
- data = {}
710
+ def process_update_job_from_file(file_path, report_email = nil, postback_url = nil, options = {})
711
+ data = options
705
712
  data['file'] = file_path
706
713
  process_job(:update, data, report_email, postback_url, 'file')
707
714
  end
708
715
 
709
716
  # implementation for snapshot job
710
- def process_snapshot_job(query = {}, report_email = nil, postback_url = nil)
711
- data = {}
717
+ def process_snapshot_job(query = {}, report_email = nil, postback_url = nil, options = {})
718
+ data = options
712
719
  data['query'] = query
713
720
  process_job(:snapshot, data, report_email, postback_url)
714
721
  end
715
722
 
716
723
  # implementation for export list job
717
- def process_export_list_job(list, report_email = nil, postback_url = nil)
718
- data = {}
724
+ def process_export_list_job(list, report_email = nil, postback_url = nil, options = {})
725
+ data = options
719
726
  data['list'] = list
720
727
  process_job(:export_list_data, data, report_email, postback_url)
721
728
  end
@@ -935,12 +942,18 @@ module Sailthru
935
942
  if _uri.scheme == 'https'
936
943
  http.use_ssl = true
937
944
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @verify_ssl != true # some openSSL client doesn't work without doing this
945
+ http.ssl_timeout = @opts[:http_ssl_timeout] || 5
938
946
  end
947
+ http.open_timeout = @opts[:http_open_timeout] || 5
948
+ http.read_timeout = @opts[:http_read_timeout] || 10
949
+ http.close_on_empty_response = @opts[:http_close_on_empty_response] || true
939
950
 
940
951
  response = http.start {
941
952
  http.request(req)
942
953
  }
943
954
 
955
+ rescue Timeout::Error, Errno::ETIMEDOUT => e
956
+ raise SailthruUnavailableException.new(["Timed out: #{_uri}", e.inspect, e.backtrace].join("\n"));
944
957
  rescue Exception => e
945
958
  raise SailthruClientException.new(["Unable to open stream: #{_uri}", e.inspect, e.backtrace].join("\n"));
946
959
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danest-sailthru-client
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.16'
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Urrutia
@@ -110,9 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.0.6
113
+ rubygems_version: 2.1.3
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: A simple client library to remotely access the Sailthru REST API. Updated
117
117
  with latest git master.
118
118
  test_files: []
119
+ has_rdoc: