showroom_api 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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/showroom_api.rb +385 -0
- data/lib/showroom_api/version.rb +3 -0
- data/showroom_api.gemspec +33 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac5bb426fa424f15fb3ba0d15d4cd4805091797032d2e0ac314336af9cd00632
|
4
|
+
data.tar.gz: 43d2b143d2b0aab8af7e29189bd4031c9ea7e26dae8a7aee8608de21a8b0af30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef1270212ba978232af0f19732e50891eb60525ddf553cd6a9f2147785544cdeeb4931bd220b9d9a1d9ba56ca485bffff10eaa5d94b35028dfbb539f31eeeb8a
|
7
|
+
data.tar.gz: abf717ec4a54e45cc866f00a142f0c82b2697737608e003940e572860dbc9c3ac7f32d614d24eb961560229be80c40f02e5004653a9ca16d6cef4a56221e904b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wwwfernand@yahoo.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Fernand
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# ShowroomApi
|
2
|
+
|
3
|
+
**API** for [showroom-live.com](https://www.showroom-live.com/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'showroom_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install showroom_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Data can be obtained using the following patterns:
|
24
|
+
|
25
|
+
> ::ShowroomApi::Live.onlives
|
26
|
+
> ::ShowroomApi::Live.live_info(room_id)
|
27
|
+
> ::ShowroomApi::Room.profile(room_id)
|
28
|
+
> ::ShowroomApi::User.profile(user_id)
|
29
|
+
|
30
|
+
|
31
|
+
## Commands
|
32
|
+
|
33
|
+
* **Live**
|
34
|
+
|
35
|
+
Contains info of currently onlive stream
|
36
|
+
| Method | Argument | Definition |
|
37
|
+
| :------------- |:-------------:| :-----|
|
38
|
+
| onlives | size(optional) | Array of room categories and their available live rooms.<br>Return all the info or just part if size is provided |
|
39
|
+
| live_info | room_id | Info of the room |
|
40
|
+
| streaming_url | room_id | List of room's streaming URLs |
|
41
|
+
| polling | room_id | Live status of the room |
|
42
|
+
| age_verification | room_id | - |
|
43
|
+
| current_user | room_id | Logged in user's info <small>(#1)</small> |
|
44
|
+
| telop | room_id | - |
|
45
|
+
| enquete_result | room_id | Room's survey result |
|
46
|
+
| summary_ranking | room_id | Room's ranking summary |
|
47
|
+
| comment_log | room_id | Room's comment log |
|
48
|
+
| gift_log | room_id | Room's gift log |
|
49
|
+
| gift_list | room_id | Room's available gift |
|
50
|
+
| stage_gift_list | room_id | List of gifts the room received |
|
51
|
+
| stage_user_list | room_id | List of users in the room |
|
52
|
+
| onlive_num | - | Count of currently available rooms |
|
53
|
+
|
54
|
+
* **Room**
|
55
|
+
|
56
|
+
Contains info of a room
|
57
|
+
| Method | Argument | Definition |
|
58
|
+
| ------------- |:-------------:| :-----|
|
59
|
+
| event_and_support | room_id | Info about event and support of the room |
|
60
|
+
| profile | room_id | Profile info of the room |
|
61
|
+
| next_live | room_id | Room's next live schedule |
|
62
|
+
| settings | room_id | Rooms available performance |
|
63
|
+
| status | room_id | Status of the room |
|
64
|
+
|
65
|
+
* **User**
|
66
|
+
|
67
|
+
Contains info of a user
|
68
|
+
| Method | Argument | Definition |
|
69
|
+
| ------------- |:-------------:| -----:|
|
70
|
+
| profile | user_id | Profile info of the user |
|
71
|
+
| detail | user_id | Detailed info of the logged-in user <small>(#1)</small> |
|
72
|
+
|
73
|
+
<small>(#1) Needs to be logged-in</small>
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wwwfernand/showroom_api.
|
78
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "showroom_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/showroom_api.rb
ADDED
@@ -0,0 +1,385 @@
|
|
1
|
+
require "showroom_api/version"
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
#https://qiita.com/takeru7584/items/f4ba4c31551204279ed2
|
6
|
+
|
7
|
+
##
|
8
|
+
# This module represents showroom_api gem
|
9
|
+
module ShowroomApi
|
10
|
+
##
|
11
|
+
# This class provides static methods for live rooms
|
12
|
+
class Live
|
13
|
+
# get the array of room categories and their available live rooms
|
14
|
+
#
|
15
|
+
# @param size [Integer]
|
16
|
+
# @return [Array]
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# ::ShowroomLive::Api::Live.onlives
|
20
|
+
def self.onlives(size=nil)
|
21
|
+
data=send_request("onlives",nil)[:onlives]
|
22
|
+
cnt=ShowroomApi.to_integer(size)
|
23
|
+
if !cnt.nil? && cnt > 0
|
24
|
+
return data[0..(cnt-1)]
|
25
|
+
end
|
26
|
+
return data
|
27
|
+
end
|
28
|
+
|
29
|
+
# get the id of the first room in the list of onlives
|
30
|
+
#
|
31
|
+
# @param size [Integer]
|
32
|
+
# @return [Array]
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# ::ShowroomLive::Api::Live.room_ids
|
36
|
+
def self.room_ids(size)
|
37
|
+
arr=[]
|
38
|
+
cnt=ShowroomApi.to_integer(size)
|
39
|
+
return [] if cnt.nil? || cnt <= 0
|
40
|
+
rooms=onlives(1)
|
41
|
+
rooms[0][:lives].each_with_index do |room,i|
|
42
|
+
break if i>=cnt
|
43
|
+
arr<<room[:room_id]
|
44
|
+
end
|
45
|
+
#$stderr.puts arr
|
46
|
+
return arr
|
47
|
+
end
|
48
|
+
|
49
|
+
# get the stream url of the first room in the list of onlives
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# ::ShowroomLive::Api::Live.first_stream_url
|
55
|
+
def self.first_stream_url
|
56
|
+
return onlives(1)[0][:lives][0][:streaming_url_list][0][:url]
|
57
|
+
end
|
58
|
+
|
59
|
+
# get the info of the room
|
60
|
+
#
|
61
|
+
# @param room_id [String]
|
62
|
+
# @return [Hash]
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# ::ShowroomLive::Api::Live.live_info(room_id)
|
66
|
+
def self.live_info(room_id)
|
67
|
+
return send_request("live_info",room_id)
|
68
|
+
end
|
69
|
+
|
70
|
+
# get the list of room's streaming URLs
|
71
|
+
#
|
72
|
+
# @param room_id [String]
|
73
|
+
# @return [Array]
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# ::ShowroomLive::Api::Live.streaming_url(room_id)
|
77
|
+
def self.streaming_url(room_id)
|
78
|
+
send_request("streaming_url",room_id)[:streaming_url_list] || []
|
79
|
+
end
|
80
|
+
|
81
|
+
# get the live status of the room
|
82
|
+
#
|
83
|
+
# @param room_id [String]
|
84
|
+
# @return [Hash]
|
85
|
+
#
|
86
|
+
# @example
|
87
|
+
# ::ShowroomLive::Api::Live.polling(room_id)
|
88
|
+
def self.polling(room_id)
|
89
|
+
return send_request("polling",room_id)
|
90
|
+
end
|
91
|
+
|
92
|
+
# age verification
|
93
|
+
#
|
94
|
+
# @param room_id [String]
|
95
|
+
# @return [boolean]
|
96
|
+
#
|
97
|
+
# @example
|
98
|
+
# ::ShowroomLive::Api::Live.age_verification(room_id)
|
99
|
+
def self.age_verification(room_id)
|
100
|
+
return send_request("age_verification",room_id)[:is_passed]
|
101
|
+
end
|
102
|
+
|
103
|
+
# get logged in user's info
|
104
|
+
#
|
105
|
+
# @param room_id [String]
|
106
|
+
# @return [Hash]
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# ::ShowroomLive::Api::Live.current_user(room_id)
|
110
|
+
def self.current_user(room_id)
|
111
|
+
return send_request("current_user",room_id)
|
112
|
+
end
|
113
|
+
|
114
|
+
# telop
|
115
|
+
#
|
116
|
+
# @param room_id [String]
|
117
|
+
# @return [Hash]
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# ::ShowroomLive::Api::Live.telop(room_id)
|
121
|
+
def self.telop(room_id)
|
122
|
+
return send_request("telop",room_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
# get room's survey result
|
126
|
+
#
|
127
|
+
# @param room_id [String]
|
128
|
+
# @return [Hash]
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# ::ShowroomLive::Api::Live.enquete_result(room_id)
|
132
|
+
def self.enquete_result(room_id)
|
133
|
+
return send_request("enquete_result",room_id)
|
134
|
+
end
|
135
|
+
|
136
|
+
# get room's ranking summary
|
137
|
+
#
|
138
|
+
# @param room_id [String]
|
139
|
+
# @return [Array]
|
140
|
+
#
|
141
|
+
# @example
|
142
|
+
# ::ShowroomLive::Api::Live.summary_ranking(room_id)
|
143
|
+
def self.summary_ranking(room_id)
|
144
|
+
return send_request("summary_ranking",room_id)[:ranking] || []
|
145
|
+
end
|
146
|
+
|
147
|
+
# get room's comment log
|
148
|
+
#
|
149
|
+
# @param room_id [String]
|
150
|
+
# @return [Array]
|
151
|
+
#
|
152
|
+
# @example
|
153
|
+
# ::ShowroomLive::Api::Live.comment_log(room_id)
|
154
|
+
def self.comment_log(room_id)
|
155
|
+
return send_request("comment_log",room_id)[:comment_log] || []
|
156
|
+
end
|
157
|
+
|
158
|
+
# get room's gift log
|
159
|
+
#
|
160
|
+
# @param room_id [String]
|
161
|
+
# @return [Array]
|
162
|
+
#
|
163
|
+
# @example
|
164
|
+
# ::ShowroomLive::Api::Live.gift_log(room_id)
|
165
|
+
def self.gift_log(room_id)
|
166
|
+
return send_request("gift_log",room_id)[:gift_log] || []
|
167
|
+
end
|
168
|
+
|
169
|
+
# get room's available gift
|
170
|
+
#
|
171
|
+
# @param room_id [String]
|
172
|
+
# @return [Hash]
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# ::ShowroomLive::Api::Live.gift_list(room_id)
|
176
|
+
def self.gift_list(room_id)
|
177
|
+
return send_request("gift_list",room_id)
|
178
|
+
end
|
179
|
+
|
180
|
+
# get the list of gifts the room received
|
181
|
+
#
|
182
|
+
# @param room_id [String]
|
183
|
+
# @return [Array]
|
184
|
+
#
|
185
|
+
# @example
|
186
|
+
# ::ShowroomLive::Api::Live.stage_gift_list(room_id)
|
187
|
+
def self.stage_gift_list(room_id)
|
188
|
+
return send_request("stage_gift_list",room_id)[:stage_gift_list] || []
|
189
|
+
end
|
190
|
+
|
191
|
+
# get the list of users in the room
|
192
|
+
#
|
193
|
+
# @param room_id [String]
|
194
|
+
# @return [Array]
|
195
|
+
#
|
196
|
+
# @example
|
197
|
+
# ::ShowroomLive::Api::Live.stage_user_list(room_id)
|
198
|
+
def self.stage_user_list(room_id)
|
199
|
+
return send_request("stage_user_list",room_id)[:stage_user_list] || []
|
200
|
+
end
|
201
|
+
|
202
|
+
# get the count of live rooms
|
203
|
+
#
|
204
|
+
# @return [Integer]
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# ::ShowroomLive::Api::Live.onlive_num
|
208
|
+
def self.onlive_num
|
209
|
+
return send_request("onlive_num",nil)[:num]
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
# performs http request to showroom
|
214
|
+
#
|
215
|
+
# @param cmd [String]
|
216
|
+
# @param room_id [String]
|
217
|
+
# @return [Hash]
|
218
|
+
def self.send_request(cmd,room_id=nil)
|
219
|
+
url="https://www.showroom-live.com/api/live/"
|
220
|
+
if room_id.nil? || room_id.to_s.empty?
|
221
|
+
ShowroomApi.showroom_live_get_api_data("#{url}#{cmd}")
|
222
|
+
else
|
223
|
+
ShowroomApi.showroom_live_get_api_data("#{url}#{cmd}?room_id=#{room_id}")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
##
|
229
|
+
# This class provides static methods for rooms
|
230
|
+
class Room
|
231
|
+
# get the info about event and support of the room
|
232
|
+
#
|
233
|
+
# @param room_id [String]
|
234
|
+
# @return [Hash]
|
235
|
+
#
|
236
|
+
# @example
|
237
|
+
# ::ShowroomLive::Api::Room.event_and_support(room_id)
|
238
|
+
def self.event_and_support(room_id)
|
239
|
+
return send_request("event_and_support",room_id)
|
240
|
+
end
|
241
|
+
|
242
|
+
# get the profile info of the room
|
243
|
+
#
|
244
|
+
# @param room_id [String]
|
245
|
+
# @return [Hash]
|
246
|
+
#
|
247
|
+
# @example
|
248
|
+
# ::ShowroomLive::Api::Room.profile(room_id)
|
249
|
+
def self.profile(room_id)
|
250
|
+
return send_request("profile",room_id)
|
251
|
+
end
|
252
|
+
|
253
|
+
# get the room's next live schedule
|
254
|
+
#
|
255
|
+
# @param room_id [String]
|
256
|
+
# @return [Hash]
|
257
|
+
#
|
258
|
+
# @example
|
259
|
+
# ::ShowroomLive::Api::Room.next_live(room_id)
|
260
|
+
def self.next_live(room_id)
|
261
|
+
return send_request("next_live",room_id)
|
262
|
+
end
|
263
|
+
|
264
|
+
# get the room's available performance
|
265
|
+
#
|
266
|
+
# @param room_id [String]
|
267
|
+
# @return [Array]
|
268
|
+
#
|
269
|
+
# @example
|
270
|
+
# ::ShowroomLive::Api::Room.settings(room_id)
|
271
|
+
def self.settings(room_id)
|
272
|
+
return send_request("settings",room_id)[:available_performance_type] || []
|
273
|
+
end
|
274
|
+
|
275
|
+
# get the status of the room
|
276
|
+
#
|
277
|
+
# @param room_id [String]
|
278
|
+
# @return [Hash]
|
279
|
+
#
|
280
|
+
# @example
|
281
|
+
# ::ShowroomLive::Api::Room.status(room_id)
|
282
|
+
def self.status(room_id)
|
283
|
+
return send_request("status",room_id)
|
284
|
+
end
|
285
|
+
|
286
|
+
# get the name and screen_name of room's owner
|
287
|
+
#
|
288
|
+
# @param room_id [String]
|
289
|
+
# @return [Hash]
|
290
|
+
#
|
291
|
+
# @example
|
292
|
+
# ::ShowroomLive::Api::Room.name(room_id)
|
293
|
+
def self.name(room_id)
|
294
|
+
url = "https://www.showroom-live.com/room/profile?room_id=#{room_id}"
|
295
|
+
begin
|
296
|
+
hash={}
|
297
|
+
page = Nokogiri::HTML(open(url))
|
298
|
+
hash[:screen_name] = page.xpath("//ul[contains(@class, 'room-profile-head-action-menu')]/li[1]/a/@href").first.value[1..-1]
|
299
|
+
hash[:name] = page.xpath("//h2[contains(@class, 'room-profile-head-name')]/text()").first.text
|
300
|
+
hash
|
301
|
+
rescue
|
302
|
+
{}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
private
|
307
|
+
# performs http request to showroom
|
308
|
+
#
|
309
|
+
# @param cmd [String]
|
310
|
+
# @param room_id [String]
|
311
|
+
# @return [Hash]
|
312
|
+
def self.send_request(cmd,room_id)
|
313
|
+
ShowroomApi.showroom_live_get_api_data("https://www.showroom-live.com/api/room/#{cmd}?room_id=#{room_id}")
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
##
|
318
|
+
# This class provides static methods for users
|
319
|
+
class User
|
320
|
+
# get the profile info of the user
|
321
|
+
#
|
322
|
+
# @param user_id [String]
|
323
|
+
# @return [Hash]
|
324
|
+
#
|
325
|
+
# @example
|
326
|
+
# ::ShowroomLive::Api::User.send_request(user_id)
|
327
|
+
def self.profile(user_id)
|
328
|
+
return send_request("profile",user_id)
|
329
|
+
end
|
330
|
+
|
331
|
+
# get the detailed info of the logged-in user
|
332
|
+
#
|
333
|
+
# @return [Hash]
|
334
|
+
#
|
335
|
+
# @example
|
336
|
+
# ::ShowroomLive::Api::User.detail
|
337
|
+
def self.detail
|
338
|
+
return send_request("detail",nil)
|
339
|
+
end
|
340
|
+
|
341
|
+
# performs http request to showroom
|
342
|
+
#
|
343
|
+
# @param cmd [String]
|
344
|
+
# @param user_id [String]
|
345
|
+
# @return [Hash]
|
346
|
+
private
|
347
|
+
def self.send_request(cmd,user_id=nil)
|
348
|
+
url="https://www.showroom-live.com/api/user/"
|
349
|
+
if user_id.nil? || user_id.to_s.empty?
|
350
|
+
ShowroomApi.showroom_live_get_api_data("#{url}#{cmd}")
|
351
|
+
else
|
352
|
+
ShowroomApi.showroom_live_get_api_data("#{url}#{cmd}?user_id=#{user_id}")
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
protected
|
358
|
+
# performs http request to showroom
|
359
|
+
#
|
360
|
+
# @param url [String]
|
361
|
+
# @return [Hash]
|
362
|
+
def self.showroom_live_get_api_data(url)
|
363
|
+
begin
|
364
|
+
uri = URI(url)
|
365
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
366
|
+
http.use_ssl = true
|
367
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
368
|
+
request = Net::HTTP::Get.new(url)
|
369
|
+
response = http.request(request)
|
370
|
+
return JSON.parse(response.read_body,:symbolize_names => true)
|
371
|
+
rescue
|
372
|
+
return {}
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
# convert string to valid integer
|
377
|
+
#
|
378
|
+
# @param num [String]
|
379
|
+
# @return [Integer]
|
380
|
+
def self.to_integer(num)
|
381
|
+
return nil if num.nil?
|
382
|
+
return num.to_i if num.to_i.to_s == num.to_s
|
383
|
+
return nil
|
384
|
+
end
|
385
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "showroom_api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "showroom_api"
|
7
|
+
spec.version = ShowroomApi::VERSION
|
8
|
+
spec.authors = ["Fernand"]
|
9
|
+
spec.email = ["wwwfernand@yahoo.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{provide API for Showroom-live}
|
12
|
+
spec.description = %q{provide API for Showroom-live}
|
13
|
+
spec.homepage = "https://github.com/wwwfernand/ShowroomApi"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.1")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "nokogiri"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: showroom_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernand
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-26 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: provide API for Showroom-live
|
70
|
+
email:
|
71
|
+
- wwwfernand@yahoo.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/showroom_api.rb
|
87
|
+
- lib/showroom_api/version.rb
|
88
|
+
- showroom_api.gemspec
|
89
|
+
homepage: https://github.com/wwwfernand/ShowroomApi
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
homepage_uri: https://github.com/wwwfernand/ShowroomApi
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.3.1
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.1.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: provide API for Showroom-live
|
113
|
+
test_files: []
|