Class: NotionOrbit::Services::Orbit
- Inherits:
-
Object
- Object
- NotionOrbit::Services::Orbit
- Defined in:
- lib/notion_orbit/services/orbit.rb
Instance Method Summary collapse
- #create_orbit_member(email) ⇒ Object
-
#initialize(orbit_workspace:, orbit_api_key:) ⇒ Orbit
constructor
A new instance of Orbit.
- #member_slug(email:) ⇒ Object
- #send_note(api_key:, member_slug:, content:) ⇒ Object
Constructor Details
#initialize(orbit_workspace:, orbit_api_key:) ⇒ Orbit
Returns a new instance of Orbit.
8 9 10 11 |
# 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 |
Instance Method Details
#create_orbit_member(email) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |