gooddata_eloqua 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 833a93676772e7e93b3745dd7f9e7ba9a9633f91
4
- data.tar.gz: 6e1e320b6553360d9a1d0f14606cbe36d90b2284
3
+ metadata.gz: b5b572c9c0cbddccb6666c0d0f2319f4b8fff155
4
+ data.tar.gz: 059040688e5d8328c6f10ea73031b3f1b28a8a9c
5
5
  SHA512:
6
- metadata.gz: 4847d22bd39cbfbf285039a989753a769d9c70fbf346bbd469a8eead823405fe1b2b5febb1044d0404711f91ec8f9eee611a2833a6c6ba3aa00977fe41b592b2
7
- data.tar.gz: 0fa933a67e09c8353b9ae74592087e61bbad434f4b29ddc01f891ed3a9102e01b7fe4f629fddc2f3681f875f362571ca8c6bb5983665f4b79d91a6d9f2e54d50
6
+ metadata.gz: 24e1bef63bc48c72174727b5fba6464c1f26d487f23ce730b66d516f05a6436bb76a7bb3c3054dbc2601805705575742e57bc852190a2aa16ca3e4f7e854af43
7
+ data.tar.gz: 158ff24551b0b092e29ef9067c1b129234c3a5e89e8932afca3a4364ac0709fcc5d8607e2da688d34ad9a279721d24f0fa57e2620966f888d3b2bcf7a604869d
@@ -0,0 +1,138 @@
1
+ class S3Helper
2
+
3
+ attr_accessor :bucket_name
4
+ attr_accessor :bucket
5
+
6
+ def initialize config = {}
7
+
8
+ public_key = config[:public_key]
9
+ private_key = config[:private_key] || config[:secret_key]
10
+ self.bucket_name = config[:bucket] || 'eloqua_connector'
11
+
12
+ AWS.config(:access_key_id => public_key, :secret_access_key => private_key)
13
+
14
+ @s3 = AWS::S3::Client.new(region: 'us-east-1')
15
+
16
+ bucket_exists = @s3.list_buckets.include? @bucket_name
17
+
18
+ if bucket_exists == false
19
+ bucket = @s3.create_bucket(:bucket_name => @bucket_name)
20
+ else
21
+ bucket = bucket_exists
22
+ end
23
+
24
+ raise 'ERROR! :public_key, :private_key must be passed for configuration.' unless public_key && private_key
25
+
26
+ end
27
+
28
+ def test
29
+ begin
30
+ self.exists? 'tmp_dumb_file'
31
+ puts "#{Time.now} => SETUP: Connect to AWS S3 Bucket:#{self.bucket_name}...success!"
32
+ true
33
+ rescue
34
+ false
35
+ end
36
+ end
37
+
38
+ def upload file
39
+ puts "#{Time.now} => Uploading:S3_Bucket#{@bucket_name}: \"#{file}\""
40
+ resp = @s3.put_object(
41
+ data: IO.read(file),
42
+ bucket_name: @bucket_name,
43
+ key: file
44
+ )
45
+ end
46
+
47
+ def download file
48
+ begin
49
+ puts "#{Time.now} => Downloading:S3_Bucket#{@bucket_name}: \"#{file}\""
50
+ resp = @s3.get_object(bucket_name: @bucket_name, key:file)
51
+ resp[:data]
52
+ rescue
53
+ nil
54
+ end
55
+ end
56
+
57
+ def get_config config = {}
58
+
59
+ file = config[:file] || 'eloqua_connector_config.json'
60
+
61
+ if self.exists? file
62
+ json = JSON.parse(self.download(file), :symbolize_names => true)
63
+
64
+ File.open(file,'w'){ |f| JSON.dump(json, f) }
65
+
66
+ self.download(file)
67
+
68
+ json
69
+
70
+ else
71
+
72
+ json = {
73
+ :id => SecureRandom.uuid,
74
+ :updated => Time.now.to_s,
75
+ :initial_load_get_multiple => false,
76
+ :initial_load_get_changes => false
77
+ }
78
+
79
+ File.open(file,'w'){ |f| JSON.dump(json, f) }
80
+
81
+ self.upload(file)
82
+
83
+ json
84
+
85
+ end
86
+
87
+ end
88
+
89
+ def set_config config = {}
90
+
91
+ if config[:file]
92
+ file = config.delete(:file)
93
+ else
94
+ file = 'eloqua_connector_config.json'
95
+ end
96
+
97
+ if self.exists? file
98
+ json = JSON.parse(self.download(file), :symbolize_names => true)
99
+ else
100
+ json = Hash.new
101
+ end
102
+
103
+ new_json = json.merge(config)
104
+
105
+ new_json[:updated] = Time.now.to_s
106
+
107
+ File.open(file,'w'){ |f| JSON.dump(new_json, f) }
108
+
109
+ self.upload(file)
110
+
111
+ new_json
112
+
113
+ end
114
+
115
+ def latest_config
116
+ if File.exists?('eloqua_connector_config.json')
117
+ File.delete('eloqua_connector_config.json')
118
+ end
119
+ self.download('eloqua_connector_config.json')
120
+ end
121
+
122
+ def exists? file
123
+ begin
124
+ @s3.get_object(bucket_name: @bucket_name, key:file)
125
+ true
126
+ rescue AWS::S3::Errors::NoSuchKey
127
+ false
128
+ end
129
+ end
130
+
131
+ alias :include? :exists?
132
+
133
+ def delete file
134
+ @s3.delete_object(bucket_name: @bucket_name, key: file)
135
+ end
136
+
137
+
138
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gooddata_eloqua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McConlogue
@@ -90,6 +90,7 @@ files:
90
90
  - lib/gooddata_eloqua/client.rb
91
91
  - lib/gooddata_eloqua/helpers/pool.rb
92
92
  - lib/gooddata_eloqua/helpers/request.rb
93
+ - lib/gooddata_eloqua/helpers/s3.rb
93
94
  - lib/gooddata_eloqua/models/campaigns.rb
94
95
  - lib/gooddata_eloqua/models/contacts.rb
95
96
  - lib/gooddata_eloqua/models/emails.rb