fuelsdk_json_bump 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +91 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.md +13 -0
  7. data/README.md +127 -0
  8. data/Rakefile +1 -0
  9. data/fuelsdk.gemspec +30 -0
  10. data/lib/fuelsdk.rb +74 -0
  11. data/lib/fuelsdk/client.rb +282 -0
  12. data/lib/fuelsdk/http_request.rb +116 -0
  13. data/lib/fuelsdk/objects.rb +757 -0
  14. data/lib/fuelsdk/rest.rb +122 -0
  15. data/lib/fuelsdk/soap.rb +288 -0
  16. data/lib/fuelsdk/targeting.rb +58 -0
  17. data/lib/fuelsdk/utils.rb +47 -0
  18. data/lib/fuelsdk/version.rb +39 -0
  19. data/lib/new.rb +1240 -0
  20. data/samples/sample-AddSubscriberToList.rb +56 -0
  21. data/samples/sample-CreateAndStartDataExtensionImport.rb +29 -0
  22. data/samples/sample-CreateAndStartListImport.rb +27 -0
  23. data/samples/sample-CreateContentAreas.rb +48 -0
  24. data/samples/sample-CreateDataExtensions.rb +54 -0
  25. data/samples/sample-CreateProfileAttributes.rb +48 -0
  26. data/samples/sample-SendEmailToDataExtension.rb +23 -0
  27. data/samples/sample-SendEmailToList.rb +23 -0
  28. data/samples/sample-SendTriggeredSends.rb +30 -0
  29. data/samples/sample-bounceevent.rb +70 -0
  30. data/samples/sample-campaign.rb +211 -0
  31. data/samples/sample-clickevent.rb +71 -0
  32. data/samples/sample-contentarea.rb +122 -0
  33. data/samples/sample-dataextension.rb +209 -0
  34. data/samples/sample-directverb.rb +55 -0
  35. data/samples/sample-email.rb +122 -0
  36. data/samples/sample-email.senddefinition.rb +134 -0
  37. data/samples/sample-folder.rb +143 -0
  38. data/samples/sample-import.rb +104 -0
  39. data/samples/sample-list.rb +105 -0
  40. data/samples/sample-list.subscriber.rb +97 -0
  41. data/samples/sample-openevent.rb +70 -0
  42. data/samples/sample-profileattribute.rb +57 -0
  43. data/samples/sample-sentevent.rb +70 -0
  44. data/samples/sample-subscriber.rb +136 -0
  45. data/samples/sample-triggeredsend.rb +130 -0
  46. data/samples/sample-unsubevent.rb +72 -0
  47. data/samples/sample_helper.rb.template +8 -0
  48. data/spec/client_spec.rb +200 -0
  49. data/spec/helper_funcs_spec.rb +11 -0
  50. data/spec/http_request_spec.rb +36 -0
  51. data/spec/objects_helper_spec.rb +32 -0
  52. data/spec/objects_spec.rb +484 -0
  53. data/spec/rest_spec.rb +48 -0
  54. data/spec/soap_spec.rb +140 -0
  55. data/spec/spec_helper.rb +14 -0
  56. data/spec/targeting_spec.rb +39 -0
  57. metadata +250 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dd6ce3a6a02009ba21e1feeb3d5f1a57aedc558
