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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84a1fe5b426fcf51fcbcd804d7150f0391c9747deb9ae4d4f2f530fe9a8c0b07
4
- data.tar.gz: b23639c4d7a0ba41e315292099c8052755454837b2e4bfe4d98e71351d00c824
3
+ metadata.gz: 677b2fcfff53c05ddb5f59305e1940b4e20d19718af145f360041c0a2357a343
4
+ data.tar.gz: d95a7ef479806fb6db59fb3b3b071c6a82cc2d05c5a1e31b0fbc8d3b9a402016
5
5
  SHA512:
6
- metadata.gz: 42a46c37bf4ab7d645b01dfd17c33cc807b66670b4f8b458cd7df9c2cf7046ecd8c3c18b4de8cb3b8e9045026f7cd3ffefd1ff66bea2efe991b80aa38177d599
7
- data.tar.gz: 9dedf905b5ef047db3dc3db46c48b8fcab46e25a4c55235dd9bdad5a19695518ae5dbd7448d77b2a0a2af99dd497556f6debd4f6dca6be7e42e44a0009055c6c
6
+ metadata.gz: 9d149fa8289060dfea9ee62638567f0426613dcbe23860971d9655406eb521eab5c69aed10e46e1f51736b7aa3c7239c830b15fe5110eb4dd343bba7466c889e
7
+ data.tar.gz: 2395f768180735e2bca893d8e764c92a038b6d735890d6b7c4b8e7be5b47c4abddbebc234d6ead51f647624892d91c6a47677c9291edb0f02c3e8a1298670b46
data/README.md CHANGED
@@ -1,35 +1,74 @@
1
- # CocRb
2
-
3
- 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 the API.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'cocRb'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle install
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install cocRb
20
-
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
-
25
- After the development will do..
26
-
27
- ## Development
28
-
29
- 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.
30
-
31
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## License
34
-
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
@@ -7,6 +7,8 @@ require_relative './cocRb/labels'
7
7
  require_relative './cocRb/league'
8
8
  require_relative './cocRb/location'
9
9
  require_relative './cocRb/player'
10
+
11
+ require 'rdoc'
10
12
  require 'faraday'
11
13
  require 'time'
12
14
  require "json"
data/lib/cocRb/api.rb CHANGED
@@ -1,50 +1,49 @@
1
- require 'faraday'
1
+ require "faraday"
2
2
  require "json"
3
3
 
4
4
  module CocRb
5
5
  class << self
6
- attr_accessor :configuration
7
- end
6
+ attr_accessor :configuration
7
+ end
8
8
 
9
- def self.configure
10
- @configuration ||= Configuration.new
11
- yield(configuration)
12
- end
9
+ def self.configure
10
+ @configuration ||= Configuration.new
11
+ yield(configuration)
12
+ end
13
13
 
14
14
  class Configuration
15
- attr_accessor :token, :url
16
-
15
+ attr_accessor :token, :url
17
16
  def initialize
18
17
  @token = nil
19
18
  @url = nil
20
- end
21
- end
19
+ end
20
+ end
21
+
22
22
  class Settings
