ebx_deliver 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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDVhYzJlMzdkOWYzMDFiZDEzM2MwN2RmMGU3MzJkNGI2YTc4MzIxYw==
4
+ YmQ1ODEyZTM5ZDUzNGIwZmZhNTNjYzM3YTUxOTYzNTFhNDdiZDYyOQ==
5
5
  data.tar.gz: !binary |-
6
- ODc4ODQwNTdhNjMxNWY3NDJmNWNkNDAxNDU1NzNlOTFkZWM3Mjg1Zg==
6
+ NWU2ZTNkOGM0Y2FkM2M2ZmYyMzEzNzQ1MDAxOWQ4NDlhMzZkYzY2OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTk4ZjdlNjJkNzUyNWU1NWQzOTA5MmNhMjVlMDc2YjQzYTBkM2NjN2FlNWQ3
10
- NmU5NTUwNzg0ZDY3YmM1YmM5MDU3YTVjODhiNGZiNGM1ZDkyMjNhNDY5YzFk
11
- ZWQyY2I0NTUzOWQ2NzQxNzU3ZjJjNmI2YmJkYWYxNzVkNjUwOGI=
9
+ NjBkYjY4MGVjNGJiMDc5MmJjZTFlMzI4MjlmYWMyNjE0MGFkN2JkYTgwM2Y1
10
+ ZDc0YzA4YzhlZmUwMjcxOTgzNzU0MmJlYWI3MzA3ZDMxM2Y5Mzk4ZDYyNWRm
11
+ MWE1MGU4Y2U3NDBkNjU0ZGEwN2VjNDFhMWZhYTcyMjY1NGQ5ODE=
12
12
  data.tar.gz: !binary |-
13
- YzdhOGM2ODRmZDgxYjAwMjg3OGNmZmQyY2Y1MmJlYjFkYjYyYTgyYTFiYWI0
14
- YWYwYjIwNzkzODZlZGExZTIzNmY2YzlmZmRkYWRkZmUwNTQ1Y2E4NmJiMTFj
15
- OGJkYjg3ZmFjODkwN2Y5MTIyMGM2MTEyNjdiN2VlNTc3MTY2MmE=
13
+ ZjZkYzg0MzcwNjM4ZTc0YzE3ZmE4OGYyZDhkMjY3OGUwYTZmODU2ZmQ0ZmI2
14
+ ZGFjZjMwNTkzMTAyZDMzYTU2NzcxMmZlNTc3ZjFmNjI5MDVmN2QxMjhhZWY2
15
+ ZWU2MWZlZmMwOTVlZmFhOWMwMDc4MjA5MDk4OGRiMTU5MjBlYmI=
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  ebx_deliver (0.0.1)
5
5
  aws-sdk (~> 1.17.0)
6
+ daemons (~> 1.1.9)
6
7
  dynamoid (~> 0.7.1)
7
8
  pry (> 0)
8
9
 
@@ -25,6 +26,7 @@ GEM
25
26
  uuidtools (~> 2.1)
26
27
  builder (3.1.4)
27
28
  coderay (1.0.9)
29
+ daemons (1.1.9)
28
30
  dynamoid (0.7.1)
29
31
  activemodel
30
32
  aws-sdk
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'daemons'
4
+ require 'ebx_deliver'
5
+
6
+ Daemons.run_proc('ebx_db_listen.rb') do
7
+ reader = EbxDeliver::AwsSqsReader.new
8
+ reader.connect!
9
+ end
@@ -14,13 +14,14 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = []
17
+ spec.executables = ['ebx_db_listen']
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
+ spec.add_runtime_dependency("daemons", "~> 1.1.9")
24
25
  spec.add_runtime_dependency("dynamoid", "~> 0.7.1")
25
26
  spec.add_runtime_dependency("aws-sdk", "~> 1.17.0")
26
27
  spec.add_runtime_dependency("pry", "> 0")
@@ -1,281 +1,17 @@
1
+ require 'dynamoid/adapter/aws_sdk'
2
+
1
3
  module Dynamoid
2
4
  module Adapter
3
5
  module AwsMultiRegionAdapter
4
- extend self
5
- @@connection = nil
6
+ extend Dynamoid::Adapter::AwsSdk
6
7
 
