tyreshopper_sqs2cb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tyreshopper_sqs2cb.rb +15 -15
- data/lib/tyreshopper_sqs2cb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b815533486530635df49b3593197ba84ccd2a7
|
4
|
+
data.tar.gz: 93008476a8cca8c5039bd4e57ce0ceec68d9cea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5178025b4ccfdfaaac65be8c759ee93471677e368ce3da45c81bc6b62c8151a010d8d24353c862172543e3ea6d528eafe2f450e1cba1ea53a27dd8fc2c19ccfc
|
7
|
+
data.tar.gz: 90457f7265da89d39b07d48028a2e9b098fd420f27ca64daefa818343f2f4029b873dd245189772d4e869aa5d14a66f0d77c512e4b0012aa9767a0eb4b69793b
|
data/lib/tyreshopper_sqs2cb.rb
CHANGED
@@ -12,7 +12,7 @@ module TyreshopperSqs2cb
|
|
12
12
|
def initialize
|
13
13
|
|
14
14
|
logfile = ENV['TYRESHOPPER_SQS2CB_LOGFILE_PATH'].nil? ? STDOUT : File.open(ENV['TYRESHOPPER_SQS2CB_LOGFILE_PATH'], 'a')
|
15
|
-
logfile =
|
15
|
+
logfile.sync = true
|
16
16
|
@logger = Logger.new logfile
|
17
17
|
|
18
18
|
|
@@ -34,7 +34,7 @@ module TyreshopperSqs2cb
|
|
34
34
|
@options = options
|
35
35
|
@logger.info "Tyreshopper Message received."
|
36
36
|
@logger.debug message.body
|
37
|
-
|
37
|
+
@logger.info "Sending..."
|
38
38
|
|
39
39
|
@caseBlocksAPIEndpoint = options[:case_blocks_api_endpoint]
|
40
40
|
@caseBlocksAPIToken = options[:caseblocks_api_token]
|
@@ -54,17 +54,17 @@ module TyreshopperSqs2cb
|
|
54
54
|
def send_to_caseblocks(msgHash)
|
55
55
|
@logger.info "Sending to CaseBlocks"
|
56
56
|
|
57
|
-
|
57
|
+
@logger.info "Sending order #{msgHash["case"]["title"]} to caseblocks..."
|
58
58
|
|
59
|
-
|
59
|
+
@logger.info "Looking for customer..."
|
60
60
|
customer = find_or_create_customer(msgHash)
|
61
61
|
|
62
62
|
msgHash["case"]["customer_ref"] = customer["customer_ref"]
|
63
63
|
|
64
|
-
|
64
|
+
@logger.info "Creating order in caseblocks..."
|
65
65
|
response = post("/case_blocks/tyre_shopper_orders", msgHash)
|
66
66
|
|
67
|
-
|
67
|
+
@logger.info "Done."
|
68
68
|
@logger.info "Received #{response}"
|
69
69
|
rescue RestClient::ExceptionWithResponse => ex
|
70
70
|
if ex.response.nil?
|
@@ -84,7 +84,7 @@ module TyreshopperSqs2cb
|
|
84
84
|
# if user was signed in then use member_id else use email
|
85
85
|
if order_details["signed_in"]
|
86
86
|
|
87
|
-
|
87
|
+
@logger.info "Searching for customer on member_id #{order_details["member"]["member_id"]}..."
|
88
88
|
|
89
89
|
customer = {
|
90
90
|
"case_type_id" => customer_case_type_id,
|
@@ -103,20 +103,20 @@ module TyreshopperSqs2cb
|
|
103
103
|
|
104
104
|
cb_customer = find_customer(:member_id => order_details["member"]["member_id"])
|
105
105
|
if cb_customer.nil?
|
106
|
-
|
106
|
+
@logger.info "Can't find customer by member_id, checking if the email is there..."
|
107
107
|
|
108
108
|
cb_customer = find_customer(:email => order_details["email"])
|
109
109
|
|
110
110
|
if cb_customer
|
111
|
-
|
111
|
+
@logger.info "Found customer, need to update member_id and data"
|
112
112
|
|
113
113
|
cb_customer = ensure_taskslists_are_populated(cb_customer)
|
114
114
|
put("/case_blocks/customer/#{cb_customer["_id"]}", {"customer" => customer})
|
115
115
|
|
116
116
|
return cb_customer
|
117
117
|
else
|
118
|
-
|
119
|
-
|
118
|
+
@logger.info "Unable to find customer"
|
119
|
+
@logger.info "Creating new customer from member details..."
|
120
120
|
|
121
121
|
result = post("/case_blocks/customer", customer)["case"]
|
122
122
|
return result
|
@@ -125,15 +125,15 @@ module TyreshopperSqs2cb
|
|
125
125
|
return cb_customer
|
126
126
|
end
|
127
127
|
else
|
128
|
-
|
128
|
+
@logger.info "Searching for customer on email #{order_details["email"]}..."
|
129
129
|
|
130
130
|
cb_customer = find_customer(:email => order_details["email"])
|
131
131
|
|
132
132
|
if cb_customer
|
133
|
-
|
133
|
+
@logger.info "Found customer"
|
134
134
|
return cb_customer
|
135
135
|
else
|
136
|
-
|
136
|
+
@logger.info "Unable to find customer"
|
137
137
|
|
138
138
|
name_parts = parse_name(order_details["customer"])
|
139
139
|
|
@@ -152,7 +152,7 @@ module TyreshopperSqs2cb
|
|
152
152
|
|
153
153
|
}
|
154
154
|
|
155
|
-
|
155
|
+
@logger.info "Creating new customer from order details..."
|
156
156
|
return post("/case_blocks/customer", customer)["case"]
|
157
157
|
end
|
158
158
|
end
|