Class: OrbitFeedbackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/services/orbit_feedback_notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feedback) ⇒ OrbitFeedbackNotifier

Returns a new instance of OrbitFeedbackNotifier.



6
7
8
# File 'lib/nexmo_developer/app/services/orbit_feedback_notifier.rb', line 6

def initialize(feedback)
  @feedback = feedback
end

Class Method Details

.call(feedback) ⇒ Object



2
3
4
# File 'lib/nexmo_developer/app/services/orbit_feedback_notifier.rb', line 2

def self.call(feedback)
  new(feedback).post!
end

Instance Method Details

#paramsObject



10
11
12
13
14
15
16
# File 'lib/nexmo_developer/app/services/orbit_feedback_notifier.rb', line 10

def params
  @params ||= {
    id: @feedback.id,
    email: @feedback.owner.email,
    resource: "Offered #{@feedback.sentiment} feedback on #{@feedback.resource.uri}",
  }
end

#post!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nexmo_developer/app/services/orbit_feedback_notifier.rb', line 22

def post!
  return unless ENV['ORBIT_WORKSPACE_ID']

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri)
  req['Accept'] = 'application/json'
  req['Content-Type'] = 'application/json'
  req['Authorization'] = "Bearer #{ENV['ORBIT_API_KEY']}"

  req.body = {
    activity: {
      activity_type: 'adp:feedback',
      key: "adp-feedback-#{params[:id]}",
      title: 'Offered feedback on ADP',
      description: params[:resource],
      occurred_at: Time.zone.now.iso8601,
    },
    identity: {
      source: 'email',
      email: params[:email],
    },
  }

  req.body = req.body.to_json

  http.request(req)
end

#uriObject



18
19
20
# File 'lib/nexmo_developer/app/services/orbit_feedback_notifier.rb', line 18

def uri
  @uri ||= URI("https://app.orbit.love/api/v1/#{ENV['ORBIT_WORKSPACE_ID']}/activities")
end