7
- # Establish the connection to DynamoDB.
8
- #
9
- # @return [AWS::DynamoDB::Connection] the raw DynamoDB connection
10
- # Call DynamoDB new, with no parameters.
11
- # Make sure the aws.yml file or aws.rb file, refer the link for more details.
12
- #https://github.com/amazonwebservices/aws-sdk-for-ruby
13
- # 1. Create config/aws.yml as follows:
14
- # Fill in your AWS Access Key ID and Secret Access Key
15
- # http://aws.amazon.com/security-credentials
16
- #access_key_id: REPLACE_WITH_ACCESS_KEY_ID
17
- #secret_access_key: REPLACE_WITH_SECRET_ACCESS_KEY
18
- #(or)
19
- #2, Create config/initializers/aws.rb as follows:
20
- # load the libraries
21
- #require 'aws'
22
- # log requests using the default rails logger
23
- #AWS.config(:logger => Rails.logger)
24
- # load credentials from a file
25
- #config_path = File.expand_path(File.dirname(__FILE__)+"/../aws.yml")
26
- #AWS.config(YAML.load(File.read(config_path)))
27
- #Additionally include any of the dynamodb paramters as needed
28
- #(eg: if you would like to change the dynamodb endpoint, then add the parameter in
29
- # the following paramter in the file aws.yml or aws.rb
30
- # dynamo_db_endpoint : dynamodb.ap-southeast-1.amazonaws.com)
31
- # @since 0.2.0
32
- def connect!
33
- @@connection = ::EbxDeliver::AwsSnsWriter.new
8
+ def self.connect!
9
+ @@connection = AWS::DynamoDB.new(config: EbxDeliver::AwsConfig.new)
34
10
  end
35
11
 
36
- # Return the established connection.
37
- #
38
- # @return [AWS::DynamoDB::Connection] the raw DynamoDB connection
39
- #
40
- # @since 0.2.0
41
- def connection
12
+ def self.connection
42
13
  @@connection
43
14
  end
