1

我正在尝试编写一个 ruby​​ on rails 应用程序,将项目发布到 eBay。Cody Fauser/Garry Tan 有一个名为 ebayApi 的 gem,它构建在 ebay gem 之上。当我尝试发布商品时,我从 ebay 收到一条错误消息,提示此类别需要条件 ID。我找到了一个不需要条件的类别,我可以发布到该类别。通过搜索 eBay API 文档,我在“item”类下找到了一个标签 conditionID。但是,在 ebayAPI 的文档中,没有这样的标签。回顾 ebay API 文档,有一种较旧的方法来指定条件,使用 lookup_attributes。我注意到返回的 xml 来自 API 版本 745,Garry Gan 更新的 ruby​​ 接口正在运行版本 609。我尝试使用查找,并且似乎得到相同的错误(需要条件)。我正在使用以下代码来指定项目:

@ebay = Ebay::Api.new :auth_token => @seller.ebay_token
item = Ebay::Types::Item.new( :primary_category => Ebay::Types::Category.new(:category_id => @ebayTemplate.categoryID),
:title => @ebayTemplate.name,
:description => @ebayTemplate.description,
:location => @ebayTemplate.location,
:start_price => Money.new((@ebayTemplate.startPrice*100).to_d, @ebayTemplate.currency),
:quantity => 1,
:listing_duration => @ebayTemplate.listingDuration,
:country => @ebayTemplate.country,
:currency => @ebayTemplate.currency,
:payment_methods => ['VisaMC', 'PayPal'],
:paypal_email_address => '********@gmail.com',
:dispatch_time_max => 3,
:lookup_attributes => [Ebay::Types::LookupAttribute.new( :name => "Condition", :value => "New")],
#         :attribute_sets => [
#           Ebay::Types::AttributeSet.new(
#             :attribute_set_id => 2919,
#             :attributes => [
#               Ebay::Types::Attribute.new(
#                 :attribute_id => 10244,
#                 :values => [ Ebay::Types::Val.new(:value_id => 10425) ]
#               )
#              ]
#           )
#         ],
:shipping_details => Ebay::Types::ShippingDetails.new(
:shipping_service_options => [
#              ShippingServiceOptions.new(
#              :shipping_service_priority => 2, # Display priority in the listing
#              :shipping_service => 'UPSNextDay',
#              :shipping_service_cost => Money.new(1000, 'USD'),
#              :shipping_surcharge => Money.new(299, 'USD')
#             ),
Ebay::Types::ShippingServiceOptions.new(
:shipping_service_priority => 1, # Display priority in the listing
:shipping_service => @ebayTemplate.shipSvc,
:shipping_service_cost => Money.new((@ebayTemplate.shipSvcCost*100).to_d, @ebayTemplate.currency),
:shipping_surcharge => Money.new((@ebayTemplate.shipSurcharge*100).to_d, @ebayTemplate.currency)
)
],
:international_shipping_service_options => [
Ebay::Types::InternationalShippingServiceOptions.new(
:shipping_service => 'USPSPriorityMailInternational',
:shipping_service_cost => Money.new((@ebayTemplate.shipSvcCost*100).to_d, @ebayTemplate.currency),
:shipping_service_priority => 2,
:ship_to_location => @ebayTemplate.shipToLocation
)
]

),
:return_policy => Ebay::Types::ReturnPolicy.new (
:description => 'this product for suckers only!',
:returns_accepted_option => 'ReturnsAccepted'
)
#:condition_id => 1000
)

@response = @ebay.add_item(:item => item)

如您所见,它只是 Cody Fauser 给出的示例的一个突变。底部的 condition_id 会报错,因为没有这样的属性。在我看来,宝石中没有此功能,因为该要求是在创建宝石后出现的。我无法找到任何其他宝石与 ebay 连接。我还注意到,尽管人们仍在下载 gem(今天有 10 人下载了它),但对此的抱怨很少。我认为有相当多的人为 ebay 写作。我是否缺少指定条件的关键字?人们一直在使用的解决方法?我错过的另一个宝石?

4

1 回答 1

0

gem 的类型目录中有一个现有的 item_conditions_codes.rb,并且只有两个值 New 和 Used。猜猜你可以在那里添加更多的值。但是仍然需要根据更新(并从属性更改)方法映射到 ID

您必须在 .. 中的 gem 库中进行修改ruby/1.8/gems/ebayapi-0.12.0/lib/ebay/types/item.rb 并添加以下新行

# added to allow ConditionID to be pushed into XML
numeric_node :condition_id, 'ConditionID', :optional => true

然后在您的 ruby​​ ebay 代码中使用以下约定

:condition_id => 1500,

至少现在这似乎对我有用。

于 2012-08-09T06:10:22.067 回答