Class: Mws::Apis::Feeds::TargetedApi

Inherits:
Object
  • Object
show all
Defined in:
lib/mws/apis/feeds/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(feeds, merchant, type) ⇒ TargetedApi

Returns a new instance of TargetedApi.



58
59
60
61
62
63
# File 'lib/mws/apis/feeds/api.rb', line 58

def initialize(feeds, merchant, type)
  @feeds = feeds
  @merchant = merchant
  @message_type = Feed::Message::Type.for(type)
  @feed_type = Feed::Type.for(type)
end

Instance Method Details

#add(*resources) ⇒ Object



65
66
67
# File 'lib/mws/apis/feeds/api.rb', line 65

def add(*resources)
  submit resources, :update, true 
end

#delete(*resources) ⇒ Object



78
79
80
# File 'lib/mws/apis/feeds/api.rb', line 78

def delete(*resources)
  submit resources, :delete
end

#patch(*resources) ⇒ Object



73
74
75
76
# File 'lib/mws/apis/feeds/api.rb', line 73

def patch(*resources)
  raise 'Operation Type not supported.' unless @feed_type == Feed::Type.PRODUCT
  submit resources, :partial_update
end

#submit(resources, def_operation_type = nil, purge_and_replace = false) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mws/apis/feeds/api.rb', line 82

def submit(resources, def_operation_type=nil, purge_and_replace=false)
  messages = []
  feed = Feed.new @merchant, @message_type do
    resources.each do | resource |
      operation_type = def_operation_type
      if resource.respond_to?(:operation_type) and resource.operation_type
        operation_type = resource.operation_type
      end 
      messages << message(resource, operation_type)
    end
  end
  Transaction.new @feeds.submit(feed.to_xml, feed_type: @feed_type, purge_and_replace: purge_and_replace) do 
    messages.each do | message |
      item message.id, message.resource.sku, message.operation_type, 
        message.resource.respond_to?(:type) ? message.resource.type : nil
    end
  end
end

#update(*resources) ⇒ Object



69
70
71
# File 'lib/mws/apis/feeds/api.rb', line 69

def update(*resources)
  submit resources, :update
end