44
-
45
- # Get many items at once from DynamoDB. More efficient than getting each item individually.
46
- #
47
- # @example Retrieve IDs 1 and 2 from the table testtable
48
- # Dynamoid::Adapter::AwsSdk.batch_get_item({'table1' => ['1', '2']}, :consistent_read => true)
49
- #
50
- # @param [Hash] table_ids the hash of tables and IDs to retrieve
51
- # @param [Hash] options to be passed to underlying BatchGet call
52
- #
53
- # @return [Hash] a hash where keys are the table names and the values are the retrieved items
54
- #
55
- # @since 0.2.0
56
- def batch_get_item(table_ids, options = {})
57
- binding.pry
58
- connection.batch_get do |batch|
59
- table_ids.each do |table, keys|
60
- batch.table(table, :all, keys)
61
- end
62
- end
63
-
64
-
65
-
66
- #return hash if table_ids.all?{|k, v| v.empty?}
67
- #table_ids.each do |t, ids|
68
- # Array(ids).in_groups_of(100, false) do |group|
69
- # batch = AWS::DynamoDB::BatchGet.new(:config => @@connection.config)
70
- # batch.table(t, :all, Array(group), options) unless group.nil? || group.empty?
71
- # batch.each do |table_name, attributes|
72
- # hash[table_name] << attributes.symbolize_keys!
73
- # end
74
- # end
75
- #end
76
- #hash
77
- end
78
-
79
- # Delete many items at once from DynamoDB. More efficient than delete each item individually.
80
- #
81
- # @example Delete IDs 1 and 2 from the table testtable
82
- # Dynamoid::Adapter::AwsSdk.batch_delete_item('table1' => ['1', '2'])
83
- #or
84
- # Dynamoid::Adapter::AwsSdk.batch_delete_item('table1' => [['hk1', 'rk2'], ['hk1', 'rk2']]]))
85
- #
86
- # @param [Hash] options the hash of tables and IDs to delete
87
- #
88
- # @return nil
89
- #
90
- def batch_delete_item(options)
91
- return nil if options.all?{|k, v| v.empty?}
92
- options.each do |t, ids|
93
- Array(ids).in_groups_of(25, false) do |group|
94
- batch = AWS::DynamoDB::BatchWrite.new(:config => @@connection.config)
95
- batch.delete(t,group)
96
- batch.process!
97
- end
98
- end
99
- nil
100
- end
101
-
102
- # Create a table on DynamoDB. This usually takes a long time to complete.
103
- #
104
- # @param [String] table_name the name of the table to create
105
- # @param [Symbol] key the table's primary key (defaults to :id)
106
- # @param [Hash] options provide a range_key here if you want one for the table
107
- #
108
- # @since 0.2.0
109
- def create_table(table_name, key = :id, options = {})
110
- Dynamoid.logger.info "Creating #{table_name} table. This could take a while."
111
- options[:hash_key] ||= {key.to_sym => :string}
112
- read_capacity = options[:read_capacity] || Dynamoid::Config.read_capacity
113
- write_capacity = options[:write_capacity] || Dynamoid::Config.write_capacity
114
- table = @@connection.tables.create(table_name, read_capacity, write_capacity, options)
115
- sleep 0.5 while table.status == :creating
116
- return table
117
- end
118
-
119
- # Removes an item from DynamoDB.
120
- #
121
- # @param [String] table_name the name of the table
122
- # @param [String] key the hash key of the item to delete
123
- # @param [Number] range_key the range key of the item to delete, required if the table has a composite key
124
- #
125
- # @since 0.2.0
126
- def delete_item(table_name, key, options = {})
127
- range_key = options.delete(:range_key)
128
- table = get_table(table_name)
129
- result = table.items.at(key, range_key)
130
- result.delete unless result.attributes.to_h.empty?
131
- true
132
- end
133
-
134
- # Deletes an entire table from DynamoDB. Only 10 tables can be in the deleting state at once,
135
- # so if you have more this method may raise an exception.
136
- #
137
- # @param [String] table_name the name of the table to destroy
138
- #
139
- # @since 0.2.0
140
- def delete_table(table_name)
141
- Dynamoid.logger.info "Deleting #{table_name} table. This could take a while."
142
- table = @@connection.tables[table_name]
143
- table.delete
144
- sleep 0.5 while table.exists? == true
145
- end
146
-
147
- # @todo Add a DescribeTable method.
148
-
149
- # Fetches an item from DynamoDB.
150
- #
151
- # @param [String] table_name the name of the table
152
- # @param [String] key the hash key of the item to find
153
- # @param [Number] range_key the range key of the item to find, required if the table has a composite key
154
- #
155
- # @return [Hash] a hash representing the raw item in DynamoDB
156
- #
157
- # @since 0.2.0
158
- def get_item(table_name, key, options = {})
159
- range_key = options.delete(:range_key)
160
- table = get_table(table_name)
161
-
162
- result = table.items.at(key, range_key).attributes.to_h(options)
163
-
164
- if result.empty?
165
- nil
166
- else
167
- result.symbolize_keys!
168
- end
169
- end
170
-
171
- def update_item(table_name, key, options = {}, &block)
172
- range_key = options.delete(:range_key)
173
- conditions = options.delete(:conditions) || {}
174
- table = get_table(table_name)
175
- item = table.items.at(key, range_key)
176
- item.attributes.update(conditions.merge(:return => :all_new), &block)
177
- rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException
178
- raise Dynamoid::Errors::ConditionalCheckFailedException
179
- end
180
-
181
- # List all tables on DynamoDB.
182
- #
183
- # @since 0.2.0
184
- def list_tables
185
- connection.db.tables.collect(&:name)
186
- end
187
-
188
- # Persists an item on DynamoDB.
189
- #
190
- # @param [String] table_name the name of the table
191
- # @param [Object] object a hash or Dynamoid object to persist
192
- #
193
- # @since 0.2.0
194
- def put_item(table_name, object, options = nil)
195
- connection.put_item(table_name, object, options)
196
- end
197
-
198
- # Query the DynamoDB table. This employs DynamoDB's indexes so is generally faster than scanning, but is
199
- # only really useful for range queries, since it can only find by one hash key at once. Only provide
200
- # one range key to the hash.
201
- #
202
- # @param [String] table_name the name of the table
203
- # @param [Hash] opts the options to query the table with
204
- # @option opts [String] :hash_value the value of the hash key to find
205
- # @option opts [Range] :range_value find the range key within this range
206
- # @option opts [Number] :range_greater_than find range keys greater than this
207
- # @option opts [Number] :range_less_than find range keys less than this
208
- # @option opts [Number] :range_gte find range keys greater than or equal to this
209
- # @option opts [Number] :range_lte find range keys less than or equal to this
210
- #
211
- # @return [Enumerator] an iterator of all matching items
212
- #
213
- # @since 0.2.0
214
- def query(table_name, opts = {})
215
- table = get_table(table_name)
216
-
217
- Enumerator.new do |yielder|
218
- consistent_opts = { :consistent_read => opts[:consistent_read] || false }
219
- if table.composite_key?
220
- table.items.query(opts).each do |data|
221
- if opts.has_key? :select
222
- yielder.yield data.attributes.symbolize_keys!
223
- else
224
- yielder.yield data.attributes.to_h(consistent_opts).symbolize_keys!
225
- end
226
- end
227
- else
228
- yielder.yield get_item(table_name, opts[:hash_value])
229
- end
230
- end
231
- end
232
-
233
- # Scan the DynamoDB table. This is usually a very slow operation as it naively filters all data on
234
- # the DynamoDB servers.
235
- #
236
- # @param [String] table_name the name of the table
237
- # @param [Hash] scan_hash a hash of attributes: matching records will be returned by the scan
238
- #
239
- # @return [Enumerator] an iterator of all matching items
240
- #
241
- # @since 0.2.0
242
- def scan(table_name, scan_hash, select_opts)
243
- table = get_table(table_name)
244
- Enumerator.new do |yielder|
245
- table.items.where(scan_hash).select(select_opts).each do |data|
246
- yielder.yield data.attributes.symbolize_keys!
247
- end
248
- end
249
- end
250
-
251
- # @todo Add an UpdateItem method.
252
-
253
- # @todo Add an UpdateTable method.
254
-
255
- def get_table(table_name)
256
- unless table = table_cache[table_name]
257
- table = @@connection.db.tables[table_name]
258
- table.load_schema
259
- table_cache[table_name] = table
260
- end
261
- table
262
- end
263
-
264
- def table_cache
265
- @table_cache ||= {}
266
- end
267
-
268
- # Number of items from a table
269
- #
270
- # @param [String] table_name the name of the table
271
- #
272
- # @return [Integer] the number of items from a table
273
- #
274
- # @since 0.6.1
275
- def count(table_name)
276
- table = get_table(table_name)
277
- table.items.count
278
- end
279
15
  end
