I'm Ruby n00b, so please excuse my first question.
I've got my Rails environment up on a web server up, and now I am trying to find a Ruby functions (methods?) that would allow me to do the following:
Function 1
suck in an XML feed from another website
cherry pick a particular field from that XML field (e.g. email addr or phone)
Function 2
send that particular XML field to phone number via Twilio.
Any suggestions on where to start would be helpful. (Even if it's to tell me to RTFM)
For your first function, you don't need to do anything with Twilio. I presume you want to parse an XML feed to get specific data from it.
You can use a gem like nokogiri to parse XML, have a look at this similar SO question to learn how:
Parsing XML with Ruby
There's tons of other resources on parsing XML using ruby here to:
https://www.google.ca/search?q=parse+xml+ruby&rlz=1C1CHFX_enCA552CA552&oq=parse+xml+ruby&aqs=chrome..69i57j0l5.3359j0j7&sourceid=chrome&es_sm=122&ie=UTF-8
For your second function, this is where you'll actually be using Twilio. First off, I'm assuming you've setup Twilio, if not, head over to and sign up:
https://www.twilio.com/
You'll want to add the Twilio ruby client in your Gemfile:
gem 'twilio-ruby'
Be sure to bundle install and if everything is good, you are ready to code your Twilio interaction. Assuming from fn1 you have the data in a variable, you'll now need to send it via SMS/MMS, here's the Twilio guide for that:
https://www.twilio.com/docs/quickstart/ruby/sms/sending-via-rest
Related
I am looking for an easy way to parse an IMAP struct that I have read from an exiting email account. Ideally if you could point me to an existing gem that handles imap emails. Everything I find is extremely old.
My app fetches email from an existing, external imap account. I am able to read the email and retrieve it and even to parse it and extract most of the information I want. However, I am not able to extract the HTML or text body parts easily. Overall, parsing the struct that is returned by the net/imap library is difficult to handle.
All the help articles that I can find on the topic seem VERY old and existing gems have not been updated in many years.
Is there not an easy way, a gem or built in library to handle imap objects? I am also open t rewriting my app to do things easier. My code below is workig fine. The envelopes struct that I receive back is just really awful to work with.
connection = Net::IMAP.new(server.inbound_server, server.inbound_port, server.inbound_encryption)
connection.login(server.inbound_user, server.inbound_password)
connection.examine("INBOX")
uid_list = connection.search(["FROM", search_term])
envelopes = connection.fetch(uid_list, "ENVELOPE")
Is there an easy way to collect click stream data from a rails application?
(for example by activating a gem)
I searched rubygems but couldn't find anything.
You are more likely to find a solution in Javascript, as it is a server side technology. For example, a service like clickstreamr only requires you to copy/paste some javascript code and it will record your click stream data
I am working with the Mail Gem to receive emails in my Rails 4 application. The mails are grabbed via POP from a mailbox, every 10 minutes or so, via the Gem.
I need to render these emails - mostly in HTML format - and am having trouble saving the body in HTML, not to mention working with things like embedded images. I'm probably missing something here- looked all over StackOverflow but haven't seen an answer to related questions yet.
I have been working with
message.body.decoded
and also looked at the html_part v. text_part - but I don't see a method to get to just the enclosed HTML. Looks like I need to strip the headers, which the Mail Gem seems to leave in the body- then also deal with any inline attachments. Surely a gem for this must exist..? Or an approach...? Your advice is valued.
I did find the Mailcatcher Gem - but that is really its own Sinatra app. I might just try adapting this gem but that appears to be a lot of work. Surely someone else has already dealt with this problem..?
I would also value a suggestion on how to best store the message body in MySQL - am thinking large text or blob type.
Thank you!
I use letter opener
It works fine... And if you are using vagrant as the main development machine you you can use this
Letter opener web
In php I am using curl but being new to Ruby and Rails, I am little lost about the best way to do this,
So I have http://example.com/api?=topmovies&ratings which returns list of 10 movies with their ratings. Unfortunately it is not in json/xml but just text so I was wondering,
How to read/retrieve the text from url in rails
How to parse/put the data in variables (it has 2 columns and 10 rows)
Thanks
You could use curl with ruby too, but the preferred way to interact with websites is with the mechanize gem. Take a look at the mechanize examples page to see how to get the page from a website and parse through the content.
You can use RestClient gem to get content of another website.
I'm working on a rails app that searches the Twitter API stream for keywords and then records those tweets.
I've used Hpricot before to parse XML but I was wondering if someone could recommend a gem (or even a best practice) to parse JSON from the Twitter search API?
If you use the newly rewritten Twitter gem, you can make a query like this:
Twitter.user_timeline("sferik").first
The response would be a Hashie::Mash object corresponding to the first status. To access the information, you just call the attribute like it was a method:
Twitter.user_timeline("sferik").first.text
The response from this is just text. You don't have to directly deal with JSON.
I believe there are many twitter gems that should work. Github has the twitter gem as the most popular.
I have used it 1 1/2 yrs ago, but it should do what you want and have support to back it up.
I use the json gem to parse Twitter responses. To access the api I use grackle and sometimes curb to do api requests in parallel (Curl::Multi).