adam 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +27 -5
- data/lib/adam.rb +1 -1
- data/lib/adam/api.rb +46 -0
- data/lib/adam/image.rb +14 -13
- data/lib/adam/kill.rb +1 -1
- data/lib/adam/killmail.rb +3 -3
- metadata +4 -3
data/README.md
CHANGED
@@ -48,14 +48,36 @@ Adam is a library for all things [EVE](http://www.eveonline.com/).
|
|
48
48
|
|
49
49
|
* Ruby 1.9
|
50
50
|
* Hpricot
|
51
|
-
* ActiveRecord
|
52
|
-
* MySQL (see note)
|
53
|
-
|
54
|
-
Note: ActiveRecord and MySQL are only required if you don't want to roll your own implementation for the "SolarSystem", "Item" and "Faction" classes.
|
51
|
+
* ActiveRecord
|
55
52
|
|
56
53
|
## Install
|
57
54
|
|
58
|
-
|
55
|
+
Adam can be installed as a Ruby gem or a Ruby on Rails plugin:
|
56
|
+
|
57
|
+
# Install as a gem
|
58
|
+
$ gem install adam
|
59
|
+
|
60
|
+
# Install as a Ruby on Rails plugin
|
61
|
+
$ rails plugin install git://github.com/jgorset/adam.git
|
62
|
+
|
63
|
+
Adam defines ActiveRecord models for `Item`, `SolarSystem` and `Faction` if your application hasn't already done so, but you'll need to
|
64
|
+
populate database tables for each model:
|
65
|
+
|
66
|
+
$ mysql adam < db/factions.sql
|
67
|
+
$ mysql adam < db/solar_systems.sql
|
68
|
+
$ mysql adam < db/items.sql
|
69
|
+
|
70
|
+
Finally, you'll need to configure Adam so it can connect to your database:
|
71
|
+
|
72
|
+
Adam::configure do |c|
|
73
|
+
c.database.adapter = 'mysql2'
|
74
|
+
c.database.username = 'username'
|
75
|
+
c.database.password = 'password'
|
76
|
+
c.database.name = 'database'
|
77
|
+
c.database.host = 'localhost'
|
78
|
+
end
|
79
|
+
|
80
|
+
That's it, you're done.
|
59
81
|
|
60
82
|
## License
|
61
83
|
|
data/lib/adam.rb
CHANGED
data/lib/adam/api.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Adam
|
5
|
+
|
6
|
+
class API
|
7
|
+
|
8
|
+
@@character_portrait_uri = "http://image.eveonline.com/Character/"
|
9
|
+
|
10
|
+
# Retrieves a character portrait.
|
11
|
+
#
|
12
|
+
# Parameters:
|
13
|
+
# * +options+ - A hash with these keys:
|
14
|
+
# * +id+ - An integer describing an EVE Online character id.
|
15
|
+
# * +size+ - An integer describing what size to retrieve. Valid sizes are 32, 64, 128 or 256.
|
16
|
+
def character_portrait(options = {})
|
17
|
+
request(@@character_portrait_uri + "#{options[:id]}_#{options[:size]}.jpg")
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Queries the EVE Online API for data.
|
23
|
+
#
|
24
|
+
# Parameters:
|
25
|
+
# * +uri+ - A string describing the URI to send a request to.
|
26
|
+
def request(uri)
|
27
|
+
uri = URI.parse(uri)
|
28
|
+
|
29
|
+
response, body = nil, nil
|
30
|
+
Net::HTTP.new(uri.host, uri.port).start do |http|
|
31
|
+
tries = 0
|
32
|
+
begin
|
33
|
+
response, body = http.get("#{uri.path}?#{uri.query}")
|
34
|
+
rescue Timeout::Error
|
35
|
+
tries += 1
|
36
|
+
sleep 5
|
37
|
+
retry if tries < 3
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
body
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/adam/image.rb
CHANGED
@@ -63,21 +63,22 @@ module Adam
|
|
63
63
|
def self.request(uri)
|
64
64
|
uri = URI.parse(uri)
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
66
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
67
|
+
http.open_timeout = 3
|
68
|
+
http.read_timeout = 20
|
69
|
+
|
70
|
+
request = Net::HTTP::Get.new(uri.path)
|
71
|
+
request['user-agent'] = "Adam #{Adam::VERSION}"
|
72
|
+
|
73
|
+
tries = 0
|
74
|
+
begin
|
75
|
+
tries += 1
|
76
|
+
response = http.request(request)
|
77
|
+
rescue Timeout::Error
|
78
|
+
sleep 5 and retry if tries < 3
|
78
79
|
end
|
79
80
|
|
80
|
-
body
|
81
|
+
response.body
|
81
82
|
end
|
82
83
|
|
83
84
|
end
|
data/lib/adam/kill.rb
CHANGED
data/lib/adam/killmail.rb
CHANGED
@@ -69,7 +69,7 @@ module Adam
|
|
69
69
|
involved_party = Adam::Kill::InvolvedParty.new do |ip|
|
70
70
|
ip.type = :PC
|
71
71
|
ip.pilot = snippet[/Name: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} pilot malformed"
|
72
|
-
ip.security_status = snippet[/Security: ([\-\.0-9]+)/, 1]
|
72
|
+
ip.security_status = (snippet[/Security: ([\-\.0-9]+)/, 1] or raise ValidationError.new(source), "Involved party #{i+1} security malformed").to_f
|
73
73
|
ip.corporation = snippet[/Corp: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} corporation malformed"
|
74
74
|
ip.alliance = snippet[/Alliance: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} alliance malformed"
|
75
75
|
ip.faction = snippet[/Faction: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} faction malformed"
|
@@ -115,7 +115,7 @@ module Adam
|
|
115
115
|
if source =~ /Destroyed items:/
|
116
116
|
source[/Destroyed items:\n\n(((.+)\n?)*)/, 1].split("\n").each_with_index do |snippet, i|
|
117
117
|
loot = Adam::Kill::Loot.new do |l|
|
118
|
-
l.name = snippet[/([^,\(\)]+)/, 1] or raise ValidationError.new(source), "Destroyed item #{i+1} name malformed"
|
118
|
+
l.name = snippet[/([^,\(\)]+[^,\(\) ]{1})/, 1] or raise ValidationError.new(source), "Destroyed item #{i+1} name malformed"
|
119
119
|
l.quantity = snippet =~ /Qty: ([0-9]+)/ ? snippet[/Qty: ([0-9]+)/, 1].to_i : 1
|
120
120
|
l.cargo = snippet[/(Cargo)/] ? true : false
|
121
121
|
l.drone_bay = snippet[/(Drone Bay)/] ? true : false
|
@@ -129,7 +129,7 @@ module Adam
|
|
129
129
|
if source =~ /Dropped items:/
|
130
130
|
source[/Dropped items:\n\n(((.+)\n?)*)/, 1].split("\n").each_with_index do |snippet, i|
|
131
131
|
loot = Adam::Kill::Loot.new do |l|
|
132
|
-
l.name = snippet[/([^,\(\)]+)/, 1] or raise ValidationError.new(source), "Dropped item #{i+1} name malformed"
|
132
|
+
l.name = snippet[/([^,\(\)]+[^,\(\) ]{1})/, 1] or raise ValidationError.new(source), "Dropped item #{i+1} name malformed"
|
133
133
|
l.quantity = snippet =~ /Qty: ([0-9]+)/ ? snippet[/Qty: ([0-9]+)/, 1].to_i : 1
|
134
134
|
l.cargo = snippet[/(Cargo)/] ? true : false
|
135
135
|
l.drone_bay = snippet[/(Drone Bay)/] ? true : false
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 1.5.
|
8
|
+
- 1
|
9
|
+
version: 1.5.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Johannes Gorset
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-16 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -27,6 +27,7 @@ extensions: []
|
|
27
27
|
extra_rdoc_files: []
|
28
28
|
|
29
29
|
files:
|
30
|
+
- lib/adam/api.rb
|
30
31
|
- lib/adam/configuration.rb
|
31
32
|
- lib/adam/image.rb
|
32
33
|
- lib/adam/kill.rb
|