280
16
  end
281
17
  end
@@ -4,7 +4,10 @@ require 'pry'
4
4
 
5
5
  require 'ebx_deliver/version'
6
6
  require 'dynamoid/adapter/aws_multi_region_adapter'
7
- require 'ebx_deliver/aws_sns_writer'
7
+ require 'ebx_deliver/writer/client'
8
+ require 'ebx_deliver/writer/sns_handler'
9
+ require 'ebx_deliver/aws_sqs_reader'
10
+ require 'ebx_deliver/aws_config'
8
11
 
9
12
  module EbxDeliver
10
13
 
@@ -0,0 +1,16 @@
1
+ module EbxDeliver
2
+ class AwsConfig < AWS::Core::Configuration
3
+
4
+ def self.accepted_options
5
+ self.superclass.accepted_options
6
+ end
7
+
8
+ def initialize(options = {})
9
+ super(options.merge(AWS.config.supplied))
10
+ end
11
+
12
+ def dynamo_db_client
13
+ Writer::Client::V20111205.new(config: self)
14
+ end
15
+ end
16
+ end
@@ -1,55 +1,37 @@
1
1
  module EbxDeliver
2
2
  class AwsSqsReader
3
- def connect!
4
- # TODO pull name from settings
5
- @queue = sqs.queues.named('development-sns')
6
3
 
4
+ def initialize
5
+ # TODO pull name from settings
6
+ @queue = AWS.sqs.queues.named('write-development-sqs')
7
7
  @db = AWS::DynamoDB.new
8
-
9
- @queue.poll do |notification|
10
- msg = JSON.parse(JSON.parse(notification.body)['Message'])
11
- Rails.logger.info "MSG Received #{msg}"
12
- send(msg['method'], *msg['args'])
13
- end
14
- end
15
-
16
- def create_table(options)
17
- @db.client.create_table(options)
18
- end
19
-
20
- def batch_delete_item(options)
21
- @db.client.batch_delete_item(options)
22
- end
23
-
24
- def create_table(options = {})
25
- @db.client.create_table(options)
26
8
  end
