order2cb 0.0.4 → 0.0.5

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: 1411a0b87f83b8fee806f6ab5b8d0fbfd3552fd5
4
- data.tar.gz: 19c3d6652a0e5d40ad5017898624ab55bc2e50a4
3
+ metadata.gz: 9e24798c9b262f11776c50c656dcd68cd0ee7185
4
+ data.tar.gz: 291052893f52cf889588a2067504269de9188b08
5
5
  SHA512:
6
- metadata.gz: 7b45fd83cd834eb8af43df5174f90db2d9c7730366d1fe7cdf6cb66187071fa0eb1fa56527d6279d68b7bbdc857a6f7dba673c2d57eeb2094e5fb446b40bc7c4
7
- data.tar.gz: 67e153c1ce427c95a8eadc5118928e1efc43a2a21543aefaf87b9d8d4c2b599602b8f2bfadf17eaf1d736dce2c904ebbaf9709b8d5a662114c3272464165d0fc
6
+ metadata.gz: e9965a702c8e29f2507dff5e85fef6002d6c8f0ee90718dc875a4b45253754a26a087c90db59a46289500ae03a8c0e2a0d6de14be0aa09fa7a7165890ce8b503
7
+ data.tar.gz: db755db5ef24d31b12857f9d35ca88fa84d6eaf6052c50a58ed475587dfa53be8b2609721c32d00d589744c10c5df81d3e4b4aa05b8e1045d32ac5b13a8a65e2
data/bin/push_order ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby -Ilib
2
+ require 'rubygems'
3
+
4
+ # Prepares the $LOAD_PATH by adding to it lib directories of the gem and
5
+ # its dependencies:
6
+ require 'order2cb'
7
+
8
+ oh = Order2cb::OrderHandler.new
9
+
10
+ oh.push_orders(ARGV)
@@ -14,8 +14,8 @@ module Order2cb
14
14
  false
15
15
  end
16
16
 
17
- def order_exists?(order_no)
18
- response = RestClient.get "#{ENV['CB_API_ENDPOINT']}/case_blocks/search.json?auth_token=#{ENV['CB_API_TOKEN']}&case_type_id=#{ENV['CB_TS_TYPE_ID']}&query=order_number:#{order_no}"
17
+ def order_exists?(order)
18
+ response = RestClient.get "#{ENV['CB_API_ENDPOINT']}/case_blocks/search.json?auth_token=#{ENV['CB_API_TOKEN']}&case_type_id=#{ENV['CB_TS_TYPE_ID']}&query=order_number:#{order.number}"
19
19
  response.code==200 && JSON.parse(response.body).count > 0
20
20
  rescue => e
21
21
  @logger.error e.message
@@ -34,7 +34,7 @@ module Order2cb
34
34
  end
35
35
 
36
36
  def market_opt_in
37
- @data['accept_marketing'] == true
37
+ @data['accept_marketing'] == 1
38
38
  end
39
39
 
40
40
  def payment_type
@@ -113,7 +113,7 @@ module Order2cb
113
113
  @operational_stock_order = true
114
114
 
115
115
  get_line_items.each do |line_item_row|
116
- if @operational_stock_order && !line_item_row['is_operational_stock']
116
+ if line_item_row['is_operational_stock']==0
117
117
  @operational_stock_order = false
118
118
  end
119
119
  line_items_results << {
@@ -1,3 +1,3 @@
1
1
  module Order2cb
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/order2cb.rb CHANGED
@@ -51,7 +51,7 @@ module Order2cb
51
51
  until @stop
52
52
  begin
53
53
  $db_client = Mysql2::Client.new(:host => @tyreshopperDatabaseHost, :username => @tyreshopperDatabaseUser, :password => @tyreshopperDatabasePassword, :database => @tyreshopperDatabaseName)
54
- process_orders
54
+ process_orders(all_recent_orders)
55
55
  $db_client.close
56
56
  @logger.debug "Waiting for #{@interval} seconds..."
57
57
  rescue => e
@@ -62,17 +62,24 @@ module Order2cb
62
62
  end
63
63
  end
64
64
 
65
+ def push_orders(order_numbers)
66
+ $db_client = Mysql2::Client.new(:host => @tyreshopperDatabaseHost, :username => @tyreshopperDatabaseUser, :password => @tyreshopperDatabasePassword, :database => @tyreshopperDatabaseName)
67
+ process_orders(order_numbers)
68
+ $db_client.close
69
+ end
70
+
71
+
65
72
  def stop
66
73
  @stop = true
67
74
  end
68
75
 
69
- def process_orders
76
+ def process_orders(orders_to_process)
70
77
  @logger.debug "Checking for orders"
71
78
  caseblocks = Caseblocks.new(@logger)
72
- orders_to_process.each do |order|
79
+ orders_to_process.each do |order_number|
73
80
  begin
74
- order = ::Order2cb::Order.find(order['number'])
75
- unless caseblocks.order_exists?(order.number)
81
+ order = ::Order2cb::Order.find(order_number)
82
+ unless caseblocks.order_exists?(order)
76
83
  @logger.debug "#{order.number} doesn't exist in caseblocks, sending it now"
77
84
  if caseblocks.create_order(order)
78
85
  @logger.info "Sent #{order.number} to caseblocks."
@@ -90,32 +97,11 @@ module Order2cb
90
97
 
91
98
  end
92
99
 
93
- def orders_to_process(start_time = DateTime.parse(4.hours.ago.to_s))
100
+ def all_recent_orders(start_time = DateTime.parse(4.hours.ago.to_s))
94
101
  results = $db_client.query("SELECT * from exp_spree_orders where completed_at > '#{start_time}';")
95
102
  @logger.debug "Found #{results.count} completed orders in the last #{time_ago_in_words(start_time)} to be processed"
96
- results
103
+ results.map{|row| row["number"]}
97
104
  end
98
105
 
99
- def order_exists_in_casebocks
100
- RestClient.get 'https://login.caseblocks/com/search', {:params => {:auth_token => @caseBlocksAPIToken, 'foo' => 'bar'}}
101
- return false
102
- end
103
-
104
- def send_to_caseblocks(msgHash)
105
- @logger.debug "Sending to CaseBlocks"
106
-
107
- response = RestClient.post(add_auth(Uri.parse("#{@caseBlocksAPIEndpoint}/case_blocks/cases")), msgHash.to_json,
108
- :content_type => :json,
109
- :accept => :json,
110
- "AUTH_TOKEN" => @caseBlocksAPIToken)
111
- @logger.info "Received #{response.code} Location: #{response.headers[:location]}"
112
- rescue RestClient::ExceptionWithResponse => ex
113
- if ex.response.nil?
114
- @logger.error "Received a bad response (null) from CaseBlocks. Re-raising."
115
- raise ex
116
- else
117
- @logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
118
- end
119
- end
120
106
  end
121
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: order2cb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - EmergeAdapt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,6 +141,7 @@ email:
141
141
  - development@emergeadapt.com
142
142
  executables:
143
143
  - order2cb
144
+ - push_order
144
145
  extensions: []
145
146
  extra_rdoc_files: []
146
147
  files:
@@ -153,6 +154,7 @@ files:
153
154
  - README.md
154
155
  - Rakefile
155
156
  - bin/order2cb
157
+ - bin/push_order
156
158
  - lib/order2cb.rb
157
159
  - lib/order2cb/caseblocks.rb
158
160
  - lib/order2cb/order.rb