23
- def self.get
24
- @conn = Faraday.new(
25
- url: CocRb.configuration.url,
23
+ def self.get
24
+ @conn = Faraday.new(
25
+ url: CocRb.configuration.url ,
26
26
  headers: {
27
- 'Content-Type' => 'application/json',
28
- 'Authorization' => "Bearer #{CocRb.configuration.token}"
27
+ 'Content-Type' => 'application/json',
28
+ 'Authorization' => "Bearer #{CocRb.configuration.token}"
29
29
  }
30
30
  )
31
- rescue => e
32
- raise "Oops Unexpected error Caught!"
33
- puts e
31
+ rescue => e
32
+ raise "Oops Unexpected error Caught!"
33
+ puts e
34
34
  end
35
35
  end
36
36
 
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
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 'faraday'
1
+ require "faraday"
2
2
  require "json"
3
3
 
4
4
  module CocRb
5
- class << self
5
+ class << self
6
6
  attr_accessor :configuration
7
7
  end
8
8
 
9
9
  def self.configure
10
- @configuration ||= Configuration.new
11
- yield(configuration)
10
+ @configuration ||= Configuration.new
11
+ yield(configuration)
12
12
  end
13
13
 
14
14
  class Configuration
15
- attr_accessor :token, :url
15
+ attr_accessor :token, :url
16
16
 
17
- def initialize
18
- @token = nil
19
- @url = nil
20
- end
17
+ def initialize
18
+ @token = nil
19
+
20
+ @url = nil
21
+ end
21
22
  end
22
- class Settings
23
- def self.get
24
- @conn = Faraday.new(
25
- url:"https://api.clashofclans.com" ,
26
- headers: {
27
- 'Content-Type' => 'application/json',
28
- 'Authorization' => "Bearer #{CocRb.configuration.token}"
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
- rescue => e
32
- raise "Oops Unexpected error Caught!"
33
- puts e
34
- end
35
- end
36
- class Clans < Settings
37
- def self.getClans(name:, filterOptions:, filterValue:, _limit: false, status: false)
38
- get
39
- options = ["warFrequency", "locationId", "minMembers", "maxMembers", "minClanPoints", "minClanLevel"]
40
- check = options.include?(filterOptions)
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
- count = name.split(/[^-a-zA-Z]/).size
47
+ count = name.split(/[^-a-zA-Z]/).size
43
48
  if count > 2
44
- res = @conn.get('v1/clans') do |req|
45
- req.params = { name: name, filterOptions:filterValue}
46
- req.params[:limit] = _limit if _limit
47
- end
48
- if status
49
- puts res.status
50
- else
51
- val = res.body
52
- convert = JSON.parse(val)
53
- end
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
- res = @conn.get('v1/clans') do |req|
56
- req.params = { name: name, filterOptions:filterValue}
57
- req.params[:limit] = _limit if _limit
58
- end
59
- if status
60
- puts res.status
61
- else
62
- val = res.body
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
- res = @conn.get('v1/clans') do |req|
67
- req.params = { name: name, filterOptions:filterValue}
68
- req.params[:limit] = _limit if _limit
69
- end
70
- if status
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
- def self.get_clans_ByTag(tag:, status: false)
83
- get
84
- io = tag
85
- clanTag = io.gsub('#', '%23')
86
- res = @conn.get("v1/clans/#{clanTag}")
87
- if status
88
- puts res.status
89
- else
90
- val = res.body
91
- convert = JSON.parse(val)
92
- end
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.get_clans_ByName(name:, _limit:false, status:false)
96
- get
97
- count = name.split(/[^-a-zA-Z]/).size
98
- if count > 2
99
- res = @conn.get('v1/clans') do |req|
100
- req.params = { name: name}
101
- req.params[:limit] = _limit if _limit
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
- puts res.status
103
+ puts res.status
105
104
  else
106
- val = res.body
107
- convert = JSON.parse(val)
108
- end
109
- elsif count == 2
110
- res = @conn.get('v1/clans') do |req|
111
- req.params = { name: name}
112
- req.params[:limit] = _limit if _limit
113
- end
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
- puts res.status
122
+ puts res.status
116
123
  else
117
- val = res.body
118
- convert = JSON.parse(val)
119
- end
120
- else
121
- res = @conn.get('v1/clans') do |req|
122
- req.params = { name: name}
123
- req.params[:limit] = _limit if _limit
124
- end
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
- puts res.status
136
+ puts res.status
127
137
  else
128
- val = res.body
129
- convert = JSON.parse(val)
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
- end
159
+ def self.get_ClanByLocationID(id:, _limit: false, status:false)
160
+ get
134
161
 
135
- def self.get_clans_ByLocationID(id:, _limit: false, status:false)
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
- if status
143
- puts res.status
144
- else
145
- val = res.body
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.get_clans_ByMinClanLevel(clanLevel:, _limit: false, status: false)
152
- get
153
- res = @conn.get('v1/clans') do |req|
154
- req.params = { minClanLevel: clanLevel }
155
- req.params[:limit] = _limit if _limit
156
- end
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
- puts res.status
187
+ puts res.status
159
188
  else
160
- val = res.body
161
- convert = JSON.parse(val)
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
- end
199
+ tag1 = io.gsub('#', '%23')
166
200
 
167
- def self.get_clan_Members(tag:, _limit:false, status:false)
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
- puts res.status
206
+ puts res.status
177
207
  else
178
- val = res.body
179
- convert = JSON.parse(val)
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
- if status
193
- puts res.status
194
- else
195
- val = res.body
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
- extract = each.map {|x| x.gsub /^#/, '%23'}
218
+ tag1 = io.gsub('#', '%23')
200
219
 
201
- resp = extract.map do |ext|
202
- anotheres = @conn.get("v1/players/#{ext}") do |req|
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
- end
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