4
+ data.tar.gz: 3758e2974637ab674579dc9efeda0ec59d182fcb
5
+ SHA512:
6
+ metadata.gz: 6afef4c8803a2e23168bc20abd94aaab4fa3b4e18a5373df6b7ada6965a7e3f29aa1af96b5a17dac6188be35a8e6103867d2ece46a05a179430ba5956ad3bd5d
7
+ data.tar.gz: 3aeda8508435db5e8dea1645ea0a076f433814e49dbd9fde15cc5d7b0667e2393bda1c9eb4475c34766a117431c3fc02a7a75a7daae2853bce060c9ec431faa1
data/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ sample.rb
20
+ ExactTargetWSDL.xml
21
+ config.yaml
22
+ /objsamples/config.yaml
23
+ /objsamples/AllTest.bat
24
+ samples/sample_helper.rb
25
+ .DS_STORE
26
+ gengem.bat
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fuelsdk (0.0.5)
5
+ json (~> 1.7.0)
6
+ jwt (~> 0.1.6)
7
+ savon (= 2.2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ akami (1.2.0)
13
+ gyoku (>= 0.4.0)
14
+ nokogiri (>= 1.4.0)
15
+ builder (3.2.2)
16
+ coderay (1.0.9)
17
+ diff-lcs (1.2.4)
18
+ ffi (1.9.0-x86-mingw32)
19
+ formatador (0.2.4)
20
+ guard (1.8.2)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 1.0.0)
23
+ lumberjack (>= 1.0.2)
24
+ pry (>= 0.9.10)
25
+ thor (>= 0.14.6)
26
+ guard-rspec (3.0.2)
27
+ guard (>= 1.8)
28
+ rspec (~> 2.13)
29
+ gyoku (1.0.0)
30
+ builder (>= 2.1.2)
31
+ httpi (2.0.2)
32
+ rack
33
+ json (1.7.7)
34
+ jwt (0.1.8)
35
+ multi_json (>= 1.5)
36
+ listen (1.3.0)
37
+ rb-fsevent (>= 0.9.3)
38
+ rb-inotify (>= 0.9)
39
+ rb-kqueue (>= 0.2)
40
+ lumberjack (1.0.4)
41
+ method_source (0.8.2)
42
+ mini_portile (0.5.1)
43
+ multi_json (1.7.9)
44
+ nokogiri (1.6.0-x86-mingw32)
45
+ mini_portile (~> 0.5.0)
46
+ nori (2.1.0)
47
+ pry (0.9.12.2-x86-mingw32)
48
+ coderay (~> 1.0.5)
49
+ method_source (~> 0.8)
50
+ slop (~> 3.4)
51
+ win32console (~> 1.3)
52
+ rack (1.5.2)
53
+ rake (10.1.0)
54
+ rb-fsevent (0.9.3)
55
+ rb-inotify (0.9.1)
56
+ ffi (>= 0.5.0)
57
+ rb-kqueue (0.2.0)
58
+ ffi (>= 0.5.0)
59
+ rspec (2.14.1)
60
+ rspec-core (~> 2.14.0)
61
+ rspec-expectations (~> 2.14.0)
62
+ rspec-mocks (~> 2.14.0)
63
+ rspec-core (2.14.5)
64
+ rspec-expectations (2.14.2)
65
+ diff-lcs (>= 1.1.3, < 2.0)
66
+ rspec-mocks (2.14.3)
67
+ savon (2.2.0)
68
+ akami (~> 1.2.0)
69
+ builder (>= 2.1.2)
70
+ gyoku (~> 1.0.0)
71
+ httpi (~> 2.0.2)
72
+ nokogiri (>= 1.4.0)
73
+ nori (~> 2.1.0)
74
+ wasabi (~> 3.1.0)
75
+ slop (3.4.6)
76
+ thor (0.18.1)
77
+ wasabi (3.1.0)
78
+ httpi (~> 2.0)
79
+ nokogiri (>= 1.4.0)
80
+ win32console (1.3.2-x86-mingw32)
81
+
82
+ PLATFORMS
83
+ x86-mingw32
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 1.3)
87
+ fuelsdk!
88
+ guard
89
+ guard-rspec
90
+ rake
91
+ rspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ guard 'rspec' do
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ end
8
+
data/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013 ExactTarget, Inc.
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ FuelSDK-Ruby
2
+ ============
3
+
4
+ ExactTarget Fuel SDK for Ruby
5
+
6
+ ## Overview ##
7
+ The Fuel SDK for Ruby provides easy access to ExactTarget's Fuel API Family services, including a collection of REST APIs and a SOAP API. These APIs provide access to ExactTarget functionality via common collection types such as array/hash.
8
+
9
+ ## New Features in Version .9 ##
10
+ - **Streamlined Folder Support**: All objects that support folders within the UI now have a standardized property called folderId.
11
+ - **Interaction Support**: Now supports Import and Email::SendDefinition objects .
12
+ - **Profile Attribute Support**: Added the ability to manage profile attributes through the ProfileAttribute object.
13
+ - **Support for single request to Add/Update**:A single request can be made which will create the object if one doesn't already or update one if it does. This works for Subscriber, DataExtension::Row, and List objects using the Put method.
14
+ - **Tracking Events Batching Support**: By default, all tracking event types will only pull new data since the last time a request was made using the same filter. If you would like to override this functionality to pull all data, simply set the GetSinceLastBatch property to false.
15
+ - **Automatic Asset Organization for Hub Apps**: Applications that authenticate by providing a JWT will automatically have all created assets placed into a folder based on the HubExchange app's name.
16
+ - **Greater Flexibility for Authentication**:Yaml config file is no longer required in order to define the authentication parameters. They are now required inputs when instantiating the Client class so they can be stored anywhere.
17
+
18
+ ## Migrating from old version ##
19
+ - FuelSDK is now a Gem. All references to require 'ET_Client.rb' will need to be replaced with a reference to the fuelsdk gem.
20
+ - Config.yaml is no longer used. ClientID/ClientSecret will now need to be passed when instantiating the Client class.
21
+ - Previous versions of the Fuel SDK exposed objects with the prefix "ET_". For backwards compatibility you can still access objects this way.
22
+ Subscriber can be accessed using FuelSDK::Subscriber or ET_Subscriber.
23
+
24
+ ## Requirements ##
25
+ - Ruby Version 1.9.3
26
+ - Savon 2.2.0
27
+
28
+ ## Getting Started ##
29
+ Build the gem from the source
30
+
31
+ ```ruby
32
+ gem build fuelsdk.gemspec
33
+ ```
34
+
35
+ Install the newly built gem
36
+
37
+ ```ruby
38
+ gem install fuelsdk-0.0.5.gem
39
+ ```
40
+
41
+ If you have not registered your application or you need to lookup your Application Key or Application Signature values, please go to App Center at [Code@: ExactTarget's Developer Community](http://code.exacttarget.com/appcenter "Code@ App Center").
42
+
43
+
44
+ ## Example Request ##
45
+
46
+ Add a require statement to reference the Fuel SDK's functionality:
47
+ > require 'fuelsdk'
48
+
49
+ Next, create an instance of the Client class:
50
+ > myClient = FuelSDK::Client.new {'client' => { 'id' => CLIENTID, 'secret' => SECRET }}
51
+
52
+ Create an instance of the object type we want to work with:
53
+ > list = FuelSDK::List.new
54
+
55
+ Associate the Client to the object using the client property:
56
+ > list.client = myClient
57
+
58
+ Utilize one of the List methods:
59
+ > response = list.get
60
+
61
+ Print out the results for viewing
62
+ > p response
63
+
64
+ **Example Output:**
65
+
66
+ <pre>
67
+ <FuelSDK::SoapResponse:0x007fb86abcf190
68
+ @body= {:retrieve_response_msg=> {:overall_status=>"OK", :request_id=>"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", :results=>..}
69
+ @code= 200,
70
+ @message= 'OK',
71
+ @request_id="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
72
+ @results=
73
+ [{:client=>{:id=>"xxxx"},
74
+ :partner_key=>nil,
75
+ :created_date=>
76
+ #<DateTime: 2013-05-30T23:02:00+00:00 ((2456443j,82920s,0n),+0s,2299161j)>,
77
+ :id=>"xxxx",
78
+ :object_id=>nil,
79
+ :email_address=>"xxxx",
80
+ :attributes=>
81
+ [{:name=>"Full Name", :value=>"Justin Barber"},
82
+ {:name=>"Gender", :value=>nil},
83
+ {:name=>"Email Address", :value=>"xxx"},
84
+ {:name=>"User Defined", :value=>"02/02/1982"}],
85
+ :subscriber_key=>"xxxx",
86
+ :status=>"Active",
87
+ :email_type_preference=>"HTML",
88
+ :"@xsi:type"=>"Subscriber"},
89
+ @success=true>
90
+ </pre>
91
+
92
+ ## Client Class ##
93
+
94
+ The Client class takes care of many of the required steps when accessing ExactTarget's API, including retrieving appropriate access tokens, handling token state for managing refresh, and determining the appropriate endpoints for API requests. In order to leverage the advantages this class provides, use a single instance of this class for an entire session. Do not instantiate a new Client object for each request made.
95
+
96
+ Client class accepts multiple parameters
97
+
98
+ **Parameters** - Allows for passing authentication information for use with SSO with a JWT or for passing ClientID/ClientSecret:
99
+
100
+ Example passing ClientID/ClientSecret:
101
+ > myclient = FuelSDK::Client.new({'client' => {'id' => 'exampleID','secret' => 'exampleSecret'}})
102
+
103
+ Example passing ClientID/ClientSecret/AppSignature/JWT:
104
+ > myclient = FuelSDK::Client.new({'client' => {'id' => 'exampleID','secret' => 'exampleSecret', 'signature'=>'examplesig'}, 'jwt'=>'exampleJWT'})
105
+
106
+ **Debug** - If 2nd parameter for debug is set to true, all API requests that the Fuel SDK is making behind the scenes will be logged. This option should only be set to true in order to troubleshoot during the development process and should never be used in a production scenario.
107
+ > myclient = FuelSDK::Client.new auth, true <br>
108
+
109
+
110
+ ## Responses ##
111
+ All methods on Fuel SDK objects return a generic object that follows the same structure, regardless of the type of call. This object contains a common set of properties used to display details about the request.
112
+
113
+ - success?: Boolean value that indicates if the call was successful
114
+ - code: HTTP Error Code (will always be 200 for SOAP requests)
115
+ - message: Text values containing more details in the event of an error
116
+ - results: Collection containing the details unique to the method called.
117
+ - more? - Boolean value that indicates on Get requests if more data is available.
118
+
119
+
120
+ ## Samples ##
121
+ Find more sample files that illustrate using all of the available functions for ExactTarget objects exposed through the API in the samples directory.
122
+
123
+
124
+
125
+
126
+
127
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/fuelsdk.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fuelsdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fuelsdk_json_bump"
8
+ spec.version = FuelSDK::VERSION
9
+ spec.authors = ["MichaelAllenClark", "barberj", "kellyjandrews"]
10
+ spec.email = ["code@exacttarget.com"]
11
+ spec.description = %q{API wrapper for SOAP and REST API with Salesforce Marketing Cloud (ExactTarget)}
12
+ spec.summary = %q{Fuel Client Library for Ruby}
13
+ spec.homepage = "https://github.com/ExactTarget/FuelSDK-Ruby"
14
+ spec.license = ""
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(samples|test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_development_dependency "rspec", '~> 0'
24
+ spec.add_development_dependency "guard", '~> 0'
25
+ spec.add_development_dependency "guard-rspec", '~> 0'
26
+
27
+ spec.add_dependency "savon", "2.2.0"
28
+ spec.add_dependency "json", "~> 1.8"
29
+ spec.add_dependency "jwt", "~> 0.1.6"
30
+ end
data/lib/fuelsdk.rb ADDED
@@ -0,0 +1,74 @@
1
+ =begin
2
+ Copyright (c) 2013 ExactTarget, Inc.
3
+
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
7
+
8
+ following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
11
+
12
+ following disclaimer.
13
+
14
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
15
+
16
+ following disclaimer in the documentation and/or other materials provided with the distribution.
17
+
18
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
19
+
20
+ products derived from this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
+
24
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+
26
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+
28
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
+
32
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
33
+
34
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+ =end
36
+
37
+ require "fuelsdk/version"
38
+
39
+ require 'rubygems'
40
+ require 'date'
41
+ require 'jwt'
42
+
43
+ module FuelSDK
44
+ require 'fuelsdk/utils'
45
+ autoload :HTTPRequest, 'fuelsdk/http_request'
46
+ autoload :Targeting, 'fuelsdk/targeting'
47
+ autoload :Soap, 'fuelsdk/soap'
48
+ autoload :Rest, 'fuelsdk/rest'
49
+ require 'fuelsdk/client'
50
+ require 'fuelsdk/objects'
51
+ end
52
+
53
+ # backwards compatability
54
+ ET_Client = FuelSDK::Client
55
+ ET_BounceEvent = FuelSDK::BounceEvent
56
+ ET_ClickEvent = FuelSDK::ClickEvent
57
+ ET_ContentArea = FuelSDK::ContentArea
58
+ ET_DataExtension = FuelSDK::DataExtension
59
+ ET_DataFolder = FuelSDK::DataFolder
60
+ ET_Folder = FuelSDK::Folder
61
+ ET_Email = FuelSDK::Email
62
+ ET_List = FuelSDK::List
63
+ ET_OpenEvent = FuelSDK::OpenEvent
64
+ ET_SentEvent = FuelSDK::SentEvent
65
+ ET_Subscriber = FuelSDK::Subscriber
66
+ ET_UnsubEvent = FuelSDK::UnsubEvent
67
+ ET_TriggeredSend = FuelSDK::TriggeredSend
68
+ ET_Campaign = FuelSDK::Campaign
69
+ ET_Get = FuelSDK::Get
70
+ ET_Post = FuelSDK::Post
71
+ ET_Delete = FuelSDK::Delete
72
+ ET_Patch = FuelSDK::Patch
73
+ ET_ProfileAttribute = FuelSDK::ProfileAttribute
74
+ ET_Import = FuelSDK::Import
@@ -0,0 +1,282 @@
1
+ =begin
2
+ Copyright (c) 2013 ExactTarget, Inc.
3
+
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
7
+
8
+ following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
11
+
12
+ following disclaimer.
13
+
14
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
15
+
16
+ following disclaimer in the documentation and/or other materials provided with the distribution.
17
+
18
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
19
+
20
+ products derived from this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
+
24
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+
26
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+
28
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
+
32
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
33
+
34
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+
36
+ =end
37
+
38
+ require 'securerandom'
39
+ module FuelSDK
40
+ class Response
41
+ # not doing accessor so user, can't update these values from response.
42
+ # You will see in the code some of these
43
+ # items are being updated via back doors and such.
44
+ attr_reader :code, :message, :results, :request_id, :body, :raw
45
+
46
+ # some defaults
47
+ def success
48
+ @success ||= false
49
+ end
50
+ alias :success? :success
51
+ alias :status :success # backward compatibility
52
+
53
+ def more
54
+ @more ||= false
55
+ end
56
+ alias :more? :more
57
+
58
+ def initialize raw, client
59
+ @client = client # keep connection with client in case we request more
60
+ @results = []
61
+ @raw = raw
62
+ unpack raw
63
+ rescue => ex # all else fails return raw
64
+ puts ex.message
65
+ raw
66
+ end
67
+
68
+ def continue
69
+ raise NotImplementedError
70
+ end
71
+
72
+ private
73
+ def unpack raw
74
+ raise NotImplementedError
75
+ end
76
+ end
77
+
78
+ class Client
79
+ attr_accessor :debug, :access_token, :auth_token, :internal_token, :refresh_token,
80
+ :id, :secret, :signature, :package_name, :package_folders, :parent_folders, :auth_token_expiration
81
+
82
+ include FuelSDK::Soap
83
+ include FuelSDK::Rest
84
+
85
+ def jwt= encoded_jwt
86
+ raise 'Require app signature to decode JWT' unless self.signature
87
+ decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)
88
+
89
+ self.auth_token = decoded_jwt['request']['user']['oauthToken']
90
+ self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
91
+ self.refresh_token = decoded_jwt['request']['user']['refreshToken']
92
+ self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
93
+ self.package_name = decoded_jwt['request']['application']['package']
94
+ end
95
+
96
+ def initialize(params={}, debug=false)
97
+ @refresh_mutex = Mutex.new
98
+ self.debug = debug
99
+ client_config = params['client']
100
+ if client_config
101
+ self.id = client_config["id"]
102
+ self.secret = client_config["secret"]
103
+ self.signature = client_config["signature"]
104
+ end
105
+
106
+ self.jwt = params['jwt'] if params['jwt']
107
+ self.refresh_token = params['refresh_token'] if params['refresh_token']
108
+
109
+ self.wsdl = params["defaultwsdl"] if params["defaultwsdl"]
110
+ end
111
+
112
+ def refresh force=false
113
+ @refresh_mutex.synchronize do
114
+ raise 'Require Client Id and Client Secret to refresh tokens' unless (id && secret)
115
+ #If we don't already have a token or the token expires within 5 min(300 seconds)
116
+ if (self.access_token.nil? || Time.new + 300 > self.auth_token_expiration || force) then
117
+ payload = Hash.new.tap do |h|
118
+ h['clientId']= id
119
+ h['clientSecret'] = secret
120
+ h['refreshToken'] = refresh_token if refresh_token
121
+ h['accessType'] = 'offline'
122
+ end
123
+
124
+ options = Hash.new.tap do |h|
125
+ h['data'] = payload
126
+ h['content_type'] = 'application/json'
127
+ h['params'] = {'legacy' => 1}
128
+ end
129
+ response = post("https://auth.exacttargetapis.com/v1/requestToken", options)
130
+ raise "Unable to refresh token: #{response['message']}" unless response.has_key?('accessToken')
131
+
132
+ self.access_token = response['accessToken']
133
+ self.internal_token = response['legacyToken']
134
+ self.auth_token_expiration = Time.new + response['expiresIn']
135
+ self.refresh_token = response['refreshToken'] if response.has_key?("refreshToken")
136
+ return true
137
+ else
138
+ return false
139
+ end
140
+ end
141
+ end
142
+
143
+ def refresh!
144
+ refresh true
145
+ end
146
+
147
+ def AddSubscriberToList(email, ids, subscriber_key = nil)
148
+ s = FuelSDK::Subscriber.new
149
+ s.client = self
150
+ lists = ids.collect{|id| {'ID' => id}}
151
+ s.properties = {"EmailAddress" => email, "Lists" => lists}
152
+ p s.properties
153
+ s.properties['SubscriberKey'] = subscriber_key if subscriber_key
154
+
155
+ # Try to add the subscriber
156
+ if(rsp = s.post and rsp.results.first[:error_code] == '12014')
157
+ # subscriber already exists we need to update.
158
+ rsp = s.patch
159
+ end
160
+ rsp
161
+ end
162
+
163
+ def CreateDataExtensions(definitions)
164
+ de = FuelSDK::DataExtension.new
165
+ de.client = self
166
+ de.properties = definitions
167
+ de.post
168
+ end
169
+ def SendTriggeredSends(arrayOfTriggeredRecords)
170
+ sendTS = ET_TriggeredSend.new
171
+ sendTS.authStub = self
172
+
173
+ sendTS.properties = arrayOfTriggeredRecords
174
+ sendResponse = sendTS.send
175
+
176
+ return sendResponse
177
+ end
178
+ def SendEmailToList(emailID, listID, sendClassficationCustomerKey)
179
+ email = ET_Email::SendDefinition.new
180
+ email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
181
+ email.properties["SendClassification"] = {"CustomerKey"=>sendClassficationCustomerKey}
182
+ email.properties["SendDefinitionList"] = {"List"=> {"ID"=>listID}, "DataSourceTypeID"=>"List"}
183
+ email.properties["Email"] = {"ID"=>emailID}
184
+ email.authStub = self
185
+ result = email.post
186
+ if result.status then
187
+ sendresult = email.send
188
+ if sendresult.status then
189
+ deleteresult = email.delete
190
+ return sendresult
191
+ else
192
+ raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
193
+ end
194
+ else
195
+ raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
196
+ end
197
+ end
198
+
199
+ def SendEmailToDataExtension(emailID, sendableDataExtensionCustomerKey, sendClassficationCustomerKey)
200
+ email = ET_Email::SendDefinition.new
201
+ email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
202
+ email.properties["SendClassification"] = {"CustomerKey"=> sendClassficationCustomerKey}
203
+ email.properties["SendDefinitionList"] = {"CustomerKey"=> sendableDataExtensionCustomerKey, "DataSourceTypeID"=>"CustomObject"}
204
+ email.properties["Email"] = {"ID"=>emailID}
205
+ email.authStub = self
206
+ result = email.post
207
+ if result.status then
208
+ sendresult = email.send
209
+ if sendresult.status then
210
+ deleteresult = email.delete
211
+ return sendresult
212
+ else
213
+ raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
214
+ end
215
+ else
216
+ raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
217
+ end
218
+ end
219
+ def CreateAndStartListImport(listId,fileName)
220
+ import = ET_Import.new
221
+ import.authStub = self
222
+ import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
223
+ import.properties["CustomerKey"] = SecureRandom.uuid
224
+ import.properties["Description"] = "SDK Generated Import"
225
+ import.properties["AllowErrors"] = "true"
226
+ import.properties["DestinationObject"] = {"ID"=>listId}
227
+ import.properties["FieldMappingType"] = "InferFromColumnHeadings"
228
+ import.properties["FileSpec"] = fileName
229
+ import.properties["FileType"] = "CSV"
230
+ import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
231
+ import.properties["UpdateType"] = "AddAndUpdate"
232
+ result = import.post
233
+
234
+ if result.status then
235
+ return import.start
236
+ else
237
+ raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
238
+ end
239
+ end
240
+
241
+ def CreateAndStartDataExtensionImport(dataExtensionCustomerKey, fileName, overwrite)
242
+ import = ET_Import.new
243
+ import.authStub = self
244
+ import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
245
+ import.properties["CustomerKey"] = SecureRandom.uuid
246
+ import.properties["Description"] = "SDK Generated Import"
247
+ import.properties["AllowErrors"] = "true"
248
+ import.properties["DestinationObject"] = {"ObjectID"=>dataExtensionCustomerKey}
249
+ import.properties["FieldMappingType"] = "InferFromColumnHeadings"
250
+ import.properties["FileSpec"] = fileName
251
+ import.properties["FileType"] = "CSV"
252
+ import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
253
+ if overwrite then
254
+ import.properties["UpdateType"] = "Overwrite"
255
+ else
256
+ import.properties["UpdateType"] = "AddAndUpdate"
257
+ end
258
+ result = import.post
259
+
260
+ if result.status then
261
+ return import.start
262
+ else
263
+ raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
264
+ end
265
+ end
266
+
267
+ def CreateProfileAttributes(allAttributes)
268
+ attrs = ET_ProfileAttribute.new
269
+ attrs.authStub = self
270
+ attrs.properties = allAttributes
271
+ return attrs.post
272
+ end
273
+
274
+ def CreateContentAreas(arrayOfContentAreas)
275
+ postC = ET_ContentArea.new
276
+ postC.authStub = self
277
+ postC.properties = arrayOfContentAreas
278
+ sendResponse = postC.post
279
+ return sendResponse
280
+ end
281
+ end
282
+ end