Skip to content
Browse files

Support for the new Mail Messages, Notifications and MailingLists API…

… methods
  • Loading branch information...
1 parent a6498e6 commit b8ef35f4bf7bb660f5c32b04d4bc388bc29a0c71 @dsander dsander committed with Lisa Seelye
Showing with 221 additions and 8 deletions.
  1. +23 −1 .gitignore
  2. +42 −3 lib/reve.rb
  3. +57 −0 lib/reve/classes.rb
  4. +4 −4 test/test_extensions.rb
  5. +57 −0 test/test_reve.rb
  6. +15 −0 test/xml/mail_messages.xml
  7. +12 −0 test/xml/mailing_lists.xml
  8. +11 −0 test/xml/notifications.xml
View
24 .gitignore
@@ -1 +1,23 @@
-doc
+doc
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+reve.gemspec
+## PROJECT::SPECIFIC
+
View
45 lib/reve.rb
@@ -87,7 +87,10 @@ class API
@@corporate_medals_url = 'http://api.eve-online.com/corp/Medals.xml.aspx'
@@corp_member_medals_url = 'http://api.eve-online.com/corp/MemberMedals.xml.aspx'
@@server_status_url = 'http://api.eve-online.com/Server/ServerStatus.xml.aspx'
-
+ @@personal_notification_url = 'http://api.eve-online.com/char/Notifications.xml.aspx'
+ @@personal_mailing_lists_url = 'http://api.eve-online.com/char/mailinglists.xml.aspx'
+ @@personal_mail_messages_url = 'http://api.eve-online.com/char/MailMessages.xml.aspx'
+
cattr_accessor :character_sheet_url, :training_skill_url, :characters_url, :personal_wallet_journal_url,
:corporate_wallet_journal_url, :personal_wallet_trans_url, :corporate_wallet_trans_url,
:personal_wallet_balance_url, :corporate_wallet_balance_url, :member_tracking_url,
@@ -99,7 +102,8 @@ class API
:personal_faction_war_stats_url, :corporate_faction_war_stats_url,
:general_faction_war_stats_url, :top_faction_war_stats_url, :faction_war_occupancy_url,
:certificate_tree_url, :character_medals_url, :corporate_medals_url,
- :corp_member_medals_url, :server_status_url, :skill_queue_url, :corporation_member_security_url
+ :corp_member_medals_url, :server_status_url, :skill_queue_url, :corporation_member_security_url,
+ :personal_notification_url, :personal_mailing_lists_url, :personal_mail_messages_url
attr_accessor :key, :userid, :charid
@@ -856,7 +860,42 @@ def character_sheet(opts = { :characterid => nil })
cs
end
-
+
+ # Gets the characters notifications. Returns a list of
+ # Reve::Classes::Notification
+ # Expects:
+ # * characterid ( Integer | String ) - Get the Notifications for this Character
+ # See also: Reve::Classes::Notification
+ def personal_notifications(opts = { :characterid => nil })
+ args = postfields(opts)
+ h = compute_hash(args.merge(:url => @@personal_notification_url))
+ return h if h
+ process_query(Reve::Classes::Notification, opts[:url] || @@personal_notification_url,false,args)
+ end
+
+ # Gets the characters notifications. Returns a list of
+ # Reve::Classes::MailingList
+ # Expects:
+ # * characterid ( Integer | String ) - Get the MailingLists for this Character
+ # See also: Reve::Classes::MailingList
+ def personal_mailing_lists(opts = { :characterid => nil })
+ args = postfields(opts)
+ h = compute_hash(args.merge(:url => @@personal_mailing_lists_url))
+ return h if h
+ process_query(Reve::Classes::MailingList, opts[:url] || @@personal_mailing_lists_url,false,args)
+ end
+
+ # Gets the characters notifications. Returns a list of
+ # Reve::Classes::MailMessage
+ # Expects:
+ # * characterid ( Integer | String ) - Get the MailMessages for this Character
+ # See also: Reve::Classes::MailMessage
+ def personal_mail_messages(opts = { :characterid => nil })
+ args = postfields(opts)
+ h = compute_hash(args.merge(:url => @@personal_mail_messages_url))
+ return h if h
+ process_query(Reve::Classes::MailMessage, opts[:url] || @@personal_mail_messages_url,false,args)
+ end
protected
# Sets up the post fields for Net::HTTP::Get hash for process_query method.
View
57 lib/reve/classes.rb 100755 → 100644
@@ -1386,5 +1386,62 @@ class CorporateWalletTransaction < WalletTransaction
# See WalletTransaction
class PersonalWalletTransaction < WalletTransaction
end
+
+ # Represents a MailingList for
+ # Reve::API#personal_mailing_lists
+ # Attributes
+ # * id ( Fixnum ) - ID of the MailingList (use this in the Reve::API#mail_messages call)
+ # * name ( String ) - Name of the MailingList
+ class MailingList
+ attr_reader :id, :name
+ def initialize(elem) #:nodoc:
+ @id = elem['listID'].to_i
+ @name = elem['displayName']
+ end
+ end
+
+ # Represents a MailMessage for
+ # Reve::API#personal_mail_messages
+ # Attributes
+ # * id ( Fixnum ) - The unique message ID number.
+ # * sender_id ( Fixnum ) - The character ID of the message originator. (use Reve::API#character_name to get their names)
+ # * send_date ( Time ) - The date the message was sent.
+ # * title ( String ) - The title of the message
+ # * to_corp_or_alliance_id ( Fixnum ) - The ID of a corporation/alliance that the message was sent to.
+ # * to_character_ids ( [Fixnum] ) - Array of character IDs of the characters that received the message.
+ # * to_list_ids ( [Fixnum] ) - Array of mailing lists that the mail was sent to. (use Reve::API#personal_mailing_lists to get their names)
+ # * read ( Boolean ) - Whether the mail/notification has been read in the EVE client. This does not change when you get it through the API.
+ class MailMessage
+ attr_reader :id, :name, :sender_id, :send_date, :title, :to_corp_or_alliance_id, :to_character_ids, :to_list_ids, :read
+ def initialize(elem) #:nodoc:
+ @id = elem['messageID'].to_i
+ @sender_id = elem['senderID'].to_i
+ @send_date = elem['sentDate'].to_time
+ @title = elem['title']
+ @to_corp_or_alliance_id = elem['toCorpOrAllianceID'] == '' ? nil : elem['toCorpOrAllianceID'].to_i
+ @to_character_ids = elem['toCharacterIDs'] == '' ? nil : elem['toCharacterIDs'].split(',').collect {|id| id.to_i }
+ @to_list_ids = elem['toListIDs'] == '' ? nil : elem['toListIDs'].split(',').collect {|id| id.to_i }
+ @read = elem['read'] == '1'
+ end
+ end
+
+ # Represents a Notification for
+ # Reve::API#personal_notifications
+ # Attributes
+ # * id ( Fixnum ) - The unique notification ID number.
+ # * notification_type_id ( Fixnum ) - The notification type indicates what has happened but not who performed the action in question nor upon whom the action was performed. See http://wiki.eve-id.net/APIv2_Char_Notifications_XML for a list of ids
+ # * sender_id ( Fixnum ) - TThe ID of the entity that sent the notification.
+ # * send_date ( Time ) - The ID of the entity that sent the notification.
+ # * read ( Boolean ) - Whether the notification has been read in the EVE client. This does not change when you get it through the API.
+ class Notification
+ attr_reader :id, :name, :notification_type_id, :sender_id, :send_date, :read
+ def initialize(elem) #:nodoc:
+ @id = elem['notificationID'].to_i
+ @notification_type_id = elem['typeID'].to_i
+ @sender_id = elem['senderID'].to_i
+ @send_date = elem['sentDate'].to_time
+ @read = elem['read'] == '1'
+ end
+ end
end
end
View
8 test/test_extensions.rb 100755 → 100644
@@ -35,14 +35,14 @@ def test_stringify_keys!
def test_cattr_reader
- assert CattrReaderTest.public_instance_methods.include?('test_reader')
+ assert CattrReaderTest.public_instance_methods.include?('test_reader'.to_sym) || CattrReaderTest.public_instance_methods.include?('test_reader')
end
def test_cattr_writer
- assert CattrWriterTest.public_instance_methods.include?('test_writer=')
+ assert CattrWriterTest.public_instance_methods.include?('test_writer='.to_sym) || CattrWriterTest.public_instance_methods.include?('test_writer=')
end
def test_cattr_accessor
- assert CattrReadWriterTest.public_instance_methods.include?('test_both')
- assert CattrReadWriterTest.public_instance_methods.include?('test_both=')
+ assert CattrReadWriterTest.public_instance_methods.include?('test_both'.to_sym) || CattrReadWriterTest.public_instance_methods.include?('test_both')
+ assert CattrReadWriterTest.public_instance_methods.include?('test_both='.to_sym) || CattrReadWriterTest.public_instance_methods.include?('test_both=')
end
def test_string_to_time_clean
View
57 test/test_reve.rb 100755 → 100644
@@ -1074,6 +1074,63 @@ def test_character_sheet_clean
end
+
+ def test_personal_notifications
+ Reve::API.personal_notification_url = XML_BASE + 'notifications.xml'
+ notifications = nil
+ assert_nothing_raised do
+ notifications = @api.personal_notifications(:characterid => 1)
+ end
+ assert_equal 2, notifications.length
+ assert_equal Reve::Classes::Notification, notifications.first.class
+ assert_equal 200076684, notifications.first.sender_id
+ assert_equal 16, notifications.first.notification_type_id
+ assert_equal Time.parse('2009-12-02 10:54:00 UTC'), notifications.first.send_date
+ end
+
+ def test_personal_mailing_lists
+ Reve::API.personal_mailing_lists_url = XML_BASE + 'mailing_lists.xml'
+ lists = nil
+ assert_nothing_raised do
+ lists = @api.personal_mailing_lists(:characterid => 1)
+ end
+ assert_equal 3, lists.length
+ assert_equal Reve::Classes::MailingList, lists.first.class
+ assert_equal 128250439, lists.first.id
+ assert_equal 'EVETycoonMail', lists.first.name
+ assert_equal 141157801, lists.last.id
+ end
+
+ def test_personal_mail_messages
+ Reve::API.personal_mail_messages_url = XML_BASE + 'mail_messages.xml'
+ mails = nil
+ assert_nothing_raised do
+ mails = @api.personal_mail_messages(:characterid => 1)
+ end
+ assert_equal 5, mails.length
+ assert_equal Reve::Classes::MailMessage, mails.first.class
+ # Corp Mail
+ assert_equal 1, mails.first.sender_id
+ assert_equal Time.parse('2009-12-01 01:04:00 UTC'), mails.first.send_date
+ assert_equal "Corp mail", mails.first.title
+ assert_equal 4, mails.first.to_corp_or_alliance_id
+ assert_equal nil, mails.first.to_character_ids
+ assert_equal nil, mails.first.to_list_ids
+ assert_equal true, mails.first.read
+ # Personal Mail
+ assert_equal nil, mails[1].to_corp_or_alliance_id
+ assert_equal [5], mails[1].to_character_ids
+ assert_equal nil, mails[1].to_list_ids
+ # list Mail
+ assert_equal nil, mails[2].to_corp_or_alliance_id
+ assert_equal nil, mails[2].to_character_ids
+ assert_equal [128250439], mails[2].to_list_ids
+ assert_equal false, mails[2].read
+ # multi personal
+ assert_equal [5,6,7], mails[3].to_character_ids
+ # multi list
+ assert_equal [128250439,141157801], mails[4].to_list_ids
+ end
# Can we reassign a URL?
def test_assignment
View
15 test/xml/mail_messages.xml
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<eveapi version="2">
+ <currentTime>2009-12-02 00:46:10</currentTime>
+ <result>
+ <rowset name="mailMessages" key="messageID" columns="messageID,senderID,sentDate,title,toCorpOrAllianceID,toCharacterIDs,toListIDs,read">
+ <row messageID="290285276" senderID="1" sentDate="2009-12-01 01:04:00" title="Corp mail" toCorpOrAllianceID="4" toCharacterIDs="" toListIDs="" read="1" />
+ <row messageID="290285275" senderID="2" sentDate="2009-12-01 01:04:00" title="Personal mail" toCorpOrAllianceID="" toCharacterIDs="5" toListIDs="" read="1" />
+ <row messageID="290285274" senderID="2" sentDate="2009-12-01 01:04:00" title="Message to mailing list" toCorpOrAllianceID="" toCharacterIDs="" toListIDs="128250439" read="0" />
+ <row messageID="290285278" senderID="2" sentDate="2009-12-01 01:04:00" title="Multi Personal mail" toCorpOrAllianceID="" toCharacterIDs="5,6,7" toListIDs="" read="1" />
+ <row messageID="290285279" senderID="2" sentDate="2009-12-01 01:04:00" title="Multi Message to mailing list" toCorpOrAllianceID="" toCharacterIDs="" toListIDs="128250439,141157801" read="0" />
+ </rowset>
+ </result>
+ <cachedUntil>2009-12-02 01:16:10</cachedUntil>
+</eveapi>
+
View
12 test/xml/mailing_lists.xml
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<eveapi version="2">
+ <currentTime>2009-12-02 06:29:32</currentTime>
+ <result>
+ <rowset name="mailingLists" key="listID" columns="listID,displayName">
+ <row listID="128250439" displayName="EVETycoonMail" />
+ <row listID="128783669" displayName="EveMarketScanner" />
+ <row listID="141157801" displayName="Exploration Wormholes" />
+ </rowset>
+ </result>
+ <cachedUntil>2009-12-02 12:29:32</cachedUntil>
+</eveapi>
View
11 test/xml/notifications.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eveapi version="2">
+ <currentTime>2009-12-03 20:34:09</currentTime>
+ <result>
+ <rowset name="notifications" key="notificationID" columns="notificationID,typeID,senderID,sentDate,read">
+ <row notificationID="290369614" typeID="16" senderID="200076684" sentDate="2009-12-02 10:54:00" read="1"/>
+ <row notificationID="289645395" typeID="1" senderID="1000064" sentDate="2009-11-26 01:34:00" read="0"/>
+ </rowset>
+ </result>
+ <cachedUntil>2009-12-03 21:04:09</cachedUntil>
+</eveapi>

0 comments on commit b8ef35f

Please sign in to comment.
Something went wrong with that request. Please try again.