I'm trying to parse an RSS file. It throws a 404 response when I do:
Feedjira::Feed.fetch_and_parse url
So I thought trying:
Feedjira::Parser::RSS.parse url
But that returns 0 entries
This is exactly what I'm trying:
<% Feedjira::Parser::RSS.parse("my url here").entries.each do |e| %>
<%= "#{e.title}" %><br />
<% end %>
The rss file is being parse with no problem with php in another web. This is the structure:
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Title here</title>
... etc ...
<item>
<title>Title here</title>
... etc ...
</item>
<item> ... etc ... </item>
</channel>
</rss>
It's weird that Feedjira::Feed.fetch_and_parse url wasn't working for you. It's working perfectly fine for me.
Here's how I did it. I'm using Railscasts RSS feed for example purpose:
url = "http://railscasts.com/subscriptions/rZNfSBu1hH7hOwV1mjqyLw/episodes.rss"
feed = Feedjira::Feed.fetch_and_parse url
feed.entries.each do |entry|
puts entry.title
end
Related
i want feed(text/html) entry appear except id, published, and tag cocat (g:)
this is My atom.builder
atom_feed ({:id => '', 'xmlns:g' => "http://base.google.com/ns/1.0"}) do |feed|
feed.title #brand.name
#products.each do |product|
url = ''
feed.entry product, url:url do |entry|
entry.name(product.name)
end
end
end
this is result
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">
<id></id>
<title>Default Shop</title>
<entry>
<id></id>
<published>2020-03-04T05:36:52+09:00</published>
<updated>2021-11-24T10:16:54+09:00</updated>
<link rel="alternate" type="text/html" href="localhost/1/1">
<name>product no</name>
</entry>
</feed>
and i want
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">
<title>Default Shop</title>
<entry>
<g:name>product no</name>
</entry>
</feed>
how can i get this result?
I'm trying to delete an invoice from Xero by updating its status to "DELETED". Following the xeroizer github page I have tried the following:
xero = XeroApp.find_by(business_id: 270);
invoice = xero.find_invoice_by_ref(372).first
delete_invoice = xero.xero_client.Invoice.build(id: invoice.id, status: 'DELETED')
delete_invoice.save #=> false
delete_invoice.status #=> "AUTHORISED"
Unfortunately this doesn't update the invoice status. I thought that maybe removing the corresponding payment may help but it didn't. Incidentally I used a similar approach for removing the payment as above which did work.
Response to delete_invoice.save is:
XeroGateway Request: GET /api.xro/2.0/Invoices/09b354ba-c659-4aac-b353-7d56cb52c2d6?unitdp=4
XeroGateway Response (200)
/api.xro/2.0/Invoices/09b354ba-c659-4aac-b353-7d56cb52c2d6?unitdp=4
== Response Body
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
<Id>3033fc56-2eed-446c-a16b-1c0a3678f6cf</Id>
<Status>OK</Status>
<ProviderName>My-App</ProviderName>
<DateTimeUTC>2022-02-24T13:40:46.7218944Z</DateTimeUTC>
<Invoices>
<Invoice>
<Contact>
<ContactID>0bb81c84-22a0-40fc-a12b-322646752710</ContactID>
<ContactStatus>ACTIVE</ContactStatus>
<Name>Sagar Pandya</Name>
<Addresses>
<Address>
<AddressType>STREET</AddressType>
</Address>
<Address>
<AddressType>POBOX</AddressType>
<AddressLine1>123 High Road</AddressLine1>
<City>London</City>
<PostalCode>SW1 8RE</PostalCode>
<Country>United Kingdom</Country>
</Address>
</Addresses>
<Phones>
<Phone>
<PhoneType>DEFAULT</PhoneType>
<PhoneNumber>07123456789</PhoneNumber>
</Phone>
<Phone>
<PhoneType>DDI</PhoneType>
</Phone>
<Phone>
<PhoneType>FAX</PhoneType>
</Phone>
<Phone>
<PhoneType>MOBILE</PhoneType>
</Phone>
</Phones>
<UpdatedDateUTC>2022-02-08T20:01:08.327</UpdatedDateUTC>
<IsSupplier>false</IsSupplier>
<IsCustomer>true</IsCustomer>
</Contact>
<Date>2022-02-24T00:00:00</Date>
<DueDate>2022-02-24T00:00:00</DueDate>
<BrandingThemeID>5d4dd402-c851-497e-aae1-9ff265c0d15a</BrandingThemeID>
<Status>AUTHORISED</Status>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<ItemCode>FOOTYT</ItemCode>
<Description>Football T-Shirt</Description>
<UnitAmount>100.0000</UnitAmount>
<TaxType>NONE</TaxType>
<TaxAmount>0.00</TaxAmount>
<LineAmount>100.00</LineAmount>
<AccountCode>200</AccountCode>
<Item>
<ItemID>0ad76998-051d-4031-9f97-fba6b9bb255e</ItemID>
<Code>FOOTYT</Code>
</Item>
<Quantity>1.0000</Quantity>
<LineItemID>497fc08c-3571-49cb-bcd7-6a28533f9d34</LineItemID>
</LineItem>
</LineItems>
<SubTotal>100.00</SubTotal>
<TotalTax>0.00</TotalTax>
<Total>100.00</Total>
<UpdatedDateUTC>2022-02-24T12:26:13.317</UpdatedDateUTC>
<CurrencyCode>GBP</CurrencyCode>
<Type>ACCREC</Type>
<InvoiceID>09b354ba-c659-4aac-b353-7d56cb52c2d6</InvoiceID>
<InvoiceNumber>INV-0073</InvoiceNumber>
<Reference>372</Reference>
<AmountDue>100.00</AmountDue>
<AmountPaid>0.00</AmountPaid>
<SentToContact>false</SentToContact>
<CurrencyRate>1.0000000000</CurrencyRate>
<HasAttachments>false</HasAttachments>
<HasErrors>false</HasErrors>
</Invoice>
</Invoices>
</Response>
== End Response Body
=> false
Use the methods outlined in the api here:
https://github.com/waynerobinson/xeroizer/blob/master/lib/xeroizer/models/invoice.rb
For this question: After retrieving the invoice use invoice.void!.
Q: How do I generate the XML nodes specific to iTunes using Ruby/Rails?
Trying to generate iTunes XML feed, e.g. (based off example):
xml.instruct! :xml, :version => "1.0"
xml.rss(:version => "2.0") do
xml.channel do
xml.title "Your Blog Title"
xml.description "A blog about software and chocolate"
xml.link posts_url
#posts.each do |post|
xml.item do
xml.title post.title
xml.description "Temporary post description"
xml.pubDate post.created_at.to_s(:rfc822)
xml.link post_url(post)
xml.guid post_url(post)
end
end
end
end
Which happily generates something like:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Your Blog Title</title>
<description>A blog about software and chocolate</description>
<link>https://pubweb-thedanielmay.c9.io/sermons</link>
<item>
... omitted ...
</item>
</channel>
</rss>
But looks like I need to generate iTunes-specific XML nodes (as per Working With iTunes, e.g.)
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <-- *
<channel>
<title>Your Blog Title </title>
... omitted ...
<itunes:subtitle>A program about everything</itunes:subtitle> <-- *
... etc ...
Not sure how I generate the iTunes-specific nodes as they have colons in them.
Standard RSS nodes are like:
xml.item --> <item>
How do I get to generating nodes like:
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<itunes:author>
Ah, answers as per code via Ryan Bates' awesome Railscasts RSS sample
xml.rss "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", :version => "2.0"
and
xml.itunes :author, author
I set up a simple XML feed for a vendor we're using (who refuses to read JSON).
<recipes type="array">
<recipe>
<id type="integer">1</id>
<name>
Hamburgers
</name>
<producturl>
http://test.com
</producturl>
...
</recipe>
...
<recipe>
However, the vendor requests that instead of having an id node, id is an attribute in the parent node. e.g.
<recipes type="array">
<recipe id="1">
<name>
Hamburgers
</name>
<producturl>
http://test.com
</producturl>
...
</recipe>
...
<recipe>
I'm building this with (basically)
xml_feed = []
recipes.each do |recipe|
xml_feed <<{id: recipe.id, name: recipe.name, ...}
end
...
render xml: xml_feed.to_xml(root: 'recipes')
But I'm unsure of how to include the id (or any field) as an attribute in the parent node like that. I googled around and couldn't find anything, nor were the http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html docs very helpful
Thanks!
I would suggest you use the nokogiri gem. It provides all you can possible need for handling XML.
builder = Nokogiri::XML::Builder.new do |xml|
xml.root {
xml.objects {
xml.object.classy.thing!
}
}
end
puts builder.to_xml
<?xml version="1.0"?>
<root>
<objects>
<object class="classy" id="thing"/>
</objects>
</root>
The suggestion to use Nokogiri is fine. Just the sintax should be a little bit different to achive what you have requested:
builder = Nokogiri::XML::Builder.new do |xml|
xml.root {
xml.object('type' => 'Client') {
xml.name 'John'
}
}
end
puts builder.to_xml
<?xml version="1.0"?>
<root>
<object type="Client">
<name>John</name>
</object>
</root>
<title>Webisode 200 Playlist</title>
<item>
<title>Testing 201</title>
<media:credit role="author">Adam Houston</media:credit>
<media:content url="http://www.youtube.com/watch?v=gb0bGZ06vXn" type="video/x-flv" />
<jwplayer:duration>200</jwplayer:duration>
</item>
i'm using rails xml to generate the corresponding xml but my question is how do i generate tags with namespace like or also how do i tell xml about the attirbutes like role="author".
Regards,
use the tag! method if you want to create such tags:
xml.tag!("SOAP:Envelope") # => <SOAP:Envelope/>
attributes are passed as hash options:
xml.target("name"=>"compile") # => <target name="compile"\>
see the documentation for more infos: http://ap.rubyonrails.org/classes/Builder/XmlMarkup.html#M000157