clashinator 1.1.1 → 1.1.2

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
  SHA1:
3
- metadata.gz: 65921cbb0680c92dd07f846e46e206ab17ec0f68
4
- data.tar.gz: bed88b225cba0ca896d9ee7fbe95677acdd37e6e
3
+ metadata.gz: 0cc8dd0d6d06c8acd03938c6dc93abbc6f401c32
4
+ data.tar.gz: 45c5acd0cbd8672a6489a05134d468161f9b0966
5
5
  SHA512:
6
- metadata.gz: 47d8dc49d3a41be2a919b75e95e512e9a231db640bdfc8331f59b22758630b1ac283321a38786007f1967ee4ba5a488b3aa7836af3fe5b96e6019ca03dd1c292
7
- data.tar.gz: 16492e7964388f78070199d351eecb001840bf601528173c634e57869299d1d09ffdd0c4a86833c23812ee99e593c4d157ff4f5e4ca2173c620aff96db240da3
6
+ metadata.gz: 9233159d5dafdda8d801320b5f3b99a4b3e6bbe39d5b3628da597bfad8919f4810200c92a8df3c113075c0eb3c20d13329da3c42c4095f92910986775924a1c1
7
+ data.tar.gz: 3b29886b78ba65f1e09148b9073aa4cfa185bedee3dec3724df1d25b9d846bd7efa211dde1d979129e8a2e212a5ad8d32969640be5bd49799814cab4705a9eac
data/.gitignore CHANGED
@@ -36,5 +36,4 @@ Gemfile.lock
36
36
  .rvmrc
37
37
 
38
38
  # hide secrets
