oksky-chat-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3462f24114c2efd418d85e99351f8786055b1fe9
4
- data.tar.gz: 1f77b4200867ae600c949d6a3d7117f3b981ae2f
3
+ metadata.gz: 8a08ddacc6d0a4c78b28faf354856e54f6267dda
4
+ data.tar.gz: 8565601722b3707abf4512208be20810ce3be2d3
5
5
  SHA512:
6
- metadata.gz: 471d340fea30e4b03cd06aa2f8571c820798dde1e9c79f0654044bdf30b6a92658a0117b18af5ba986fd8e1330d52bc608c2721664e2654d2866209162bf7a28
7
- data.tar.gz: 9be40b019e6ce76d9b73d003d74da56f27ffe84042ddecedb6b911f5596e5d8d9c2f53bb185242c50af9687df649eba6bb5b1bdd93ad03ac17432d1a4f38b568
6
+ metadata.gz: 6a0ac7db527474897eb46f58129b645cfd3802ddc4837ad3ed7ed764e407e905ee0ddda8caabca12e83fc999ab7a77fcd8805fdb6e5bde6df736f1f6b2e88255
7
+ data.tar.gz: 466a07c0441b5db22030ef817e32bfea3dfd4712590fa1fcd939a6b4fa38a46a70c4695523cc1537296ef4cfa49587650f0434da94661adfc40c16e916111757
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/oksky-chat-api.svg)](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.
@@ -1,7 +1,7 @@
1
1
  module Oksky
2
2
  module Chat
3
3
  module API
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,2 +1,3 @@
1
1
  require 'oksky/chat/client/base'
2
- require 'oksky/chat/client/message'
2
+ require 'oksky/chat/client/message'
3
+ require 'oksky/chat/client/suggestion'
@@ -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
@@ -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; charset=UTF-8',
31
- 'User-Agent' => "OKSKY-CHAT-SDK-Ruby/#{Oksky::Chat::API::VERSION}",
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.0
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-06-27 00:00:00.000000000 Z
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