cadooz 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +23 -0
- data/lib/cadooz.rb +55 -0
- data/lib/cadooz/models/immutable/address.rb +25 -0
- data/lib/cadooz/models/immutable/attributes.rb +15 -0
- data/lib/cadooz/models/immutable/catalog.rb +14 -0
- data/lib/cadooz/models/immutable/catalog_product.rb +19 -0
- data/lib/cadooz/models/immutable/catalog_product_variation.rb +14 -0
- data/lib/cadooz/models/immutable/generation_profile_product.rb +14 -0
- data/lib/cadooz/models/immutable/greeting_card.rb +12 -0
- data/lib/cadooz/models/immutable/invoice_information.rb +12 -0
- data/lib/cadooz/models/immutable/order.rb +34 -0
- data/lib/cadooz/models/immutable/order_position.rb +24 -0
- data/lib/cadooz/models/immutable/order_status.rb +18 -0
- data/lib/cadooz/models/immutable/payment.rb +19 -0
- data/lib/cadooz/models/immutable/product_category.rb +17 -0
- data/lib/cadooz/models/immutable/voucher.rb +23 -0
- data/lib/cadooz/models/mutable/address.rb +22 -0
- data/lib/cadooz/models/mutable/greeting_card.rb +10 -0
- data/lib/cadooz/models/mutable/invoice_information.rb +10 -0
- data/lib/cadooz/models/mutable/order.rb +32 -0
- data/lib/cadooz/models/mutable/order_position.rb +22 -0
- data/lib/cadooz/services/business_order_service.rb +137 -0
- data/lib/cadooz/version.rb +3 -0
- data/lib/mixins.rb +51 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab2ddfaf51e4f3d4a9738c44d67e5f27613c4f94
|
4
|
+
data.tar.gz: 9cdf595ef7b41eb4e65859c89a7d3413034aaa8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9a1ddef2d7d4aa5baadc7d73721f3addcf6e6d0b25b85446762bb913cb1e35dfc82fda25875c722d423dfb608ec5b71b6efc33679dc0a232f464ab9e01b5c18
|
7
|
+
data.tar.gz: c4a0cb0b900188cace244816f618f9a19d8b923792acc1fc911406cf907c20ae9dee4d3d11718d77b4c477f799380e5e7dabb5ef5afd9fb3b4adfe1f47891cf2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Smartly, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'cadooz'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
data/lib/cadooz.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'money'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'pry'
|
5
|
+
require 'savon'
|
6
|
+
|
7
|
+
module Cadooz
|
8
|
+
class Configuration
|
9
|
+
attr_accessor :username, :password, :wsdl, :generation_profile
|
10
|
+
|
11
|
+
WSDL = 'https://webservices.cadooz.com/services/businessorder/1.5.2/BusinessOrderService/BusinessOrder?wsdl'
|
12
|
+
TEST_USERNAME = 'cadooz'
|
13
|
+
TEST_PASSWORD = 'Cadooz2015'
|
14
|
+
|
15
|
+
def initialize(username, password, generation_profile)
|
16
|
+
self.username = username || TEST_USERNAME
|
17
|
+
self.password = password || TEST_PASSWORD
|
18
|
+
self.wsdl = WSDL
|
19
|
+
self.generation_profile = generation_profile
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
@configuration ||= Configuration.new(nil, nil, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure
|
28
|
+
yield(configuration) if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
module Immutable end
|
32
|
+
module Mutable end
|
33
|
+
end
|
34
|
+
|
35
|
+
require_relative 'mixins'
|
36
|
+
require_relative 'cadooz/models/immutable/address'
|
37
|
+
require_relative 'cadooz/models/immutable/attributes'
|
38
|
+
require_relative 'cadooz/models/immutable/catalog'
|
39
|
+
require_relative 'cadooz/models/immutable/catalog_product'
|
40
|
+
require_relative 'cadooz/models/immutable/catalog_product_variation'
|
41
|
+
require_relative 'cadooz/models/immutable/generation_profile_product'
|
42
|
+
require_relative 'cadooz/models/immutable/greeting_card'
|
43
|
+
require_relative 'cadooz/models/immutable/invoice_information'
|
44
|
+
require_relative 'cadooz/models/immutable/order'
|
45
|
+
require_relative 'cadooz/models/immutable/order_position'
|
46
|
+
require_relative 'cadooz/models/immutable/order_status'
|
47
|
+
require_relative 'cadooz/models/immutable/payment'
|
48
|
+
require_relative 'cadooz/models/immutable/product_category'
|
49
|
+
require_relative 'cadooz/models/immutable/voucher'
|
50
|
+
require_relative 'cadooz/models/mutable/address'
|
51
|
+
require_relative 'cadooz/models/mutable/greeting_card'
|
52
|
+
require_relative 'cadooz/models/mutable/invoice_information'
|
53
|
+
require_relative 'cadooz/models/mutable/order'
|
54
|
+
require_relative 'cadooz/models/mutable/order_position'
|
55
|
+
require_relative 'cadooz/services/business_order_service'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Cadooz::Immutable::Address
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :city, :company, :country, :department, :email, :firstname,
|
5
|
+
:lastname, :phone, :salutation, :state, :street,
|
6
|
+
:street_add_on, :zip_code
|
7
|
+
|
8
|
+
def initialize(open_struct)
|
9
|
+
@city = open_struct&.city
|
10
|
+
@company =open_struct&.company
|
11
|
+
@country = open_struct&.country
|
12
|
+
@department = open_struct&.department
|
13
|
+
@email = open_struct&.email
|
14
|
+
@firstname = open_struct&.firstname
|
15
|
+
@lastname = open_struct&.lastname
|
16
|
+
@phone = open_struct&.phone
|
17
|
+
@salutation = open_struct&.salutation
|
18
|
+
@state = open_struct&.state
|
19
|
+
@street = open_struct&.street
|
20
|
+
@street_add_on = open_struct&.street_add_on
|
21
|
+
@zip_code = open_struct&.zipcode
|
22
|
+
|
23
|
+
self.freeze
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Cadooz::Immutable::Attributes
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :attribute, :values
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@attribute = open_struct&.attribute
|
8
|
+
@values = open_struct&.values
|
9
|
+
&.map_entries
|
10
|
+
&.elements
|
11
|
+
&.inject({}) { |hash, element| hash.merge(element.key.to_sym => element.value) }
|
12
|
+
|
13
|
+
self.freeze
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Cadooz::Immutable::Catalog
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :id, :name, :description, :products
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@id = open_struct&.id
|
8
|
+
@name = open_struct&.name
|
9
|
+
@description = open_struct&.description
|
10
|
+
@products = Array(open_struct&.products)&.each_with_object([]) { |p, arr| arr << Cadooz::Immutable::CatalogProduct.new(p) }
|
11
|
+
|
12
|
+
self.freeze
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Cadooz::Immutable::CatalogProduct
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :attributes, :categories, :mobile_shippable, :name, :number, :offline_shippable, :online_shippable, :type, :variations
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@attributes = Array(open_struct&.attributes)&.each_with_object([]) { |a, arr| arr << Cadooz::Immutable::Attributes.new(a) }
|
8
|
+
@categories = Array(open_struct&.categories)&.each_with_object([]) { |c, arr| arr << Cadooz::Immutable::ProductCategory.new(c) }
|
9
|
+
@mobile_shippable = open_struct&.mobile_shippable
|
10
|
+
@name = open_struct&.name
|
11
|
+
@number = open_struct&.number
|
12
|
+
@offline_shippable = open_struct&.offline_shippable
|
13
|
+
@online_shippable = open_struct&.online_shippable
|
14
|
+
@type = open_struct&.type
|
15
|
+
@variations = Array(open_struct&.variations)&.each_with_object([]) { |v, arr| arr << Cadooz::Immutable::CatalogProductVariation.new(v) }
|
16
|
+
|
17
|
+
self.freeze
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Cadooz::Immutable::CatalogProductVariation
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :currency, :name, :number, :value
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@currency = open_struct&.currency
|
8
|
+
@name = open_struct&.name
|
9
|
+
@number = open_struct&.number
|
10
|
+
@value = Money.new((open_struct&.value.to_f * 100) || 0, @currency || 'USD')
|
11
|
+
|
12
|
+
self.freeze
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Cadooz::Immutable::GenerationProfileProduct
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :cadooz_product_number, :custom_value, :external_product_number, :value
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@cadooz_product_number = open_struct&.cadooz_product_number
|
8
|
+
@custom_value = open_struct&.custom_value
|
9
|
+
@external_product_number = open_struct&.external_product_number
|
10
|
+
@value = open_struct&.value
|
11
|
+
|
12
|
+
self.freeze
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Cadooz::Immutable::Order
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :client, :commission, :cost_owner, :cost_unit, :credit_or_number,
|
5
|
+
:customer_reference_number, :delivery_address, :generation_profile,
|
6
|
+
:greeting_card, :invoice_address, :invoice_information, :language,
|
7
|
+
:order_attributes, :order_description, :order_positions, :payment_informations,
|
8
|
+
:queue, :send_mail, :test, :website
|
9
|
+
|
10
|
+
def initialize(open_struct)
|
11
|
+
@client = open_struct&.client
|
12
|
+
@commission = open_struct&.commission
|
13
|
+
@cost_owner = open_struct&.cost_owner
|
14
|
+
@cost_unit = open_struct&.cost_unit
|
15
|
+
@credit_or_number = open_struct&.credit_or_number
|
16
|
+
@customer_reference_number = open_struct&.customer_reference_number
|
17
|
+
@delivery_address = Cadooz::Immutable::Address.new(open_struct&.delivery_address)
|
18
|
+
@generation_profile = open_struct&.generation_profile
|
19
|
+
@greeting_card = Cadooz::Immutable::GreetingCard.new(open_struct&.greeting_card)
|
20
|
+
@invoice_address = Cadooz::Immutable::Address.new(open_struct&.invoice_address)
|
21
|
+
@invoice_information = Array(open_struct&.invoice_information)&.each_with_object([]) { |i, arr| arr << Cadooz::Immutable::InvoiceInformation.new(i) }
|
22
|
+
@language = open_struct&.language
|
23
|
+
@order_attributes = open_struct&.order_attributes&.inject({}) { |hash, element| hash.merge(element.key.to_sym => element.value) }
|
24
|
+
@order_description = open_struct&.order_description
|
25
|
+
@order_positions = Array(open_struct&.order_positions)&.each_with_object([]) { |o, arr| arr << Cadooz::Immutable::OrderPosition.new(o) }
|
26
|
+
@payment_informations = open_struct&.payment_informations
|
27
|
+
@queue = open_struct&.queue
|
28
|
+
@send_mail = open_struct&.send_mail
|
29
|
+
@test = open_struct&.test
|
30
|
+
@website = open_struct&.website
|
31
|
+
|
32
|
+
self.freeze
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Cadooz::Immutable::OrderPosition
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :amount, :attributes, :cadooz_product_number, :currency,
|
5
|
+
:delivery_address, :external_reference_number, :greeting_card,
|
6
|
+
:value, :voucher_address, :voucher_address_editable,
|
7
|
+
:voucher_address_preset
|
8
|
+
|
9
|
+
def initialize(open_struct)
|
10
|
+
@amount = open_struct&.amount
|
11
|
+
@attributes = open_struct&.attributes&.inject({}) { |hash, element| hash.merge(element.key.to_sym => element.value) }
|
12
|
+
@cadooz_product_number = open_struct&.cadooz_product_number
|
13
|
+
@currency = open_struct&.currency
|
14
|
+
@delivery_address = open_struct&.delivery_address
|
15
|
+
@external_reference_number = open_struct&.external_reference_number
|
16
|
+
@greeting_card = open_struct&.greeting_card
|
17
|
+
@value = open_struct&.value
|
18
|
+
@voucher_address = open_struct&.voucher_address
|
19
|
+
@voucher_address_editable = open_struct&.voucher_address_editable
|
20
|
+
@voucher_address_preset = open_struct&.voucher_address_preset
|
21
|
+
|
22
|
+
self.freeze
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Cadooz::Immutable::OrderStatus
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :delivery_state, :message, :order_number, :order_state,
|
5
|
+
:packet_number, :return_reason, :shipping_provider
|
6
|
+
|
7
|
+
def initialize(open_struct)
|
8
|
+
@delivery_state = open_struct&.delivery_state
|
9
|
+
@message = open_struct&.message
|
10
|
+
@order_number = open_struct&.order_number
|
11
|
+
@order_state = open_struct&.order_state
|
12
|
+
@packet_number = open_struct&.packet_number
|
13
|
+
@return_reason = open_struct&.return_reason
|
14
|
+
@shipping_provider = open_struct&.shipping_provider
|
15
|
+
|
16
|
+
self.freeze
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Cadooz::Immutable::Payment
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :attributes, :description, :paid, :type, :value, :verified
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@attributes = open_struct&.attributes
|
8
|
+
&.map_entries
|
9
|
+
&.elements
|
10
|
+
&.inject({}) { |hash, element| hash.merge(element.key.to_sym => element.value) }
|
11
|
+
@description = open_struct&.description
|
12
|
+
@paid = open_struct&.paid
|
13
|
+
@type = open_struct&.type
|
14
|
+
@value = open_struct&.value
|
15
|
+
@verified = open_struct&.verified
|
16
|
+
|
17
|
+
self.freeze
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Cadooz::Immutable::ProductCategory
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :id, :description, :internal_name, :shop_name
|
5
|
+
|
6
|
+
def initialize(open_struct)
|
7
|
+
@id = open_struct&.id
|
8
|
+
@description = open_struct&.description
|
9
|
+
@internal_name = open_struct&.internal_name
|
10
|
+
@shop_name = open_struct&.shop_name
|
11
|
+
&.map_entries
|
12
|
+
&.elements
|
13
|
+
&.inject({}) { |hash, element| hash.merge(element.key.to_sym => element.value) }
|
14
|
+
|
15
|
+
self.freeze
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Cadooz::Immutable::Voucher
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_reader :address, :code, :ecard_link, :evoucher_link,
|
5
|
+
:pin, :product_name, :product_number,
|
6
|
+
:product_variation_number, :serial_number, :value
|
7
|
+
|
8
|
+
def initialize(open_struct)
|
9
|
+
@address = Cadooz::Immutable::Address.new(open_struct&.address)
|
10
|
+
@code = open_struct&.code
|
11
|
+
@currency = open_struct&.currency
|
12
|
+
@ecard_link = open_struct&.ecard_link
|
13
|
+
@evoucher_link = open_struct&.evoucher_link
|
14
|
+
@pin = open_struct&.pin
|
15
|
+
@product_name = open_struct&.product_name
|
16
|
+
@product_number = open_struct&.product_number
|
17
|
+
@product_variation_number = open_struct&.product_variation_number
|
18
|
+
@serial_number = open_struct&.serial_number
|
19
|
+
@value = Money.new((open_struct&.value.to_f * 100) || 0, @currency || 'USD')
|
20
|
+
|
21
|
+
self.freeze
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Cadooz::Mutable::Address
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_accessor :city, :company, :country, :department, :email, :firstname,
|
5
|
+
:lastname, :phone, :salutation, :state, :street,
|
6
|
+
:street_add_on, :zipcode
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@company = nil
|
10
|
+
@country = nil
|
11
|
+
@department = nil
|
12
|
+
@email = nil
|
13
|
+
@firstname = nil
|
14
|
+
@lastname = nil
|
15
|
+
@phone = nil
|
16
|
+
@salutation = nil
|
17
|
+
@state = nil
|
18
|
+
@street = nil
|
19
|
+
@street_add_on = nil
|
20
|
+
@zipcode = nil
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Cadooz::Mutable::Order
|
2
|
+
include ::Mixins
|
3
|
+
|
4
|
+
attr_accessor :client, :commission, :cost_owner, :cost_unit, :credit_or_number,
|
5
|
+
:customer_reference_number, :delivery_address, :generation_profile,
|
6
|
+
:greeting_card, :invoice_address, :invoice_information, :language,
|
7
|
+
:order_attributes, :order_description, :order_positions, :payment_informations,
|
8
|
+
:queue, :send_mail, :test, :website
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@client = nil
|
12
|
+
@commission = nil
|
13
|
+
@cost_owner = nil
|
14
|
+
@cost_unit = nil
|
15
|
+
@credit_or_number = nil
|
16
|
+
@customer_reference_number = nil
|
17
|
+
@delivery_address = Cadooz::Mutable::Address.new
|
18
|
+
@generation_profile = nil
|
19
|
+
@greeting_card = Cadooz::Mutable::GreetingCard.new
|
20
|
+
@invoice_address = Cadooz::Mutable::Address.new
|
21
|
+
@invoice_information = [] # Cadooz::InvoiceInformation
|
22
|
+
@language = nil
|
23
|
+
@order_attributes = nil
|
24
|
+
@order_description = nil
|
25
|
+
@order_positions = [] # Cadooz::OrderPosition
|
26
|
+
@payment_informations = nil
|
27
|
+
@queue = nil
|
28
|
+
@send_mail = nil
|
29
|
+
@test = nil
|
30
|
+
@website = nil
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Cadooz::Mutable::OrderPosition
|
2
|
+
include Mixins
|
3
|
+
|
4
|
+
attr_accessor :amount, :attributes, :cadooz_product_number, :currency,
|
5
|
+
:delivery_address, :external_reference_number, :greeting_card,
|
6
|
+
:value, :voucher_address, :voucher_address_editable,
|
7
|
+
:voucher_address_preset
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@amount = nil
|
11
|
+
@attributes = nil
|
12
|
+
@cadooz_product_number = nil
|
13
|
+
@currency = nil
|
14
|
+
@delivery_address = nil
|
15
|
+
@external_reference_number = nil
|
16
|
+
@greeting_card = nil
|
17
|
+
@value = nil
|
18
|
+
@voucher_address = nil
|
19
|
+
@voucher_address_editable = nil
|
20
|
+
@voucher_address_preset = nil
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
class Cadooz::BusinessOrderService
|
2
|
+
DEFAULT_TIMEOUT = 10
|
3
|
+
DEFAULT_GENERATION_PROFILE = 'XML Schnittstelle (Test)'
|
4
|
+
|
5
|
+
def initialize(open_timeout = DEFAULT_TIMEOUT, read_timeout = DEFAULT_TIMEOUT)
|
6
|
+
@client = Savon.client(
|
7
|
+
wsdl: Cadooz.configuration.wsdl,
|
8
|
+
basic_auth: [
|
9
|
+
Cadooz.configuration.username,
|
10
|
+
Cadooz.configuration.password
|
11
|
+
],
|
12
|
+
headers: { 'SOAPAction' => '' },
|
13
|
+
open_timeout: open_timeout,
|
14
|
+
read_timeout: read_timeout
|
15
|
+
)
|
16
|
+
|
17
|
+
@call = -> o, m { m ? @client.call(o, message: m) : @client.call(o) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates an order in the cadooz system based on the information given in Order. You should always create an order with a given customer reference number to avoid multiple orders of on order. The customer reference number should be unique over all your orders you do and you should save it on your site.
|
21
|
+
# Returns:
|
22
|
+
# The order result object contains informations about the created order.
|
23
|
+
#
|
24
|
+
### IMPORTANT ###
|
25
|
+
# The minimum set of information that is needed in the Order object is a unique customer_reference_number, a delivery_address and a product_number.
|
26
|
+
#################
|
27
|
+
def create_order(order)
|
28
|
+
response_class = Cadooz::Immutable::OrderStatus
|
29
|
+
|
30
|
+
deserialize(@call.(__callee__, order.serialize), response_class, __callee__)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns informations about an order.
|
34
|
+
# Returns:
|
35
|
+
# The order result object contains informations about the created order.
|
36
|
+
def get_order_status(order_number)
|
37
|
+
response_class = Cadooz::Immutable::OrderStatus
|
38
|
+
|
39
|
+
deserialize(@call.(__callee__, {order_number: order_number}), response_class, __callee__)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns informations about an order based on the customer order reference number given during createOrder(Order) in the field CustomerReferenceNumber.
|
43
|
+
# Returns:
|
44
|
+
# The order result object contains informations about the created order.
|
45
|
+
def get_order_status_by_customer_reference_number(customer_reference_number)
|
46
|
+
response_class = Cadooz::Immutable::OrderStatus
|
47
|
+
|
48
|
+
deserialize(@call.(__callee__, {customer_reference_number: customer_reference_number}), response_class, __callee__)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns informations about changes in one of the created order since the lastCheckTime. You should use this task to get changes in orders. Use the lastCheckTime to reduce the data size and the response time for the needed informations. For example: You have created an order on 01.01.2013. In the best situation you will get between 1-3 days later new change states because the order is delivered. If the order returns after a week, you will receive a new change state. Be aware, that you store your "lastCheckTime" on first request and use it next time. All changes since that time are returned.
|
52
|
+
# Returns:
|
53
|
+
# A list of of order result object containing informations about changed orders.
|
54
|
+
def get_changed_orders(last_check_time)
|
55
|
+
response_class = Cadooz::Immutable::OrderStatus
|
56
|
+
|
57
|
+
deserialize(@call.(__callee__, {last_check_time: last_check_time}), response_class, __callee__)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Order getOrder(java.lang.String orderNumber)
|
61
|
+
# Returns all known data about an order identified by the cadooz order number. Be aware that not all information that we received (invoice informations etc) can be returned. Only the "necessary" informations like what is orders are stored on the order number.
|
62
|
+
# Returns:
|
63
|
+
# The order object or null if no order was found.
|
64
|
+
def get_order(order_number)
|
65
|
+
response_class = Cadooz::Immutable::Order
|
66
|
+
|
67
|
+
deserialize(@call.(__callee__, {order_number: order_number}), response_class, __callee__)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns a list of catalog's for the authenticated user. If an error occurs or the user is not allowed to query any catalog, an empty list will be returned.
|
71
|
+
# Parameters:
|
72
|
+
# includeExtraContent - If true, then some extra content is not included (like attributes and categories)
|
73
|
+
# Returns:
|
74
|
+
# A list of all available catalog id's for context-principal or an empty List.
|
75
|
+
def get_available_catalogs(include_extra_content = false)
|
76
|
+
response_class = Cadooz::Immutable::Catalog
|
77
|
+
|
78
|
+
deserialize(@call.(__callee__, {include_extra_content: include_extra_content }), response_class, __callee__)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns a List of ProductCategory models for CatalogProduct models or an empty list if an error occurs.
|
82
|
+
# Returns:
|
83
|
+
# A list of all categories or an empty list.z
|
84
|
+
def get_available_categories
|
85
|
+
response_class = Cadooz::Immutable::ProductCategory
|
86
|
+
|
87
|
+
deserialize(@call.(__callee__, nil), response_class, __callee__)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns a list of products that can be used within a order. This is specific for a generation profile and should not be mixed up with the merchant catalog getAvailableCatalogs(boolean).
|
91
|
+
# Parameters:
|
92
|
+
# generationProfile - a name of a generation profile defined by cadooz
|
93
|
+
# Returns:
|
94
|
+
# A list of generation profile products that can be used for an order inside createOrder(Order)
|
95
|
+
def get_available_products(generation_profile = DEFAULT_GENERATION_PROFILE)
|
96
|
+
response_class = Cadooz::Immutable::GenerationProfileProduct
|
97
|
+
|
98
|
+
deserialize(@call.(__callee__, {generation_profile: generation_profile }), response_class, __callee__)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns a VoucherInformation Object. The status of the response can be determined using the method VoucherInformation.getResponseState().
|
102
|
+
# If one of the passed arguments is empty the status will be VoucherInformationState.INCORRECT_USAGE.
|
103
|
+
# If passed name of the generation profile is unknown the status will be VoucherInformationState.UNKNOWN_GENERAION_PROFILE.
|
104
|
+
# If passed order number is not existent or does not match the generation profile name or the authenticated user is not allow to query the order informations the status will be VoucherInformationState.ORDER_NOT_FOUND.
|
105
|
+
# Successful queries will have the status VoucherInformationState.SUCCESS.
|
106
|
+
# Parameters:
|
107
|
+
# generationProfileName - The name of the generation profile used to create the order.
|
108
|
+
# orderNumber - The number of the order.
|
109
|
+
# Returns:
|
110
|
+
# A VoucherInformation object. Never null.
|
111
|
+
def get_vouchers_for_order(generation_profile_name = DEFAULT_GENERATION_PROFILE, order_number)
|
112
|
+
response_class = Cadooz::Immutable::Voucher
|
113
|
+
|
114
|
+
deserialize(@call.(__callee__, {generation_profile_name: generation_profile_name, order_number: order_number }), response_class, __callee__)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def deserialize(response, response_class, operation)
|
120
|
+
key = (operation.to_s + '_response').to_sym
|
121
|
+
body = response.body[key][:return]
|
122
|
+
|
123
|
+
if body.blank?
|
124
|
+
object = OpenStruct.new
|
125
|
+
else
|
126
|
+
object = JSON.parse(body.to_json, object_class: OpenStruct)
|
127
|
+
end
|
128
|
+
|
129
|
+
if object.class == Array
|
130
|
+
object.each_with_object([]) { |o, arr| arr << Object::const_get(response_class.to_s).new(o) }
|
131
|
+
elsif object.class == OpenStruct
|
132
|
+
Object::const_get(response_class.to_s).new(object)
|
133
|
+
else
|
134
|
+
# TODO handle exception
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/mixins.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Mixins
|
2
|
+
def serialize(data_only = false)
|
3
|
+
class_name = self.class.to_s.gsub(/Cadooz::[a-z]*::/i, '').underscore
|
4
|
+
result = data_only ? {} : { class_name.to_sym => {} }
|
5
|
+
|
6
|
+
hash_assign = ->name, value { data_only ? result[name] = value : result[class_name.to_sym][name] = value }
|
7
|
+
|
8
|
+
self.instance_variables.each do |var|
|
9
|
+
name = var.to_s.gsub('@', '').to_sym
|
10
|
+
value = self.instance_variable_get(var)
|
11
|
+
|
12
|
+
if value.class.method_defined? :serialize
|
13
|
+
hash_assign.(name, value.serialize(true)) unless instance_variables_empty?(value)
|
14
|
+
elsif value.class == Array
|
15
|
+
arr = []
|
16
|
+
value.each do |val|
|
17
|
+
arr << val.serialize(true) unless instance_variables_empty?(val)
|
18
|
+
end
|
19
|
+
hash_assign.(name, arr) unless arr.blank?
|
20
|
+
elsif !cadooz_class(value.class)
|
21
|
+
hash_assign.(name, value) unless value.blank?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def instance_variables_empty?(instance)
|
29
|
+
instance.instance_variables.each do |var|
|
30
|
+
return false unless instance.instance_variable_get(var).blank?
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def cadooz_class(klass)
|
37
|
+
klass = klass.name.split('::').last.to_sym
|
38
|
+
|
39
|
+
Cadooz.constants.include?(klass)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class String
|
44
|
+
def underscore
|
45
|
+
self.gsub(/::/, '/').
|
46
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
47
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
48
|
+
tr("-", "_").
|
49
|
+
downcase
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cadooz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.11.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.11.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.4.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.24.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.24.0
|
55
|
+
description: cadooz is a world leader in incentive marketing and distribution of digital
|
56
|
+
rewards, including gift cards, e-vouchers, etc. This gem wraps cadooz's BusinessOrderService
|
57
|
+
SOAP API (http://business.cadooz.com/api/businessorder/v1.5.2/com/cadooz/webservice/businessorder/v152/package-summary.html)
|
58
|
+
email:
|
59
|
+
- andrew@bonus.ly
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/cadooz.rb
|
68
|
+
- lib/cadooz/models/immutable/address.rb
|
69
|
+
- lib/cadooz/models/immutable/attributes.rb
|
70
|
+
- lib/cadooz/models/immutable/catalog.rb
|
71
|
+
- lib/cadooz/models/immutable/catalog_product.rb
|
72
|
+
- lib/cadooz/models/immutable/catalog_product_variation.rb
|
73
|
+
- lib/cadooz/models/immutable/generation_profile_product.rb
|
74
|
+
- lib/cadooz/models/immutable/greeting_card.rb
|
75
|
+
- lib/cadooz/models/immutable/invoice_information.rb
|
76
|
+
- lib/cadooz/models/immutable/order.rb
|
77
|
+
- lib/cadooz/models/immutable/order_position.rb
|
78
|
+
- lib/cadooz/models/immutable/order_status.rb
|
79
|
+
- lib/cadooz/models/immutable/payment.rb
|
80
|
+
- lib/cadooz/models/immutable/product_category.rb
|
81
|
+
- lib/cadooz/models/immutable/voucher.rb
|
82
|
+
- lib/cadooz/models/mutable/address.rb
|
83
|
+
- lib/cadooz/models/mutable/greeting_card.rb
|
84
|
+
- lib/cadooz/models/mutable/invoice_information.rb
|
85
|
+
- lib/cadooz/models/mutable/order.rb
|
86
|
+
- lib/cadooz/models/mutable/order_position.rb
|
87
|
+
- lib/cadooz/services/business_order_service.rb
|
88
|
+
- lib/cadooz/version.rb
|
89
|
+
- lib/mixins.rb
|
90
|
+
homepage: http://bonus.ly
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Ruby Wrapper for cadooz SOAP API
|
114
|
+
test_files: []
|