39
- secrets.yml
40
- spec/fixtures/*.yml
39
+ secrets.yml
@@ -0,0 +1,4 @@
1
+ // Place your settings in this file to overwrite default and user settings.
2
+ {
3
+ "ruby.rubocop.onSave": false
4
+ }
@@ -28,9 +28,10 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.11"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "webmock", "~> 2.1", ">= 2.1.0"
32
- spec.add_development_dependency "vcr", "~> 3.0", ">= 3.0.3"
31
+ # spec.add_development_dependency "webmock", "~> 2.1", ">= 2.1.0"
32
+ # spec.add_development_dependency "vcr", "~> 3.0", ">= 3.0.3"
33
33
  spec.add_development_dependency "minitest", "~> 5.9", ">= 5.9.1"
34
34
 
35
- spec.add_dependency "httparty", "~> 0.14.0"
35
+ spec.add_dependency "faraday", "~> 0.10.0"
36
+ spec.add_dependency "json", "~> 2.0", ">= 2.0.2"
36
37
  end
@@ -0,0 +1 @@
1
+ url: 'https://api.clashofclans.com'
@@ -1,4 +1,6 @@
1
- require 'httparty'
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'yaml'
2
4
 
3
5
  require 'clashinator/base.rb'
4
6
  require 'clashinator/array_resource.rb'
@@ -4,12 +4,9 @@ require_relative 'util/underscore.rb'
4
4
  module Clashinator
5
5
  # This is the base class for the other entities
6
6
  class Base
7
- include HTTParty
8
7
  include Underscorable
9
8
  extend Camelizable
10
9
 
11
- base_uri 'https://api.clashofclans.com'
12
-
13
10
  CLASS_MAP = {
14
11
  member_list: 'Player', achievements: 'Achievement',
15
12
  troops: 'Troop', heroes: 'Hero', spells: 'Spell'
@@ -67,15 +64,7 @@ module Clashinator
67
64
  val
68
65
  end
69
66
 
70
- def self.http_default_options(token)
71
- {
72
- headers: {
73
- 'Authorization' => "Bearer #{token}"
74
- }
75
- }
76
- end
77
-
78
- def self.prepare_options(token, query_options = {})
67
+ def self.prepare_options(query_options = {})
79
68
  # new hash to store camelcased attributes, to make it work
80
69
  # with the official API
81
70
  new_query_options = {}
@@ -85,10 +74,7 @@ module Clashinator
85
74
  new_query_options[name.to_sym] = val
86
75
  end
87
76
 
88
- # duplicate http_default_options to add new_query_options
89
- http_default_options(token).dup.merge(query: new_query_options)
77
+ new_query_options
90
78
  end
91
-
92
- private_class_method :http_default_options
93
79
  end
94
80
  end
@@ -5,60 +5,57 @@ module Clashinator
5
5
  super(attrs)
6
6
  end
7
7
 
8
- def self.clan_info(token, clan_tag)
8
+ def self.clan_info(http, clan_tag)
9
9
  clan_tag.gsub!('#', '%23')
10
- new_options = prepare_options(token)
11
- response = get(
12
- "/v1/clans/#{clan_tag}",
13
- new_options
10
+ response = http.get(
11
+ "/v1/clans/#{clan_tag}"
14
12
  )
13
+ parsed = JSON.parse(response.body)
15
14
 
16
- return new(response.parsed_response) if response.ok?
17
- raise response['reason'] unless response.ok?
15
+ return new(parsed) if response.success?
16
+ raise parsed['reason'] unless response.success?
18
17
  end
19
18
 
20
- def self.search_clans(token, options)
21
- new_options = prepare_options(token, options)
22
- # TODO: options[:name] should be at least 3 chars long
23
- response = get('/v1/clans', new_options)
19
+ def self.search_clans(http, options)
20
+ new_options = prepare_options(options)
21
+ response = http.get('/v1/clans', new_options)
22
+ parsed = JSON.parse(response.body)
24
23
 
25
- if response.ok?
24
+ if response.success?
26
25
  return Clashinator::ArrayResource.new(
27
- Clashinator::Clan,
28
- response.parsed_response['items'],
29
- response.parsed_response['paging']
26
+ Clashinator::Clan, parsed['items'], parsed['paging']
30
27
  )
31
28
  end
32
- raise response['message'] unless response.ok?
29
+
30
+ raise parsed['message'] unless response.success?
33
31
  end
34
32
 
35
- def self.list_clan_members(token, clan_tag, options = {})
36
- new_options = prepare_options(token, options)
33
+ def self.list_clan_members(http, clan_tag, options = {})
34
+ new_options = prepare_options(options)
37
35
  clan_tag.gsub!('#', '%23')
38
- response = get("/v1/clans/#{clan_tag}/members", new_options)
39
-
40
- if response.ok?
36
+ response = http.get("/v1/clans/#{clan_tag}/members", new_options)
37
+ parsed = JSON.parse(response.body)
38
+ if response.success?
41
39
  return Clashinator::ArrayResource.new(
42
- Clashinator::Player, response.parsed_response['items'],
43
- response.parsed_response['paging']
40
+ Clashinator::Player, parsed['items'], parsed['paging']
44
41
  )
45
42
  end
46
- raise response['message'] unless response.ok?
43
+ raise parsed['message'] unless response.success?
47
44
  end
48
45
 
49
- def self.clan_war_log(token, clan_tag, options = {})
46
+ def self.clan_war_log(http, clan_tag, options = {})
50
47
  # response.code will be 403 if clan war log is set to private
51
- new_options = prepare_options(token, options)
48
+ new_options = prepare_options(options)
52
49
  clan_tag.gsub!('#', '%23')
53
- response = get("/v1/clans/#{clan_tag}/warlog", new_options)
50
+ response = http.get("/v1/clans/#{clan_tag}/warlog", new_options)
51
+ parsed = JSON.parse(response.body)
54
52
 
55
- if response.ok?
53
+ if response.success?
56
54
  return Clashinator::ArrayResource.new(
57
- Clashinator::Warlog, response.parsed_response['items'],
58
- response.parsed_response['paging']
55
+ Clashinator::Warlog, parsed['items'], parsed['paging']
59
56
  )
60
57
  end
61
- raise response['reason'] unless response.ok?
58
+ raise parsed['reason'] unless response.success?
62
59
  end
63
60
  end
64
61
  end
@@ -3,76 +3,82 @@ module Clashinator
3
3
  # interface of http methods
4
4
  # available for the client itself
5
5
  class Client
6
- attr_reader :token
6
+ attr_reader :token, :uri, :headers
7
7
 
8
8
  def initialize(token)
9
9
  @token = token
10
+ @uri = YAML.load_file('config/config.yml')['url']
11
+ @headers = { 'Authorization' => "Bearer #{@token}" }
12
+ @conn = Faraday.new(
13
+ url: @uri,
14
+ headers: @headers
15
+ )
10
16
  end
11
17
 
12
18
  # client class methods
13
19
 
14
20
  def search_clans(options)
15
- Clashinator::Clan.search_clans(@token, options)
21
+ Clashinator::Clan.search_clans(@conn, @token, options)
16
22
  end
17
23
 
18
24
  def clan_info(tag)
19
- Clashinator::Clan.clan_info(@token, tag)
25
+ Clashinator::Clan.clan_info(@conn, @token, tag)
20
26
  end
21
27
 
22
28
  def list_clan_members(tag, options = {})
23
- Clashinator::Clan.list_clan_members(@token, tag, options)
29
+ Clashinator::Clan.list_clan_members(@conn, @token, tag, options)
24
30
  end
25
31
 
26
32
  def clan_war_log(tag, options = {})
27
- Clashinator::Clan.clan_war_log(@token, tag, options)
33
+ Clashinator::Clan.clan_war_log(@conn, @token, tag, options)
28
34
  end
29
35
 
30
36
  # location class methods
31
37
 
32
38
  def list_locations(options = {})
33
- Clashinator::Location.list_locations(@token, options)
39
+ Clashinator::Location.list_locations(@conn, @token, options)
34
40
  end
35
41
 
36
42
  def location_info(location_id)
37
- Clashinator::Location.location_info(@token, location_id)
43
+ Clashinator::Location.location_info(@conn, @token, location_id)
38
44
  end
39
45
 
40
46
  def location_clan_rankings(location_id, options = {})
41
47
  Clashinator::Locaton.location_clan_rankings(
42
- @token, location_id, options
48
+ @conn, @token, location_id, options
43
49
  )
44
50
  end
45
51
 
46
52
  def location_player_rankings(player_tag, options = {})
47
53
  Clashinator::Location.location_player_rankings(
48
- @token, player_tag, options
54
+ @conn, @token, player_tag, options
49
55
  )
50
56
  end
51
57
 
52
58
  # league class methods
53
59
 
54
60
  def list_leagues(options = {})
55
- Clashinator::League.list_leagues(@token, options)
61
+ Clashinator::League.list_leagues(@conn, @token, options)
56
62
  end
57
63
 
58
64
  def league_info(league_id)
59
- Clashinator::League.league_info(@token, league_id)
65
+ Clashinator::League.league_info(@conn, @token, league_id)
60
66
  end
61
67
 
62
68
  def league_seasons(league_id, options = {})
63
- Clashinator::League.league_seasons(@token, league_id, options)
69
+ Clashinator::League.league_seasons(@conn, @token, league_id, options)
64
70
  end
65
71
 
66
72
  def league_season_rankings(league_id, season_id, options = {})
67
73
  Clashinator::League.league_season_rankings(
68
- @token, league_id, season_id, options
74
+ @conn, @token, league_id, season_id, options
69
75
  )
70
76
  end
71
77
 
72
78
  # player class methods
73
79
 
74
80
  def player_info(tag)
75
- Clashinator::Player.player_info(@token, tag)
81
+ Clashinator::Player.player_info(@conn, @token, tag)
76
82
  end
77
83
  end
78
84
  end
@@ -5,58 +5,59 @@ module Clashinator
5
5
  super(attrs)
6
6
  end
7
7
 
8
- def self.list_leagues(token, options = {})
9
- new_options = prepare_options(token, options)
10
- response = get('/v1/leagues', new_options)
8
+ def self.list_leagues(http, options = {})
9
+ new_options = prepare_options(options)
10
+ response = http.get('/v1/leagues', new_options)
11
+ parsed = JSON.parse(response.body)
11
12
 
12
- if response.ok?
13
+ if response.success?
13
14
  return Clashinator::ArrayResource.new(
14
- Clashinator::League, response.parsed_response['items'],
15
- response.parsed_response['paging']
15
+ Clashinator::League, parsed['items'], parsed['paging']
16
16
  )
17
17
  end
18
- raise response['message'] unless response.ok?
18
+ raise parsed['message'] unless response.success?
19
19
  end
20
20
 
21
- def self.league_info(token, league_id)
22
- new_options = prepare_options(token)
23
- response = get("/v1/leagues/#{league_id}", new_options)
21
+ def self.league_info(http, league_id)
22
+ response = http.get("/v1/leagues/#{league_id}")
23
+ parsed = JSON.parse(response.body)
24
24
 
25
- return new(response.parsed_response) if response.ok?
26
- raise response['message'] unless response.ok?
25
+ return new(parsed) if response.success?
26
+ raise parsed['message'] unless response.success?
27
27
  end
28
28
 
29
- def self.league_seasons(token, league_id, options = {})
30
- new_options = prepare_options(token, options)
31
- response = get("/v1/leagues/#{league_id}/seasons", new_options)
29
+ def self.league_seasons(http, league_id, options = {})
30
+ new_options = prepare_options(options)
31
+ response = http.get("/v1/leagues/#{league_id}/seasons", new_options)
32
+ parsed = JSON.parse(response.body)
32
33
 
33
- if response.ok?
34
+ if response.success?
34
35
  return Clashinator::ArrayResource.new(
35
- Clashinator::Season, response.parsed_response['items'],
36
- response.parsed_response['paging']
36
+ Clashinator::Season, parsed['items'], parsed['paging']
37
37
  )
38
38
  end
39
- raise response['reason'] unless response.ok?
39
+ raise parsed['reason'] unless response.success?
40
40
  end
41
41
 
42
- def self.league_season_rankings(token, league_id, season_id, options = {})
42
+ def self.league_season_rankings(http, league_id, season_id, options = {})
43
43
  # only available for legend_league
44
44
  response = prepare_response_season_rankings(
45
- league_id, season_id, token, options
45
+ league_id, season_id, http, options
46
46
  )
47
- if response.ok?
47
+ parsed = JSON.parse(response.body)
48
+
49
+ if response.success?
48
50
  return Clashinator::ArrayResource.new(
49
- Clashinator::PlayerRanking, response.parsed_response['items'],
50
- response.parsed_response['paging']
51
+ Clashinator::PlayerRanking, parsed['items'], parsed['paging']
51
52
  )
52
53
  end
53
- raise response['reason'] unless response.ok?
54
+ raise parsed['reason'] unless response.success?
54
55
  end
55
56
 
56
- def self.prepare_response_season_rankings(league_id, season_id, token, options)
57
- get(
57
+ def self.prepare_response_season_rankings(league_id, season_id, http, options)
58
+ http.get(
58
59
  "/v1/leagues/#{league_id}/seasons/#{season_id}",
59
- prepare_options(token, options)
60
+ prepare_options(options)
60
61
  )
61
62
  end
62
63
 
@@ -5,51 +5,51 @@ module Clashinator
5
5
  super(attrs)
6
6
  end
7
7
 
8
- def self.list_locations(token, options = {})
9
- new_options = prepare_options(token, options)
10
- response = get('/v1/locations', new_options)
8
+ def self.list_locations(http, options = {})
9
+ new_options = prepare_options(options)
10
+ response = http.get('/v1/locations', new_options)
11
+ parsed = JSON.parse(response.body)
11
12
 
12
- if response.ok?
13
+ if response.success?
13
14
  return Clashinator::ArrayResource.new(
14
- Clashinator::Location, response.parsed_response['items'],
15
- response.parsed_response['paging']
15
+ Clashinator::Location, parsed['items'], parsed['paging']
16
16
  )
17
17
  end
18
- raise response['message'] unless response.ok?
18
+ raise parsed['message'] unless response.success?
19
19
  end
20
20
 
21
- def self.location_info(token, location_id)
22
- new_options = prepare_options(token)
23
- response = get("/v1/locations/#{location_id}", new_options)
21
+ def self.location_info(http, location_id)
22
+ response = http.get("/v1/locations/#{location_id}")
23
+ parsed = JSON.parse(response.body)
24
24
 
25
- return new(response.parsed_response) if response.ok?
26
- raise response['message'] unless response.ok?
25
+ return new(parsed) if response.success?
26
+ raise parsed['message'] unless response.success?
27
27
  end
28
28
 
29
- def self.location_clan_rankings(token, location_id, options = {})
30
- new_options = prepare_options(token, options)
31
- response = get("/v1/locations/#{location_id}/rankings/clans", new_options)
29
+ def self.location_clan_rankings(http, location_id, options = {})
30
+ new_options = prepare_options(options)
31
+ response = http.get("/v1/locations/#{location_id}/rankings/clans", new_options)
32
+ parsed = JSON.parse(response.body)
32
33
 
33
- if response.ok?
34
+ if response.success?
34
35
  return Clashinator::ArrayResource.new(
35
- Clashinator::ClanRanking, response.parsed_response['items'],
36
- response.parsed_response['paging']
36
+ Clashinator::ClanRanking, parsed['items'], parsed['paging']
37
37
  )
38
38
  end
39
- raise response['reason'] unless response.ok?
39
+ raise parsed['reason'] unless response.success?
40
40
  end
41
41
 
42
- def self.location_player_rankings(token, location_id, options = {})
43
- response = get(
42
+ def self.location_player_rankings(http, location_id, options = {})
43
+ response = http.get(
44
44
  "/v1/locations/#{location_id}/rankings/players",
45
- prepare_options(token, options)
45
+ prepare_options(options)
46
46
  )
47
+ parsed = JSON.parse(response.body)
47
48
 
48
49
  return Clashinator::ArrayResource.new(
49
- Clashinator::PlayerRanking, response.parsed_response['items'],
50
- response.parsed_response['paging']
51
- ) if response.ok?
52
- raise response['reason'] unless response.ok?
50
+ Clashinator::PlayerRanking, parsed['items'], parsed['paging']
51
+ ) if response.success?
52
+ raise parsed['reason'] unless response.success?
53
53
  end
54
54
  end
55
55
  end
@@ -5,13 +5,13 @@ module Clashinator
5
5
  super(attrs)
6
6
  end
7
7
 
8
- def self.player_info(token, player_tag)
8
+ def self.player_info(http, player_tag)
9
9
  player_tag.gsub!('#', '%23')
10
- new_options = prepare_options(token)
11
- response = get("/v1/players/#{player_tag}", new_options)
10
+ response = http.get("/v1/players/#{player_tag}")
11
+ parsed = JSON.parse(response.body)
12
12
 
13
- return new(response.parsed_response) if response.ok?
14
- raise response['reason'] unless response.ok?
13
+ return new(parsed) if response.success?
14
+ raise parsed['reason'] unless response.success?
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Clashinator
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clashinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Cabeza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,79 +39,59 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: webmock
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '5.9'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 2.1.0
50
+ version: 5.9.1
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '2.1'
57
+ version: '5.9'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 2.1.0
60
+ version: 5.9.1
61
61
  - !ruby/object:Gem::Dependency
62
- name: vcr
62
+ name: faraday
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.0'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 3.0.3
71
- type: :development
67
+ version: 0.10.0
68
+ type: :runtime
72
69
  prerelease: false
73
70
  version_requirements: !ruby/object:Gem::Requirement
74
71
  requirements:
75
72
  - - "~>"
76
73
  - !ruby/object:Gem::Version
77
- version: '3.0'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 3.0.3
74
+ version: 0.10.0
81
75
  - !ruby/object:Gem::Dependency
82
- name: minitest
76
+ name: json
83
77
  requirement: !ruby/object:Gem::Requirement
84
78
  requirements:
85
79
  - - "~>"
86
80
  - !ruby/object:Gem::Version
87
- version: '5.9'
81
+ version: '2.0'
88
82
  - - ">="
89
83
  - !ruby/object:Gem::Version
90
- version: 5.9.1
91
- type: :development
84
+ version: 2.0.2
85
+ type: :runtime
92
86
  prerelease: false
93
87
  version_requirements: !ruby/object:Gem::Requirement
94
88
  requirements:
95
89
  - - "~>"
96
90
  - !ruby/object:Gem::Version
97
- version: '5.9'
91
+ version: '2.0'
98
92
  - - ">="
99
93
  - !ruby/object:Gem::Version
100
- version: 5.9.1
101
- - !ruby/object:Gem::Dependency
102
- name: httparty
103
- requirement: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - "~>"
106
- - !ruby/object:Gem::Version
107
- version: 0.14.0
108
- type: :runtime
109
- prerelease: false
110
- version_requirements: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - "~>"
113
- - !ruby/object:Gem::Version
114
- version: 0.14.0
94
+ version: 2.0.2
115
95
  description:
116
96
  email:
117
97
  - info@leonardocabeza.com
@@ -120,6 +100,7 @@ extensions: []
120
100
  extra_rdoc_files: []
121
101
  files:
122
102
  - ".gitignore"
103
+ - ".vscode/settings.json"
123
104
  - CODE_OF_CONDUCT.md
124
105
  - Gemfile
125
106
  - LICENSE
@@ -129,6 +110,7 @@ files:
129
110
  - bin/console
130
111
  - bin/setup
131
112
  - clashinator.gemspec
113
+ - config/config.yml
132
114
  - config/secrets.sample.yml
133
115
  - lib/clashinator.rb
134
116
  - lib/clashinator/achievement.rb