Module: LinkedIn::Api::UpdateMethods

Includes:
Helpers::Request
Included in:
Client
Defined in:
lib/linked_in/api/update_methods.rb

Constant Summary

Constants included from Helpers::Request

Helpers::Request::API_PATH, Helpers::Request::DEFAULT_HEADERS

Instance Method Summary collapse

Instance Method Details

#add_share(share) ⇒ Object



8
9
10
11
12
# File 'lib/linked_in/api/update_methods.rb', line 8

def add_share(share)
  path = "/people/~/shares"
  defaults = {:visibility => {:code => "anyone"}}
  post(path, defaults.merge(share).to_json, "Content-Type" => "application/json")
end

#message_to_xml(member_id, subject, message) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/linked_in/api/update_methods.rb', line 60

def message_to_xml(member_id, subject, message)
    %Q{<?xml version="1.0" encoding="UTF-8"?>
      <mailbox-item>
          <recipients>
            <recipient>
              <person path="/people/#{member_id}" />
            </recipient>
          </recipients>
          <subject>#{subject}</subject>
          <body>#{message.strip}</body>
        </mailbox-item>}
end

#post(path, body = '', options = {}) ⇒ Object



73
74
75
76
77
# File 'lib/linked_in/api/update_methods.rb', line 73

def post(path, body='', options={})
  response = access_token.post("#{API_PATH}#{path}", body, options)
  raise_errors(response)
  response
end

#send_message(member_id, subject, message) ⇒ Object

def share(options={})

path = "/people/~/shares"
defaults = { :visability => 'anyone' }
post(path, share_to_xml(defaults.merge(options)))

end

def update_comment(network_key, comment)

path = "/people/~/network/updates/key=#{network_key}/update-comments"
post(path, comment_to_xml(comment))

end

def update_network(message)

path = "/people/~/person-activities"
post(path, network_update_to_xml(message))

end

def send_message(subject, body, recipient_paths)

path = "/people/~/mailbox"

message         = LinkedIn::Message.new
message.subject = subject
message.body    = body
recipients      = LinkedIn::Recipients.new

recipients.recipients = recipient_paths.map do |profile_path|
  recipient             = LinkedIn::Recipient.new
  recipient.person      = LinkedIn::Person.new
  recipient.person.path = "/people/#{profile_path}"
  recipient
end
message.recipients = recipients
post(path, message_to_xml(message)).code

end

def clear_status

path = "/people/~/current-status"
delete(path).code

end



54
55
56
57
58
# File 'lib/linked_in/api/update_methods.rb', line 54

def send_message(member_id, subject, message)
  path = "/people/~/mailbox"
  resp = post(path, message_to_xml(member_id, subject, message), {'Content-Type' => 'application/xml'})
  (resp.message == "Created" || resp.code.to_s == '201')  ? true : false
end