oksky-chat-api 0.1.1 → 0.1.2

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: 8a08ddacc6d0a4c78b28faf354856e54f6267dda
4
- data.tar.gz: 8565601722b3707abf4512208be20810ce3be2d3
3
+ metadata.gz: f529de9ffd8cda1abbc63d41fbcb34901d5aade8
4
+ data.tar.gz: d6d2c5d961dc5a11fe937b8862e84d203487f41c
5
5
  SHA512:
6
- metadata.gz: 6a0ac7db527474897eb46f58129b645cfd3802ddc4837ad3ed7ed764e407e905ee0ddda8caabca12e83fc999ab7a77fcd8805fdb6e5bde6df736f1f6b2e88255
7
- data.tar.gz: 466a07c0441b5db22030ef817e32bfea3dfd4712590fa1fcd939a6b4fa38a46a70c4695523cc1537296ef4cfa49587650f0434da94661adfc40c16e916111757
6
+ metadata.gz: 8ce138fc5ee4b0be8511ec0e433f7048e917e95f0c932b55fdc6456e59a26803310835161e454480f232f1e2f61cd2b6a3d184962da21bca634816c96f8f6561
7
+ data.tar.gz: 3d993fa08c0818ae5e4aade60fcefaf7ff15bb62a4c3e4c22b277d8f04a51d0ce19fa6442ffd3b2c6c5e14b5eb7483b02b2659a4c18150238f93cd6a2a897f9c
@@ -1,7 +1,7 @@
1
1
  module Oksky
2
2
  module Chat
3
3
  module API
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,5 @@
1
1
  require 'oksky/chat/client/base'
2
2
  require 'oksky/chat/client/message'
3
- require 'oksky/chat/client/suggestion'
3
+ require 'oksky/chat/client/suggestion'
4
+ require 'oksky/chat/client/room'
5
+ require 'oksky/chat/client/support'
@@ -0,0 +1,77 @@
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 Room < Base
11
+
12
+ # Push rooms to OK SKY Chat server and to user.
13
+ #
14
+ # @param user_id [String] User's identifiers
15
+ # @param rooms [Hash or Array]
16
+ #
17
+ # @return [Net::HTTPResponse]
18
+ def push_room(rooms)
19
+ raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
20
+
21
+ rooms = [rooms] if rooms.is_a?(Hash)
22
+
23
+ request = Request.new do |config|
24
+ config.httpclient = httpclient
25
+ config.endpoint = endpoint
26
+ config.endpoint_path = '/rooms'
27
+ config.credentials = credentials
28
+ config.rooms = rooms
29
+ end
30
+
31
+ request.post
32
+ end
33
+
34
+ # Get room content.
35
+ #
36
+ # @param identifier [String] Message's identifier
37
+ #
38
+ # @return [Oksky::Chat::Event::Message]
39
+ def get_room_content(room_id, option = {}, is_parse = true)
40
+ endpoint_path = "/rooms/#{room_id}"
41
+ result = get(endpoint_path, option)
42
+
43
+ if is_parse
44
+ json = JSON.parse(result.body)
45
+ Oksky::Chat::Event::Room.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
+ unless option.empty?
60
+ params = URI.encode_www_form(option)
61
+ endpoint_path = "#{endpoint_path}?#{params}"
62
+ end
63
+
64
+ request = Request.new do |config|
65
+ config.httpclient = httpclient
66
+ config.endpoint = endpoint
67
+ config.endpoint_path = endpoint_path
68
+ config.credentials = credentials
69
+ end
70
+
71
+ request.get
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,96 @@
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 Support < Base
11
+
12
+ # Push supports to OK SKY Chat server and to user.
13
+ #
14
+ # @param user_id [String] User's identifiers
15
+ # @param supports [Hash or Array]
16
+ #
17
+ # @return [Net::HTTPResponse]
18
+ def push_support(supports)
19
+ raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
20
+
21
+ supports = [supports] if supports.is_a?(Hash)
22
+
23
+ request = Request.new do |config|
24
+ config.httpclient = httpclient
25
+ config.endpoint = endpoint
26
+ config.endpoint_path = '/supports'
27
+ config.credentials = credentials
28
+ config.supports = supports
29
+ end
30
+
31
+ request.post
32
+ end
33
+
34
+ # Get supports content.
35
+ #
36
+ # @param identifier [String] Support's identifier
37
+ #
38
+ # @return Array [Oksky::Chat::Event::Message]
39
+ def get_supports_content(option = {}, is_parse = true)
40
+ endpoint_path = "/supports"
41
+ result = get(endpoint_path, option)
42
+
43
+ if is_parse
44
+ json = JSON.parse(result.body)
45
+ json["data"].map{|d|
46
+ Oksky::Chat::Event::Support.new(d)
47
+ }
48
+ else
49
+ return result
50
+ end
51
+ end
52
+
53
+ # Get support content.
54
+ #
55
+ # @param identifier [String] Message's identifier
56
+ #
57
+ # @return [Oksky::Chat::Event::Message]
58
+ def get_support_content(support_id, option = {}, is_parse = true)
59
+ endpoint_path = "/supports/#{support_id}"
60
+ result = get(endpoint_path, option)
61
+
62
+ if is_parse
63
+ json = JSON.parse(result.body)
64
+ Oksky::Chat::Event::Support.new(json["data"])
65
+ else
66
+ return result
67
+ end
68
+ end
69
+
70
+ # Fetch data, get content of specified URL.
71
+ #
72
+ # @param endpoint_path [String]
73
+ #
74
+ # @return [Net::HTTPResponse]
75
+ def get(endpoint_path, option = {})
76
+ raise Oksky::Chat::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
77
+
78
+ unless option.empty?
79
+ params = URI.encode_www_form(option)
80
+ endpoint_path = "#{endpoint_path}?#{params}"
81
+ end
82
+
83
+ request = Request.new do |config|
84
+ config.httpclient = httpclient
85
+ config.endpoint = endpoint
86
+ config.endpoint_path = endpoint_path
87
+ config.credentials = credentials
88
+ end
89
+
90
+ request.get
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,2 +1,4 @@
1
1
  require 'oksky/chat/event/base'
