sailthru-client-notest 1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +1 -1
  2. data/lib/sailthru.rb +93 -3
  3. metadata +4 -3
data/README.md CHANGED
@@ -4,7 +4,7 @@ sailthru-ruby-client
4
4
  For installation instructions, documentation, and examples please visit:
5
5
  [http://getstarted.sailthru.com/developers/api-libraries/ruby](http://getstarted.sailthru.com/developers/api-libraries/ruby)
6
6
 
7
- 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)
7
+ A simple client library to remotely access the `Sailthru REST API` as per [http://getstarted.sailthru.com/api](http://getstarted.sailthru.com/developers/api)
8
8
 
9
9
  By default, it will make request in `JSON` format.
10
10
 
@@ -9,7 +9,7 @@ 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
@@ -406,7 +406,26 @@ module Sailthru
406
406
  if request.post?
407
407
  [:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
408
408
 
409
- return false unless params[:action] == :optout
409
+ return false unless params[:action] == 'optout'
410
+
411
+ sig = params.delete(:sig)
412
+ return false unless sig == get_signature_hash(params, @secret)
413
+ return true
414
+ else
415
+ return false
416
+ end
417
+ end
418
+
419
+ # params:
420
+ # params, Hash
421
+ # request, String
422
+ # returns:
423
+ # TrueClass or FalseClass, Returns true if the incoming request is an authenticated hardbounce post.
424
+ def receive_hardbounce_post(params, request)
425
+ if request.post?
426
+ [:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
427
+
428
+ return false unless params[:action] == 'hardbounce'
410
429
 
411
430
  sig = params.delete(:sig)
412
431
  return false unless sig == get_signature_hash(params, @secret)
@@ -530,6 +549,7 @@ module Sailthru
530
549
  # date, String
531
550
  # tags, Array or Comma separated string
532
551
  # vars, Hash
552
+ # options, Hash
533
553
  #
534
554
  # Push a new piece of content to Sailthru, triggering any applicable alerts.
535
555
  # http://docs.sailthru.com/api/content
@@ -716,6 +736,76 @@ module Sailthru
716
736
  api_post(:user, data)
717
737
  end
718
738
 
739
+ # params
740
+ # Get an existing trigger
741
+ def get_triggers()
742
+ api_get(:trigger, {})
743
+ end
744
+
745
+ # params
746
+ # template, String
747
+ # trigger_id, String
748
+ # Get an existing trigger
749
+ def get_trigger_by_template(template, trigger_id = nil)
750
+ data = {}
751
+ data['template'] = template
752
+ if trigger_id != nil then data['trigger_id'] = trigger_id end
753
+ api_get(:trigger, data)
754
+ end
755
+
756
+ # params
757
+ # event, String
758
+ # Get an existing trigger
759
+ def get_trigger_by_event(event)
760
+ data = {}
761
+ data['event'] = event
762
+ api_get(:trigger, data)
763
+ end
764
+
765
+ # params
766
+ # template, String
767
+ # time, String
768
+ # time_unit, String
769
+ # event, String
770
+ # zephyr, String
771
+ # Create or update a trigger
772
+ def post_template_trigger(template, time, time_unit, event, zephyr)
773
+ data = {}
774
+ data['template'] = template
775
+ data['time'] = time
776
+ data['time_unit'] = time_unit
777
+ data['event'] = event
778
+ data['zephyr'] = zephyr
779
+ api_post(:trigger, data)
780
+ end
781
+
782
+ # params
783
+ # template, String
784
+ # time, String
785
+ # time_unit, String
786
+ # zephyr, String
787
+ # Create or update a trigger
788
+ def post_event_trigger(event, time, time_unit, zephyr)
789
+ data = {}
790
+ data['time'] = time
791
+ data['time_unit'] = time_unit
792
+ data['event'] = event
793
+ data['zephyr'] = zephyr
794
+ api_post(:trigger, data)
795
+ end
796
+
797
+ # params
798
+ # id, String
799
+ # event, String
800
+ # options, Hash (Can contain vars, Hash and/or key)
801
+ # Notify Sailthru of an Event
802
+ def post_event(id, event, options = {})
803
+ data = options
804
+ data['id'] = id
805
+ data['event'] = event
806
+ api_post(:event, data)
807
+ end
808
+
719
809
  # Perform API GET request
720
810
  def api_get(action, data)
721
811
  api_request(action, data, 'GET')
@@ -841,7 +931,7 @@ module Sailthru
841
931
  }
842
932
 
843
933
  rescue Exception => e
844
- raise SailthruClientException.new("Unable to open stream: #{_uri}\n#{e}");
934
+ raise SailthruClientException.new(["Unable to open stream: #{_uri}", e.inspect, e.backtrace].join("\n"));
845
935
  end
846
936
 
847
937
  if response.body
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sailthru-client-notest
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Prajwal Tuladhar
9
+ - Dennis Yu
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-07-24 00:00:00.000000000 Z
13
+ date: 2013-09-06 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
@@ -44,7 +45,7 @@ dependencies:
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
47
  description:
47
- email: dyu@sailthru.com
48
+ email: praj@sailthru.com
48
49
  executables: []
49
50
  extensions: []
50
51
  extra_rdoc_files: