Skip to content

Instantly share code, notes, and snippets.

@ryuchan00
Created April 12, 2017 12:18
Show Gist options
  • Save ryuchan00/f168b29289afdf31d2e4a9af4c320ce4 to your computer and use it in GitHub Desktop.
Save ryuchan00/f168b29289afdf31d2e4a9af4c320ce4 to your computer and use it in GitHub Desktop.
require 'net/https'
require 'uri'
require 'json'
client_id = ''
client_secret = ''
topic_id = ''
msg = 'Hello!'
# setup a http client
http = Net::HTTP.new('typetalk.in', 443)
http.use_ssl = true
# get an access token
#res = http.post(
# '/oauth2/access_token',
# "client_id=#{client_id}&client_secret=#{client_secret}&grant_type=client_credentials&scope=topic.post"
#)
res = http.post(
'/oauth2/access_token',
"client_id=#{client_id}&client_secret=#{client_secret}&grant_type=client_credentials&scope=my"
)
json = JSON.parse(res.body)
access_token = json['access_token']
# post a message
req = Net::HTTP::Get.new("/api/v1/topics")
#req = Net::HTTP::Post.new("/api/v1/topics/#{topic_id}")
req['Authorization'] = "Bearer #{access_token}"
#req.set_form_data({:message=>msg})
return_json = http.request(req)
#p JSON.parse(return_json.body)
puts return_json
#puts res.code
#puts res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment