A way to talk to messaging api of linkedin through rails - ruby-on-rails

Scenario:
I'm a registered user of a site(a rails app).
I have my contacts in linked in whom I would like to invite to see this app(it would be followed up with their registration into this app).
For this , I would be sending them a message with a subject and body.
Rays of Hope:
I need to make use of the messaging api of linkedin and make it talk with my rails app. I can't use the connections api of linked in to retrieve the email addresses as basically any of the linkedin api's don't expose my(the registered user of linked in) contacts email.
To talk with the connections api in my rails app, I was making use of the linkedin gem. It doesn't look like this gem as of now has support for the messaging api of linkedin.
Finally:
Any ideas where can I get started on this..?. I'm kinda clueless as I have never played around with api's directly, ..yet..:).
I'm on Ubuntu 10.04 OS.
Thank you

I had the same problem with the gem lacking messaging functionality. By using the existing code as a reference, I threw this code in an initializer file (config/initializer) and it worked. Give it a try.
LinkedIn::Client.class_eval do
# options should be a hash like this:
# options = {:recipients => {:values => [:person => {:_path => "/people/~" }, :person => {:_path => "/people/USER_ID"} ]}, :subject => "Something",:body => "To read" }
def send_message(options)
path = "/people/~/mailbox"
post(path, options.to_json, "Content-Type" => "application/json")
end
end

This might not exactly answer the question, but could be of some help..
Have you looked here:
https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/api/update_methods.rb
If you'll log an issue on the project repo and include some code, the
whole community can try to help:
https://github.com/pengwynn/linkedin/issues
This was provided by Wynn Netherland on contacting him. Credit goes to him..:)

Related

Receive Mails with Rails

I would like to scrap mails from a MailBox, this is the situation:
It's about a Technical support with a Ticket System.
A client make a demand on the contact form on the website,
The ticket have a page with a chat and a task list made by the admin in charge of the ticket, so a link to this page is sent to the client who made the demand,
Then when the Admin answer to the ticket in the chat, a mail is sent to the Client, everything to there is ok, the problem is that when the client answer to this email, the content of the mail must be scrapped and added to the database to be seen in the Ticket Chat.
So the Idea is that the Client Can follow the progress of his Ticket by mail instead of going to the ticket page.
I've tried MailMan, but that didn't work, the deamon was starting and then crashed after a couple of minutes whitout scrapping anything, I don't use SendGrid but a private SMTP server so I can't use the Grabber gem of this service.
I'm running Rails 5, my DB is in PostGre, and I'm using ActionMailer as mailing system.
I'm running out of ideas about how to make this feature..
I hope my question is clear enough and my English not too bad.
I suggest you to make an email(any popular provider except gmail) box and configure it to use the pop server. To read it from box use the mail gem.
Mail.defaults do
retriever_method :pop3, :address => "pop.supermail.com",
:port => 995,
:user_name => '<username>',
:password => '<password>',
:enable_ssl => true
end
Then make a daemon to read all income emails and save it to the database, mail gem is just a wrapper around Net::POP3 ruby library and it is super useful for read\receive\parse\build mails.
The ActionMailer here is not a helper for you, it is very handy only for send mails and it does nothing to recieve mail.

Where in the Shopify Rails App should I create uninstall webhooks?

I'm trying to create an 'app/uninstall' webhook in my Shopify app. The app boilerplate was generated using the Shopify API gem(https://github.com/Shopify/shopify_app), and I've followed the instructions in their readme to the letter.
To create these webhooks, I'm assuming they'd have to be somewhere when the client shop first connects with the app - but I'm not sure where exactly that takes place in the whole thing. I've pushed the boilerplate code here: https://github.com/shabbirun/shopify-help-app
I first guessed that the code should be in the Shop model, so I tried implementing it using :after_create , but I'm getting an error.
Any ideas as to where I can place the code?
Thank you!
You will need to post/put a new webhook through the API.
Example code is in node: (ruby will be different)
shopify.post('/admin/webhooks.json', {
webhook: {
topic: 'app/uninstalled',
address: 'https://yoururl.com/shopify/uninstall',
format: 'json'
}
}, done);
Once the admin webhook has been added, anytime a user uninstalls the app it will hit your api route for shopify uninstalls.
In terms of placing the code we recommend doing it when a user first approves your app, whichever route that may be.
https://docs.shopify.com/api/webhook
To register a webhook, you can run the add_webhook generator or add a line manually in the shopify_app.rb initializer:
config.webhooks = [
{topic: 'app/uninstalled', address: 'https://myapp.url/webhooks/app_uninstalled', format: 'json'},
{topic: 'orders/create', address: 'https://myapp.url/webhooks/orders_create', format: 'json'},
]
With this setup, your app will register the webhooks automatically when your app gets installed in a shop.

