Class: MaropostApi::ProductsAndRevenue
- Inherits:
-
Object
- Object
- MaropostApi::ProductsAndRevenue
- Defined in:
- lib/maropost_api/products_and_revenue.rb
Instance Method Summary collapse
- #create_order(require_unique, contact: {}, order: {}, order_items: [], add_tags: [], remove_tags: [], uid: nil, list_ids: nil, grand_total: nil, campaign_id: nil, coupon_code: nil) ⇒ Object
- #delete_for_order_id(order_id) ⇒ Object
- #delete_for_original_order_id(original_order_id) ⇒ Object
- #delete_products_for_order_id(order_id, product_ids) ⇒ Object
- #delete_products_for_original_order_id(original_order_id, product_ids) ⇒ Object
- #get_order(id) ⇒ Object
- #get_order_for_original_order_id(original_order_id) ⇒ Object
-
#initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) ⇒ ProductsAndRevenue
constructor
A new instance of ProductsAndRevenue.
- #update_order_for_order_id(order_id, order: {}) ⇒ Object
- #update_order_for_original_order_id(original_order_id, order: {}) ⇒ Object
Constructor Details
#initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) ⇒ ProductsAndRevenue
Returns a new instance of ProductsAndRevenue.
7 8 9 10 |
# File 'lib/maropost_api/products_and_revenue.rb', line 7 def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) MaropostApi.instance_variable_set(:@api_key, api_key) MaropostApi.instance_variable_set(:@account, account) end |
Instance Method Details
#create_order(require_unique, contact: {}, order: {}, order_items: [], add_tags: [], remove_tags: [], uid: nil, list_ids: nil, grand_total: nil, campaign_id: nil, coupon_code: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/maropost_api/products_and_revenue.rb', line 26 def create_order( require_unique, contact: {}, order: {}, order_items: [], add_tags: [], remove_tags: [], uid: nil, list_ids: nil, grand_total: nil, campaign_id: nil, coupon_code: nil ) # required contacts fields to check for [:email,].each do |contact_field| raise ArgumentError.new "contact[:#{contact_field}] is required!" if contact.has_key?(contact_field.to_sym) == false end # order items validation order_items.each do |item| raise TypeError.new("Each order item must be an instance of maropost_api/custom_types/OrderItem: " << item.class.to_s << " given") unless item.kind_of?(OrderItem) order[:order_items] ||= [] order[:order_items].push(item.to_hash) end # required order fields to check for [:order_date, :order_status, :original_order_id].each do |order_field| raise ArgumentError.new "order[:#{order_field}] is required!" if order.has_key?(order_field) == false end params = order params[:order_items] = order_items params[:contact] = contact params[:uid] = uid params[:list_ids] = list_ids params[:grand_total] = grand_total params[:campaign_id] = campaign_id params[:coupon_code] = coupon_code full_path = full_resource_path MaropostApi.post_result(full_path, {"order" => params}) end |
#delete_for_order_id(order_id) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/maropost_api/products_and_revenue.rb', line 109 def delete_for_order_id(order_id) full_path = full_resource_path('/find') query_params = MaropostApi.set_query_params({'where[id]' => order_id}) MaropostApi.delete_result(full_path, query_params) end |
#delete_for_original_order_id(original_order_id) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/maropost_api/products_and_revenue.rb', line 102 def delete_for_original_order_id(original_order_id) full_path = full_resource_path("/#{original_order_id}") query_params = MaropostApi.set_query_params MaropostApi.delete_result(full_path, query_params) end |
#delete_products_for_order_id(order_id, product_ids) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/maropost_api/products_and_revenue.rb', line 124 def delete_products_for_order_id(order_id, product_ids) raise TypeError.new('product_ids should be an Array') if ! product_ids.kind_of? Array full_path = full_resource_path("/find") query_params = MaropostApi.set_query_params({"product_ids" => product_ids.join(','), 'where[id]' => order_id}) MaropostApi.delete_result(full_path, query_params) end |
#delete_products_for_original_order_id(original_order_id, product_ids) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/maropost_api/products_and_revenue.rb', line 116 def delete_products_for_original_order_id(original_order_id, product_ids) raise TypeError.new('product_ids should be an Array') if ! product_ids.kind_of? Array full_path = full_resource_path("/#{original_order_id}") query_params = MaropostApi.set_query_params({"product_ids" => product_ids.join(',')}) MaropostApi.delete_result(full_path, query_params) end |
#get_order(id) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/maropost_api/products_and_revenue.rb', line 12 def get_order(id) full_path = full_resource_path("/find") query_params = MaropostApi.set_query_params({"where[id]" => id}) MaropostApi.get_result(full_path, query_params) end |
#get_order_for_original_order_id(original_order_id) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/maropost_api/products_and_revenue.rb', line 19 def get_order_for_original_order_id(original_order_id) full_path = full_resource_path("/#{original_order_id}") query_params = MaropostApi.set_query_params MaropostApi.get_result(full_path, query_params) end |
#update_order_for_order_id(order_id, order: {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/maropost_api/products_and_revenue.rb', line 85 def update_order_for_order_id(order_id, order: {}) raise ArgumentError.new('order_id is required') if order_id.nil? [:order_date, :order_status, :order_items].each do |f| raise ArgumentError.new("order[:#{f}] is required") unless order.has_key?(f) end order[:order_items].each do |oi| raise TypeError.new('each order item should be a type of ' << OrderItem.class.to_s) unless oi.kind_of? OrderItem end order[:order_items].map! {|i| i.to_hash } full_path = full_resource_path("/find") query_params = MaropostApi.set_query_params({"where[id]" => order_id}) MaropostApi.put_result(full_path, {order: order}, query_params) end |
#update_order_for_original_order_id(original_order_id, order: {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/maropost_api/products_and_revenue.rb', line 68 def update_order_for_original_order_id(original_order_id, order: {}) raise ArgumentError.new('original_order_id is required') if original_order_id.nil? [:order_date, :order_status, :order_items].each do |f| raise ArgumentError.new("order[:#{f}] is required") unless order.has_key?(f) end order[:order_items].each do |oi| raise TypeError.new('each order item should be a type of ' << OrderItem.class.to_s) unless oi.kind_of? OrderItem end order[:order_items].map! {|i| i.to_hash } full_path = full_resource_path("/#{original_order_id}") form_body = {order: order} MaropostApi.put_result(full_path, form_body) end |