2
- require 'oksky/chat/event/message'
2
+ require 'oksky/chat/event/message'
3
+ require 'oksky/chat/event/room'
4
+ require 'oksky/chat/event/support'
@@ -1,3 +1,5 @@
1
+ # require 'oksky/chat/client/room'
2
+
1
3
  module Oksky
2
4
  module Chat
3
5
  module Event
@@ -104,8 +106,20 @@ module Oksky
104
106
  end
105
107
  end
106
108
 
107
- def relationships
109
+ def room_id
110
+ if exist_relationships? && @src['relationships'].has_key?("room") && !@src['relationships']["room"].empty? && @src['relationships']["room"].has_key?("data") && !@src['relationships']["room"]["data"].empty? && @src['relationships']["room"]["data"].has_key?("id") && !@src['relationships']["room"]["data"]["id"].empty?
111
+ return @src['relationships']["room"]["data"]["id"]
112
+ else
113
+ return nil
114
+ end
115
+ end
108
116
 
117
+ def relationships
118
+ if exist_relationships?
119
+ return @src['relationships']
120
+ else
121
+ {}
122
+ end
109
123
  end
110
124
 
111
125
  private
@@ -113,6 +127,10 @@ module Oksky
113
127
  !@src.empty? && @src.has_key?('attributes') && !@src['attributes'].empty?
114
128
  end
115
129
 
130
+ def exist_relationships?
131
+ !@src.empty? && @src.has_key?('relationships') && !@src['relationships'].empty?
132
+ end
133
+
116
134
  def content_value(key)
117
135
  if exist_attributes? && @src['attributes'].has_key?("#{key}") && !@src['attributes']["#{key}"].empty?
118
136
  return @src['attributes']["#{key}"]
