cocRb 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cocRb/gp.rb CHANGED
@@ -1,72 +1,74 @@
1
- require 'faraday'
1
+ require "faraday"
2
2
  require "json"
3
3
  require "time"
4
4
 
5
5
  module CocRb
6
+
6
7
  class << self
7
- attr_accessor :configuration
8
+ attr_accessor :configuration
8
9
  end
9
10
 
10
11
  def self.configure
11
- @configuration ||= Configuration.new
12
- yield(configuration)
12
+ @configuration ||= Configuration.new
13
+ yield(configuration)
13
14
  end
14
15
 
15
16
  class Configuration
16
- attr_accessor :token
17
+ attr_accessor :token
17
18
 
18
- def initialize
19
- @token = nil
20
- @url = nil
21
- end
19
+ def initialize
20
+ @token = nil
21
+ @url = nil
22
+ end
22
23
  end
24
+
23
25
  class Settings
24
- def self.get
25
- @conn = Faraday.new(
26
- url:"https://api.clashofclans.com" ,
27
- headers: {
28
- 'Content-Type' => 'application/json',
29
- 'Authorization' => "Bearer #{CocRb.configuration.token}"
26
+
27
+ def self.get
28
+ @conn = Faraday.new(
29
+ url:"https://api.clashofclans.com" ,
30
+ headers: {
31
+ 'Content-Type' => 'application/json',
32
+ 'Authorization' => "Bearer #{CocRb.configuration.token}"
30
33
  }
31
- )
32
- rescue => e
33
- raise "Oops Unexpected error Caught!"
34
- puts e
34
+ )
35
+ rescue => e
36
+ raise "Oops Unexpected error Caught!"
37
+ puts e
38
+ end
39
+ end
35
40
 
36
- end
37
- end
38
41
  class GoldPass < Settings
39
- def self.get_GoldPassInfo(status:false)
40
- get
41
- res = @conn.get("v1/goldpass/seasons/current")
42
-
43
- if status
44
- res.status
45
- else
46
- val = res.body
47
- convert = JSON.parse(val)
48
42
 
49
- startTime = convert["startTime"]
43
+ def self.get_GoldPassInfo(status: false)
44
+ get
45
+ res = @conn.get("v1/goldpass/seasons/current")
50
46
 
51
- endTime = convert["endTime"]
47
+ if status
48
+ res.status
49
+ else
50
+ val = res.body
52
51
 
53
- t = Time.parse(startTime).strftime('%y-%m-%d, %H:%M:%S %p')
52
+ convert = JSON.parse(val)
54
53
 
55
- t1 = Time.parse(endTime).strftime('%y-%m-%d, %H:%M:%S %p')
54
+ startTime = convert["startTime"]
56
55
 
57
- gp = {
58
- "startTime" => startTime,
59
- "endTime" => endTime
60
- },
61
- {
62
- "parsed_startTime" => t,
63
- "parsed_endTime" => t1
64
- }.freeze
65
- end
56
+ endTime = convert["endTime"]
66
57
 
58
+ t = Time.parse(startTime).strftime('%y-%m-%d, %H:%M:%S %p')
67
59
 
60
+ t1 = Time.parse(endTime).strftime('%y-%m-%d, %H:%M:%S %p')
68
61
 
69
- end
62
+ gp = {
63
+ "startTime" => startTime,
64
+ "endTime" => endTime
65
+ },
66
+ {
67
+ "parsed_startTime" => t,
68
+ "parsed_endTime" => t1
69
+ }.freeze
70
70
 
71
- end
71
+ end
72
+ end
73
+ end
72
74
  end
data/lib/cocRb/labels.rb CHANGED
@@ -1,68 +1,71 @@
1
- require 'faraday'
1
+ require "faraday"
2
2
  require "json"
3
3
 
4
4
 
5
5
  module CocRb
6
- class << self
7
- attr_accessor :configuration
6
+
7
+ class << self
8
+ attr_accessor :configuration
8
9
  end
9
10
 
10
11
  def self.configure
11
- @configuration ||= Configuration.new
12
- yield(configuration)
12
+ @configuration ||= Configuration.new
13
+ yield(configuration)
13
14
  end
14
15
 
15
16
  class Configuration
16
- attr_accessor :token, :url
17
-
18
- def initialize
19
- @token = nil
20
- @url = nil
21
- end
17
+ attr_accessor :token, :url
18
+ def initialize
19
+ @token = nil
20
+ @url = nil
21
+ end
22
22
  end
23
+
23
24
  class Settings
25
+
24
26
  def self.get
25
- @conn = Faraday.new(
26
- url:"https://api.clashofclans.com" ,
27
- headers: {
28
- 'Content-Type' => 'application/json',
29
- 'Authorization' => "Bearer #{CocRb.configuration.token}"
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
- rescue => e
33
- raise "Oops Unexpected error Caught!"
34
- puts e
34
+ rescue => e
35
+ raise "Oops Unexpected error Caught!"
36
+ puts e
37
+ end
35
38
  end
36
- end
39
+
37
40
  class Label < Settings
38
- def self.getLabel_Player(_limit:false, status:false)
39
- get
40
- res = @conn.get("v1/labels/players") do |req|
41
- req.params[:limit] = _limit if _limit
42
- end
43
41
 
44
- if status
45
- res.status
46
- else
47
- val = res.body
48
- convert = JSON.parse(val)
42
+ def self.get_LabelPlayer(_limit:false, status: false)
43
+ get
44
+ res = @conn.get("v1/labels/players") do |req|
45
+ req.params[:limit] = _limit if _limit
49
46
  end
50
47
 
48
+ if status
49
+ res.status
50
+ else
51
+ val = res.body
52
+ convert = JSON.parse(val)
53
+ end
54
+ end
51
55
 
52
- end
56
+ def self.get_LabelClan(_limit:false, status: false)
57
+ get
58
+ res = @conn.get("v1/labels/clans") do |req|
59
+ req.params[:limit] = _limit if _limit
60
+ end
53
61
 
54
- def self.getLabel_Clan(_limit:false, status:false)
55
- get
56
- res = @conn.get("v1/labels/clans") do |req|
57
- req.params[:limit] = _limit if _limit
58
- end
62
+ if status
63
+ res.status
64
+ else
65
+ val = res.body
66
+ convert = JSON.parse(val)
59
67
 
60
- if status
61
- res.status
62
- else
63
- val = res.body
64
- convert = JSON.parse(val)
68
+ end
69
+ end
70
+ end
65
71
  end
66
- end
67
- end
68
- end
data/lib/cocRb/league.rb CHANGED
@@ -1,140 +1,130 @@
1
- require 'faraday'
1
+ require "faraday"
2
2
  require "json"
3
3
 
4
4
  module CocRb
5
5
  class << self
6
- attr_accessor :configuration
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
- class Configuration
15
- attr_accessor :token, :url
14
+ class Configuration
15
+ attr_accessor :token, :url
16
16
 
17
17
  def initialize
18
- @token = nil
19
- @url = nil
18
+ @token = nil
19
+ @url = nil
20
20
  end
21
21
  end
22
+
22
23
  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}"
24
+
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
32
  )
31
- rescue => e
32
- raise "Oops Unexpected error Caught!"
33
- puts e
33
+ rescue => e
34
+ raise "Oops Unexpected error Caught!"
35
+ puts e
34
36
  end
35
37
  end
36
- class League < Settings
37
- def self.getLeaguesID(_limit:false, status:false)
38
- get
39
- res = @conn.get('v1/leagues') do |req|
40
- req.params[:limit] = _limit if _limit
41
- end
42
-
43
- if status
44
- res.status
45
38
 
46
- else
47
- val = res.body
48
- convert = JSON.parse(val)
49
- end
39
+ class League < Settings
50
40
 
51
- end
41
+ def self.get_LeaguesID(_limit:false, status:false)
42
+ get
43
+ res = @conn.get('v1/leagues') do |req|
44
+ req.params[:limit] = _limit if _limit
45
+ end
52
46
 
53
- def self.getSeasons(leagueId:, _limit:false, status:false)
54
- get
55
- if leagueId != 29000022
56
- puts "Not a valid League id,Seasons are only available for Legend League"
57
- else
58
- res = @conn.get("v1/leagues/#{leagueId}/seasons") do |req|
59
- req.params[:limit] = _limit if _limit
60
- end
47
+ if status
48
+ res.status
61
49
 
62
- if status
63
- res.status
50
+ else
51
+ val = res.body
52
+ convert = JSON.parse(val)
64
53
 
65
- else
66
- val = res.body
67
- convert = JSON.parse(val)
68
54
  end
69
-
70
- end
71
55
  end
72
56
 
73
- def self.getLeague_SeasonRank(leagueId:, seasonId:, _limit:false, status:false)
74
- get
75
- if leagueId != 29000022
76
- puts "Not a valid League id,Seasons are only available for Legend League"
77
- else
78
- res = @conn.get("v1/leagues/#{leagueId}/seasons/#{seasonId}") do |req|
79
- req.params[:limit] = _limit if _limit
80
- end
81
-
82
- if status
83
- res.status
84
-
85
- else
86
- val = res.body
87
- convert = JSON.parse(val)
88
- end
57
+ def self.get_Seasons(leagueId:, _limit:false, status:false)
58
+ get
59
+ if leagueId != 29000022
60
+ puts "Not a valid League id,Seasons are only available for Legend League"
61
+ else
62
+ res = @conn.get("v1/leagues/#{leagueId}/seasons") do |req|
63
+ req.params[:limit] = _limit if _limit
89
64
  end
90
65
 
91
- end
92
-
93
- def self.get_LeagueInfo(leagueId:, status:false)
94
- get
95
- res = @conn.get("v1/leagues/#{leagueId}")
96
-
97
- if status
98
- res.status
99
-
100
- else
101
- val = res.body
102
- convert = JSON.parse(val)
103
-
104
- end
66
+ if status
67
+ res.status
68
+ else
69
+ val = res.body
70
+ convert = JSON.parse(val)
71
+ end
72
+ end
73
+ end
105
74
 
75
+ def self.get_LeagueSeasonRank(leagueId:, seasonId:, _limit:false, status:false)
76
+ get
77
+ if leagueId != 29000022
78
+ puts "Not a valid League id,Seasons are only available for Legend League"
79
+ else
80
+ res = @conn.get("v1/leagues/#{leagueId}/seasons/#{seasonId}") do |req|
81
+ req.params[:limit] = _limit if _limit
82
+ end
83
+ if status
84
+ res.status
85
+ else
86
+ val = res.body
87
+ convert = JSON.parse(val)
88
+ end
89
+ end
106
90
  end
107
91
 
92
+ def self.get_LeagueInfo(leagueId:, status:false)
93
+ get
94
+ res = @conn.get("v1/leagues/#{leagueId}")
95
+ if status
96
+ res.status
97
+ else
98
+ val = res.body
99
+ convert = JSON.parse(val)
108
100
 
109
- def self.get_WarLeagueId(_limit:false, status:false)
110
- get
111
- res = @conn.get("v1/warleagues") do |req|
112
- req.params[:limit] = _limit if _limit
113
- end
114
-
115
- if status
116
- res.status
117
- else
118
- val = res.body
119
- convert = JSON.parse(val)
120
- end
121
-
101
+ end
122
102
  end
123
- def self.get_WarLeagueInfo(warLeagueId:, status:false)
124
- get
125
- res = @conn.get("v1/warleagues/#{warLeagueId}")
126
-
127
- if status
128
- res.status
129
-
130
- else
131
- val = res.body
132
- convert = JSON.parse(val)
133
103
 
134
- end
135
- end
136
104
 
105
+ def self.get_WarLeagueId(_limit:false, status:false)
106
+ get
107
+ res = @conn.get("v1/warleagues") do |req|
108
+ req.params[:limit] = _limit if _limit
109
+ end
137
110
 
138
- end
111
+ if status
112
+ res.status
113
+ else
114
+ val = res.body
115
+ convert = JSON.parse(val)
116
+ end
117
+ end
139
118
 
119
+ def self.get_WarLeagueInfo(warLeagueId:, status:false)
120
+ get
121
+ res = @conn.get("v1/warleagues/#{warLeagueId}")
122
+ if status
123
+ res.status
124
+ else
125
+ val = res.body
126
+ convert = JSON.parse(val)
127
+ end
128
+ end
129
+ end
140
130
  end