sqs2cb 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sqs2cb/version.rb +1 -1
  3. data/lib/sqs2cb.rb +23 -15
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d13b17afb061e9bd5adfa1aeecd9d4b1de117ec2
4
- data.tar.gz: 03ec74ce88f11e961e7f8eca963ec7770381b58c
3
+ metadata.gz: eed989f967e5d6f66d406bb25793445f15e6c725
4
+ data.tar.gz: 4f94c77efa4f3595483c60f3bf2b89200264b30f
5
5
  SHA512:
6
- metadata.gz: ea903a107fb1362425facb00d089958fe26c825a002b321c4fc5616c889e4a1ebaba5dbbbad35d55a270de73ae9acb314891fc61e32d4690d3c1660ff89bcdcc
7
- data.tar.gz: 3eb4c2ea008d8edcb996b4163274deb1ab73a6521f17a4016a4dcbdf8c35a06c4c65f96a9c5faf9d6f2848990a3747126e803e2117e1877f611b8c8754d2e19d
6
+ metadata.gz: 21b54f520ffe5691d08e7ad2a46de933dc5c8df8561cddd2dc486160af742ab4c3608a29a904980cf7e77622fcf289b3c45f380ad67720ca0be6b4db1502fb7c
7
+ data.tar.gz: dbdc1b0be2ea16ee7eb92e747f635ab8f9b0bfa1df9295e6848287f352481c7d41fc899d7f52865d04595464adef3377d21e72f7f4819aca5bc1642fb888e304
@@ -1,3 +1,3 @@
1
1
  module Sqs2cb
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/sqs2cb.rb CHANGED
@@ -17,6 +17,8 @@ module Sqs2cb
17
17
  @logger = Logger.new logfile
18
18
  @stop = false
19
19
 
20
+ @options = {:use_patch_command => @usePatchCommand, :case_blocks_api_endpoint => @caseBlocksAPIEndpoint, :caseblocks_api_token => @caseBlocksAPIToken}
21
+
20
22
  raise RuntimeError, "Please ensure AWS_ACCESS_KEY is set." if @awsAccessKeyId.nil? or @awsAccessKeyId.empty?
21
23
  raise RuntimeError, "Please ensure AWS_SECRET_ACCESS_KEY is set." if @awsSecretAccessKey.nil? or @awsSecretAccessKey.empty?
22
24
  raise RuntimeError, "Please ensure CB_API_ENDPOINT is set." if @caseBlocksAPIEndpoint.nil? or @caseBlocksAPIEndpoint.empty?
@@ -34,7 +36,11 @@ module Sqs2cb
34
36
  begin
35
37
  sqs = AWS::SQS.new(region: 'us-east-1', access_key_id: @awsAccessKeyId, secret_access_key: @awsSecretAccessKey)
36
38
  sqs.queues[@caseBlocksQueue].poll do |message|
37
- handle_received_message(message)
39
+ if block_given?
40
+ yield message, @options
41
+ else
42
+ handle_received_message(message)
43
+ end
38
44
  return if @stop
39
45
  end
40
46
  rescue Exception => ex
@@ -60,12 +66,12 @@ module Sqs2cb
60
66
  @logger.error ex
61
67
  end
62
68
 
63
- def update_caseblocks(msgHash)
69
+ def update_caseblocks(msgHash)
64
70
  caseId = msgHash.delete('id')
65
71
  caseTypeCode = msgHash.delete('case_type_code')
66
- initialResponse = RestClient.get("#{@caseBlocksAPIEndpoint}/case_blocks/#{caseTypeCode}/#{caseId}.json?auth_token=#{@caseBlocksAPIToken}",
67
- :content_type => :json,
68
- :accept => :json,
72
+ initialResponse = RestClient.get("#{@caseBlocksAPIEndpoint}/case_blocks/#{caseTypeCode}/#{caseId}.json?auth_token=#{@caseBlocksAPIToken}",
73
+ :content_type => :json,
74
+ :accept => :json,
69
75
  "AUTH_TOKEN" => @caseBlocksAPIToken)
70
76
  currentCase = JSON.parse(initialResponse.body)
71
77
  data = currentCase[caseTypeCode]
@@ -73,34 +79,36 @@ module Sqs2cb
73
79
  %w(tasklists conversations).each {|k| data.delete k}
74
80
  currentCase[caseTypeCode] = data
75
81
 
76
- secondResponse = RestClient.put("#{@caseBlocksAPIEndpoint}/case_blocks/#{caseTypeCode}/#{caseId}.json?auth_token=#{@caseBlocksAPIToken}", currentCase.to_json,
77
- :content_type => :json,
78
- :accept => :json,
82
+ secondResponse = RestClient.put("#{@caseBlocksAPIEndpoint}/case_blocks/#{caseTypeCode}/#{caseId}.json?auth_token=#{@caseBlocksAPIToken}", currentCase.to_json,
83
+ :content_type => :json,
84
+ :accept => :json,
79
85
  "AUTH_TOKEN" => @caseBlocksAPIToken)
80
- @logger.info "Received #{secondResponse.code}"
86
+ @logger.info "Received #{secondResponse.code}"
81
87
  rescue RestClient::ExceptionWithResponse => ex
82
88
  if ex.response.nil?
83
89
  @logger.error "Received a bad response (null) from CaseBlocks. Re-raising."
84
90
  raise ex
85
91
  else
86
- @logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
92
+ @logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
87
93
  end
88
94
  end
89
95
 
90
96
  def send_to_caseblocks(msgHash)
91
97
  @logger.info "Sending to CaseBlocks"
92
- response = RestClient.post("#{@caseBlocksAPIEndpoint}/case_blocks/cases?auth_token=#{@caseBlocksAPIToken}", msgHash.to_json,
93
- :content_type => :json,
94
- :accept => :json,
98
+
99
+ response = RestClient.post(add_auth(Uri.parse("#{@caseBlocksAPIEndpoint}/case_blocks/cases")), msgHash.to_json,
100
+ :content_type => :json,
101
+ :accept => :json,
95
102
  "AUTH_TOKEN" => @caseBlocksAPIToken)
96
- @logger.info "Received #{response.code} Location: #{response.headers[:location]}"
103
+ @logger.info "Received #{response.code} Location: #{response.headers[:location]}"
97
104
  rescue RestClient::ExceptionWithResponse => ex
98
105
  if ex.response.nil?
99
106
  @logger.error "Received a bad response (null) from CaseBlocks. Re-raising."
100
107
  raise ex
101
108
  else
102
- @logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
109
+ @logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
103
110
  end
104
111
  end
105
112
  end
113
+ end
106
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqs2cb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - EmergeAdapt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-04 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler