class IdobataGraphQL
Constants
- IDOBATA_PUBLIC_API_URI
Public Class Methods
create_message(room_id, source, format = 'MARKDOWN')
click to toggle source
# File idobata_graph_ql.rb, line 18 def create_message(room_id, source, format = 'MARKDOWN') default.create_message(room_id, source, format) end
new(uri, token)
click to toggle source
# File idobata_graph_ql.rb, line 33 def initialize(uri, token) @uri = uri @token = token end
query(query)
click to toggle source
# File idobata_graph_ql.rb, line 10 def query(query) default.query(query) end
rooms()
click to toggle source
# File idobata_graph_ql.rb, line 14 def rooms default.rooms end
Private Class Methods
default()
click to toggle source
# File idobata_graph_ql.rb, line 24 def default new(IDOBATA_PUBLIC_API_URI, default_token) end
default_token()
click to toggle source
# File idobata_graph_ql.rb, line 28 def default_token ENV.fetch("IDOBATA_TOKEN") end
Public Instance Methods
create_message(room_id, source, format)
click to toggle source
# File idobata_graph_ql.rb, line 45 def create_message(room_id, source, format) variables = { input: { roomId: room_id, source: source, format: format } } query(<<~MUTATION, variables) mutation Mutation($input: CreateMessageInput!) { createMessage(input: $input) { clientMutationId } } MUTATION end
query(query, variables = nil)
click to toggle source
# File idobata_graph_ql.rb, line 38 def query(query, variables = nil) body = JSON.generate({ query: query, variables: variables }.compact) res = start { |http| http.post(@uri.path, body, headers) } res.value JSON.parse(res.body).fetch('data') end
rooms()
click to toggle source
# File idobata_graph_ql.rb, line 56 def rooms fetch_rooms.dig('viewer', 'rooms', 'edges').map do |room_edge| Room.new( room_edge.dig('node', 'id'), room_edge.dig('node', 'name'), room_edge.dig('node', 'organization', 'name'), ) end end
Private Instance Methods
fetch_rooms()
click to toggle source
# File idobata_graph_ql.rb, line 88 def fetch_rooms query('query { viewer { rooms { edges { node { id, name, organization { name } } } } } }') end
headers()
click to toggle source
# File idobata_graph_ql.rb, line 72 def headers {"Content-Type" => "application/json", "Authorization" => "Bearer #{@token}" } end
host()
click to toggle source
# File idobata_graph_ql.rb, line 76 def host @uri.host end
port()
click to toggle source
# File idobata_graph_ql.rb, line 80 def port @uri.port end
scheme()
click to toggle source
# File idobata_graph_ql.rb, line 84 def scheme @uri.scheme end
start() { |http| ... }
click to toggle source
# File idobata_graph_ql.rb, line 68 def start Net::HTTP.start(host, port, use_ssl: scheme == "https") { |http| yield http } end