Class: LinkedinOrbit::Interactions::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/linkedin_orbit/interactions/comment.rb

Instance Method Summary collapse

Constructor Details

#initialize(title:, comment:, orbit_workspace:, orbit_api_key:) ⇒ Comment



8
9
10
11
12
13
14
15
# 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

Instance Method Details

#after_initialize!Object



17
18
19
20
21
22
23
24
25
# 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_bodyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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"]}",
      link_text: "View on LinkedIn",
      member: {
        name: name
      }
    },
    identity: {
      source: "linkedin",
      name: name,
      uid: @comment["actor"]
    }
  }
end

#construct_descriptionObject



58
59
60
61
62
63
64
65
66
# File 'lib/linkedin_orbit/interactions/comment.rb', line 58

def construct_description
  "    LinkedIn post: \"\#{@title}...\"\n    \\n\n    Comment:\n    \\n\n    \"\#{@comment[\"message\"][\"text\"]}\"\n  HEREDOC\nend\n"

#nameObject



50
51
52
53
54
55
56
# File 'lib/linkedin_orbit/interactions/comment.rb', line 50

def name
  @name ||= begin
    return @comment["actor~"]["localizedName"] if @comment["actor~"]["localizedName"]

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