cocRb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 677b2fcfff53c05ddb5f59305e1940b4e20d19718af145f360041c0a2357a343
|
4
|
+
data.tar.gz: d95a7ef479806fb6db59fb3b3b071c6a82cc2d05c5a1e31b0fbc8d3b9a402016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d149fa8289060dfea9ee62638567f0426613dcbe23860971d9655406eb521eab5c69aed10e46e1f51736b7aa3c7239c830b15fe5110eb4dd343bba7466c889e
|
7
|
+
data.tar.gz: 2395f768180735e2bca893d8e764c92a038b6d735890d6b7c4b8e7be5b47c4abddbebc234d6ead51f647624892d91c6a47677c9291edb0f02c3e8a1298670b46
|
data/README.md
CHANGED
@@ -1,35 +1,74 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
![coc Rb](https://media.discordapp.net/attachments/662341843861766164/840316348554412042/unknown-removebg-preview.png)
|
2
|
+
|
3
|
+
# CocRb
|
4
|
+
|
5
|
+
Welcome everyone to your Ruby Gem CocRb. By using this gem you can easily interact with the Game API of Clash of Clans without using any external gems to call this API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cocRb'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cocRb
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
CocRb Gem is categorized with [Classes](https://www.tutorialspoint.com/ruby/ruby_classes.htm) and [Methods](https://www.tutorialspoint.com/ruby/ruby_methods.htm) as below down you can see but before accessing any of those we have to set **Configuration** in order to setup the Authorization for accessing the [Clash of Clans API](https://developer.clashofclans.com/#) so to do that we have set **Configure** block and inside that block we have configured our **TOKEN** and the **URL**.
|
25
|
+
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
token = <Your_Token>
|
29
|
+
requestUrl = <Your_Url>
|
30
|
+
|
31
|
+
CocRb.configure do |config|
|
32
|
+
config.token = token
|
33
|
+
config.url = requestUrl
|
34
|
+
end
|
35
|
+
```
|
36
|
+
After done setting up the Authorization we now need to call the API as you can see down below we called the API using **call_API** method now just before that line we have set the class **ClashApi** by name_spacing with **CocRb** [Module](https://www.tutorialspoint.com/ruby/ruby_modules.htm).
|
37
|
+
|
38
|
+
**Note:** All the data that we will get from the API reponse was in [JSON](https://jsonapi.org/) but since you are using this gem all of the responses has been **parsed** to Ruby [Hashes](https://www.tutorialspoint.com/ruby/ruby_hashes.htm) so that its get easy for you to access the data.
|
39
|
+
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
set_Class = CocRb::ClashApi
|
43
|
+
|
44
|
+
response = set_Class.call_API
|
45
|
+
|
46
|
+
puts response
|
47
|
+
|
48
|
+
# data from the API in Ruby Hashes...
|
49
|
+
```
|
50
|
+
|
51
|
+
The API can also be called without using the **URL** in the Configuration block the way you can do is shown down below. As you can we have almost followed the same procedure like we did before just changed few things those are we have removed the *config.url* line, We now have called a new class and a method. This method now takes two parameters one is your [Player Tag](https://clashofclans.fandom.com/wiki/Player_Profile#:~:text=The%20player%27s%20name%20and%20player,they%20are%20in%20a%20clan) and another thing is your [Player API Token](eddit.com/r/ClashOfClans/comments/apebtq/ask_what_is_an_api_token/) which you will find **In-Game Settings**.
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
The Detailed info about all the Classes and Methods for this Library can be found in our Documentation.
|
56
|
+
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
|
60
|
+
CocRb.configure do |config|
|
61
|
+
config.token = token
|
62
|
+
end
|
63
|
+
|
64
|
+
set_var = CocRb::Player
|
65
|
+
|
66
|
+
response = set_var.verify_PlayerByToken(tag: "#PG8RLGQ2", playertoken: "7jeagw4c")
|
67
|
+
|
68
|
+
# Response => {"tag"=>"#PG8RLGQ2", "token"=>"7jeagw4c", "status"=>"ok"}
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/cocRb.rb
CHANGED
data/lib/cocRb/api.rb
CHANGED
@@ -1,50 +1,49 @@
|
|
1
|
-
require
|
1
|
+
require "faraday"
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module CocRb
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
6
|
+
attr_accessor :configuration
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def self.configure
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
13
|
|
14
14
|
class Configuration
|
15
|
-
|
16
|
-
|
15
|
+
attr_accessor :token, :url
|
17
16
|
def initialize
|
18
17
|
@token = nil
|
19
18
|
@url = nil
|
20
|
-
|
21
|
-
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
22
|
class Settings
|
23
|
-
|
24
|
-
|
25
|
-
url: CocRb.configuration.url,
|
23
|
+
def self.get
|
24
|
+
@conn = Faraday.new(
|
25
|
+
url: CocRb.configuration.url ,
|
26
26
|
headers: {
|
27
|
-
|
28
|
-
|
27
|
+
'Content-Type' => 'application/json',
|
28
|
+
'Authorization' => "Bearer #{CocRb.configuration.token}"
|
29
29
|
}
|
30
30
|
)
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
rescue => e
|
32
|
+
raise "Oops Unexpected error Caught!"
|
33
|
+
puts e
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
def self.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
class ClashApi < Settings
|
38
|
+
def self.call_API(status: false)
|
39
|
+
get
|
40
|
+
res = @conn.get(CocRb.configuration.url)
|
41
|
+
if status
|
42
|
+
res.status
|
43
|
+
else
|
44
|
+
val = res.body
|
45
|
+
convert = JSON.parse(val)
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
data/lib/cocRb/clan.rb
CHANGED
@@ -1,212 +1,250 @@
|
|
1
|
-
require
|
1
|
+
require "faraday"
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module CocRb
|
5
|
-
|
5
|
+
class << self
|
6
6
|
attr_accessor :configuration
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.configure
|
10
|
-
|
11
|
-
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
12
|
end
|
13
13
|
|
14
14
|
class Configuration
|
15
|
-
|
15
|
+
attr_accessor :token, :url
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def initialize
|
18
|
+
@token = nil
|
19
|
+
|
20
|
+
@url = nil
|
21
|
+
end
|
21
22
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
|
24
|
+
class Settings
|
25
|
+
def self.get
|
26
|
+
@conn = Faraday.new(
|
27
|
+
url:"https://api.clashofclans.com" ,
|
28
|
+
headers: {
|
29
|
+
'Content-Type' => 'application/json',
|
30
|
+
'Authorization' => "Bearer #{CocRb.configuration.token}"
|
29
31
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
)
|
33
|
+
rescue => e
|
34
|
+
raise "Oops Unexpected error Caught!"
|
35
|
+
puts e
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Clan < Settings
|
40
|
+
def self.get_FiltredClan(name:, filterOptions:, filterValue:, _limit: false, status: false)
|
41
|
+
get
|
42
|
+
|
43
|
+
options = ["warFrequency", "locationId", "minMembers", "maxMembers", "minClanPoints", "minClanLevel"]
|
44
|
+
|
45
|
+
check = options.include?(filterOptions)
|
41
46
|
if check
|
42
|
-
|
47
|
+
count = name.split(/[^-a-zA-Z]/).size
|
43
48
|
if count > 2
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
res = @conn.get('v1/clans') do |req|
|
50
|
+
|
51
|
+
req.params = { name: name, filterOptions: filterValue }
|
52
|
+
|
53
|
+
req.params[:limit] = _limit if _limit
|
54
|
+
end
|
55
|
+
if status
|
56
|
+
puts res.status
|
57
|
+
else
|
58
|
+
val = res.body
|
59
|
+
|
60
|
+
convert = JSON.parse(val)
|
61
|
+
end
|
54
62
|
elsif count == 2
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
convert = JSON.parse(val)
|
64
|
-
end
|
63
|
+
res = @conn.get('v1/clans') do |req|
|
64
|
+
|
65
|
+
req.params = { name: name, filterOptions: filterValue }
|
66
|
+
|
67
|
+
req.params[:limit] = _limit if _limit
|
68
|
+
end
|
69
|
+
if status
|
70
|
+
puts res.status
|
65
71
|
else
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
puts res.status
|
72
|
-
else
|
73
|
-
val = res.body
|
74
|
-
convert = JSON.parse(val)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
else
|
78
|
-
puts "Not a valid input option for this method"
|
79
|
-
end
|
80
|
-
end
|
72
|
+
val = res.body
|
73
|
+
convert = JSON.parse(val)
|
74
|
+
end
|
75
|
+
else
|
76
|
+
res = @conn.get('v1/clans') do |req|
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
78
|
+
req.params = { name: name, filterOptions: filterValue }
|
79
|
+
|
80
|
+
req.params[:limit] = _limit if _limit
|
81
|
+
end
|
82
|
+
if status
|
83
|
+
puts res.status
|
84
|
+
else
|
85
|
+
val = res.body
|
86
|
+
|
87
|
+
convert = JSON.parse(val)
|
88
|
+
end
|
93
89
|
end
|
90
|
+
else
|
91
|
+
puts "Not a valid input option for this method"
|
92
|
+
end
|
93
|
+
end
|
94
94
|
|
95
|
-
def self.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
95
|
+
def self.get_ClanByTag(tag:, status: false)
|
96
|
+
get
|
97
|
+
io = tag
|
98
|
+
|
99
|
+
clanTag = io.gsub('#', '%23')
|
100
|
+
|
101
|
+
res = @conn.get("v1/clans/#{clanTag}")
|
103
102
|
if status
|
104
|
-
|
103
|
+
puts res.status
|
105
104
|
else
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
105
|
+
val = res.body
|
106
|
+
|
107
|
+
convert = JSON.parse(val)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.get_ClanByName(name:, _limit: false, status: false)
|
112
|
+
get
|
113
|
+
count = name.split(/[^-a-zA-Z]/).size
|
114
|
+
if count > 2
|
115
|
+
res = @conn.get('v1/clans') do |req|
|
116
|
+
|
117
|
+
req.params = { name: name}
|
118
|
+
|
119
|
+
req.params[:limit] = _limit if _limit
|
120
|
+
end
|
114
121
|
if status
|
115
|
-
|
122
|
+
puts res.status
|
116
123
|
else
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
val = res.body
|
125
|
+
|
126
|
+
convert = JSON.parse(val)
|
127
|
+
end
|
128
|
+
elsif count == 2
|
129
|
+
res = @conn.get('v1/clans') do |req|
|
130
|
+
|
131
|
+
req.params = { name: name}
|
132
|
+
|
133
|
+
req.params[:limit] = _limit if _limit
|
134
|
+
end
|
125
135
|
if status
|
126
|
-
|
136
|
+
puts res.status
|
127
137
|
else
|
128
|
-
|
129
|
-
|
138
|
+
val = res.body
|
139
|
+
|
140
|
+
convert = JSON.parse(val)
|
141
|
+
end
|
142
|
+
else
|
143
|
+
res = @conn.get('v1/clans') do |req|
|
144
|
+
|
145
|
+
req.params = { name: name}
|
146
|
+
|
147
|
+
req.params[:limit] = _limit if _limit
|
148
|
+
end
|
149
|
+
if status
|
150
|
+
puts res.status
|
151
|
+
else
|
152
|
+
val = res.body
|
153
|
+
|
154
|
+
convert = JSON.parse(val)
|
130
155
|
end
|
131
|
-
end
|
156
|
+
end
|
157
|
+
end
|
132
158
|
|
133
|
-
|
159
|
+
def self.get_ClanByLocationID(id:, _limit: false, status:false)
|
160
|
+
get
|
134
161
|
|
135
|
-
|
136
|
-
get
|
137
|
-
res = @conn.get('v1/clans') do |req|
|
138
|
-
req.params = { locationId: id}
|
139
|
-
req.params[:limit] = _limit if _limit
|
140
|
-
end
|
162
|
+
res = @conn.get('v1/clans') do |req|
|
141
163
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
convert = JSON.parse(val)
|
147
|
-
end
|
164
|
+
req.params = { locationId: id}
|
165
|
+
|
166
|
+
req.params[:limit] = _limit if _limit
|
167
|
+
end
|
148
168
|
|
169
|
+
if status
|
170
|
+
puts res.status
|
171
|
+
else
|
172
|
+
val = res.body
|
173
|
+
|
174
|
+
convert = JSON.parse(val)
|
175
|
+
end
|
149
176
|
end
|
150
177
|
|
151
|
-
def self.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
178
|
+
def self.get_ClanByMinClanLevel(clanLevel:, _limit: false, status: false)
|
179
|
+
get
|
180
|
+
res = @conn.get('v1/clans') do |req|
|
181
|
+
|
182
|
+
req.params = { minClanLevel: clanLevel }
|
183
|
+
|
184
|
+
req.params[:limit] = _limit if _limit
|
185
|
+
end
|
157
186
|
if status
|
158
|
-
|
187
|
+
puts res.status
|
159
188
|
else
|
160
|
-
|
161
|
-
|
189
|
+
val = res.body
|
190
|
+
|
191
|
+
convert = JSON.parse(val)
|
162
192
|
end
|
193
|
+
end
|
163
194
|
|
195
|
+
def self.get_ClanMembers(tag:, _limit:false, status:false)
|
196
|
+
get
|
197
|
+
io = tag
|
164
198
|
|
165
|
-
|
199
|
+
tag1 = io.gsub('#', '%23')
|
166
200
|
|
167
|
-
|
168
|
-
get
|
169
|
-
io = tag
|
170
|
-
tag1 = io.gsub('#', '%23')
|
171
|
-
res = @conn.get("v1/clans/#{tag1}/members") do |req|
|
172
|
-
req.params[:limit] = _limit if _limit
|
173
|
-
end
|
201
|
+
res = @conn.get("v1/clans/#{tag1}/members") do |req|
|
174
202
|
|
203
|
+
req.params[:limit] = _limit if _limit
|
204
|
+
end
|
175
205
|
if status
|
176
|
-
|
206
|
+
puts res.status
|
177
207
|
else
|
178
|
-
|
179
|
-
|
208
|
+
val = res.body
|
209
|
+
convert = JSON.parse(val)
|
180
210
|
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
def self.get_detailed_ClanMembers(tag:, _limit: false, status: false)
|
185
|
-
get
|
186
|
-
io = tag
|
187
|
-
tag1 = io.gsub('#', '%23')
|
188
|
-
res = @conn.get("v1/clans/#{tag1}/members") do |req|
|
189
|
-
req.params[:limit] = _limit if _limit
|
190
211
|
end
|
191
212
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
convert = JSON.parse(val)
|
197
|
-
each = convert["items"].map {|m| m["tag"]}
|
213
|
+
def self.get_DetailedClanMembers(tag:, _limit: false, status: false)
|
214
|
+
get
|
215
|
+
|
216
|
+
io = tag
|
198
217
|
|
199
|
-
|
218
|
+
tag1 = io.gsub('#', '%23')
|
200
219
|
|
201
|
-
|
202
|
-
|
203
|
-
req.params[:limit] = _limit if _limit
|
220
|
+
res = @conn.get("v1/clans/#{tag1}/members") do |req|
|
221
|
+
req.params[:limit] = _limit if _limit
|
204
222
|
end
|
205
|
-
response = anotheres.body
|
206
|
-
val = JSON.parse(response)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
223
|
|
211
|
-
|
224
|
+
if status
|
225
|
+
puts res.status
|
226
|
+
else
|
227
|
+
val = res.body
|
228
|
+
|
229
|
+
convert = JSON.parse(val)
|
230
|
+
|
231
|
+
each = convert["items"].map {|m| m["tag"]}
|
232
|
+
|
233
|
+
extract = each.map {|x| x.gsub /^#/, '%23'}
|
234
|
+
|
235
|
+
resp = extract.map do |ext|
|
236
|
+
|
237
|
+
anotheres = @conn.get("v1/players/#{ext}") do |req|
|
238
|
+
|
239
|
+
req.params[:limit] = _limit if _limit
|
240
|
+
|
241
|
+
end
|
242
|
+
response = anotheres.body
|
243
|
+
|
244
|
+
val = JSON.parse(response)
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
212
250
|
end
|