eve 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +174 -0
  3. data/PostInstall.txt +6 -0
  4. data/README.rdoc +126 -0
  5. data/Rakefile +128 -0
  6. data/features/support/env.rb +1 -0
  7. data/lib/eve.rb +31 -0
  8. data/lib/eve/api.rb +247 -0
  9. data/lib/eve/api/connectivity.rb +39 -0
  10. data/lib/eve/api/request.rb +74 -0
  11. data/lib/eve/api/response.rb +100 -0
  12. data/lib/eve/api/response/inspection.rb +62 -0
  13. data/lib/eve/api/response/rowset.rb +56 -0
  14. data/lib/eve/api/response/rowsets.rb +42 -0
  15. data/lib/eve/api/response/wrap_object.rb +15 -0
  16. data/lib/eve/api/services.rb +20 -0
  17. data/lib/eve/api/services/account.rb +12 -0
  18. data/lib/eve/api/services/character.rb +96 -0
  19. data/lib/eve/api/services/corporation.rb +150 -0
  20. data/lib/eve/api/services/eve.rb +76 -0
  21. data/lib/eve/api/services/map.rb +45 -0
  22. data/lib/eve/api/services/misc.rb +24 -0
  23. data/lib/eve/api/services/server.rb +20 -0
  24. data/lib/eve/core_extensions.rb +3 -0
  25. data/lib/eve/core_extensions/hash.rb +51 -0
  26. data/lib/eve/core_extensions/string.rb +11 -0
  27. data/lib/eve/dependencies.rb +18 -0
  28. data/lib/eve/errors.rb +129 -0
  29. data/lib/eve/errors/authentication_errors.rb +33 -0
  30. data/lib/eve/errors/internal_errors.rb +64 -0
  31. data/lib/eve/errors/miscellaneous_errors.rb +19 -0
  32. data/lib/eve/errors/user_input_errors.rb +62 -0
  33. data/lib/eve/helpers.rb +12 -0
  34. data/lib/eve/helpers/javascript_helper.rb +198 -0
  35. data/lib/eve/helpers/view_helper.rb +13 -0
  36. data/lib/eve/trust.rb +88 -0
  37. data/lib/eve/trust/controller_helpers.rb +90 -0
  38. data/lib/eve/trust/igb_interface.rb +88 -0
  39. data/lib/eve/trust/mime_types.rb +4 -0
  40. data/script/console +10 -0
  41. data/script/console.cmd +1 -0
  42. data/script/destroy +14 -0
  43. data/script/destroy.cmd +1 -0
  44. data/script/generate +14 -0
  45. data/script/generate.cmd +1 -0
  46. data/spec/lib/eve/api/calls/account/characters_spec.rb +22 -0
  47. data/spec/lib/eve/api/calls/character/account_balance_spec.rb +21 -0
  48. data/spec/lib/eve/api/calls/character/asset_list_spec.rb +23 -0
  49. data/spec/lib/eve/api/calls/character/character_sheet_spec.rb +51 -0
  50. data/spec/lib/eve/api/calls/character/fac_war_stats_spec.rb +31 -0
  51. data/spec/lib/eve/api/calls/character/industry_jobs_spec.rb +27 -0
  52. data/spec/lib/eve/api/calls/character/kill_log_spec.rb +27 -0
  53. data/spec/lib/eve/api/calls/character/mail_messages_spec.rb +21 -0
  54. data/spec/lib/eve/api/calls/character/mailing_lists_spec.rb +21 -0
  55. data/spec/lib/eve/api/calls/character/market_orders_spec.rb +21 -0
  56. data/spec/lib/eve/api/calls/character/medals_spec.rb +24 -0
  57. data/spec/lib/eve/api/calls/character/research_spec.rb +21 -0
  58. data/spec/lib/eve/api/calls/character/skill_in_training_spec.rb +44 -0
  59. data/spec/lib/eve/api/calls/character/skill_queue_spec.rb +21 -0
  60. data/spec/lib/eve/api/calls/character/standings_spec.rb +26 -0
  61. data/spec/lib/eve/api/calls/character/wallet_journal_spec.rb +21 -0
  62. data/spec/lib/eve/api/calls/character/wallet_transactions_spec.rb +21 -0
  63. data/spec/lib/eve/api/calls/character_portrait_spec.rb +17 -0
  64. data/spec/lib/eve/api/calls/corporation/account_balances_spec.rb +21 -0
  65. data/spec/lib/eve/api/calls/corporation/asset_list_spec.rb +25 -0
  66. data/spec/lib/eve/api/calls/corporation/container_log_spec.rb +23 -0
  67. data/spec/lib/eve/api/calls/corporation/corporation_sheet_spec.rb +36 -0
  68. data/spec/lib/eve/api/calls/corporation/fac_war_stats_spec.rb +23 -0
  69. data/spec/lib/eve/api/calls/corporation/industry_jobs_spec.rb +30 -0
  70. data/spec/lib/eve/api/calls/corporation/kill_log_spec.rb +27 -0
  71. data/spec/lib/eve/api/calls/corporation/market_orders_spec.rb +22 -0
  72. data/spec/lib/eve/api/calls/corporation/medals_spec.rb +21 -0
  73. data/spec/lib/eve/api/calls/corporation/member_medals_spec.rb +21 -0
  74. data/spec/lib/eve/api/calls/corporation/member_security_log_spec.rb +24 -0
  75. data/spec/lib/eve/api/calls/corporation/member_security_spec.rb +25 -0
  76. data/spec/lib/eve/api/calls/corporation/member_tracking_spec.rb +22 -0
  77. data/spec/lib/eve/api/calls/corporation/shareholders_spec.rb +23 -0
  78. data/spec/lib/eve/api/calls/corporation/standings_spec.rb +30 -0
  79. data/spec/lib/eve/api/calls/corporation/starbase_detail_spec.rb +32 -0
  80. data/spec/lib/eve/api/calls/corporation/starbase_list_spec.rb +22 -0
  81. data/spec/lib/eve/api/calls/corporation/titles_spec.rb +26 -0
  82. data/spec/lib/eve/api/calls/corporation/wallet_journal_spec.rb +22 -0
  83. data/spec/lib/eve/api/calls/corporation/wallet_transactions_spec.rb +22 -0
  84. data/spec/lib/eve/api/calls/empty_call_spec.rb +29 -0
  85. data/spec/lib/eve/api/calls/eve/alliance_list_spec.rb +26 -0
  86. data/spec/lib/eve/api/calls/eve/certificate_tree_spec.rb +18 -0
  87. data/spec/lib/eve/api/calls/eve/character_id_spec.rb +27 -0
  88. data/spec/lib/eve/api/calls/eve/conquerable_station_list_spec.rb +11 -0
  89. data/spec/lib/eve/api/calls/eve/error_list_spec.rb +21 -0
  90. data/spec/lib/eve/api/calls/eve/fac_war_stats_spec.rb +25 -0
  91. data/spec/lib/eve/api/calls/eve/fac_war_top_stats_spec.rb +54 -0
  92. data/spec/lib/eve/api/calls/eve/ref_types_spec.rb +11 -0
  93. data/spec/lib/eve/api/calls/eve/skill_tree_spec.rb +17 -0
  94. data/spec/lib/eve/api/calls/map/fac_war_systems_spec.rb +11 -0
  95. data/spec/lib/eve/api/calls/map/jumps_spec.rb +11 -0
  96. data/spec/lib/eve/api/calls/map/kills_spec.rb +15 -0
  97. data/spec/lib/eve/api/calls/map/sovereignty_spec.rb +11 -0
  98. data/spec/lib/eve/api/calls/server_status_spec.rb +24 -0
  99. data/spec/lib/eve/api/request_spec.rb +17 -0
  100. data/spec/lib/eve/api/response/error_spec.rb +13 -0
  101. data/spec/lib/eve/api/response/rowset_spec.rb +28 -0
  102. data/spec/lib/eve/api/response_spec.rb +79 -0
  103. data/spec/lib/eve/api_spec.rb +13 -0
  104. data/spec/lib/eve/core_extensions/hash_spec.rb +23 -0
  105. data/spec/lib/eve/core_extensions/string_spec.rb +8 -0
  106. data/spec/lib/eve/helpers/javascript_helper_spec.rb +80 -0
  107. data/spec/lib/eve/helpers/view_helper_spec.rb +12 -0
  108. data/spec/lib/eve/trust/controller_helpers_spec.rb +70 -0
  109. data/spec/lib/eve/trust/igb_interface_spec.rb +102 -0
  110. data/spec/rcov.opts +2 -0
  111. data/spec/readme_spec.rb +36 -0
  112. data/spec/sample_api_key.yml +20 -0
  113. data/spec/spec.opts +4 -0
  114. data/spec/spec_helper.rb +22 -0
  115. data/spec/support/behaves_like_rowset.rb +50 -0
  116. data/spec/support/controllers/trust_controller.rb +7 -0
  117. data/spec/support/jpg/mock_portrait.jpg +0 -0
  118. data/spec/support/mock_api_helpers.rb +41 -0
  119. data/spec/support/xml/account/characters.xml +15 -0
  120. data/spec/support/xml/character/account_balance.xml +10 -0
  121. data/spec/support/xml/character/asset_list.xml +50 -0
  122. data/spec/support/xml/character/character_sheet.xml +65 -0
  123. data/spec/support/xml/character/fac_war_stats.xml +20 -0
  124. data/spec/support/xml/character/industry_jobs.xml +70 -0
  125. data/spec/support/xml/character/kill_log.xml +51 -0
  126. data/spec/support/xml/character/mail_messages.xml +12 -0
  127. data/spec/support/xml/character/mailing_lists.xml +12 -0
  128. data/spec/support/xml/character/market_orders.xml +11 -0
  129. data/spec/support/xml/character/medals.xml +13 -0
  130. data/spec/support/xml/character/research.xml +13 -0
  131. data/spec/support/xml/character/skill_in_training.xml +14 -0
  132. data/spec/support/xml/character/skill_not_in_training.xml +7 -0
  133. data/spec/support/xml/character/skill_queue.xml +11 -0
  134. data/spec/support/xml/character/standings.xml +32 -0
  135. data/spec/support/xml/character/wallet_journal.xml +39 -0
  136. data/spec/support/xml/character/wallet_transactions.xml +44 -0
  137. data/spec/support/xml/corporation/account_balance.xml +15 -0
  138. data/spec/support/xml/corporation/asset_list.xml +50 -0
  139. data/spec/support/xml/corporation/container_log.xml +32 -0
  140. data/spec/support/xml/corporation/fac_war_stats.xml +19 -0
  141. data/spec/support/xml/corporation/industry_jobs.xml +70 -0
  142. data/spec/support/xml/corporation/kill_log.xml +51 -0
  143. data/spec/support/xml/corporation/market_orders.xml +37 -0
  144. data/spec/support/xml/corporation/medals.xml +8 -0
  145. data/spec/support/xml/corporation/member_corporation_sheet.xml +51 -0
  146. data/spec/support/xml/corporation/member_medals.xml +10 -0
  147. data/spec/support/xml/corporation/member_security.xml +21 -0
  148. data/spec/support/xml/corporation/member_security_log.xml +55 -0
  149. data/spec/support/xml/corporation/member_tracking.xml +18 -0
  150. data/spec/support/xml/corporation/non_member_corporation_sheet.xml +30 -0
  151. data/spec/support/xml/corporation/shareholders.xml +11 -0
  152. data/spec/support/xml/corporation/standings.xml +33 -0
  153. data/spec/support/xml/corporation/starbase_detail.xml +33 -0
  154. data/spec/support/xml/corporation/starbase_list.xml +17 -0
  155. data/spec/support/xml/corporation/titles.xml +34 -0
  156. data/spec/support/xml/corporation/wallet_journal.xml +40 -0
  157. data/spec/support/xml/corporation/wallet_transactions.xml +12 -0
  158. data/spec/support/xml/errors/106.xml +5 -0
  159. data/spec/support/xml/errors/516.xml +5 -0
  160. data/spec/support/xml/eve/alliance_list.xml +22 -0
  161. data/spec/support/xml/eve/certificate_tree.xml +49 -0
  162. data/spec/support/xml/eve/character_id.xml +15 -0
  163. data/spec/support/xml/eve/conquerable_station_list.xml +24 -0
  164. data/spec/support/xml/eve/error_list.xml +78 -0
  165. data/spec/support/xml/eve/fac_war_stats.xml +31 -0
  166. data/spec/support/xml/eve/fac_war_top_stats.xml +238 -0
  167. data/spec/support/xml/eve/ref_types.xml +105 -0
  168. data/spec/support/xml/eve/skill_tree.xml +52 -0
  169. data/spec/support/xml/map/fac_war_systems.xml +180 -0
  170. data/spec/support/xml/map/jumps.xml +166 -0
  171. data/spec/support/xml/map/kills.xml +191 -0
  172. data/spec/support/xml/map/sovereignty.xml +20 -0
  173. data/spec/support/xml/rowset_with_mismatched_attributes.xml +6 -0
  174. data/spec/support/xml/server/server_status.xml +9 -0
  175. metadata +364 -0
