albion-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/albion-api.rb +20 -0
- data/lib/albion-api/guild_search.rb +43 -0
- data/lib/albion-api/user_killboard.rb +83 -0
- data/lib/albion-api/user_search.rb +32 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e270371de44a7af735659f767d31c8a24820385f
|
4
|
+
data.tar.gz: 1c21d9ea0beaab949b04d3ac6e48310120dae7d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90260faab449f607d55b9019f98b1adb4062c32290efb4b87eb4166cfbce553cf713a39f5f6590e2ae1ac7863d55ea3cbfa43c081789fd73bc05600da7919e20
|
7
|
+
data.tar.gz: 62b7ee5085a557c573f91ba6bcd94b55de18db8393c7d317a50750cc3f4ad8198d128ea60f773b60428b8c4f7f10c64563ea86b4469fd49e77dabca21eceb7a1
|
data/lib/albion-api.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
BASE_API_URL = "https://gameinfo.albiononline.com/api/gameinfo".freeze
|
4
|
+
|
5
|
+
# this module contains all of the classes needed to make requests to the Albion Online API
|
6
|
+
module AlbionApi
|
7
|
+
class AlbionRequest
|
8
|
+
include HTTParty
|
9
|
+
base_uri BASE_API_URL
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.base_api_url
|
13
|
+
BASE_API_URL
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# require all of our classes that belong to this module
|
18
|
+
require 'albion-api/user_killboard.rb'
|
19
|
+
require 'albion-api/user_search.rb'
|
20
|
+
require 'albion-api/guild_search.rb'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AlbionApi
|
2
|
+
# this class is used to look up information about a guild
|
3
|
+
class GuildSearch < AlbionRequest
|
4
|
+
def initialize(guild_name)
|
5
|
+
@guild_name = guild_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def find
|
9
|
+
response = self.class.get("/search?q=#{guild_name}")
|
10
|
+
Response.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_accessor :guild_name
|
16
|
+
|
17
|
+
# the response class for the GuildSearch request
|
18
|
+
class Response
|
19
|
+
def initialize(response)
|
20
|
+
guild_info = response['guilds'][0]
|
21
|
+
@_guild_api_id = guild_info['Id']
|
22
|
+
@_alliance_name = guild_info['AllianceName']
|
23
|
+
@_alliance_api_id = guild_info['AllianceId']
|
24
|
+
end
|
25
|
+
|
26
|
+
def guild_api_id
|
27
|
+
@_guild_api_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def alliance_name
|
31
|
+
@_alliance_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def alliance_api_id
|
35
|
+
@_alliance_api_id
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_accessor :_guild_api_id, :_alliance_name, :_alliance_api_id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module AlbionApi
|
2
|
+
# this class can make the calls to the UserKillboard APIs
|
3
|
+
class UserKillboard < AlbionRequest
|
4
|
+
def initialize(character_api_id)
|
5
|
+
@character_api_id = character_api_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def top_kills_in_range(start_time, end_time)
|
9
|
+
# get the difference between the end and start time
|
10
|
+
# determine how long ago it was from now, likely 1 day max
|
11
|
+
# make the top kills request with teh proper `range` param
|
12
|
+
# filter the raw response down to only those kills within the timestamp range
|
13
|
+
# return a response class
|
14
|
+
@raw_kills = []
|
15
|
+
page = 0
|
16
|
+
resp = top_kills
|
17
|
+
until resp.empty? do
|
18
|
+
@raw_kills.concat JSON.parse(resp.body)
|
19
|
+
page += 1
|
20
|
+
resp = top_kills(page)
|
21
|
+
end
|
22
|
+
Response.new(filter_kills(start_time, end_time))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_accessor :character_api_id, :raw_kills
|
28
|
+
|
29
|
+
def top_kills(page = 0)
|
30
|
+
offset = page * 51
|
31
|
+
self.class.get("/players/#{@character_api_id}/topkills?range=month&limit=51&offset=#{offset}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def filter_kills(start_time, end_time)
|
35
|
+
@raw_kills.select do |kill|
|
36
|
+
Time.parse(kill['TimeStamp']).between?(start_time, end_time) && kill['GvGMatch'].nil?
|
37
|
+
end.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
# class that contains the relevant information about a killboard API response
|
41
|
+
class Response
|
42
|
+
def initialize(response)
|
43
|
+
@_group_members = extract_group_members(response)
|
44
|
+
@_items_dropped = extract_dropped_items(response)
|
45
|
+
@_players_killed = extract_players_killed(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def group_members
|
49
|
+
_group_members
|
50
|
+
end
|
51
|
+
|
52
|
+
def items_dropped
|
53
|
+
_items_dropped
|
54
|
+
end
|
55
|
+
|
56
|
+
def players_killed
|
57
|
+
_players_killed
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
attr_accessor :_group_members, :_items_dropped, :_players_killed
|
63
|
+
|
64
|
+
def extract_group_members(response)
|
65
|
+
response.collect { |kill| kill['GroupMembers'] }.flatten.collect do |member|
|
66
|
+
member['Name']
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def extract_dropped_items(response)
|
71
|
+
response.collect { |kill| kill['Victim'] }.flatten.collect do |victim|
|
72
|
+
victim['Inventory'].concat(victim['Equipment'].values).compact
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def extract_players_killed(response)
|
77
|
+
response.collect { |kill| kill['Victim'] }.flatten.collect do |victim|
|
78
|
+
victim['Name']
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module AlbionApi
|
2
|
+
# this is the class used to search for users, namely to get their API ID
|
3
|
+
class UserSearch < AlbionRequest
|
4
|
+
def initialize(character_name)
|
5
|
+
@character_name = character_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def find
|
9
|
+
response = self.class.get("/search?q=#{character_name}")
|
10
|
+
Response.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_accessor :character_name
|
16
|
+
|
17
|
+
# this class wraps the response from the API
|
18
|
+
class Response
|
19
|
+
def initialize(response)
|
20
|
+
@_api_id = response['players'][0]['Id']
|
21
|
+
end
|
22
|
+
|
23
|
+
def api_id
|
24
|
+
@_api_id
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor :_api_id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: albion-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Montag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a gem that wraps the Albion Online API.
|
14
|
+
email: thekylemontag@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/albion-api.rb
|
20
|
+
- lib/albion-api/guild_search.rb
|
21
|
+
- lib/albion-api/user_killboard.rb
|
22
|
+
- lib/albion-api/user_search.rb
|
23
|
+
homepage: https://github.com/kmontag42/albion-api
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.6.11
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: A Ruby Library for the Albion Online API
|
47
|
+
test_files: []
|