class NotionOrbit::Services::Orbit

Public Class Methods

new(orbit_workspace:, orbit_api_key:) click to toggle source
# File lib/notion_orbit/services/orbit.rb, line 8
def initialize(orbit_workspace:, orbit_api_key:)
  @orbit_workspace = orbit_workspace
  @orbit_api_key = orbit_api_key
end

Public Instance Methods

create_orbit_member(email) click to toggle source
# File lib/notion_orbit/services/orbit.rb, line 32
def create_orbit_member(email)
  url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(url)
  request["Accept"] = 'application/json'
  request["Content-Type"] = 'application/json'
  request["Authorization"] = "Bearer #{@orbit_api_key}"
  request["Content-Type"] = "application/json"
  request["User-Agent"] = "community-ruby-notion-orbit/#{NotionOrbit::VERSION}",
  request.body = "{\"member\":{\"email\":\"#{email}\"},\"identity\":{\"source\":\"notion\",\"email\":\"#{email}\"}}"

  response = http.request(request)

  json = JSON.parse(response.read_body)

  return json["data"]["id"] if json["data"]

  nil
end
member_slug(email:) click to toggle source
# File lib/notion_orbit/services/orbit.rb, line 13
def member_slug(email:) 
  url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members/find?source=email&email=#{email}")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(url)
  request["Accept"] = 'application/json'
  request["Content-Type"] = "application/json"
  request["Authorization"] = "Bearer #{@orbit_api_key}"

  response = http.request(request)
  json = JSON.parse(response.read_body)

  return json["data"]["attributes"]["slug"] if json["data"]

  create_orbit_member(email)
end
send_note(api_key:, member_slug:, content:) click to toggle source
# File lib/notion_orbit/services/orbit.rb, line 55
def send_note(api_key:, member_slug:, content:)
  url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/members/#{member_slug}/notes")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(url)
  request["Accept"] = 'application/json'
  request["Content-Type"] = 'application/json'
  request["Authorization"] = "Bearer #{api_key}"
  request["Content-Type"] = "application/json"
  request["User-Agent"] = "community-ruby-notion-orbit/#{NotionOrbit::VERSION}"
  request.body = "{\"body\":\"#{content}\"}"

  response = http.request(request)
end