cocRb 0.1.3 → 0.1.4
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 +74 -35
- data/lib/cocRb.rb +2 -0
- data/lib/cocRb/api.rb +29 -30
- data/lib/cocRb/clan.rb +200 -162
- data/lib/cocRb/clanWar.rb +198 -191
- data/lib/cocRb/gp.rb +47 -45
- data/lib/cocRb/labels.rb +47 -44
- data/lib/cocRb/league.rb +92 -102
- data/lib/cocRb/location.rb +78 -97
- data/lib/cocRb/player.rb +44 -40
- data/lib/cocRb/utility.rb +28 -24
- data/lib/cocRb/version.rb +1 -1
- metadata +16 -2
data/lib/cocRb/clanWar.rb
CHANGED
@@ -1,300 +1,307 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "faraday"
|
2
|
+
require "time"
|
3
3
|
require "json"
|
4
4
|
|
5
5
|
module CocRb
|
6
|
+
|
6
7
|
class << self
|
7
|
-
|
8
|
-
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
9
10
|
|
10
11
|
def self.configure
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
yield(configuration)
|
14
|
+
end
|
14
15
|
|
15
16
|
class Configuration
|
16
|
-
|
17
|
+
attr_accessor :token, :url
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def initialize
|
20
|
+
@token = nil
|
21
|
+
@url = nil
|
21
22
|
end
|
22
|
-
|
23
|
+
end
|
24
|
+
|
23
25
|
class Settings
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def self.get
|
27
|
+
@conn = Faraday.new(
|
28
|
+
url:"https://api.clashofclans.com" ,
|
29
|
+
headers: {
|
30
|
+
'Content-Type' => 'application/json',
|
31
|
+
'Authorization' => "Bearer #{CocRb.configuration.token}"
|
30
32
|
}
|
31
33
|
)
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
rescue => e
|
35
|
+
raise "Oops Unexpected error Caught!"
|
36
|
+
puts e
|
37
|
+
end
|
35
38
|
end
|
36
|
-
end
|
37
|
-
class ClanWar < Settings
|
38
|
-
def self.get_WarLog(tag:, _limit:false, status: false)
|
39
|
-
get
|
40
|
-
io = tag
|
41
|
-
tag = io.gsub('#', '%23')
|
42
|
-
res = @conn.get("v1/clans/#{tag}/warlog") do |req|
|
43
|
-
req.params[:limit] = _limit if _limit
|
44
|
-
end
|
45
|
-
|
46
|
-
if status
|
47
|
-
puts res.status
|
48
|
-
else
|
49
|
-
val = res.body
|
50
|
-
convert = JSON.parse(val)
|
51
|
-
end
|
52
|
-
end
|
53
39
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
val = res.body
|
64
|
-
convert = JSON.parse(val)
|
65
|
-
end
|
40
|
+
class ClanWar < Settings
|
41
|
+
def self.get_WarLog(tag:, _limit:false, status: false)
|
42
|
+
get
|
43
|
+
io = tag
|
44
|
+
tag = io.gsub('#', '%23')
|
45
|
+
res = @conn.get("v1/clans/#{tag}/warlog") do |req|
|
46
|
+
req.params[:limit] = _limit if _limit
|
47
|
+
end
|
66
48
|
|
49
|
+
if status
|
50
|
+
puts res.status
|
51
|
+
else
|
52
|
+
val = res.body
|
53
|
+
convert = JSON.parse(val)
|
54
|
+
end
|
67
55
|
end
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
def self.get_ClanWar(tag:, status: false)
|
58
|
+
get
|
59
|
+
io = tag
|
60
|
+
tag = io.gsub('#', '%23')
|
61
|
+
res = @conn.get("v1/clans/#{tag}/currentwar")
|
72
62
|
|
73
|
-
|
63
|
+
if status
|
64
|
+
puts res.status
|
65
|
+
else
|
66
|
+
val = res.body
|
74
67
|
|
75
|
-
|
68
|
+
convert = JSON.parse(val)
|
69
|
+
end
|
70
|
+
end
|
76
71
|
|
77
|
-
|
72
|
+
def self.get_ClanWarMembers(tag:, teamInput:, status: false)
|
73
|
+
get
|
74
|
+
teamInput_Options = ["clan", "opponent"]
|
78
75
|
|
79
|
-
|
76
|
+
check = teamInput_Options.include?(teamInput)
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
if check == false
|
79
|
+
puts 'Not a valid teamInput Option'
|
80
|
+
elsif check == true
|
81
|
+
io = tag
|
82
|
+
tag = io.gsub('#', '%23')
|
83
|
+
res = @conn.get("v1/clans/#{tag}/currentwar")
|
84
84
|
|
85
85
|
if status
|
86
|
-
|
86
|
+
puts res.status
|
87
87
|
else
|
88
|
-
|
89
|
-
convert = JSON.parse(val)
|
88
|
+
val = res.body
|
90
89
|
|
91
|
-
|
90
|
+
convert = JSON.parse(val)
|
92
91
|
|
93
|
-
|
92
|
+
getClan_War_Members = convert[teamInput]['members']
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
94
|
+
hash = getClan_War_Members.sort_by { |s| s['townhallLevel'] }
|
99
95
|
|
96
|
+
sort = hash.sort_by { |_k, v| v }.reverse
|
100
97
|
|
98
|
+
end
|
99
|
+
end
|
101
100
|
end
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
if status
|
111
|
-
puts res.status
|
102
|
+
def self.get_WarTime(tag:, status: false)
|
103
|
+
get
|
104
|
+
io = tag
|
105
|
+
tag = io.gsub('#', '%23')
|
106
|
+
res = @conn.get("v1/clans/#{tag}/currentwar")
|
107
|
+
if status
|
108
|
+
puts res.status
|
112
109
|
else
|
113
|
-
|
110
|
+
val = res.body
|
114
111
|
|
115
|
-
|
112
|
+
convert = JSON.parse(val)
|
116
113
|
|
117
|
-
|
114
|
+
time = convert["preparationStartTime"]
|
118
115
|
|
119
|
-
|
116
|
+
time2 = convert["startTime"]
|
120
117
|
|
121
|
-
|
118
|
+
time3 = convert["endTime"]
|
122
119
|
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
t = Time.parse(time).strftime('%y-%m-%d, %I:%M:%S %p')
|
121
|
+
t1 = Time.parse(time2).strftime('%y-%m-%d, %I:%M:%S %p')
|
122
|
+
t2 = Time.parse(time3).strftime('%y-%m-%d, %I:%M:%S %p')
|
126
123
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
124
|
+
warTimes = {
|
125
|
+
"preparationStartTime" => time,
|
126
|
+
"startTime" => time2,
|
127
|
+
"endTime" => time3
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"parsed_preparationStartTime" => t,
|
131
|
+
"parsed_startTime" => t1,
|
132
|
+
"parsed_endTime" => t2
|
133
|
+
}.freeze
|
134
|
+
end
|
135
|
+
end
|
139
136
|
end
|
137
|
+
|
140
138
|
class ClanWarLeague < Settings
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
tag = io.gsub('#', '%23')
|
145
|
-
res = @conn.get("v1/clans/#{tag}/currentwar/leaguegroup")
|
139
|
+
def self.get_ClanWarLeagueGroup(tag:,status: false)
|
140
|
+
get
|
141
|
+
io = tag
|
146
142
|
|
147
|
-
|
148
|
-
res.status
|
149
|
-
else
|
150
|
-
val = res.body
|
151
|
-
convert = JSON.parse(val)
|
152
|
-
end
|
153
|
-
end
|
143
|
+
tag = io.gsub('#', '%23')
|
154
144
|
|
145
|
+
res = @conn.get("v1/clans/#{tag}/currentwar/leaguegroup")
|
155
146
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
147
|
+
if status
|
148
|
+
res.status
|
149
|
+
else
|
150
|
+
val = res.body
|
151
|
+
convert = JSON.parse(val)
|
152
|
+
end
|
153
|
+
end
|
160
154
|
|
161
|
-
|
155
|
+
def self.get_ClanWarLeagueClanItems(tag:,status: false)
|
156
|
+
get
|
157
|
+
io = tag
|
158
|
+
tag = io.gsub('#', '%23')
|
159
|
+
|
160
|
+
res = @conn.get("v1/clans/#{tag}/currentwar/leaguegroup")
|
162
161
|
|
163
162
|
if status
|
164
|
-
|
163
|
+
res.status
|
165
164
|
else
|
166
|
-
|
165
|
+
parse = res.body
|
167
166
|
|
168
|
-
|
167
|
+
convert = JSON.parse(parse)
|
169
168
|
|
170
|
-
|
169
|
+
clans = convert['clans']
|
171
170
|
|
172
|
-
|
171
|
+
items_name = clans.map { |n| n['name'] }
|
173
172
|
|
174
|
-
|
173
|
+
items_tag = clans.map { |t| t['tag'] }
|
175
174
|
|
176
|
-
|
175
|
+
items_clanLevel = clans.map { |c| c['clanLevel'] }
|
177
176
|
|
178
|
-
|
177
|
+
items_badgeUrls = clans.map { |b| b['badgeUrls'] }
|
179
178
|
|
180
|
-
|
179
|
+
clanItems = {
|
181
180
|
'tag' => items_tag[0],
|
182
181
|
'name' => items_name[0],
|
183
182
|
'clanLevel' => items_clanLevel[0],
|
184
183
|
'badgeUrls' => items_badgeUrls[0]
|
185
|
-
|
186
|
-
|
184
|
+
},
|
185
|
+
{
|
187
186
|
'tag' => items_tag[1],
|
188
187
|
'name' => items_name[1],
|
189
188
|
'clanLevel' => items_clanLevel[1],
|
190
189
|
'badgeUrls' => items_badgeUrls[1]
|
191
|
-
|
192
|
-
|
190
|
+
},
|
191
|
+
{
|
193
192
|
'tag' => items_tag[2],
|
194
193
|
'name' => items_name[2],
|
195
194
|
'clanLevel' => items_clanLevel[2],
|
196
195
|
'badgeUrls' => items_badgeUrls[2]
|
197
|
-
|
198
|
-
|
196
|
+
},
|
197
|
+
{
|
199
198
|
'tag' => items_tag[3],
|
200
199
|
'name' => items_name[3],
|
201
200
|
'clanLevel' => items_clanLevel[3],
|
202
201
|
'badgeUrls' => items_badgeUrls[3]
|
203
|
-
|
204
|
-
|
202
|
+
},
|
203
|
+
{
|
205
204
|
'tag' => items_tag[4],
|
206
205
|
'name' => items_name[4],
|
207
206
|
'clanLevel' => items_clanLevel[4],
|
208
207
|
'badgeUrls' => items_badgeUrls[4]
|
209
|
-
|
210
|
-
|
208
|
+
},
|
209
|
+
{
|
211
210
|
'tag' => items_tag[5],
|
212
211
|
'name' => items_name[5],
|
213
212
|
'clanLevel' => items_clanLevel[5],
|
214
213
|
'badgeUrls' => items_badgeUrls[5]
|
215
|
-
|
216
|
-
|
214
|
+
},
|
215
|
+
{
|
217
216
|
'tag' => items_tag[6],
|
218
217
|
'name' => items_name[6],
|
219
218
|
'clanLevel' => items_clanLevel[6],
|
220
219
|
'badgeUrls' => items_badgeUrls[6]
|
221
|
-
|
222
|
-
|
220
|
+
},
|
221
|
+
{
|
223
222
|
'tag' => items_tag[7],
|
224
223
|
'name' => items_name[7],
|
225
224
|
'clanLevel' => items_clanLevel[7],
|
226
225
|
'badgeUrls' => items_badgeUrls[7]
|
227
|
-
|
226
|
+
}.freeze
|
228
227
|
|
229
|
-
|
228
|
+
end
|
230
229
|
end
|
231
230
|
|
232
231
|
def self.get_WarTags(tag:, status:false)
|
233
|
-
|
234
|
-
io = tag
|
235
|
-
tag = io.gsub('#', '%23')
|
232
|
+
get
|
236
233
|
|
237
|
-
|
234
|
+
io = tag
|
238
235
|
|
239
|
-
|
240
|
-
|
236
|
+
tag = io.gsub('#', '%23')
|
237
|
+
|
238
|
+
res = @conn.get("v1/clans/#{tag}/currentwar/leaguegroup")
|
241
239
|
|
240
|
+
if status
|
241
|
+
res.status
|
242
242
|
else
|
243
|
-
|
244
|
-
convert = JSON.parse(val)
|
245
|
-
rounds = convert['rounds']
|
243
|
+
val = res.body
|
246
244
|
|
247
|
-
|
248
|
-
end
|
245
|
+
convert = JSON.parse(val)
|
249
246
|
|
250
|
-
|
251
|
-
get
|
252
|
-
io = warTag
|
253
|
-
tag = io.gsub('#', '%23')
|
254
|
-
res = @conn.get("v1/clanwarleagues/wars/#{tag}")
|
247
|
+
rounds = convert['rounds']
|
255
248
|
|
256
|
-
if status
|
257
|
-
res.status
|
258
|
-
else
|
259
|
-
val = res.body
|
260
|
-
convert = JSON.parse(val)
|
261
249
|
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.get_ClanWarLeagueWars(warTag:, status:false)
|
253
|
+
get
|
254
|
+
io = warTag
|
255
|
+
|
256
|
+
tag = io.gsub('#', '%23')
|
257
|
+
|
258
|
+
res = @conn.get("v1/clanwarleagues/wars/#{tag}")
|
259
|
+
|
260
|
+
if status
|
261
|
+
res.status
|
262
|
+
else
|
263
|
+
val = res.body
|
264
|
+
convert = JSON.parse(val)
|
265
|
+
end
|
262
266
|
end
|
263
267
|
|
264
|
-
def self.
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
268
|
+
def self.get_ClanWarLeagueWarTimes(warTag:, status: false)
|
269
|
+
get
|
270
|
+
io = warTag
|
271
|
+
|
272
|
+
tag = io.gsub('#', '%23')
|
273
|
+
|
274
|
+
res = @conn.get("v1/clanwarleagues/wars/#{tag}")
|
269
275
|
|
270
|
-
|
271
|
-
|
276
|
+
if status
|
277
|
+
res.status
|
272
278
|
else
|
273
|
-
|
274
|
-
|
275
|
-
prepStartTime = convert["preparationStartTime"]
|
276
|
-
startTime = convert["startTime"]
|
277
|
-
endTime = convert["endTime"]
|
278
|
-
|
279
|
-
parsed_preparationStartTime = Time.parse(prepStartTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
280
|
-
parsed_startTime = Time.parse(startTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
281
|
-
parsed_endTime = Time.parse(endTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
282
|
-
|
283
|
-
times = {
|
284
|
-
"preparationStartTime" => prepStartTime,
|
285
|
-
"startTime" => startTime,
|
286
|
-
"endTime" => endTime
|
287
|
-
},
|
288
|
-
{
|
289
|
-
"parsed_preparationStartTime" => parsed_preparationStartTime,
|
290
|
-
"parsed_startTime" => parsed_startTime,
|
291
|
-
"parsed_endTime" => parsed_endTime
|
292
|
-
}
|
279
|
+
val = res.body
|
280
|
+
convert = JSON.parse(val)
|
293
281
|
|
294
|
-
|
282
|
+
prepStartTime = convert["preparationStartTime"]
|
295
283
|
|
284
|
+
startTime = convert["startTime"]
|
296
285
|
|
286
|
+
endTime = convert["endTime"]
|
297
287
|
|
298
|
-
|
299
|
-
|
288
|
+
parsed_preparationStartTime = Time.parse(prepStartTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
289
|
+
|
290
|
+
parsed_startTime = Time.parse(startTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
291
|
+
|
292
|
+
parsed_endTime = Time.parse(endTime).strftime('%y-%m-%d, %I:%M:%S %p')
|
293
|
+
|
294
|
+
times = {
|
295
|
+
"preparationStartTime" => prepStartTime,
|
296
|
+
"startTime" => startTime,
|
297
|
+
"endTime" => endTime
|
298
|
+
},
|
299
|
+
{
|
300
|
+
"parsed_preparationStartTime" => parsed_preparationStartTime,
|
301
|
+
"parsed_startTime" => parsed_startTime,
|
302
|
+
"parsed_endTime" => parsed_endTime
|
303
|
+
}
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
300
307
|
end
|