Skip to content

Commit

Permalink
Move ip info to its own type and get more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Sep 3, 2020
1 parent cde71de commit 65063c2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
23 changes: 19 additions & 4 deletions app/graphql/types/ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
module Types
class IP < GraphQL::Schema::Object
field :address, String, null: false
field :country, String, null: true
field :info, Types::IPInfo, null: true

# Should return nil if we can't access the ip service
def country
def info
r = query(object[:address])
r["country"] if r
return if r.nil?

# We're writing this out explicitly so we're not binding
# our parameter names directly to those returned by the
# service
{
country: r["country"],
country_code: r["countryCode"],
region: r["region"],
region_name: r["regionName"],
city: r["city"],
lat: r["lat"],
lng: r["lng"],
timezone: r["timezone"],
isp: r["isp"],
org: r["org"]
}
end

private
Expand Down
16 changes: 16 additions & 0 deletions app/graphql/types/ip_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Types
class IPInfo < GraphQL::Schema::Object
field :country, String, null: false
field :country_code, String, null: false
field :region, String, null: false
field :region_name, String, null: false
field :city, String, null: false
field :lat, Float, null: false
field :lng, Float, null: false
field :timezone, String, null: false
field :isp, String, null: false
field :org, String, null: false
end
end
11 changes: 10 additions & 1 deletion app/views/deliveries/_click_events.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
%th OS
%th IP
%th Country
%th Region
%th City
%th
%abbr{title: "Internet Service Provider"} ISP
%th Org
%tbody
- delivery.click_events.each do |event|
%tr
Expand All @@ -23,4 +28,8 @@
- if event.os.version
%span.muted (#{event.os.version})
%td= event.ip.address
%td= event.ip.country
%td= event.ip.info.country
%td= event.ip.info.region_name
%td= event.ip.info.city
%td= event.ip.info.isp
%td= event.ip.info.org
11 changes: 10 additions & 1 deletion app/views/deliveries/_open_events.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
%th OS
%th IP
%th Country
%th Region
%th City
%th
%abbr{title: "Internet Service Provider"} ISP
%th Org
%tbody
- delivery.open_events.each do |event|
%tr
Expand All @@ -21,4 +26,8 @@
- if event.os.version
%span.muted (#{event.os.version})
%td= event.ip.address
%td= event.ip.country
%td= event.ip.info.country
%td= event.ip.info.region_name
%td= event.ip.info.city
%td= event.ip.info.isp
%td= event.ip.info.org
16 changes: 14 additions & 2 deletions lib/api/deliveries/show.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ query($id: ID!) {
openEvents {
ip {
address
country
info {
country
regionName
city
isp
org
}
}
userAgent {
family
Expand All @@ -48,7 +54,13 @@ query($id: ID!) {
url
ip {
address
country
info {
country
regionName
city
isp
org
}
}
userAgent {
family
Expand Down

0 comments on commit 65063c2

Please sign in to comment.