27
9
 
28
- def delete_item(options = {})
29
- @db.client.delete_item(options)
10
+ # TODO Fix
11
+ def response_pool
12
+ r = AWS.config.region
13
+ AWS.config(region: 'us-west-2')
14
+ @command_notifications ||= AWS.sns.topics.create('read-development-sns')
15
+ ensure
16
+ AWS.config(region: r)
30
17
  end
31
18
 
32
- def delete_table(options = {})
33
- @db.client.delete_table(options)
34
- end
19
+ def connect!
20
+ # TODO remove poll to avoid autodelete
21
+ @queue.poll do |notification|
22
+ msg = JSON.parse(JSON.parse(notification.body)['Message'])
23
+ puts "MSG Received #{msg}"
35
24
 
36
- def put_item(table_name, object, options = {})
37
- table = @db.tables[table_name]
38
- table.load_schema
39
- table.items.create(
40
- object.delete_if{|k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?)},
41
- options || {}
42
- )
43
- rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException => e
44
- raise Dynamoid::Errors::ConditionalCheckFailedException
45
- end
25
+ response = @db.client.send(msg['method'], msg['args'])
26
+ puts "RESPONSE #{response.data}"
46
27
 
47
- def update_item(options = {})
48
- @db.client.update_item(options)
49
- end
28
+ response_pool.publish({
29
+ request_id: msg['request_id'],
30
+ response: response.http_response
31
+ }.to_json)
50
32
 
51
- def update_table(options = {})
52
- @db.client.update_table(options)
33
+ notification.delete
34
+ end
53
35
  end
54
36
  end
55
37
  end
@@ -1,3 +1,3 @@
1
1
  module EbxDeliver
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,46 @@
1
+ module EbxDeliver
2
+ module Writer
3
+ module Client
4
+ class V20111205 < AWS::DynamoDB::Client
5
+
6
+ def initialize(options = {})
7
+ super(options)
8
+ @net_http_handler = @http_handler
9
+ @sns_handler = Writer::SNSHandler.new
10
+ end
11
+
12
+ def self.service_name
13
+ 'DynamoDB'
14
+ end
15
+
16
+ define_client_methods('2011-12-05')
17
+ api_config = load_api_config('2011-12-05')
18
+ api_config[:operations].each do |operation|
19
+ method_name = operation[:method]
20
+ define_method(method_name) do |*args, &block|
21
+ options = args.first ? args.first : {}
22
+ set_http_handler(method_name)
23
+ client_request(method_name, options, &block)
24
+ end
25
+ end
26
+
27
+ def set_http_handler(method_name)
28
+ @http_handler = case method_name
29
+ when :batch_get_item,
30
+ :describe_table,
31
+ :get_item,
32
+ :list_tables,
33
+ :query,
34
+ :scan
35
+ @net_http_handler
36
+ else
37
+ @sns_handler
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ class Request < AWS::DynamoDB::Request
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,60 @@
1
+ module EbxDeliver
2
+ module Writer
3
+ class SNSHandler
4
+ attr_reader :response_queue
5
+
6
+ def initialize
7
+ @response_queue = AWS.sqs.queues.named('read-development-sqs')
8
+ end
9
+
10
+ def command_notifications
11
+ r = AWS.config.region
12
+ AWS.config(region: 'us-west-2')
13
+ @command_notifications ||= AWS.sns.topics.create('write-development-sns')
14
+ ensure
15
+ AWS.config(region: r)
16
+ end
17
+
18
+ def handle(request, response, &read_block)
19
+ name = request.headers['x-amz-target'].split('.')[-1].underscore
20
+ options = JSON.parse(request.body).reduce({}) {|h, (k, v)| h[k.underscore] = v; h}
21
+ puts request.http_method
22
+ request_id = SecureRandom.uuid
23
+ publish_command(request_id, name, options)
24
+
25
+ retrieve_response(request_id, response)
26
+ end
27
+
28
+ def publish_command(request_id, name, args)
29
+ command_notifications.publish({
30
+ method: name,
31
+ args: args,
32
+ request_id: request_id
33
+ }.to_json)
34
+ end
35
+
36
+ def retrieve_response(request_id, response)
37
+ start_time = Time.now
38
+ found = false
39
+ loop do
40
+ msgs = response_queue.receive_messages(limit: 10)
41
+ msgs.each do |notification|
42
+ msg = JSON.parse(JSON.parse(notification.body)['Message'])
43
+ if msg['request_id'] == request_id
44
+ found = true
45
+ response.status = msg['response']['status']
46
+ response.headers = msg['response']['headers']
47
+ response.body= msg['response']['body']
48
+ notification.delete
49
+ end
50
+ end
51
+
52
+ break if found
53
+ #raise 'Timeout' if (Time.now - start_time) > 5
54
+ end
55
+
56
+ nil
57
+ end
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebx_deliver
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
  - Alex Bullard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: daemons
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.9
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: dynamoid
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +97,8 @@ dependencies:
83
97
  description: eb eXtended cross region db command distributor
