Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- whitespace cleanup

  • Loading branch information...
commit fa964d1755b16d10bccabeb167a6db1804a2ea9f 1 parent 124c2dc
@darix darix authored
View
4 History.txt
@@ -1,8 +1,8 @@
== 0.1.7 2011-03-16
* 1 fix:
- * should now work with current active_support / rails
+ * should now work with current active_support / rails
-== 0.1.6 2010-01-21
+== 0.1.6 2010-01-21
* 1 fix:
* should now work with latest hpricot
View
12 README.rdoc
@@ -3,7 +3,7 @@
== DESCRIPTION:
-EAAL (Eve API Access Layer) is a ruby library for accessing data of the API of
+EAAL (Eve API Access Layer) is a ruby library for accessing data of the API of
the game Eve Online
== FEATURES/PROBLEMS:
@@ -18,7 +18,7 @@ Initialize the API Object
api = EAAL::API.new("my Userid", "my API key"[, "scope for requests"])
-the scope is the one used for the API requests,
+the scope is the one used for the API requests,
ex. account/char/corp/eve/map/server
see http://wiki.eve-id.net/APIv2_Page_Index
the scope can be changed during runtime and defaults to account
@@ -44,17 +44,17 @@ Example 2, getting the id for a given character name
Example 3, Example 2 in short
puts EAAL::Api.new("my userid", "my API key", "eve").CharacterID(:names => "Peter Powers").characters.name
-
+
Errors returned by the EVE API are handled a bit unique,
-since i wanted to have them pretty much dynamic (so i dont need to hack EAAL
+since i wanted to have them pretty much dynamic (so i dont need to hack EAAL
whenever CCP adds a new Error) you have to use dynamic created classes to catch 'em
(if you dont want to catch EAAL::Exception::EveAPIException in general)
so what you do is:
Example 4, catching a specific EVE API Exception
begin
- api.Killlog("characterID" => "12345") #this example offcourse
+ api.Killlog("characterID" => "12345") #this example offcourse
# assumes your not having the key for character 12345 loaded ;)
rescue EAAL::Exception.EveAPIException(201)
#dosomething
@@ -89,7 +89,7 @@ the XML file will be load.
* sudo gem install eaal
== THANKS:
-special thanks go to James "Ix_Forres" Harrison for his code cleanups and
+special thanks go to James "Ix_Forres" Harrison for his code cleanups and
his memcache cache handler
thanks also go to Davide Rambaldi and Ian Delahorno who contributed
several bug fixes.
View
12 README.txt
@@ -3,7 +3,7 @@
== DESCRIPTION:
-EAAL (Eve API Access Layer) is a ruby library for accessing data of the API of
+EAAL (Eve API Access Layer) is a ruby library for accessing data of the API of
the game Eve Online
== FEATURES/PROBLEMS:
@@ -18,7 +18,7 @@ Initialize the API Object
api = EAAL::API.new("my Userid", "my API key"[, "scope for requests"])
-the scope is the one used for the API requests,
+the scope is the one used for the API requests,
ex. account/char/corp/eve/map/server
see http://wiki.eve-id.net/APIv2_Page_Index
the scope can be changed during runtime and defaults to account
@@ -44,17 +44,17 @@ Example 2, getting the id for a given character name
Example 3, Example 2 in short
puts EAAL::Api.new("my userid", "my API key", "eve").CharacterID(:names => "Peter Powers").characters.name
-
+
Errors returned by the EVE API are handled a bit unique,
-since i wanted to have them pretty much dynamic (so i dont need to hack EAAL
+since i wanted to have them pretty much dynamic (so i dont need to hack EAAL
whenever CCP adds a new Error) you have to use dynamic created classes to catch 'em
(if you dont want to catch EAAL::Exception::EveAPIException in general)
so what you do is:
Example 4, catching a specific EVE API Exception
begin
- api.Killlog("characterID" => "12345") #this example offcourse
+ api.Killlog("characterID" => "12345") #this example offcourse
# assumes your not having the key for character 12345 loaded ;)
rescue EAAL::Exception.EveAPIException(201)
#dosomething
@@ -89,7 +89,7 @@ the XML file will be load.
* sudo gem install eaal
== THANKS:
-special thanks go to James "Ix_Forres" Harrison for his code cleanups and
+special thanks go to James "Ix_Forres" Harrison for his code cleanups and
his memcache cache handler
thanks also go to Davide Rambaldi and Ian Delahorno who contributed
several bug fixes.
View
8 lib/eaal.rb
@@ -3,7 +3,7 @@
# This library is licensed under the terms found in
# the LICENSE file distributed with it
#
-# TODO:
+# TODO:
# - more documenation
# - write tests (i know, i know, i fail badly)
# - more error handling (im certain i missed a few possibles)
@@ -12,7 +12,7 @@
# THANKS:
# thanks go to all people on irc.coldfront.net, channel #eve-dev
# special thanks go to lisa (checkout her eve api library, reve,
-# much more mature then mine) for answering my endless questions
+# much more mature then mine) for answering my endless questions
# about ruby stuff (and for one or two snippets i stole from reve)
#++
# Neat little hack to get around path issues on require
@@ -37,10 +37,10 @@ module EAAL
mattr_reader :version_string
VERSION = "0.1.7" # fix for Hoe.spec 2.x
@@version_string = "EAAL" + VERSION # the version string, used as client name in http requests
-
+
mattr_accessor :api_base, :additional_request_parameters, :cache
@@api_base = "http://api.eve-online.com/" # the url used as basis for all requests, you might want to use gatecamper url or a personal proxy instead
- @@additional_request_parameters = {} # hash, if :key => value pairs are added those will be added to each request
+ @@additional_request_parameters = {} # hash, if :key => value pairs are added those will be added to each request
@@cache = EAAL::Cache::NoCache.new # caching object, see EAAL::Cache::FileCache for an Example
end
require 'eaal/api'
View
20 lib/eaal/api.rb
@@ -8,7 +8,7 @@
# }
class EAAL::API
attr_accessor :userid, :key, :scope
-
+
# constructor
# Expects:
# * userid (String | Integer) the users id
@@ -19,19 +19,19 @@ def initialize(userid, key, scope="account")
self.key = key.to_s
self.scope = scope.to_s
end
-
+
# create an xml request according to the method called
- # this is used to dynamicaly create api calls and
+ # this is used to dynamicaly create api calls and
# should usually not be called directly
- # * method (const)
- # * args
+ # * method (const)
+ # * args
def method_missing(method, *args)
scope = self.scope
args_hash = args.first
args_hash = {} unless args_hash
self.request_xml(scope, method.id2name, args_hash)
end
-
+
# make a request to the api. will use cache if set.
# usually not called by the user directly
# * scope (String)
@@ -43,16 +43,16 @@ def request_xml(scope, name, opts)
if not xml
source = URI.parse(EAAL.api_base + scope + '/' + name +'.xml.aspx')
req_path = source.path + format_url_request(opts.merge({
- :userid => self.userid,
+ :userid => self.userid,
:apikey => self.key}))
req = Net::HTTP::Get.new(req_path)
req[EAAL.version_string]
- res = Net::HTTP.new(source.host, source.port).start {|http| http.request(req) } #one request for now
+ res = Net::HTTP.new(source.host, source.port).start {|http| http.request(req) } #one request for now
case res
when Net::HTTPOK
when Net::HTTPNotFound
raise EAAL::Exception::APINotFoundError.new("The requested API (#{scope} / #{name}) could not be found.")
- else
+ else
raise EAAL::Exception::HTTPError.new("An HTTP Error occured, body: " + res.body)
end
EAAL.cache.save(self.userid, self.key, scope,name,opts, res.body)
@@ -61,7 +61,7 @@ def request_xml(scope, name, opts)
doc = Hpricot.XML(xml)
result = EAAL::Result.new(scope.capitalize + name, doc)
end
-
+
# Turns a hash into ?var=baz&bam=boo
# stolen from Reve (thx lisa)
# * opts (Hash)
View
2  lib/eaal/cache/base.rb
@@ -21,7 +21,7 @@ def load(userid, apikey, scope, name, args)
def save(userid, apikey, scope, name, args, xml)
end
end
-
+
end
end
View
16 lib/eaal/cache/file.rb
@@ -6,17 +6,17 @@
# EAAL.cache = EAAL::Cache::FileCache.new("/path/to/place/to/store/xml/data")
class EAAL::Cache::FileCache
attr_accessor :basepath
-
+
# constructor, takes one argument which is the path
# where files should be written
# * basepath (String) path which should be used to store cached data. defaults to $HOME/.eaal/cache/
def initialize(basepath = "#{ENV['HOME']}/.eaal/cache")
if basepath[(basepath.length) -1, basepath.length] != "/"
- basepath += "/"
+ basepath += "/"
end
@basepath = basepath
end
-
+
# create the path/filename for the cache file
def filename(userid, apikey, scope, name, args)
ret =""
@@ -26,7 +26,7 @@ def filename(userid, apikey, scope, name, args)
hash = ret.gsub(/:$/,'')
"#{@basepath}#{userid}/#{apikey}/#{scope}/#{name}/Request_#{hash}.xml"
end
-
+
# load xml if available, return false if not available, or cachedUntil ran out
def load(userid, apikey, scope, name, args)
filename = self.filename(userid, apikey,scope,name,args)
@@ -42,23 +42,23 @@ def load(userid, apikey, scope, name, args)
end
ret
end
-
+
# validate cached datas cachedUntil
def validate_cache(xml, name)
doc = Hpricot.XML(xml)
cached_until = (doc/"/eveapi/cachedUntil").inner_html.to_time
if name == "WalletJournal"
result = Time.at(cached_until.to_i + 3600) > Time.now.utc
- else
+ else
result = cached_until > Time.now.utc
end
result
end
-
+
# save xml data to file
def save(userid, apikey, scope, name, args, xml)
filename = self.filename(userid, apikey,scope,name,args)
FileUtils.mkdir_p(File.dirname(filename))
- File.open(filename,'w') { |f| f.print xml }
+ File.open(filename,'w') { |f| f.print xml }
end
end
View
14 lib/eaal/exception.rb
@@ -6,7 +6,7 @@
module EAAL::Exception
# creates the class for an EveAPIException
def self.EveAPIException(nr)
- classname = "EveAPIException#{nr}"
+ classname = "EveAPIException#{nr}"
if not Object.const_defined? classname
klass = Object.const_set(classname, Class.new(EAAL::Exception::EveAPIException))
else
@@ -14,27 +14,27 @@ def self.EveAPIException(nr)
end
klass
end
-
+
# raise the eve API exceptions, class will be dynamicaly created by classname
# EveAPIException followed by the APIs exception Number
def self.raiseEveAPIException(nr, msg)
raise EAAL::Exception.EveAPIException(nr).new(msg)
end
-
+
# all EAAL exceptions should extend this.
class EAALError < StandardError
end
-
+
# Used when an http error is encountered
class HTTPError < EAALError
end
-
+
# Used when the Eve API returns a 404
class APINotFoundError < HTTPError
end
-
+
# All API Errors should be derived from this
class EveAPIException < EAALError
end
-
+
end
View
22 lib/eaal/result.rb
@@ -6,20 +6,20 @@
module EAAL
module Result
-
+
# base class for automated result class creation
class ResultBase
attr_accessor :request_time, :cached_until
end
-
- # Result Container class, ...
+
+ # Result Container class, ...
class ResultContainer
attr_accessor :container
def initialize
self.container = {}
end
-
+
def add_element(key, val)
self.container.merge!({key => val})
end
@@ -34,7 +34,7 @@ class ResultElement
attr_accessor :name, :value, :attribs
def initialize(name, value)
self.name = name
- self.value = value
+ self.value = value
self.attribs = {}
end
@@ -46,12 +46,12 @@ def method_missing(method, *args)
if self.attribs.has_key?(method.id2name)
self.attribs[method.id2name]
else
- self.value.send(method, *args)
+ self.value.send(method, *args)
end
-
+
end
-
- # parses an xml element to create either the ResultElement, ResultContainer or Rowset
+
+ # parses an xml element to create either the ResultElement, ResultContainer or Rowset
# necessary
def self.parse_element(prefix, element)
if element.name == "rowset" then
@@ -64,7 +64,7 @@ def self.parse_element(prefix, element)
cel = EAAL::Result::ResultElement.parse_element(prefix, celement)
if celement.attributes.to_hash.length > 0
container.add_element(cel.name, cel)
- else
+ else
container.add_element(cel.name, cel.value)
end
}
@@ -104,7 +104,7 @@ def self.new(prefix, xml)
end
}
if not Object.const_defined? classname
- klass = Object.const_set(classname, Class.new(EAAL::Result::ResultBase))
+ klass = Object.const_set(classname, Class.new(EAAL::Result::ResultBase))
klass.class_eval do
attr_accessor(*members)
end
View
20 lib/eaal/rowset.rb
@@ -6,11 +6,11 @@
module EAAL
module Rowset
-
+
# RowsetBase class, all RowSets should be derived from this
class RowsetBase < Array
attr_accessor :name, :columns, :rowclass
-
+
# create a new row in this RowSet
def create_row(xml)
row = self.rowclass.new
@@ -22,32 +22,32 @@ def create_row(xml)
el = EAAL::Result::ResultElement.parse_element(self.rowclass.name, child)
row.add_element(el.name, el)
}
- end
+ end
row
end
end
-
+
# BaseClass for Rows, all Rows should be derived from this
class RowBase < EAAL::Result::ResultContainer
end
-
+
# create a new RowSet Object
# * prefix string prefix for building the RowSet name
# * xml the xml for the RowSet
def self.new(prefix, xml)
name = xml['name']
columns = xml['columns'].split(',')
-
+
classname = prefix + 'Rowset' + name.capitalize
rowname = classname + 'Row'
-
+
if not Object.const_defined? classname
- klass = Object.const_set(classname, Class.new(EAAL::Rowset::RowsetBase))
+ klass = Object.const_set(classname, Class.new(EAAL::Rowset::RowsetBase))
else
klass = Object.const_get(classname)
end
rowset = klass.new
-
+
if not Object.const_defined? rowname
klass = Object.const_set(rowname, Class.new(EAAL::Rowset::RowBase))
klass.class_eval do
@@ -56,7 +56,7 @@ def self.new(prefix, xml)
else
klass = Object.const_get(rowname)
end
-
+
rowset.name = name
rowset.columns = columns
rowset.rowclass = klass
View
12 test/test_eaal.rb
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/test_helper.rb'
class TestEaal < Test::Unit::TestCase
-
- # prepare the api object. sets EAAL to use FileCache to load fixtures
+
+ # prepare the api object. sets EAAL to use FileCache to load fixtures
def setup
EAAL.cache = EAAL::Cache::FileCache.new(File.dirname(__FILE__) + '/fixtures/')
@api = EAAL::API.new('test','test')
@@ -15,7 +15,7 @@ def test_api_class
# some random tests if parsing the xml builds the right class
def test_api_classes
- @api.scope = "char"
+ @api.scope = "char"
assert_raise EAAL::Exception.EveAPIException(105) do @api.Killlog end
assert_equal @api.Killlog(:characterID => 12345).class.name, "CharKilllogResult"
assert_equal @api.Killlog(:characterID => 12345).kills.class.name, "CharKilllogRowsetKills"
@@ -23,13 +23,13 @@ def test_api_classes
assert_equal @api.Killlog(:characterID => 12345).kills.first.victim.class.name, "EAAL::Result::ResultElement"
assert_equal @api.Killlog(:characterID => 12345).kills.first.attackers.first.class.name, "CharKilllogRowsetKillsRowRowsetAttackersRow"
end
-
+
# some random data checks to ensure stuff can be read
def test_api_parse_data
@api.scope = "account"
assert_equal @api.Characters.characters.first.name, "Test Tester"
assert_equal @api.Characters.characters.second.corporationID, "7890"
- @api.scope = "char"
+ @api.scope = "char"
assert_equal @api.Killlog(:characterID => 12345).kills.length, 1
assert_equal @api.Killlog(:characterID => 12345).kills.first.victim.characterName, "Peter Powers"
assert_equal @api.Killlog(:characterID => 12345).kills.first.attackers.first.characterID, "12345"
@@ -81,7 +81,7 @@ def test_memcached
# Note if I run memcached I get a new error: EAAL::Exception::APINotFoundError: The requested API (account / Chracters) could not be found.
# this beacuse eaal request to EVE api the Test Tester PG....
# TODO: API needs mocking properly instead of depending on file cache for test loading.
-
+
EAAL.cache = EAAL::Cache::MemcachedCache.new
assert_instance_of EAAL::Cache::MemcachedCache, EAAL.cache
Please sign in to comment.
Something went wrong with that request. Please try again.