Skip to content

Commit

Permalink
Extract interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Aug 7, 2018
1 parent ee769c7 commit e1c693d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
14 changes: 2 additions & 12 deletions app/graphql/types/click_event_type.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# TODO: ClickEvent and OpenEvent should inherit from the same interface

class Types::ClickEventType < Types::BaseObject
implements Types::UserAgentEventType

description "Information about someone clicking on a link in an email"
field :created_at, Types::DateTimeType, null: true, description: "When the click happened"
field :url, String, null: false, description: "The URL of the link"
field :user_agent, Types::FamilyAndVersionType, null: true, description: "Information about the browser/mail reader"
def user_agent
{ family: object.calculate_ua_family, version: object.calculate_ua_version }
end
field :os, Types::FamilyAndVersionType, null: true, description: "The operating system the person was using"
def os
{ family: object.calculate_os_family, version: object.calculate_os_version }
end
field :ip, String, null: true, description: "The IP address the click originated from"
end
12 changes: 2 additions & 10 deletions app/graphql/types/open_event_type.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
class Types::OpenEventType < Types::BaseObject
implements Types::UserAgentEventType

description "Information about someone opening an email"
field :created_at, Types::DateTimeType, null: true, description: "When the email was opened"
field :user_agent, Types::FamilyAndVersionType, null: true, description: "The browser / email client that was being used"
def user_agent
{ family: object.ua_family, version: object.ua_version }
end
field :os, Types::FamilyAndVersionType, null: true, description: "The operating system that was being used at the time"
def os
{ family: object.os_family, version: object.os_version }
end
field :ip, String, null: true, description: "The originating IP address"
end
14 changes: 14 additions & 0 deletions app/graphql/types/user_agent_event_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Types::UserAgentEventType
include Types::BaseInterface
description "An event initiated by someone from a browser / email client"
field :created_at, Types::DateTimeType, null: true, description: "The time of the event"
field :user_agent, Types::FamilyAndVersionType, null: true, description: "The browser / email client being used"
def user_agent
{ family: object.calculate_ua_family, version: object.calculate_ua_version }
end
field :os, Types::FamilyAndVersionType, null: true, description: "The operating system being used"
def os
{ family: object.calculate_os_family, version: object.calculate_os_version }
end
field :ip, String, null: true, description: "The originating IP address"
end

0 comments on commit e1c693d

Please sign in to comment.