adam 1.3.1 → 1.4.0

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.
Files changed (3) hide show
  1. data/lib/adam.rb +2 -1
  2. data/lib/adam/image.rb +83 -0
  3. metadata +5 -4
@@ -1,8 +1,9 @@
1
1
  module Adam
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
 
4
4
  autoload :Killmail, 'adam/killmail'
5
5
  autoload :KillLog, 'adam/kill_log'
6
6
  autoload :Kill, 'adam/kill'
7
7
  autoload :Killboard, 'adam/killboard'
8
+ autoload :Image, 'adam/image'
8
9
  end
@@ -0,0 +1,83 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module Adam
5
+
6
+ class Image
7
+
8
+ @@character_portrait_uri = "http://image.eveonline.com/Character/"
9
+ @@corporation_logo_uri = "http://image.eveonline.com/Corporation/"
10
+ @@alliance_logo_uri = "http://image.eveonline.com/Alliance/"
11
+
12
+ # Retrieves a character portrait.
13
+ #
14
+ # Parameters:
15
+ # * +options+ - A hash with these keys:
16
+ # * +id+ - An integer describing an EVE Online character id.
17
+ # * +size+ - An integer describing what size to retrieve. Valid sizes are 32, 64, 128 or 256.
18
+ def self.character_portrait(options = {})
19
+ id = options.fetch(:id)
20
+ size = options.fetch(:size)
21
+
22
+ raise ArgumentError, "Valid sizes are 32, 64, 128 or 256" unless [32, 64, 128, 256].include?(size)
23
+
24
+ request(@@character_portrait_uri + "#{id}_#{size}.jpg")
25
+ end
26
+
27
+ # Retrieves a corporation logo.
28
+ #
29
+ # Parameters:
30
+ # * +options+ - A hash with these keys:
31
+ # * +id+ - An integer describing an EVE Online character id.
32
+ # * +size+ - An integer describing what size to retrieve. Valid sizes are 32, 64, 128 or 256.
33
+ def self.corporation_logo(options = {})
34
+ id = options.fetch(:id)
35
+ size = options.fetch(:size)
36
+
37
+ raise ArgumentError, "Valid sizes are 32, 64, 128 or 256" unless [32, 64, 128, 256].include?(size)
38
+
39
+ request(@@corporation_logo_uri + "#{id}_#{size}.png")
40
+ end
41
+
42
+ # Retrieves a alliance logo.
43
+ #
44
+ # Parameters:
45
+ # * +options+ - A hash with these keys:
46
+ # * +id+ - An integer describing an EVE Online character id.
47
+ # * +size+ - An integer describing what size to retrieve. Valid sizes are 32, 64 or 128.
48
+ def self.alliance_logo(options = {})
49
+ id = options.fetch(:id)
50
+ size = options.fetch(:size)
51
+
52
+ raise ArgumentError, "Valid sizes are 32, 64 or 128" unless [32, 64, 128].include?(size)
53
+
54
+ request(@@alliance_logo_uri + "#{id}_#{size}.png")
55
+ end
56
+
57
+ private
58
+
59
+ # Queries the EVE Online API for data.
60
+ #
61
+ # Parameters:
62
+ # * +uri+ - A string describing the URI to send a request to.
63
+ def self.request(uri)
64
+ uri = URI.parse(uri)
65
+
66
+ response, body = nil, nil
67
+ Net::HTTP.new(uri.host, uri.port).start do |http|
68
+ tries = 0
69
+ begin
70
+ response, body = http.get("#{uri.path}?#{uri.query}")
71
+ rescue Timeout::Error
72
+ tries += 1
73
+ sleep 5
74
+ retry if tries < 3
75
+ end
76
+ end
77
+
78
+ body
79
+ end
80
+
81
+ end
82
+
83
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 3
8
- - 1
9
- version: 1.3.1
7
+ - 4
8
+ - 0
9
+ version: 1.4.0
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-04 00:00:00 +02:00
17
+ date: 2010-10-07 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -31,6 +31,7 @@ files:
31
31
  - db/factions.sql
32
32
  - db/items.sql
33
33
  - db/solar_systems.sql
34
+ - lib/adam/image.rb
34
35
  - lib/adam/kill.rb
35
36
  - lib/adam/kill_log/validation_error.rb
36
37
  - lib/adam/kill_log.rb