Class: LinkedIn::ShareAndSocialStream

Inherits:
APIResource show all
Defined in:
lib/linked_in/share_and_social_stream.rb

Overview

Share and Social Stream APIs

LinkedIn’s v2 API adherence to the documentation is shaky at best. Several of the calls simply don’t work if you, e.g., pass the URN in as a path element for a resource - you have to use the ids= format w/ a single URN. Or sometimes passing in an “actor” parameter in the request body simply doesn’t work, and you have to pass it in as a URL parameter. What you see in this file is the result of trial-and-error getting these endpoints to work, and the inconsistency is usually a result of either misunderstanding the docs or the API not working as advertised. It’s also a bit unclear when the API wants an activity URN vs, e.g., an article URN. Caveat emptor.

[(contribute here)](github.com/mdesjardins/linkedin-v2)

Instance Method Summary collapse

Methods inherited from APIResource

#id_to_urn, #initialize, #urn_to_id

Constructor Details

This class inherits a constructor from LinkedIn::APIResource

Instance Method Details

#comment(options = {}) ⇒ Object

Adds a comment to a specific post.

Permissions:

urn:li:article:123)

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :urn, (String)

    specifies activity queried for comments (e.g.,

  • :actor, (String)

    specifies the entity performing the action. It should b # represented by a urn:li:person:id or urn:li:organization:id URN.

  • :message, (String)

    the text content of the comment.

See Also:



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/linked_in/share_and_social_stream.rb', line 128

def comment(options = {})
  urn = options.delete(:urn)
  actor = options.delete(:actor)
  message = options.delete(:message)
  body = {
    actor: actor,
    message: {
      attributes: [],
      text: message
    }
  }
  path = "/socialActions/#{urn}/comments"
  post(path, MultiJson.dump(body), 'Content-Type' => 'application/json')
end

#comments(options = {}) ⇒ Object

Retrieves the comments for a specific post.

urn:li:article:123)

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :urn, (String)

    specifies activity queried for comments (e.g.,

See Also:



111
112
113
114
115
# File 'lib/linked_in/share_and_social_stream.rb', line 111

def comments(options = {})
  urn = options.delete(:urn)
  path = "/socialActions/#{urn}/comments"
  get(path, options)
end

#like(options = {}) ⇒ Object

Likes a specific share or comment.

This object should be a sub-entity of the top-level share indicated in the request URL, and should be represented as an URN either of format urn:li:share:id represented by a urn:li:person:id or urn:li:organization:id URN.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :object, (String)

    specifies the URN of the entity to which the like belongs.

  • :urn, (String)

    specifies activity being un-liked (e.g., urn:li:activity::123)

  • :actor, (String)

    specifies the entity performing the action. It should be

See Also:



86
87
88
89
90
# File 'lib/linked_in/share_and_social_stream.rb', line 86

def like(options = {})
  urn = options.delete(:urn)
  path = "/socialActions/#{urn}/likes"
  post(path, MultiJson.dump(options), 'Content-Type' => 'application/json')
end

#likes(options = {}) ⇒ LinkedIn::Mash

Retrieves the likes for a specific post.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :urn, (String)

    the URN of the relevant share, UGC post, or comment

Returns:

See Also:



70
71
72
73
74
# File 'lib/linked_in/share_and_social_stream.rb', line 70

def likes(options = {})
  urn = options.delete(:urn)
  path = "/socialActions/#{urn}/likes"
  get(path, options)
end

#share(options = {}) ⇒ LinkedIn::Mash

Create one share from a person, organization, or organizationBrand.

Permissions:

1.) For personal shares, you may only post shares as the authorized member.
2.) For organization shares, you may only post shares as an organization for which the
    authorized member is an administrator.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :owner, (String)

    the URN of the entity posting the share.

Returns:

See Also:



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/linked_in/share_and_social_stream.rb', line 51

def share(options = {})
  path = '/shares'
  defaults = {
    distribution: {
      linkedInDistributionTarget: {
        visibleToGuest: true
      }
    }
  }
  post(path, MultiJson.dump(defaults.merge(options)), 'Content-Type' => 'application/json')
end

#shares(options = {}) ⇒ LinkedIn::Mash

Retrieve shares from a person, organization, or organizationBrand.

Permissions:

1.) For personal shares, you may only retrieve shares for the authorized members.
2.) For organization shares, you may only retrieve shares for organizations for which the
    authorized member is an administrator.


33
34
35
36
37
# File 'lib/linked_in/share_and_social_stream.rb', line 33

def shares(options = {})
  urn = options.delete(:urn)
  path = "/shares?q=owners&owners=#{urn}"
  get(path, options)
end

#unlike(options = {}) ⇒ Object

Un-likes a previously liked share or comment.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :urn, (String)

    specifies activity being un-liked (e.g., urn:li:activity:123)

  • :actor, (String)

    specifies the entity performing the action. It should b # represented by a urn:li:person:id or urn:li:organization:id URN.

See Also:



98
99
100
101
102
103
# File 'lib/linked_in/share_and_social_stream.rb', line 98

def unlike(options = {})
  urn = options.delete(:urn)
  actor = options.delete(:actor)
  path = "/socialActions/#{urn}/likes/#{actor}?actor=#{CGI::escape(actor)}"
  delete(path, MultiJson.dump(options), 'Content-Type' => 'application/json') #options)
end