@@ -0,0 +1,19 @@
1
+ module Eve
2
+ module Errors
3
+ # 9xx - Miscellaneous
4
+ class MiscellaneousError < StandardError; end
5
+
6
+ module MiscellaneousErrors
7
+ # 900 - Beta in progress, access denied.
8
+ class BetaInProgress < MiscellaneousError; end
9
+ # 901 - Web site database temporarily disabled.
10
+ class SiteDatabaseDisabled < MiscellaneousError; end
11
+ # 902 - EVE backend database temporarily disabled.
12
+ class BackendDatabaseDisabled < MiscellaneousError; end
13
+ # 903 - Rate limited [#]: please obey all cachedUntil timers.
14
+ class RateLimited < MiscellaneousError; end
15
+ # 999 - User forced test error condition.
16
+ class TestErrorForced < MiscellaneousError; end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ module Eve
2
+ module Errors
3
+ # 1xx - User Input Error
4
+ class UserInputError < StandardError; end
5
+
6
+ module UserInputErrors
7
+ # 100 - Expected beforeRefID = 0: wallet not previously loaded.
8
+ class WalletNotLoaded < UserInputError; end
9
+ # 101 - Wallet exhausted: retry after #.
10
+ class WalletExhausted < UserInputError; end
11
+ # 102 - Expected beforeRefID [#], got [#]: wallet previously loaded.
12
+ class WalletPreviouslyLoaded < UserInputError; end
13
+ # 103 - Already returned one week of data: retry after #.
14
+ class RetryLater < UserInputError; end
15
+ # 104 - GetAccountByKey(#): key not found.
16
+ class KeyNotFound < UserInputError; end
17
+ # 105 - Invalid characterID.
18
+ class InvalidCharacterID < UserInputError; end
19
+ # 106 - Must provide userID parameter for authentication.
20
+ class MissingUserID < UserInputError; end
21
+ # 107 - Invalid beforeRefID provided.
22
+ class InvalidBeforeRefID < UserInputError; end
23
+ # 108 - Invalid accountKey provided.
24
+ class InvalidAccountKey < UserInputError; end
25
+ # 109 - Invalid accountKey: must be in the range 1000 to 1006.
26
+ class AccountKeyOutOfBounds < UserInputError; end
27
+ # 110 - Invalid beforeTransID provided.
28
+ class InvalidBeforeTransID < UserInputError; end
29
+ # 111 - '#' is not a valid integer.
30
+ class InvalidInteger < UserInputError; end
31
+ # 112 - Version mismatch.
32
+ class VersionMismatch < UserInputError; end
33
+ # 113 - Version escalation is not allowed at this time.
34
+ class VersionEscalationNotAllowed < UserInputError; end
35
+ # 114 - Invalid itemID provided.
36
+ class InvalidItemID < UserInputError; end
37
+ # 115 - Assets already downloaded: retry after #.
38
+ class AssetsAlreadyDownloaded < UserInputError; end
39
+ # 116 - Industry jobs already downloaded: retry after #.
40
+ class IndustryJobsAlreadyDownloaded < UserInputError; end
41
+ # 117 - Market orders already downloaded: retry after #.
42
+ class MarketOrdersAlreadyDownloaded < UserInputError; end
43
+ # 118 - Expected beforeKillID = 0: wallet not previously loaded.
44
+ class KillsNotLoaded < UserInputError; end
45
+ # 119 - Kills exhausted: retry after #.
46
+ class KillsExhausted < UserInputError; end
47
+ # 120 - Expected beforeKillID [#] but supplied [#]: kills previously loaded.
48
+ class KillsPreviouslyLoaded < UserInputError; end
49
+ # 121 - Invalid beforeKillID provided.
50
+ class InvalidBeforeKillID < UserInputError; end
51
+ # 122 - Invalid or missing list of names.
52
+ class InvalidNameList < UserInputError; end
53
+ # 123 - Invalid or missing list of IDs.
54
+ class InvalidIDList < UserInputError; end
55
+ # 124 - Character not enlisted in Factional Warfare.
56
+ class CharacterNotEnlisted < UserInputError; end
57
+ # 125 - Corporation not enlisted in Factional Warfare.
58
+ class CorporationNotEnlisted < UserInputError; end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,12 @@
1
+ require 'eve/helpers/view_helper'
2
+ require 'eve/helpers/javascript_helper'
3
+
4
+ module Eve
5
+ module Helpers
6
+ if defined?(ActionView::Base)
7
+ ActionView::Base.send(:include, Eve::Helpers::ViewHelper)
8
+ ActionView::Base.send(:include, Eve::Helpers::JavascriptHelper)
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,198 @@
1
+ module Eve
2
+ module Helpers
3
+ # In addition to the helpers listed below, this library also exposes the "igb" method as described in
4
+ # Eve::Trust.
5
+ module JavascriptHelper
6
+ # Returns the numeric type ID for a string, so you don't have to manage "magic numbers" in your application.
7
+ # The argument can be a string or a symbol, and is case insensitive. Underscores will be converted to spaces.
8
+ #
9
+ # Examples:
10
+ # type_id('alliance') # => 16159
11
+ # type_id('character') # => 1377
12
+ # type_id('corporation') # => 2
13
+ # type_id('constellation') # => 4
14
+ # type_id('region') # => 3
15
+ # type_id('Solar System') # => 5
16
+ # type_id(:solar_system) # => 5
17
+ # type_id(:station) # => 3867
18
+ #
19
+ def type_id(which)
20
+ which = which.to_s.humanize unless which.kind_of?(String)
21
+ which.downcase!
22
+ case which
23
+ when 'alliance' then 16159
24
+ when 'character' then 1377
25
+ when 'corporation' then 2
26
+ when 'constellation' then 4
27
+ when 'region' then 3
28
+ when 'solar system', 'solarsystem' then 5
29
+ when 'station' then 3867
30
+ else raise ArgumentError, "Unknown type: #{which}"
31
+ end
32
+ end
33
+
34
+ # Creates a hyperlink that results in opening the client's EVE mail inbox.
35
+ def link_to_evemail(text, *args)
36
+ link_to_function(text, "CCPEVE.openEveMail()", *args)
37
+ end
38
+
39
+ # Creates a hyperlink that results in the "show info" dialog being displayed on the client's screen.
40
+ # If item_id is given, the show info window will open for that item.
41
+ #
42
+ # type_id (Number)
43
+ # Type ID of item to show info on.
44
+ # item_id (Number)
45
+ # Optional item ID of specific item of type type_id to show info on. This is required for specific types of
46
+ # items, such as solar systems, stations, regions, and constellations.
47
+ #
48
+ def link_to_info(text, type_id, item_id = nil, *args)
49
+ function = "CCPEVE.showInfo(#{type_id.inspect}"
50
+ function.concat ", #{item_id.inspect}" if item_id
51
+ function.concat ")"
52
+ link_to_function text, function, *args
53
+ end
54
+
55
+ # Creates a hyperlink that results in opening the preview window for type_id.
56
+ #
57
+ # type_id (Number)
58
+ # Type ID of item to preview.
59
+ #
60
+ def link_to_preview(text, type_id, *args)
61
+ link_to_function text, "CCPEVE.showPreview(#{type_id.inspect})", *args
62
+ end
63
+
64
+ # Creates a hyperlink that results in showing the route to the destination_id from the source_id.
65
+ # If source_id is not given, the source system is taken to be the system the user is currently in.
66
+ #
67
+ def link_to_route(text, destination_id, source_id = nil, *args)
68
+ function = "CCPEVE.showRouteTo(#{destination_id.inspect}"
69
+ function.concat ", #{source_id.inspect}" if source_id
70
+ function.concat ")"
71
+ link_to_function text, function, *args
72
+ end
73
+
74
+ # Creates a hyperlink that results in opening the map. If system_id is given, the map will focus on that system.
75
+ #
76
+ # system_id (Number)
77
+ # Optional ID of solar system to focus map on.
78
+ #
79
+ def link_to_map(text, system_id = nil, *args)
80
+ link_to_function text, "CCPEVE.showMap(#{system_id ? system_id.inspect : ''})", *args
81
+ end
82
+
83
+ # Creates a hyperlink that results in opening the fitting window and displays the fitting represented by fitting.
84
+ #
85
+ # fitting (String)
86
+ # A Ship DNA string.
87
+ #
88
+ # See http://wiki.eveonline.com/en/wiki/Ship_DNA for details
89
+ def link_to_fitting(text, ship_dna_string, *args)
90
+ link_to_function text, "CCPEVE.showFitting(#{ship_dna_string.inspect})", *args
91
+ end
92
+
93
+ # Creatse a hyperlink that results in opening the contract window and displaying the contract represented by the
94
+ # contract_id argument. Contracts are, however, assigned per-solar-system, and so a solar_system_id must also be
95
+ # provided.
96
+ #
97
+ # solar_system_id (Number)
98
+ # The ID number of the solar system in which the contract is located.
99
+ # contract_id (Number)
100
+ # The ID number of the contract to display.
101
+ def link_to_contract(text, solar_system_id, contract_id, *args)
102
+ link_to_function text, "CCPEVE.showContract(#{solar_system_id.inspect}, #{contract_id.inspect})", *args
103
+ end
104
+
105
+ # Creates a hyperlink which results in opening the market details window and displays the information about the
106
+ # item represented by type_id.
107
+ #
108
+ # typeID (Number)
109
+ # Type ID to display market details about
110
+ #
111
+ def link_to_market_details(text, type_id, *args)
112
+ link_to_function text, "CCPEVE.showMarketDetails(#{type_id.inspect})", *args
113
+ end
114
+
115
+ # Produces a hyperlink that will result in a pop-up a trust prompt in the client, allowing the user to either
116
+ # grant the trust request, ignore it, or always ignore trust requests from your site.
117
+ #
118
+ # trust_url (String)
119
+ # This is a fully-qualified domain name and path (e.g. http://wiki.eveonline.com/w/) to which your site would
120
+ # like the user to grant trust.
121
+ #
122
+ # The page will not be automatically refreshed if the user grants the trust request. Trust will take effect the
123
+ # next time the user refreshes the page, or navigates within the site.
124
+ #
125
+ # Note that trust_url is processed and only the protocol, domain and path will be used from it. If you supply a
126
+ # query string or anchor, they will be discarded. It is recommended that you primarily pass in only
127
+ # fully-qualified domain names without paths (e.g. http://wiki.eveonline.com instead of
128
+ # http://wiki.eveonline.com/w/index.php), as this avoids pestering the user for trust on every page.
129
+ #
130
+ def link_to_trust_request(text, trust_url = "http://#{request.host}/", *args)
131
+ trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
132
+ link_to_function text, "CCPEVE.requestTrust(#{trust_url.inspect})", *args
133
+ end
134
+
135
+ # This will generate a method call that produces a pop-up a trust prompt in the client, allowing the user to
136
+ # either grant the trust request, ignore it, or always ignore trust requests from your site.
137
+ #
138
+ # trust_url (String)
139
+ # This is a fully-qualified domain name and path (e.g. http://wiki.eveonline.com/w/) to which your site would
140
+ # like the user to grant trust.
141
+ #
142
+ # The page will not be automatically refreshed if the user grants the trust request. Trust will take effect the
143
+ # next time the user refreshes the page, or navigates within the site.
144
+ #
145
+ # Note that trust_url is processed and only the protocol, domain and path will be used from it. If you supply a
146
+ # query string or anchor, they will be discarded. It is recommended that you primarily pass in only
147
+ # fully-qualified domain names without paths (e.g. http://wiki.eveonline.com instead of
148
+ # http://wiki.eveonline.com/w/index.php), as this avoids pestering the user for trust on every page.
149
+ #
150
+ def request_trust(trust_url = "http://#{request.host}/", *args)
151
+ trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
152
+ javascript_tag "CCPEVE.requestTrust(#{trust_url.inspect});", *args
153
+ end
154
+
155
+ # Sets the client's autopilot destination to the specified solar system.
156
+ #
157
+ # solar_system_id (Number)
158
+ # The numerical identifier of the solar system to which you wish to set the client's autopilot destination.
159
+ #
160
+ # This method requires that the user grant Trust to the calling site.
161
+ def link_to_destination(text, solar_system_id, *args)
162
+ link_to_function text, "CCPEVE.setDestination(#{solar_system_id.inspect})", *args
163
+ end
164
+
165
+ # Adds the specified solar system to the end of the client's autopilot route. If the solar system is already in
166
+ # the route, no changes are made and the method fails silently.
167
+ #
168
+ # solar_system_id (Number)
169
+ # The numerical identifier of the solar system which you wish to append to the client's autopilot route.
170
+ #
171
+ # This method requires that the user grant Trust to the calling site.
172
+ def link_to_waypoint(text, solar_system_id, *args)
173
+ link_to_function text, "CCPEVE.addWaypoint(#{solar_system_id.inspect})", *args
174
+ end
175
+
176
+ # Causes the user to attempt to join the named channel. Normal channel access control rules apply. If the user is
177
+ # unable to join the channel, the method fails silently.
178
+ #
179
+ # channel_name (String)
180
+ # The name of the channel which the user will join.
181
+ #
182
+ # This method requires that the user grant Trust to the calling site.
183
+ def link_to_channel(text, channel_name, *args)
184
+ link_to_function text, "CCPEVE.joinChannel(#{channel_name.inspect})", *args
185
+ end
186
+
187
+ # Causes the user to subscribe to the named mailing list.
188
+ #
189
+ # mailing_list_name (String)
190
+ # The name of the mailing list which the user will join.
191
+ #
192
+ # This method requires that the user grant Trust to the calling site.
193
+ def link_to_mailing_list(text, mailing_list_name, *args)
194
+ link_to_function text, "CCPEVE.joinMailingList(#{mailing_list_name.inspect})", *args
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,13 @@
1
+ module Eve
2
+ module Helpers
3
+ # Provides various IGB-specific helper methods.
4
+ module ViewHelper
5
+ def self.included(base)
6
+ base.instance_eval do
7
+ delegate :igb, :to => :controller
8
+ delegate :igb?, :to => :igb
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,88 @@
1
+ require 'eve/trust/mime_types'
2
+ require 'eve/trust/controller_helpers'
3
+ require 'eve/trust/igb_interface'
4
+
5
+ module Eve
6
+ # == Trust
7
+ # The primary purpose for the ActionController is to figure out which View should be rendered, and what data to send
8
+ # to that View. In keeping with this design, a few helper methods have been established that allow you to establish
9
+ # trust with the In-Game Browser (IGB), which in turn provides access to more useful information such as the player's
10
+ # current location. To establish trust with a compatible browser, simply add one line to your controller:
11
+ #
12
+ # class AnyController < ApplicationController
13
+ # requires_trust
14
+ # end
15
+ #
16
+ # This will cause the in-game browser to prompt the user, asking him/her to complete the handshake. If they refuse,
17
+ # the page will not load. To establish _optional_ trust -- that is, to allow the page to load even if the user hasn't
18
+ # granted the trust request -- you can use +prefers_trust+ instead:
19
+ #
20
+ # class AnyController < ApplicationController
21
+ # prefers_trust
22
+ # end
23
+ #
24
+ # Both methods also accept a custom trust request message that will be shown to the user when they are prompted:
25
+ #
26
+ # class AnyController < ApplicationController
27
+ # prefers_trust "To take full advantage of the features on this site, please grant this trust request."
28
+ # end
29
+ #
30
+ # == IGB Headers
31
+ # After trust has been established, the IGB sends additional content headers to the server with every request. These
32
+ # headers contain the most up-to-date information regarding the current user, his/her location, his/her character ID,
33
+ # and so on. The character ID could, for example, be used in conjunction with Eve::API to show the character's
34
+ # portrait in a forum.
35
+ #
36
+ # To gain access to this extra information, use the +igb+ method:
37
+ #
38
+ # class AnyController < ApplicationController
39
+ # . . .
40
+ # def index
41
+ # if igb? && igb.trusted? # if the client is using the IGB and trust has been established
42
+ # @solar_system = igb.solar_system_name # then make a note of the current solar system
43
+ # @character_id = igb.character_id # and the character ID
44
+ # else
45
+ # . . . # handle a non-IGB browser such as Internet Explorer or Firefox.
46
+ # end
47
+ # end
48
+ #
49
+ # To find out which methods are exposed by the +igb+ method, take a look at Eve::Trust::IgbInterface.
50
+ #
51
+ # == View Format
52
+ # In Rails, the View is usually rendered in HTML format. That means the view template is usually called
53
+ # +some_action_name.html.erb+ , where "some_action_name" is the name of the current action and "html" is the file
54
+ # format. This library exposes a new format, "igb", which allows you to render an IGB-specific response. This response
55
+ # is expected to be in IGB-compatible HTML format. Here's an example of what an IGB file might look like:
56
+ #
57
+ # <%=link_to_evemail "Check Your Mail!"%>
58
+ # <%if igb.trusted?%>
59
+ # <p>Thanks for your trust! I see you're currently in <%=igb.solar_system_name%>.</p>
60
+ # <p>Here's some information about our secret headquarters:</p>
61
+ # <ul>
62
+ # <li><%=link_to_route "Click For Directions", "Jita"%></li>
63
+ # <li><%=link_to_map "Show On Map", "Jita"%></li>
64
+ # </ul>
65
+ # <%end%>
66
+ #
67
+ # For more information about the various helpers available to your IGB-specific views, take a look at
68
+ # Eve::Helpers::JavascriptHelper.
69
+ #
70
+ # If the client is using the EVE In-Game Browser, then the "action_name.igb.erb" file will be automatically used,
71
+ # provided it exists. If the matching file is not found, then "action_name.html.erb" will be used in its place, just
72
+ # as if the client were using any other browser such as Internet Explorer or Firefox. You can also explicitly require
73
+ # that the .igb file be rendered using the +set_igb+ method:
74
+ #
75
+ # class AnyController < ApplicationController
76
+ # before_filter :check_for_igb_requirement
77
+ # private
78
+ # def check_for_igb_requirement
79
+ # if (some_condition)
80
+ # set_igb # force the IGB template for this action to be rendered
81
+ # end
82
+ # end
83
+ # end
84
+ #
85
+ module Trust
86
+
87
+ end
88
+ end
@@ -0,0 +1,90 @@
1
+ module Eve
2
+ module Trust
3
+ module ControllerHelpers
4
+ # None of this exists unless ActionController exists first.
5
+ if defined?(ActionController::Base)
6
+ class ::ApplicationController < ActionController::Base
7
+ hide_action :trust_message, :trust_message=, :detect_igb, :template_exists?,
8
+ :set_igb_or_default, :default_template_exists?, :mock_methods_for_testing!,
9
+ :igb, :igb?, :set_igb, :require_trust, :prefer_trust, :deliver_trust_message
10
+ class_inheritable_accessor :trust_message
11
+ read_inheritable_attribute(:trust_message) || write_inheritable_attribute(:trust_message,
12
+ "This web site is requesting your trust.")
13
+ delegate :igb?, :to => :igb
14
+ attr_reader :igb
15
+ before_filter :detect_igb
16
+
17
+ def require_trust(trust_message = self.class.trust_message)
18
+ if igb? && !igb.trusted?
19
+ deliver_trust_message(trust_message)
20
+ return false
21
+ end
22
+ true
23
+ end
24
+
25
+ def prefer_trust(trust_message = self.class.trust_message)
26
+ if igb? && !igb.trusted?
27
+ deliver_trust_message(trust_message)
28
+ end
29
+ true
30
+ end
31
+
32
+ def deliver_trust_message(trust_message = self.class.trust_message)
33
+ trust_uri = "http://#{request.host}/"
34
+ head 'eve.trustme' => "#{trust_uri}::#{trust_message}"
35
+ end
36
+
37
+ def detect_igb
38
+ @igb = Eve::Trust::IgbInterface.new(request)
39
+ mock_methods_for_testing! if request.headers['mock_methods']
40
+ if igb.igb?
41
+ set_igb_or_default
42
+ end
43
+ end
44
+
45
+ def set_igb_or_default
46
+ if default_template_exists? :igb
47
+ set_igb
48
+ end
49
+ end
50
+
51
+ def set_igb
52
+ request.format = :igb
53
+ end
54
+
55
+ def default_template_exists?(format = response.template.template_format)
56
+ template_exists?(default_template_name, format)
57
+ end
58
+
59
+ def template_exists?(template_name, format = response.template.template_format)
60
+ self.view_paths.find_template(template_name, format)
61
+ rescue ActionView::MissingTemplate, Errno::ENOENT
62
+ false
63
+ end
64
+
65
+ # a quick and dirty mocking solution. I should really make it better, but it works fine, and doesn't interfere
66
+ # with anything in prod, so I'll procrastinate a bit.
67
+ def mock_methods_for_testing! #:nodoc:
68
+ request.headers['mock_methods'].each do |method_name, return_value|
69
+ (class << self; self; end).instance_eval do
70
+ define_method(method_name) { |*not_used| return_value }
71
+ end
72
+ end
73
+ end
74
+
75
+ class << self
76
+ def requires_trust(message = trust_message)
77
+ self.trust_message = message if message != trust_message
78
+ before_filter :require_trust
79
+ end
80
+
81
+ def prefers_trust(message = trust_message)
82
+ self.trust_message = message if message != trust_message
83
+ before_filter :prefer_trust
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end