Why is webhook which has been successfully created by the app not showing up in the Shopify admin?

I am creating a demo plugin for Shopify and getting issues with creating Webhooks for the admin. I am doing something as below.
pry(#<HomeController>)> webhook = ShopifyAPI::Webhook.create(:format => "json", :topic => "carts/create", :address => "http://requestb.in/1k49wje1/")
=> #<ShopifyAPI::Webhook:0x007fe8207141d8
#attributes=
{"format"=>"json",
"topic"=>"carts/create",
"address"=>"http://requestb.in/1k49wje1/",
"id"=>6726111,
"created_at"=>"2014-08-12T08:33:42-04:00",
"fields"=>[],
"metafield_namespaces"=>[],
"updated_at"=>"2014-08-12T08:33:42-04:00"},
#errors=#<ActiveResource::Errors:0x007fe82071f0d8 #base=#
<ShopifyAPI::Webhook:0x007fe8207141d8 ...>, #messages={}>,
#persisted=true,
#prefix_options={},
#remote_errors=nil,
#validation_context=nil>
pry(#<HomeController>)> ShopifyAPI::Webhook.all.count
=> 1
If I create another webhook for the same topic, it throws an error. Why is the webhook not showing up in my shopify admin? What am I missing here?
EDIT: I tried running the same code on my friend's system and he could access my webhook using count and when he created, I also could access the webhook. What is happening here? Webhooks are being created on two different systems but not showing up in admin section? If not on admin, where are they getting persisted?
Webhooks never show up in the Admin. For good reason. You created them with the API for a reason. If they showed up in the Admin, anyone with access to the Admin could just delete them, completely screwing up your App. So you just read webhooks using the API and your key and then determine if they are there or not.. pretty neat eh?

How to hide sensitive Twilio account information (account_sid & auth_token)

I am getting introduced the wonderful world of Twilio + RoR and have so far had a pleasant experience.
However, I've noticed that if I were to make my projects public, I would exposing sensitive Twilio account information:
Account_sid
Auth_token
Twilio phone number
My question is, how can I hide these three pieces of information in a Rails application so that when pushed to GitHub, they remain unaccessible to others?
Here is some sample code below:
class SMS < ApplicationController
def text
message = params[:message]
number = params[:number]
account_sid = 'xxxxxxxxxxxxHIDExxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyHIDEyyyyyyyyyyyyyy'
#client = Twilio::REST::Client.new account_sid, auth_token
#message = #client.account.messages.create({:to => "+1"+"#{number}",
:from => "zzzzHIDEzzzz",
:body => "#{message}"})
redirect_to '/index'
end
end
The answer is to not publish that information to GitHub in the first place.
When I worked with Twilio applications, I used a localsettings.py (Python, but should be the same for Ruby) file holding the sensitive information that I downloaded and distributed out-of-band.
A user-friendly interface could be a setup script to download this file from a server credentials.
Alternatively, if you must check it into github, encrypt it symmetrically with something like gnupg and decrypt it on your host machine.
In all these cases, you have to be careful not to accidentally check it in to git. Adding localsettings.rb to your .gitignore file is a great idea.
(If you've already pushed it to github, see here for how to undo that.)
a bit late my answer but you should use environment variables instead hardcoded strings.
in production you can use some tools like Vault to store it safely. here is a nice article about it https://medium.com/adessoturkey/getting-started-with-hashicorp-vault-658a3e523949

Sending SMS messages from a Rails Application without Gems

What are the links/keys needed to create a ruby application to send an SMS using an API. Without having to write gems for it? I have a link to the service and an API key. I need to know where to start. Im new to ruby and am trying to follow this tutorial but cant seem to get anywhere without knowing what i do without using clickatell. http://lukeredpath.co.uk/blog/sending-sms-messages-from-your-rails-application.html
For sending the actual HTTP request, you can use one of the several ruby HTTP libraries/gems, like REST Client, httparty or plain Net/HTTP.
The most simple one might be REST Client, example:
require 'rest_client'
API_URL = 'http://yourapiurl.com/resource'
API_KEY = 'thatoneapikey'
RestClient.post API_URL, :api_key => API_KEY, :number => '7812637813', :body => 'Foo SMS Text Bar Baz'
Best regards
Tobias
There is a gem done by a friend for the routo messaging system
https://github.com/weboglobin/Routo
you can use it, or just take it as an inspiration

Resources