@@ -0,0 +1,120 @@
1
+ module Oksky
2
+ module Chat
3
+ module Event
4
+ module RoomKind
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 Room < Base
24
+
25
+ # @return [String<Oksky::Chat::Event::Room>]
26
+ def name
27
+ content_value('name')
28
+ end
29
+
30
+ # @return [String<Oksky::Chat::Event::RoomKind::>]
31
+ def kind
32
+ begin
33
+ Oksky::Chat::Event::RoomKind.const_get(content_value("kind").split("_").map{|w| w[0] = w[0].capitalize; w}.join)
34
+ rescue NameError => e
35
+ Oksky::Chat::Event::RoomKind::Unsupport
36
+ end
37
+ end
38
+
39
+ # @return [Hash<Oksky::Chat::Event::Room>]
40
+ def description
41
+ content_value("description")
42
+ end
43
+
44
+ # @return [String<Oksky::Chat::Event::Room>]
45
+ def is_private
46
+ content_value("is_private")
47
+ end
48
+
49
+ # @return [Hash<Oksky::Chat::Event::Room>]
50
+ def settings
51
+ content_value("info")
52
+ end
53
+
54
+ # @return [Time<Oksky::Chat::Event::Room>]
55
+ def enabled
56
+ content_value("enabled")
57
+ end
58
+
59
+ # @return [Time<Oksky::Chat::Event::Room>]
60
+ def room_code
61
+ content_value("room_code")
62
+ end
63
+
64
+ # @return [Time<Oksky::Chat::Event::Room>]
65
+ def awaiting_support
66
+ content_value("awaiting_support")
67
+ end
68
+
69
+ # @return [Time<Oksky::Chat::Event::Room>]
70
+ def created_at_unix
71
+ content_value("created_at_unix")
72
+ end
73
+
74
+ # @return [Time<Oksky::Chat::Event::Room>]
75
+ def created_at
76
+ content_value("created_at")
77
+ end
78
+
79
+ # @return [String<Oksky::Chat::Event::Room>]
80
+ def unread_message_count
81
+ content_value("unread_message_count")
82
+ end
83
+
84
+ # @return [Boolean<Oksky::Chat::Event::Room>]
85
+ def is_external
86
+ content_value("is_external")
87
+ end
88
+
89
+ def room
90
+ if @src.has_key?('attributes')
91
+ @src['attributes']
92
+ else
93
+ @src
94
+ end
95
+ end
96
+
97
+ def relationships
98
+ if exist_relationships?
99
+ return @src['relationships']
100
+ else
101
+ {}
102
+ end
103
+ end
104
+
105
+ private
106
+ def exist_attributes?
107
+ !@src.empty? && @src.has_key?('attributes') && !@src['attributes'].empty?
108
+ end
109
+
110
+ def content_value(key)
111
+ if exist_attributes? && @src['attributes'].has_key?("#{key}") && !@src['attributes']["#{key}"].empty?
112
+ return @src['attributes']["#{key}"]
113
+ elsif @src.has_key?("#{key}") && !@src["#{key}"].empty?
114
+ return @src["#{key}"]
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,47 @@
1
+ module Oksky
2
+ module Chat
3
+ module Event
4
+ class Support < Base
5
+
6
+ # @return [String<Oksky::Chat::Event::Support>]
7
+ def end_time_unix
8
+ content_value('end_time_unix')
9
+ end
10
+
11
+ # @return [Hash<Oksky::Chat::Event::Support>]
12
+ def start_time_unix
13
+ content_value("start_time_unix")
14
+ end
15
+
16
+ def support
17
+ if @src.has_key?('attributes')
18
+ @src['attributes']
19
+ else
20
+ @src
21
+ end
22
+ end
23
+
24
+ def relationships
25
+ if exist_relationships?
26
+ return @src['relationships']
27
+ else
28
+ {}
29
+ end
30
+ end
31
+
32
+ private
33
+ def exist_attributes?
34
+ !@src.empty? && @src.has_key?('attributes') && !@src['attributes'].empty?
35
+ end
36
+
37
+ def content_value(key)
38
+ if exist_attributes? && @src['attributes'].has_key?("#{key}") && !@src['attributes']["#{key}"].empty?
39
+ return @src['attributes']["#{key}"]
40
+ elsif @src.has_key?("#{key}") && !@src["#{key}"].empty?
41
+ return @src["#{key}"]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
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.1
4
+ version: 0.1.2
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-07-23 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,10 +110,14 @@ 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/room.rb
113
114
  - lib/oksky/chat/client/suggestion.rb
115
+ - lib/oksky/chat/client/support.rb
114
116
  - lib/oksky/chat/event.rb
115
117
  - lib/oksky/chat/event/base.rb
116
118
  - lib/oksky/chat/event/message.rb
119
+ - lib/oksky/chat/event/room.rb
120
+ - lib/oksky/chat/event/support.rb
117
121
  - lib/oksky/chat/httpclient.rb
118
122
  - lib/oksky/chat/request.rb
119
123
  - lib/oksky/chat/whclient.rb
@@ -138,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
142
  version: '0'
139
143
  requirements: []
140
144
  rubyforge_project:
141
- rubygems_version: 2.6.11
145
+ rubygems_version: 2.6.14
142
146
  signing_key:
143
147
  specification_version: 4
144
148
  summary: ''