84
98
  email:
85
99
  - abullrd@gmail.com
86
- executables: []
100
+ executables:
101
+ - ebx_db_listen
87
102
  extensions: []
88
103
  extra_rdoc_files: []
89
104
  files:
@@ -94,12 +109,15 @@ files:
94
109
  - LICENSE
95
110
  - README.md
96
111
  - Rakefile
112
+ - bin/ebx_db_listen
97
113
  - ebx_deliver.gemspec
98
114
  - lib/dynamoid/adapter/aws_multi_region_adapter.rb
99
115
  - lib/ebx_deliver.rb
100
- - lib/ebx_deliver/aws_sns_writer.rb
116
+ - lib/ebx_deliver/aws_config.rb
101
117
  - lib/ebx_deliver/aws_sqs_reader.rb
102
118
  - lib/ebx_deliver/version.rb
119
+ - lib/ebx_deliver/writer/client.rb
120
+ - lib/ebx_deliver/writer/sns_handler.rb
103
121
  homepage: https://github.com/Funnerator/ebx_deliver.git
104
122
  licenses:
105
123
  - MIT
@@ -1,100 +0,0 @@
1
- module EbxDeliver
2
- class AwsSnsWriter
3
- attr_accessor :db
4
-
5
- def initialize
6
- # TODO fix
7
- @topic = AWS.sns.topics.create('development-sns')
8
-
9
- @db = AWS::DynamoDB.new
10
- end
11
-
12
- def batch_get_item(&block)
13
- @db.batch_get_item(&block)
14
- end
15
-
16
- def batch_write_item(options)
17
- @db.client.batch_write_item(options)
18
- @topic.publish({
19
- method: 'batch_write_item',
20
- args: [options]
21
- }.to_json)
22
- end
23
-
24
- def batch_delete_item(options)
25
- @topic.publish({
26
- method: 'batch_delete_item',
27
- args: [options]
28
- }.to_json)
29
- end
30
-
31
- def create_table(options = {})
32
- @topic.publish({
33
- method: 'create_table',
34
- args: [options]
35
- }.to_json)
36
- end
37
-
38
- def delete_item(options = {})
39
- @topic.publish({
40
- method: 'delete_item',
41
- args: [options]
42
- }.to_json)
43
- end
44
-
45
- def delete_table(options = {})
46
- @topic.publish({
47
- method: 'delete_table',
48
- args: [table_name]
49
- }.to_json)
50
- end
51
-
52
- def describe_table(options = {})
53
- @db.client.describe_table(options)
54
- end
55
-
56
- def get_item(table_name, key, options = {})
57
- @db.client.get_item(options)
58
- end
59
-
60
- def list_tables
61
- @db.client.list_tables(options)
62
- end
63
-
64
- def put_item(table_name, object, options = nil)
65
- @topic.publish({
66
- method: 'put_item',
67
- args: [table_name, object, options]
68
- }.to_json)
69
- end
70
-
71
- def query(table_name, opts = {})
72
- @db.client.query(options)
73
- end
74
-
75
- def scan(options)
76
- @db.client.scan(options)
77
- end
78
-
79
- def update_item(options = {})
80
- @topic.publish({
81
- method: 'update_item',
82
- args: [options]
83
- }.to_json)
84
- end
85
-
86
- def update_table(options = {})
87
- @topic.publish({
88
- method: 'update_item',
89
- args: [options]
90
- }.to_json)
91
- end
92
-
93
- def self.send_test
94
- w = AwsSnsWriter.new
95
- w.connect!
96
-
97
- w.create_table('testtt')
98
- end
99
- end
100
- end