class LinkedinOrbit::Interactions::Comment

Public Class Methods

new(title:, comment:, orbit_workspace:, orbit_api_key:) click to toggle source
# File lib/linkedin_orbit/interactions/comment.rb, line 8
def initialize(title:, comment:, orbit_workspace:, orbit_api_key:)
  @title = title
  @comment = comment
  @orbit_workspace = orbit_workspace
  @orbit_api_key = orbit_api_key

  after_initialize!
end

Public Instance Methods

after_initialize!() click to toggle source
# File lib/linkedin_orbit/interactions/comment.rb, line 17
def after_initialize!
  OrbitActivities::Request.new(
    api_key: @orbit_api_key,
    workspace_id: @orbit_workspace,
    user_agent: "community-ruby-linkedin-orbit/#{LinkedinOrbit::VERSION}",
    action: "new_activity",
    body: construct_body.to_json
  )
end
construct_body() click to toggle source
# File lib/linkedin_orbit/interactions/comment.rb, line 27
def construct_body
  {
    activity: {
      activity_type: "linkedin:comment",
      tags: ["channel:linkedin"],
      title: "Commented on LinkedIn Post",
      description: construct_description,
      occurred_at: Time.at(@comment["created"]["time"] / 1000).utc,
      key: @comment["id"],
      link: "https://www.linkedin.com/feed/update/#{@comment["object"]}",
      member: {
        name: name
      }
    },
    identity: {
      source: "linkedin",
      name: name,
      uid: @comment["actor"]
    }
  }
end
construct_description() click to toggle source
# File lib/linkedin_orbit/interactions/comment.rb, line 57
      def construct_description
        <<~HEREDOC
          LinkedIn post: "#{@title}..."
          \n
          Comment:
          \n
          "#{@comment["message"]["text"]}"
        HEREDOC
      end
name() click to toggle source
# File lib/linkedin_orbit/interactions/comment.rb, line 49
def name
  @name ||= begin
    return @comment["actor~"]["localizedName"] if @comment["actor~"]["localizedName"]

    "#{@comment["actor~"]["localizedFirstName"]} #{@comment["actor~"]["localizedLastName"]}"
  end
end