Oksky::Chat::Api
About the OK SKY CHAT API
See the official API reference documentation for more information.
Installation
Add this line to your application's Gemfile:
gem 'oksky-chat-api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install oksky-chat-api
Usage
# app.rb
require 'sinatra'
require 'oksky/chat'
def webhook_client
@webhook_client ||= Oksky::Chat::WhClient.new
end
post '/callback' do
body = request.body.read
event = webhook_client.parse_events_from(body)
case event
when Oksky::Chat::Event::Message
client = Oksky::Chat::Client.new { |config|
config.access_token = EVN['OKSKY_CHAT_ACCESS_TOKEN']
config.endpoint = EVN['OKSKY_CHAT_ENDPOINT']
}
result = client.find("messages", event["id"], {}, false)
p JSON.parse(result.body) if !result.nil? && result.kind_of?(Net::HTTPResponse) && !result.body.blank?
end
"OK"
end
GET Resource Object
client = Oksky::Chat::Client.new(
access_token: "38d9b3ed60587820840857dfdf14561b",
endpoint: "http://127.0.0.1:3000/rapi/v1"
)
client.find("messages", 1) #=> Oksky::Chat::Object::MessagesResource
GET Resource Objects
client = Oksky::Chat::Client.new(
access_token: "38d9b3ed60587820840857dfdf14561b",
endpoint: "http://127.0.0.1:3000/rapi/v1"
)
client.where("messages", {"filter[room_id]": 1}) #=> Array Oksky::Chat::Object::MessagesResource
CREATE Resource Object
client = Oksky::Chat::Client.new(
access_token: "38d9b3ed60587820840857dfdf14561b",
endpoint: "http://127.0.0.1:3000/rapi/v1"
)
client.create("messages", {"data"=>{"type"=>"messages", "attributes"=>{"content"=>"test0001", "kind"=>"text", "settings"=>{}, "status"=>"", "info"=>"", "tags"=>[]}, "relationships"=>{"room"=>{"data"=>{"type"=>"rooms", "id"=>"369249"}}}}})
EDIT Resource Object
client = Oksky::Chat::Client.new(
access_token: "38d9b3ed60587820840857dfdf14561b",
endpoint: "http://127.0.0.1:3000/rapi/v1"
)
client.edit("messages", 1, {"data"=>{"type"=>"messages", "attributes"=>{"content"=>"test0001", "kind"=>"text", "settings"=>{}, "status"=>"", "info"=>"", "tags"=>[]}, "relationships"=>{"room"=>{"data"=>{"type"=>"rooms", "id"=>"369249"}}}}})
License
Copyright (C) 2017 SOLAIRO, INC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.