omniorder 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 +4 -4
- data/README.md +1 -0
- data/lib/omniorder/import_strategy/base.rb +4 -0
- data/lib/omniorder/import_strategy/groupon.rb +10 -2
- data/lib/omniorder/utils.rb +34 -0
- data/lib/omniorder/version.rb +1 -1
- data/lib/omniorder.rb +1 -0
- data/omniorder.gemspec +1 -0
- data/spec/{assets/imports/groupon → import_strategy}/base_spec.rb +6 -0
- data/spec/import_strategy/groupon_spec.rb +5 -3
- data/spec/spec_helper.rb +3 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 797f0af13bcfa4627aa6a123ba34bbde2b471d73
|
4
|
+
data.tar.gz: 93add816bee91c523b972efc180a6f6d04ad5fe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26a793eaff12bdefb446d2936eca79f0440e815535538b8e79be17a4ef85fe5ee373eab92ebe5f733e1a44ed3f836935023f94c34be0574561ad390df19946ab
|
7
|
+
data.tar.gz: 5cc5b99c959e7c84656c6dbea7914a45c1876da9dea4771a455c319c2a41602c1329ee33bc306433928d322bea3f07df643cc50f5b5fc969682c96adb13b79b2
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Omniorder
|
2
2
|
|
3
3
|
[![Build Status](http://img.shields.io/travis/watsonbox/omniorder.svg?style=flat)](https://travis-ci.org/watsonbox/omniorder)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/watsonbox/omniorder.svg?style=flat)](https://coveralls.io/r/watsonbox/omniorder)
|
4
5
|
|
5
6
|
Import online orders from various channels for fulfillment.
|
6
7
|
|
@@ -27,7 +27,7 @@ module Omniorder
|
|
27
27
|
result = Crack::JSON.parse do_request(mark_exported_url(order_info), :post)
|
28
28
|
|
29
29
|
unless result['success']
|
30
|
-
raise "Failed to mark Groupon order ##{order_info['orderid']} as exported"
|
30
|
+
raise "Failed to mark Groupon order ##{order_info['orderid']} as exported (#{result['reason']})"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -86,7 +86,15 @@ module Omniorder
|
|
86
86
|
http = Net::HTTP.new(uri.host, 443)
|
87
87
|
http.use_ssl = true
|
88
88
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
89
|
-
|
89
|
+
|
90
|
+
# Send post request params in body
|
91
|
+
if type == :get
|
92
|
+
http.request(Net::HTTP::Get.new(uri.request_uri)).body
|
93
|
+
else
|
94
|
+
request = Net::HTTP::Post.new(uri.path)
|
95
|
+
request.body = uri.query
|
96
|
+
http.request(request).body
|
97
|
+
end
|
90
98
|
end
|
91
99
|
end
|
92
100
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Omniorder
|
2
|
+
module Utils
|
3
|
+
# Extracted from activesupport/lib/active_support/inflector/methods.rb
|
4
|
+
def self.constantize(camel_cased_word)
|
5
|
+
names = camel_cased_word.split('::')
|
6
|
+
names.shift if names.empty? || names.first.empty?
|
7
|
+
|
8
|
+
names.inject(Object) do |constant, name|
|
9
|
+
if constant == Object
|
10
|
+
constant.const_get(name)
|
11
|
+
else
|
12
|
+
candidate = constant.const_get(name)
|
13
|
+
next candidate if constant.const_defined?(name, false)
|
14
|
+
next candidate unless Object.const_defined?(name)
|
15
|
+
|
16
|
+
# Go down the ancestors to check it it's owned
|
17
|
+
# directly before we reach Object or the end of ancestors.
|
18
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
19
|
+
break const if ancestor == Object
|
20
|
+
break ancestor if ancestor.const_defined?(name, false)
|
21
|
+
const
|
22
|
+
end
|
23
|
+
|
24
|
+
# owner is in Object, so raise
|
25
|
+
constant.const_get(name, false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.camelize(str)
|
31
|
+
str.to_s.split('_').map { |w| w.capitalize }.join
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/omniorder/version.rb
CHANGED
data/lib/omniorder.rb
CHANGED
data/omniorder.gemspec
CHANGED
@@ -14,4 +14,10 @@ describe Omniorder::ImportStrategy::Base do
|
|
14
14
|
expect(strategy_class.new(nil, local_option: true).options).to eq(global_option: true, local_option: true)
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
describe '.from_name' do
|
19
|
+
it 'selects a specific strategy from its name' do
|
20
|
+
expect(Omniorder::ImportStrategy::Base.from_name(:groupon)).to eq(Omniorder::ImportStrategy::Groupon)
|
21
|
+
end
|
22
|
+
end
|
17
23
|
end
|
@@ -63,7 +63,9 @@ describe Omniorder::ImportStrategy::Groupon do
|
|
63
63
|
let!(:mark_exported_stub) do
|
64
64
|
stub_request(
|
65
65
|
:post,
|
66
|
-
"https://scm.commerceinterface.com/api/v2/mark_exported
|
66
|
+
"https://scm.commerceinterface.com/api/v2/mark_exported"
|
67
|
+
).with(
|
68
|
+
body: "supplier_id=1&token=xYRPKcoakMoiRzWgKLV5TqPSdNAaZQT&ci_lineitem_ids=[54553920,54553921]"
|
67
69
|
).to_return(
|
68
70
|
body: mark_exported_result,
|
69
71
|
status: 200
|
@@ -76,12 +78,12 @@ describe Omniorder::ImportStrategy::Groupon do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
context "mark exported API call fails" do
|
79
|
-
let(:mark_exported_result) { '{ "success": false }' }
|
81
|
+
let(:mark_exported_result) { '{ "success": false, "reason": "Something went wrong" }' }
|
80
82
|
|
81
83
|
it 'raises an exception' do
|
82
84
|
expect {
|
83
85
|
strategy.import_orders { |o| true if o.order_number == "FFB7A68990" }
|
84
|
-
}.to raise_exception "Failed to mark Groupon order #FFB7A68990 as exported"
|
86
|
+
}.to raise_exception "Failed to mark Groupon order #FFB7A68990 as exported (Something went wrong)"
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Howard Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: crack
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.20.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Import online orders from various channels for fulfillment.
|
84
98
|
email:
|
85
99
|
- howard@watsonbox.net
|
@@ -107,11 +121,12 @@ files:
|
|
107
121
|
- lib/omniorder/orderable.rb
|
108
122
|
- lib/omniorder/product.rb
|
109
123
|
- lib/omniorder/purchasable.rb
|
124
|
+
- lib/omniorder/utils.rb
|
110
125
|
- lib/omniorder/version.rb
|
111
126
|
- omniorder.gemspec
|
112
|
-
- spec/assets/imports/groupon/base_spec.rb
|
113
127
|
- spec/assets/imports/groupon/get_orders.json
|
114
128
|
- spec/customerable_spec.rb
|
129
|
+
- spec/import_strategy/base_spec.rb
|
115
130
|
- spec/import_strategy/groupon_spec.rb
|
116
131
|
- spec/orderable_spec.rb
|
117
132
|
- spec/spec_helper.rb
|
@@ -140,9 +155,9 @@ signing_key:
|
|
140
155
|
specification_version: 4
|
141
156
|
summary: Import online orders from various channels for fulfillment.
|
142
157
|
test_files:
|
143
|
-
- spec/assets/imports/groupon/base_spec.rb
|
144
158
|
- spec/assets/imports/groupon/get_orders.json
|
145
159
|
- spec/customerable_spec.rb
|
160
|
+
- spec/import_strategy/base_spec.rb
|
146
161
|
- spec/import_strategy/groupon_spec.rb
|
147
162
|
- spec/orderable_spec.rb
|
148
163
|
- spec/spec_helper.rb
|