我仍处于学习编码的早期阶段,我对API响应的格式有些困难。下面是我的代码以及我从控制台获得的响应。
def etsy_response
# Reading the access tokens from a text file
auth = File.open("access_hash.txt", "r").read
access = eval(auth)
# Making the API request
response_request = Etsy::Request.get('private/shops/MYSTORE/transactions', access.merge(:limit => 5))
puts response_request
end
etsy_response
以下是我在控制台中收到的回复
#<Etsy::User:0x007f8bb3c30cf8>
我认为我可能要么完全错误,要么可能是我在代码中遗漏的小事。理想情况下,我希望以JSON格式返回响应。
任何帮助或指导都会非常感激,因为我已经在这个网站上搜索过了。
非常感谢 迈克:)
尝试了一个新请求,因为第一个请求没有有效的端点
response_request = Etsy::Request.get('/listings/127178505/transactions', access.merge(:limit => 5))
控制台中的响应是 #&GT;
因此,这确认了端点有效。但是,我的回复仍然不会返回JSON格式化数据。
................ UPDATE ....................
好的,我得到它来使用API返回一些数据但是我无法弄清楚下面数据的格式是更新的工作代码
def etsy_response
# Reading the access tokens from a text file
auth = File.open("access_hash.txt", "r").read
access = eval(auth)
# Making the API request
response_request = Etsy::Transaction.get('/private/shops/UrbanMooseApparel/receipts', access.merge(:limit => 2))
auth_file = File.open("data.txt", "w")
auth_file.print response_request
auth_file.close
print response_request.inspect
end
etsy_response
这是回复
[#<Etsy::Transaction:0x007fc143b82110 @result={"receipt_id"=>1039333045, "order_id"=>344455819, "seller_user_id"=>31058936, "buyer_user_id"=>1234456, "creation_tsz"=>354354, "last_modified_tsz"=>1441662724, "name"=>"reretrt", "first_line"=>"rggfdgfdg", "second_line"=>nil, "city"=>"aaaaa", "state"=>"OH", "zip"=>"34324", "country_id"=>209, "payment_method"=>"pp", "payment_email"=>"MY@EMAIL.com", "message_from_seller"=>nil, "message_from_buyer"=>"", "was_paid"=>true, "total_tax_cost"=>"0.00", "total_vat_cost"=>"0.00", "total_price"=>"5.99", "total_shipping_cost"=>"0.00", "currency_code"=>"EUR", "message_from_payment"=>"", "was_shipped"=>true, "buyer_email"=>"SELLEREMAIL", "seller_email"=>"MY@EMAIL.com", "discount_amt"=>"0.00", "subtotal"=>"5.99", "grandtotal"=>"5.99", "adjusted_grandtotal"=>"5.99", "shipping_tracking_code"=>"", "shipping_tracking_url"=>nil, "shipping_carrier"=>"", "shipping_note"=>"fgfdgsdgvfvfgvfk", "shipping_notification_date"=>1441662724, "shipments"=>[{"receipt_shipping_id"=>nil, "mailing_date"=>1441641600, "carrier_name"=>nil, "tracking_code"=>nil, "current_step"=>nil, "current_step_date"=>nil, "mail_class"=>nil, "buyer_note"=>"fdgfdgfdgfgf", "notification_date"=>1441662724, "tracking_url"=>nil}], "has_local_delivery"=>false, "shipping_details"=>{"can_mark_as_shipped"=>false, "was_shipped"=>true, "is_future_shipment"=>false, "shipment_date"=>1441662724, "shipping_method"=>"Standard Shipping", "requested_start_time"=>"8:00pm", "requested_end_time"=>"11:00pm", "requested_time_formatted"=>"8-11pm, Dec 31", "requested_time_is_now"=>false, "requested_time_is_today"=>false}}, @token="MyToken", @secret="MySecret">, #<Etsy::Transaction:0x007fc143b82070 @result={"receipt_id"=>103698249df0, "order_id"=>343127fdsf3689, "seller_user_id"=>310358976, "buyer_user_id"=>37428099, "creation_tsz"=>1441019886, "last_modified_tsz"=>1441027632, "name"=>"3243", "first_line"=>"3423", "second_line"=>"A3326", "city"=>"RE342G", "state"=>"ID", "zip"=>"8334440", "country_id"=>209, "payment_method"=>"pp", "payment_email"=>"MY@EMAIL.com", "message_from_seller"=>nil, "message_from_buyer"=>nil, "was_paid"=>true, "total_tax_cost"=>"0.00", "total_vat_cost"=>"0.00", "total_price"=>"7.99", "total_shipping_cost"=>"0.00", "currency_code"=>"EUR", "message_from_payment"=>"", "was_shipped"=>true, "buyer_email"=>"SELLEREMAIL", "seller_email"=>"MY@EMAIL.com", "discount_amt"=>"0.00", "subtotal"=>"7.99", "grandtotal"=>"7.99", "adjusted_grandtotal"=>"7.99", "shipping_tracking_code"=>"", "shipping_tracking_url"=>nil, "shipping_carrier"=>"", "shipping_note"=>"dsffdsfdsfds", "shipping_notification_date"=>1441027632, "shipments"=>[{"receipt_shipping_id"=>nil, "mailing_date"=>1441036800, "carrier_name"=>nil, "tracking_code"=>nil, "current_step"=>nil, "current_step_date"=>nil, "mail_class"=>nil, "buyer_note"=>"ff dfdfd", "notification_date"=>1441027632, "tracking_url"=>nil}], "has_local_delivery"=>false, "shipping_details"=>{"can_mark_as_shipped"=>false, "was_shipped"=>true, "is_future_shipment"=>false, "shipment_date"=>1441027632, "shipping_method"=>"Standard Shipping", "requested_start_time"=>"8:00pm", "requested_end_time"=>"11:00pm", "requested_time_formatted"=>"8-11pm, Dec 31", "requested_time_is_now"=>false, "requested_time_is_today"=>false}}, @token="TOKEN", @secret="Secret">]
将此转换为JSON的任何帮助或指导都将非常感激。