oksky-chat-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3462f24114c2efd418d85e99351f8786055b1fe9
4
+ data.tar.gz: 1f77b4200867ae600c949d6a3d7117f3b981ae2f
5
+ SHA512:
6
+ metadata.gz: 471d340fea30e4b03cd06aa2f8571c820798dde1e9c79f0654044bdf30b6a92658a0117b18af5ba986fd8e1330d52bc608c2721664e2654d2866209162bf7a28
7
+ data.tar.gz: 9be40b019e6ce76d9b73d003d74da56f27ffe84042ddecedb6b911f5596e5d8d9c2f53bb185242c50af9687df649eba6bb5b1bdd93ad03ac17432d1a4f38b568
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright (C) 2017 SOLAIRO, INC.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Oksky::Chat::Api
2
+
3
+ ## About the OK SKY CHAT API
4
+
5
+ See the official API reference documentation for more information.
6
+
7
+ <https://support.ok-sky.com>
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'oksky-chat-api'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install oksky-chat-api
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ # app.rb
30
+ require 'sinatra'
31
+ require 'oksky/chat'
32
+
33
+ def webhook_client
34
+ @webhook_client ||= Oksky::Chat::WhClient.new
35
+ end
36
+
37
+ post '/callback' do
38
+ body = request.body.read
39
+
40
+ event = webhook_client.parse_events_from(body)
41
+ case event
42
+ when Oksky::Chat::Event::Message
43
+ client = Oksky::Chat::Client::Message.new { |config|
44
+ config.access_token = EVN['OKSKY_CHAT_ACCESS_TOKEN']
45
+ config.endpoint = EVN['OKSKY_CHAT_ENDPOINT']
46
+ }
47
+ result = client.get_message_content(event["id"])
48
+ p JSON.parse(result.body) if !result.nil? && result.kind_of?(Net::HTTPResponse) && !result.body.blank?
49
+ end
50
+
51
+ "OK"
52
+ end
53
+ ```
54
+
55
+ ## Development
56
+
57
+ 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.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/OKSKY/oksky-chat-sdk-ruby>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+
66
+ ## License
67
+
68
+ Copyright (C) 2017 SOLAIRO, INC.
69
+
70
+ Licensed under the Apache License, Version 2.0 (the "License");
71
+ you may not use this file except in compliance with the License.
72
+ You may obtain a copy of the License at
73
+
74
+ http://www.apache.org/licenses/LICENSE-2.0
75
+
76
+ Unless required by applicable law or agreed to in writing, software
77
+ distributed under the License is distributed on an "AS IS" BASIS,
78
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
79
+ See the License for the specific language governing permissions and
80
+ limitations under the License.
81
+
data/lib/oksky/chat.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'oksky/chat/api'
2
+ require 'oksky/chat/api/errors'
3
+ require 'oksky/chat/api/version'
4
+ require 'oksky/chat/request'
5
+ require 'oksky/chat/httpclient'
6
+ require 'oksky/chat/event'
7
+ require 'oksky/chat/client'
8
+ require 'oksky/chat/whclient'
@@ -0,0 +1,9 @@
1
+ require "oksky/chat/api/version"
2
+
3
+ module Oksky
4
+ module Chat
5
+ module API
6
+ DEFAULT_ENDPOINT = ENV['OKSKY_CHAT_ENDPOINT'] || "https://solairo-co.ok-sky.com/rapi/v1"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Oksky
2
+ module Chat
3
+ module API
4
+ class Error < StandardError; end
5
+ class InvalidCredentialsError < Error; end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Oksky
2
+ module Chat
3
+ module API
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'oksky/chat/client/base'
2
+ require 'oksky/chat/client/message'
@@ -0,0 +1,44 @@
1
+ module Oksky
2
+ module Chat
3
+ module Client
4
+ class Base
5
+ # @return [String]
6
+ attr_accessor :access_token, :endpoint
7
+
8
+ # @return [Object]
9
+ attr_accessor :httpclient
10
+
11
+ # Initialize a new Bot Client.
12
+ #
13
+ # @param options [Hash]
14
+ #
15
+ # @return [Oksky::Chat::Message::Client]
16
+ def initialize(options = {})
17
+ options.each do |key, value|
18
+ instance_variable_set("@#{key}", value)
19
+ end
20
+ yield(self) if block_given?
21
+ end
22
+
23
+ def httpclient
24
+ @httpclient ||= Oksky::Chat::HTTPClient.new
25
+ end
26
+
27
+ def endpoint
28
+ @endpoint ||= Oksky::Chat::API::DEFAULT_ENDPOINT
29
+ end
30
+
31
+ # @return [Hash]
32
+ def credentials
33
+ {
34
+ "X-Access-Token" => access_token
35
+ }
36
+ end
37
+
38
+ def credentials?
39
+ credentials.values.all?
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -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 Message < Base
11
+
12
+ # Push messages to OK SKY Chat server and to user.
13
+ #
14
+ # @param user_id [String] User's identifiers
15
+ # @param messages [Hash or Array]
16
+ #
17
+ # @return [Net::HTTPResponse]
18
+ def push_message(messages)
19
+ raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
20
+
21
+ messages = [messages] if messages.is_a?(Hash)
22
+
23
+ request = Request.new do |config|
24
+ config.httpclient = httpclient
25
+ config.endpoint = endpoint
26
+ config.endpoint_path = '/messages'
27
+ config.credentials = credentials
28
+ config.messages = messages
29
+ end
30
+
31
+ request.post
32
+ end
33
+
34
+ # Get message content.
35
+ #
36
+ # @param identifier [String] Message's identifier
37
+ #
38
+ # @return [Oksky::Chat::Event::Message]
39
+ def get_message_content(message_id, option = {}, is_parse = true)
40
+ endpoint_path = "/messages/#{message_id}"
41
+ result = get(endpoint_path)
42
+
43
+ if is_parse
44
+ json = JSON.parse(result.body)
45
+ Oksky::Chat::Event::Message.new(json["data"])
46
+ else
47
+ return result
48
+ end
49
+ end
50
+
51
+ # Fetch data, get content of specified URL.
52
+ #
53
+ # @param endpoint_path [String]
54
+ #
55
+ # @return [Net::HTTPResponse]
56
+ def get(endpoint_path, option = {})
57
+ raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
58
+
59
+ request = Request.new do |config|
60
+ config.httpclient = httpclient
61
+ config.endpoint = endpoint
62
+ config.endpoint_path = endpoint_path
63
+ config.credentials = credentials
64
+ end
65
+
66
+ request.get
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,2 @@
1
+ require 'oksky/chat/event/base'
2
+ require 'oksky/chat/event/message'
@@ -0,0 +1,18 @@
1
+ module Oksky
2
+ module Chat
3
+ module Event
4
+ class Base
5
+
6
+ def initialize(src)
7
+ @src = src
8
+ end
9
+
10
+ def [](key)
11
+ @src[key]
12
+ end
13
+
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,127 @@
1
+ module Oksky
2
+ module Chat
3
+ module Event
4
+ module MessageKind
5
+ Text = "text"
6
+ Link = "link"
7
+ Image = "image"
8
+ Video = "video"
9
+ Audio = "audio"
10
+ Location = "location"
11
+ Sticker = "sticker"
12
+ ActionLink = "action_link"
13
+ Maltiple = "maltiple"
14
+ RichContent = "rich_content"
15
+ Stamp = "stamp"
16
+ Contact = "contact"
17
+ Form = "form"
18
+ Item = "item"
19
+ File = "file"
20
+ Unsupport = 'unsupport'
21
+ end
22
+
23
+ class Message < Base
24
+
25
+ # @return [String<Oksky::Chat::Event::Message>]
26
+ def content
27
+ content_value('content')
28
+ end
29
+
30
+ # @return [String<Oksky::Chat::Event::MessageKind::>]
31
+ def kind
32
+ begin
33
+ Oksky::Chat::Event::MessageKind.const_get(content_value("kind").split("_").map{|w| w[0] = w[0].capitalize; w}.join)
34
+ rescue NameError => e
35
+ Oksky::Chat::Event::MessageKind::Unsupport
36
+ end
37
+ end
38
+
39
+ # @return [Hash<Oksky::Chat::Event::Message>]
40
+ def settings
41
+ content_value("settings")
42
+ end
43
+
44
+ # @return [String<Oksky::Chat::Event::Message>]
45
+ def status
46
+ content_value("status")
47
+ end
48
+
49
+ # @return [Hash<Oksky::Chat::Event::Message>]
50
+ def info
51
+ content_value("info")
52
+ end
53
+
54
+ # @return [Array<Oksky::Chat::Event::Message>]
55
+ def tags
56
+ content_value("tags")
57
+ end
58
+
59
+ # @return [Time<Oksky::Chat::Event::Message>]
60
+ def created_at
61
+ content_value("created_at")
62
+ end
63
+
64
+ # @return [Time<Oksky::Chat::Event::Message>]
65
+ def deleted_at
66
+ content_value("deleted_at")
67
+ end
68
+
69
+ # @return [Time<Oksky::Chat::Event::Message>]
70
+ def updated_at
71
+ content_value("updated_at")
72
+ end
73
+
74
+ # @return [Time<Oksky::Chat::Event::Message>]
75
+ def created_at_unix
76
+ content_value("created_at_unix")
77
+ end
78
+
79
+ # @return [Time<Oksky::Chat::Event::Message>]
80
+ def deleted_at_unix
81
+ content_value("deleted_at_unix")
82
+ end
83
+
84
+ # @return [String<Oksky::Chat::Event::Message>]
85
+ def username
86
+ content_value("username")
87
+ end
88
+
89
+ # @return [Boolean<Oksky::Chat::Event::Message>]
90
+ def user_is_guest
91
+ content_value("user_is_guest")
92
+ end
93
+
94
+ # @return [String<Oksky::Chat::Event::Message>]
95
+ def roomname
96
+ content_value("roomname")
97
+ end
98
+
99
+ def message
100
+ if @src.has_key?('attributes')
101
+ @src['attributes']
102
+ else
103
+ @src
104
+ end
105
+ end
106
+
107
+ def relationships
108
+
109
+ end
110
+
111
+ private
112
+ def exist_attributes?
113
+ !@src.empty? && @src.has_key?('attributes') && !@src['attributes'].empty?
114
+ end
115
+
116
+ def content_value(key)
117
+ if exist_attributes? && @src['attributes'].has_key?("#{key}") && !@src['attributes']["#{key}"].empty?
118
+ return @src['attributes']["#{key}"]
119
+ elsif @src.has_key?("#{key}") && !@src["#{key}"].empty?
120
+ return @src["#{key}"]
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,32 @@
1
+ require "oksky/chat/api/version"
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Oksky
7
+ module Chat
8
+ class HTTPClient
9
+
10
+ # @return [Net::HTTP]
11
+ def http(uri)
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ if uri.scheme == "https"
14
+ http.use_ssl = true
15
+ end
16
+
17
+ http
18
+ end
19
+
20
+ def get(url, header = {})
21
+ uri = URI(url)
22
+ http(uri).get(uri.request_uri, header)
23
+ end
24
+
25
+ def post(url, payload, header = {})
26
+ uri = URI(url)
27
+ http(uri).post(uri.request_uri, payload, header)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,66 @@
1
+ require 'oksky/chat/api/version'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Oksky
7
+ module Chat
8
+ class Request
9
+ attr_accessor :endpoint, :endpoint_path, :credentials, :httpclient
10
+
11
+ # Initializes a new Request
12
+ #
13
+ # @return [Oksky::Chat::Request]
14
+ def initialize
15
+ yield(self) if block_given?
16
+ end
17
+
18
+ # @return [Hash]
19
+ def payload
20
+ payload = {
21
+
22
+ }
23
+
24
+ payload.delete_if{|k, v| v.nil?}.to_json
25
+ end
26
+
27
+ # @return [Hash]
28
+ def header
29
+ header = {
30
+ 'Content-Type' => 'application/json; charset=UTF-8',
31
+ 'User-Agent' => "OKSKY-CHAT-SDK-Ruby/#{Oksky::Chat::API::VERSION}",
32
+ }
33
+ hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
34
+
35
+ header.merge(hash)
36
+ end
37
+
38
+ # Get content of specified URL.
39
+ #
40
+ # @return [Net::HTTPResponse]
41
+ def get
42
+ assert_for_getting_message
43
+ httpclient.get(endpoint + endpoint_path, header)
44
+ end
45
+
46
+ # Post content of specified URL.
47
+ #
48
+ # @raise [ArgumentError]
49
+ #
50
+ # @return [Net::HTTPResponse]
51
+ def post
52
+ assert_for_posting_message
53
+ httpclient.post(endpoint + endpoint_path, payload, header)
54
+ end
55
+
56
+ def assert_for_getting_message
57
+ raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
58
+ end
59
+
60
+ def assert_for_posting_message
61
+ raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,22 @@
1
+ module Oksky
2
+ module Chat
3
+ class WhClient
4
+
5
+ # Parse events from request.body
6
+ #
7
+ # @param request_body [String]
8
+ #
9
+ # @return [Array<Oksky::Chat::Event::Class>]
10
+ def parse_events_from(request_body)
11
+ json = JSON.parse(request_body)
12
+
13
+ begin
14
+ klass = Oksky::Chat::Event.const_get(json['object_name'].capitalize)
15
+ klass.new(json['object'])
16
+ rescue NameError => e
17
+ Oksky::Chat::Event::Base.new(json['object'])
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oksky/chat'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oksky-chat-api"
8
+ spec.version = Oksky::Chat::API::VERSION
9
+ spec.authors = ["SOLAIRO, INC."]
10
+ spec.email = ["fukushi@solairo.co.jp"]
11
+
12
+ spec.summary = ""
13
+ spec.description = ""
14
+ spec.homepage = "https://github.com/OKSKY/oksky-chat-sdk-ruby"
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = %w(LICENSE.txt README.md oksky-chat-api.gemspec) + Dir['lib/**/*.rb']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.4.1'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "webmock", "~> 1.24"
26
+ spec.add_development_dependency "addressable", "~> 2.3"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+
29
+ spec.add_dependency "thor"
30
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oksky-chat-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SOLAIRO, INC.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.24'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.24'
55
+ - !ruby/object:Gem::Dependency
56
+ name: addressable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - fukushi@solairo.co.jp
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/oksky/chat.rb
107
+ - lib/oksky/chat/api.rb
108
+ - lib/oksky/chat/api/errors.rb
109
+ - lib/oksky/chat/api/version.rb
110
+ - lib/oksky/chat/client.rb
111
+ - lib/oksky/chat/client/base.rb
112
+ - lib/oksky/chat/client/message.rb
113
+ - lib/oksky/chat/event.rb
114
+ - lib/oksky/chat/event/base.rb
115
+ - lib/oksky/chat/event/message.rb
116
+ - lib/oksky/chat/httpclient.rb
117
+ - lib/oksky/chat/request.rb
118
+ - lib/oksky/chat/whclient.rb
119
+ - oksky-chat-api.gemspec
120
+ homepage: https://github.com/OKSKY/oksky-chat-sdk-ruby
121
+ licenses:
122
+ - Apache-2.0
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.4.1
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.11
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: ''
144
+ test_files: []