oksky-chat-api 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/oksky/chat/api/version.rb +1 -1
- data/lib/oksky/chat/client.rb +2 -1
- data/lib/oksky/chat/client/suggestion.rb +72 -0
- data/lib/oksky/chat/request.rb +5 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a08ddacc6d0a4c78b28faf354856e54f6267dda
|
4
|
+
data.tar.gz: 8565601722b3707abf4512208be20810ce3be2d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0ac7db527474897eb46f58129b645cfd3802ddc4837ad3ed7ed764e407e905ee0ddda8caabca12e83fc999ab7a77fcd8805fdb6e5bde6df736f1f6b2e88255
|
7
|
+
data.tar.gz: 466a07c0441b5db22030ef817e32bfea3dfd4712590fa1fcd939a6b4fa38a46a70c4695523cc1537296ef4cfa49587650f0434da94661adfc40c16e916111757
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://badge.fury.io/rb/oksky-chat-api)
|
2
|
+
|
1
3
|
# Oksky::Chat::Api
|
2
4
|
|
3
5
|
## About the OK SKY CHAT API
|
@@ -52,6 +54,17 @@ post '/callback' do
|
|
52
54
|
end
|
53
55
|
```
|
54
56
|
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
suggestion_client = Oksky::Chat::Client::Suggestion.new(access_token: "38d9b3ed60587820840857dfdf14561b", endpoint: "http://127.0.0.1:3000/rapi/v1")
|
60
|
+
|
61
|
+
suggestions = [{"kind": "text","content": "test","settings": {}}]
|
62
|
+
room_id = 49
|
63
|
+
|
64
|
+
result = suggestion_client.create(suggestion_messages_data: suggestions, room_id: room_id)
|
65
|
+
|
66
|
+
```
|
67
|
+
|
55
68
|
## Development
|
56
69
|
|
57
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/oksky/chat/client.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'oksky/chat/request'
|
2
|
+
require 'oksky/chat/api/errors'
|
3
|
+
require 'base64'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
|
7
|
+
module Oksky
|
8
|
+
module Chat
|
9
|
+
module Client
|
10
|
+
class Suggestion < Base
|
11
|
+
|
12
|
+
# Push suggestion to OK SKY Chat server
|
13
|
+
#
|
14
|
+
# @param user_id [String] User's identifiers
|
15
|
+
# @param messages [Hash or Array]
|
16
|
+
#
|
17
|
+
# @return [Net::HTTPResponse]
|
18
|
+
def create(suggestion_messages_data:, room_id:)
|
19
|
+
raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
|
20
|
+
|
21
|
+
suggestion_payload = {
|
22
|
+
"data": {
|
23
|
+
"type": "suggestions",
|
24
|
+
"attributes": {
|
25
|
+
"suggestion_messages_data": suggestion_messages_data
|
26
|
+
},
|
27
|
+
"relationships": {
|
28
|
+
"room": {
|
29
|
+
"data": {
|
30
|
+
"type": "rooms",
|
31
|
+
"id": room_id
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
p suggestion_payload
|
38
|
+
|
39
|
+
request = Request.new do |config|
|
40
|
+
config.httpclient = httpclient
|
41
|
+
config.endpoint = endpoint
|
42
|
+
config.endpoint_path = '/suggestions'
|
43
|
+
config.credentials = credentials
|
44
|
+
config.payload = suggestion_payload
|
45
|
+
end
|
46
|
+
|
47
|
+
request.post
|
48
|
+
end
|
49
|
+
|
50
|
+
# Fetch data, get content of specified URL.
|
51
|
+
#
|
52
|
+
# @param endpoint_path [String]
|
53
|
+
#
|
54
|
+
# @return [Net::HTTPResponse]
|
55
|
+
def get(endpoint_path, option = {})
|
56
|
+
raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
|
57
|
+
|
58
|
+
request = Request.new do |config|
|
59
|
+
config.httpclient = httpclient
|
60
|
+
config.endpoint = endpoint
|
61
|
+
config.endpoint_path = endpoint_path
|
62
|
+
config.credentials = credentials
|
63
|
+
end
|
64
|
+
|
65
|
+
request.get
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/oksky/chat/request.rb
CHANGED
@@ -6,7 +6,7 @@ require 'uri'
|
|
6
6
|
module Oksky
|
7
7
|
module Chat
|
8
8
|
class Request
|
9
|
-
attr_accessor :endpoint, :endpoint_path, :credentials, :httpclient
|
9
|
+
attr_accessor :endpoint, :endpoint_path, :credentials, :httpclient, :payload
|
10
10
|
|
11
11
|
# Initializes a new Request
|
12
12
|
#
|
@@ -17,18 +17,15 @@ module Oksky
|
|
17
17
|
|
18
18
|
# @return [Hash]
|
19
19
|
def payload
|
20
|
-
payload
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
payload.delete_if{|k, v| v.nil?}.to_json
|
20
|
+
!@payload.empty? && @payload.kind_of?(Hash) ? @payload.delete_if{|k, v| v.nil?}.to_json : {}
|
25
21
|
end
|
26
22
|
|
27
23
|
# @return [Hash]
|
28
24
|
def header
|
29
25
|
header = {
|
30
|
-
'Content-Type' => 'application/json
|
31
|
-
'
|
26
|
+
'Content-Type' => 'application/vnd.api+json',
|
27
|
+
'Accept' => 'application/vnd.api+json',
|
28
|
+
'User-Agent' => "OKSKY-CHAT-SDK-Ruby/#{Oksky::Chat::API::VERSION}"
|
32
29
|
}
|
33
30
|
hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
|
34
31
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oksky-chat-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SOLAIRO, INC.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/oksky/chat/client.rb
|
111
111
|
- lib/oksky/chat/client/base.rb
|
112
112
|
- lib/oksky/chat/client/message.rb
|
113
|
+
- lib/oksky/chat/client/suggestion.rb
|
113
114
|
- lib/oksky/chat/event.rb
|
114
115
|
- lib/oksky/chat/event/base.rb
|
115
116
|
- lib/oksky/chat/event/message.rb
|