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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c03ee4b2df4c0589a2a01e7787556544cf5bc382
4
- data.tar.gz: e229b29ba52d8c82adc3b083933c6112f8c20011
3
+ metadata.gz: 797f0af13bcfa4627aa6a123ba34bbde2b471d73
4
+ data.tar.gz: 93add816bee91c523b972efc180a6f6d04ad5fe6
5
5
  SHA512:
6
- metadata.gz: ce3a0db160edea671d7c571be7251616f7832cf85d842cd0f54f6ec2f2e389540744ca6c6b023042ad87c53fd56293fad8c5ae14b72d2a3976d4b4da913b4d9d
7
- data.tar.gz: 2b70815df33f45e01f465aefec85797e292ef9e33f9caefafba0680f3407194d9acbdc8c4ad4c8ec168daa3eae09986be793ce8be8d8f51baad77e60040bf4f3
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
 
@@ -16,6 +16,10 @@ module Omniorder
16
16
  def clear_options
17
17
  @options = nil
18
18
  end
19
+
20
+ def from_name(name)
21
+ Utils.constantize "Omniorder::ImportStrategy::#{Utils.camelize name}"
22
+ end
19
23
  end
20
24
 
21
25
  def initialize(import, options = {})
@@ -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
- http.request((type == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri.request_uri)).body
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
@@ -1,3 +1,3 @@
1
1
  module Omniorder
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/omniorder.rb CHANGED
@@ -3,6 +3,7 @@ require "net/https"
3
3
  require "crack"
4
4
 
5
5
  require "omniorder/version"
6
+ require "omniorder/utils"
6
7
  require "omniorder/entity"
7
8
  require "omniorder/customerable"
8
9
  require "omniorder/customer"
data/omniorder.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec", "~> 3.1.0"
26
26
  spec.add_development_dependency "webmock", "~> 1.20.4"
27
+ spec.add_development_dependency "coveralls"
27
28
  end
@@ -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?supplier_id=1&token=xYRPKcoakMoiRzWgKLV5TqPSdNAaZQT&ci_lineitem_ids=[54553920,54553921]"
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
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'webmock/rspec'
2
5
  require 'omniorder'
3
6
 
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.1
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-19 00:00:00.000000000 Z
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