sfmc-fuelsdk-ruby 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +90 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.md +13 -0
  7. data/README.md +143 -0
  8. data/Rakefile +1 -0
  9. data/lib/marketingcloudsdk/client.rb +296 -0
  10. data/lib/marketingcloudsdk/http_request.rb +118 -0
  11. data/lib/marketingcloudsdk/objects.rb +757 -0
  12. data/lib/marketingcloudsdk/rest.rb +118 -0
  13. data/lib/marketingcloudsdk/soap.rb +282 -0
  14. data/lib/marketingcloudsdk/targeting.rb +99 -0
  15. data/lib/marketingcloudsdk/utils.rb +47 -0
  16. data/lib/marketingcloudsdk/version.rb +39 -0
  17. data/lib/marketingcloudsdk.rb +74 -0
  18. data/lib/new.rb +1240 -0
  19. data/marketingcloudsdk.gemspec +30 -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 +54 -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 +103 -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 +56 -0
  43. data/samples/sample-sentevent.rb +70 -0
  44. data/samples/sample-subscriber.rb +135 -0
  45. data/samples/sample-triggeredsend.rb +129 -0
  46. data/samples/sample-unsubevent.rb +72 -0
  47. data/samples/sample_helper.rb.template +10 -0
  48. data/spec/client_spec.rb +218 -0
  49. data/spec/default_values_fallback_spec.rb +30 -0
  50. data/spec/helper_funcs_spec.rb +11 -0
  51. data/spec/http_request_spec.rb +61 -0
  52. data/spec/objects_helper_spec.rb +32 -0
  53. data/spec/objects_spec.rb +484 -0
  54. data/spec/rest_spec.rb +48 -0
  55. data/spec/soap_spec.rb +140 -0
  56. data/spec/spec_helper.rb +14 -0
  57. data/spec/targeting_spec.rb +44 -0
  58. metadata +262 -0
@@ -0,0 +1,118 @@
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 'open-uri'
38
+ require 'net/https'
39
+ require 'json'
40
+ require 'marketingcloudsdk/version'
41
+
42
+ module MarketingCloudSDK
43
+
44
+ class HTTPResponse < MarketingCloudSDK::Response
45
+ def initialize raw, client, request
46
+ super raw, client
47
+ @request = request
48
+ end
49
+
50
+ def continue
51
+ rsp = nil
52
+ if more?
53
+ @request['options']['page'] = @results['page'].to_i + 1
54
+ rsp = unpack @client.rest_get(@request['url'], @request['options'])
55
+ else
56
+ puts 'No more data'
57
+ end
58
+
59
+ rsp
60
+ end
61
+
62
+ def [] key
63
+ @results[key]
64
+ end
65
+
66
+ private
67
+ def unpack raw
68
+ @code = raw.code.to_i
69
+ @message = raw.message
70
+ @body = JSON.parse(raw.body) rescue {}
71
+ @results = @body
72
+ @more = ((@results['count'] || @results['totalCount']) > @results['page'] * @results['pageSize']) rescue false
73
+ @success = @message == 'OK'
74
+ end
75
+
76
+ # by default try everything against results
77
+ def method_missing method, *args, &block
78
+ @results.send(method, *args, &block)
79
+ end
80
+ end
81
+
82
+ module HTTPRequest
83
+ request_methods = ['get', 'post', 'patch', 'delete']
84
+ request_methods.each do |method|
85
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
86
+ def #{method}(url, options={}) # def post(url, options)
87
+ request Net::HTTP::#{method.capitalize}, url, options # request Net::HTTP::Post, url, options
88
+ end # end
89
+ EOT
90
+ end
91
+
92
+ def generate_uri(url, params=nil)
93
+ uri = URI.parse(url)
94
+ uri.query = URI.encode_www_form(params) if params
95
+ uri
96
+ end
97
+
98
+ def request(method, url, options={})
99
+ uri = generate_uri url, options['params']
100
+ http = Net::HTTP.new(uri.host, uri.port)
101
+ http.use_ssl = true
102
+
103
+ data = options['data']
104
+ _request = method.new uri.request_uri
105
+ _request.body = data.to_json if data
106
+ _request.content_type = options['content_type'] if options['content_type']
107
+ _request.add_field('User-Agent', 'FuelSDK-Ruby-v' + MarketingCloudSDK::VERSION)
108
+
109
+ # Add Authorization header if we have an access token
110
+ if options['access_token']
111
+ _request.add_field('Authorization', 'Bearer ' + options['access_token'])
112
+ end
113
+
114
+ response = http.request(_request)
115
+ HTTPResponse.new(response, self, :url => url, :options => options)
116
+ end
117
+ end
118
+ end