Class: DevOrbit::Interactions::Comment
- Inherits:
-
Object
- Object
- DevOrbit::Interactions::Comment
- Defined in:
- lib/dev_orbit/interactions/comment.rb
Instance Method Summary collapse
- #after_initialize! ⇒ Object
- #construct_body ⇒ Object
-
#initialize(article_title:, url:, comment:, workspace_id:, api_key:) ⇒ Comment
constructor
A new instance of Comment.
Constructor Details
#initialize(article_title:, url:, comment:, workspace_id:, api_key:) ⇒ Comment
Returns a new instance of Comment.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dev_orbit/interactions/comment.rb', line 10 def initialize(article_title:, url:, comment:, workspace_id:, api_key:) @article_title = article_title @url = url @id = comment[:id_code] @created_at = comment[:created_at] @body = sanitize_comment(comment[:body_html]) @commenter = construct_commenter(comment[:user].transform_keys(&:to_sym)) @workspace_id = workspace_id @api_key = api_key after_initialize! end |
Instance Method Details
#after_initialize! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dev_orbit/interactions/comment.rb', line 23 def after_initialize! OrbitActivities::Request.new( api_key: @api_key, workspace_id: @workspace_id, user_agent: "community-ruby-dev-orbit/#{DevOrbit::VERSION}", action: "new_activity", body: construct_body.to_json ) end |
#construct_body ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dev_orbit/interactions/comment.rb', line 33 def construct_body hash = { activity: { activity_type: "dev:comment", tags: ["channel:dev"], key: "dev-comment-#{@id}", title: "Commented on the DEV blog post: #{@article_title}", description: @body, occurred_at: @created_at, link: @url, member: { name: @commenter[:name], devto: @commenter[:username] } }, identity: { source: "devto", username: @commenter[:username] } } hash[:activity][:member].merge!(twitter: @commenter[:twitter]) if @commenter[:twitter] hash[:activity][:member].merge!(github: @commenter[:github]) if @commenter[:github] hash[:activity][:member].merge(url: @commenter[:url]) if @commenter[:url] hash end |