sending invitation using linkedin gem
Can I use linkedi开发者_如何学Cn gem to send invitation by email??
looks like you can not, yet. From the Readme:
TODO
Change to json api
Update and correct test suite
Change to Faraday for authentication
Implement Messaging APIs
config/initializers/linkedin.rb
LinkedIn::Client.class_eval do
def send_invitation(options)
path = "/people/~/mailbox"
message = {
"recipients" => {
"values" => [
{
"person" => {
"_path" => "/people/email=#{options[:email]}",
"first-name" => options[:first_name],
"last-name" => options[:last_name]
}
}]
},
"subject" => "Invitation to connect.",
"body" => options[:body],
"item-content" => {
"invitation-request" => {
"connect-type" => "friend"
}
}
}
post(path, message.to_json, "Content-Type" => "application/json")
end
end
use like any other gem methods
client.send_invitation({:email=>"email", :first_name=>"first name", :last_name=>"last name", :body=>"body"})
LinkedIn::Client.class_eval do
def send_invitation(options)
path = "/people/~/mailbox"
message = {
"recipients" => {
"values" => [
{
"person" => {
"_path" => "/people/#{options[:id]}",
"first-name" => options[:first_name],
"last-name" => options[:last_name]
}
}]
},
"subject" => "Invitation to connect.",
"body" => options[:body],
"item-content" => {
"invitation-request" => {
"connect-type" => "friend",
"authorization" => {:"name" => 'NAME_SEARCH',:"value" => 'Mjwh'}
}
}
}
post(path, MultiJson.dump(message), "Content-Type" => "application/json")
end
end
invite people should be add "authorization" => {:"name" => 'NAME_SEARCH',:"value" => 'Mjwh'}
from the searched people
client.search(:fields => [{ :people => %w(id first-name last-name api-standard-profile-request)}],:'first-name' => params["first_name"])
精彩评论