eve 1.0.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +43 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +109 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +24 -3
  6. data/Rakefile +26 -117
  7. data/eve.gemspec +35 -0
  8. data/lib/eve.rb +5 -10
  9. data/lib/eve/api.rb +3 -1
  10. data/lib/eve/api/response/inspection.rb +1 -1
  11. data/lib/eve/api/response/rowsets.rb +1 -1
  12. data/lib/eve/dependencies.rb +42 -12
  13. data/lib/eve/deprecation.rb +3 -0
  14. data/lib/eve/javascript_helper.rb +196 -0
  15. data/lib/eve/trust.rb +1 -2
  16. data/lib/eve/trust/controller_helpers.rb +62 -66
  17. data/lib/eve/trust/igb_interface.rb +14 -10
  18. data/lib/eve/version.rb +8 -0
  19. data/spec/controllers/controller_helpers_spec.rb +91 -0
  20. data/spec/{lib/eve/helpers → helpers}/javascript_helper_spec.rb +2 -2
  21. data/spec/helpers/view_helper_spec.rb +7 -0
  22. data/spec/lib/eve/api/calls/eve/character_id_spec.rb +8 -8
  23. data/spec/lib/eve/api/calls/server_status_spec.rb +4 -0
  24. data/spec/lib/eve/api/request_spec.rb +1 -0
  25. data/spec/lib/eve/trust/igb_interface_spec.rb +5 -5
  26. data/spec/spec_helper.rb +42 -1
  27. data/spec/support/controllers/trust_controller.rb +18 -1
  28. data/spec/support/mock_api_helpers.rb +6 -1
  29. data/spec/support/views/trust/html_and_igb.html.erb +1 -0
  30. data/spec/support/views/trust/html_and_igb.igb.erb +1 -0
  31. data/spec/support/views/trust/html_only.html.erb +1 -0
  32. data/spec/support/views/trust/igb_only.igb.erb +1 -0
  33. metadata +226 -169
  34. data/Manifest.txt +0 -174
  35. data/PostInstall.txt +0 -6
  36. data/features/support/env.rb +0 -1
  37. data/lib/eve/core_extensions.rb +0 -3
  38. data/lib/eve/core_extensions/hash.rb +0 -51
  39. data/lib/eve/core_extensions/string.rb +0 -11
  40. data/lib/eve/helpers.rb +0 -12
  41. data/lib/eve/helpers/javascript_helper.rb +0 -198
  42. data/lib/eve/helpers/view_helper.rb +0 -13
  43. data/script/console +0 -10
  44. data/script/console.cmd +0 -1
  45. data/script/destroy +0 -14
  46. data/script/destroy.cmd +0 -1
  47. data/script/generate +0 -14
  48. data/script/generate.cmd +0 -1
  49. data/spec/lib/eve/helpers/view_helper_spec.rb +0 -12
  50. data/spec/lib/eve/trust/controller_helpers_spec.rb +0 -70
@@ -217,7 +217,8 @@ module Eve
217
217
  [@options[:includes]].flatten.each do |mod|
218
218
  next unless mod
219
219
  mod = mod.to_s unless mod.kind_of?(String)
220
- eigenclass.send(:include, "::Eve::API::Services::#{mod.camelize}".constantize)
220
+ mod = "::Eve::API::Services::#{mod.camelize}".constantize
221
+ eigenclass.send(:include, mod)
221
222
  end
222
223
  end
223
224
 
@@ -226,6 +227,7 @@ module Eve
226
227
  next unless mod
227
228
  instance_variable_set("@#{mod}", ::Eve::API.new(options.merge(:includes => mod, :submodules => nil)))
228
229
  eigenclass.send(:attr_reader, mod)
230
+ eigenclass.send(:public, mod)
229
231
  end
230
232
  end
231
233
 
@@ -5,7 +5,7 @@ module Eve
5
5
  def protected_instance_variables
6
6
  (respond_to?(:content) && !content.blank? ? [] : ["@content"]) +
7
7
  #(respond_to?(:rowsets) && !rowsets.empty? ? rowsets.collect { |r| "@#{r.name}" } : []) +
8
- %w(@rowsets @options @xml @columns @row @name)
8
+ [:@rowsets, :@options, :@xml, :@columns, :@row, :@name]
9
9
  end
10
10
 
11
11
  def inspected_name
@@ -33,7 +33,7 @@ module Eve
33
33
 
34
34
  def value_for(candidate)
35
35
  candidate.kind_of?(String) ? YAML::load(candidate) : candidate
36
- rescue
36
+ rescue (defined?(Psych::SyntaxError) ? Psych::SyntaxError : StandardError)
37
37
  candidate
38
38
  end
39
39
  end
@@ -1,18 +1,48 @@
1
- unless defined?(Gem)
2
- require 'rubygems'
3
- gem 'hpricot', '>= 0.8.2'
4
- gem 'actionpack', '>= 2.3.5'
5
- gem 'activesupport', '>= 2.3.5'
6
- end
7
-
8
1
  require 'net/http'
9
2
  require 'hpricot'
10
3
  require 'yaml'
11
- require 'action_pack'
12
- require 'action_controller'
13
- require 'action_view'
4
+ require 'sc-core-ext'
14
5
 
15
6
  gem_path = File.expand_path(File.dirname(__FILE__), "..")
16
7
  $LOAD_PATH.unshift gem_path
17
- ActiveSupport::Dependencies.load_paths.unshift gem_path
18
- ActiveSupport::Dependencies.load_once_paths.unshift gem_path
8
+
9
+ module Eve
10
+ autoload :Errors, "eve/errors"
11
+ autoload :API, "eve/api"
12
+ autoload :Errors, "eve/errors"
13
+ autoload :JavascriptHelper, "eve/javascript_helper"
14
+ autoload :Trust, "eve/trust"
15
+ autoload :Version, "eve/version"
16
+ autoload :VERSION, "eve/version"
17
+
18
+ require 'eve/deprecation'
19
+
20
+ # Railtie for bootstrapping to Rails
21
+ begin
22
+ require 'rails'
23
+ # we just required Rails -- are these next 3 necessary?
24
+ require 'action_pack'
25
+ require 'action_controller'
26
+ require 'action_view'
27
+
28
+ class Railtie < Rails::Railtie
29
+ config.after_initialize do
30
+ if defined?(Mime::Type)
31
+ # *.igb.erb format
32
+ Mime::Type.register_alias "text/html", :eve
33
+ Mime::Type.register_alias "text/html", :igb
34
+ end
35
+
36
+ # controller extensions
37
+ ActionController::Base.send(:include, Eve::Trust::ControllerHelpers)
38
+
39
+ # view extensions
40
+ ActionView::Base.send(:delegate, :igb, :to => :controller)
41
+ ActionView::Base.send(:delegate, :igb?, :to => :igb)
42
+ ActionView::Base.send(:include, Eve::JavascriptHelper)
43
+ end
44
+ end
45
+ rescue LoadError
46
+ # no rails? no problem.
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ ActiveSupport::Deprecation.deprecate_methods(Eve::Trust::ControllerHelpers, {
2
+ :prefer_trust => "The EVE IGB no longer accepts trust headers. Please use <%=request_trust%> in your view, instead."
3
+ })
@@ -0,0 +1,196 @@
1
+ module Eve
2
+ # In addition to the helpers listed below, this library also exposes the "igb" method as described in
3
+ # Eve::Trust.
4
+ module JavascriptHelper
5
+ # Returns the numeric type ID for a string, so you don't have to manage "magic numbers" in your application.
6
+ # The argument can be a string or a symbol, and is case insensitive. Underscores will be converted to spaces.
7
+ #
8
+ # Examples:
9
+ # type_id('alliance') # => 16159
10
+ # type_id('character') # => 1377
11
+ # type_id('corporation') # => 2
12
+ # type_id('constellation') # => 4
13
+ # type_id('region') # => 3
14
+ # type_id('Solar System') # => 5
15
+ # type_id(:solar_system) # => 5
16
+ # type_id(:station) # => 3867
17
+ #
18
+ def type_id(which)
19
+ which = which.to_s.humanize unless which.kind_of?(String)
20
+ which.downcase!
21
+ case which
22
+ when 'alliance' then 16159
23
+ when 'character' then 1377
24
+ when 'corporation' then 2
25
+ when 'constellation' then 4
26
+ when 'region' then 3
27
+ when 'solar system', 'solarsystem' then 5
28
+ when 'station' then 3867
29
+ else raise ArgumentError, "Unknown type: #{which}"
30
+ end
31
+ end
32
+
33
+ # Creates a hyperlink that results in opening the client's EVE mail inbox.
34
+ def link_to_evemail(text, *args)
35
+ link_to_function(text, "CCPEVE.openEveMail()", *args)
36
+ end
37
+
38
+ # Creates a hyperlink that results in the "show info" dialog being displayed on the client's screen.
39
+ # If item_id is given, the show info window will open for that item.
40
+ #
41
+ # type_id (Number)
42
+ # Type ID of item to show info on.
43
+ # item_id (Number)
44
+ # Optional item ID of specific item of type type_id to show info on. This is required for specific types of
45
+ # items, such as solar systems, stations, regions, and constellations.
46
+ #
47
+ def link_to_info(text, type_id, item_id = nil, *args)
48
+ function = "CCPEVE.showInfo(#{type_id.inspect}"
49
+ function.concat ", #{item_id.inspect}" if item_id
50
+ function.concat ")"
51
+ link_to_function text, function, *args
52
+ end
53
+
54
+ # Creates a hyperlink that results in opening the preview window for type_id.
55
+ #
56
+ # type_id (Number)
57
+ # Type ID of item to preview.
58
+ #
59
+ def link_to_preview(text, type_id, *args)
60
+ link_to_function text, "CCPEVE.showPreview(#{type_id.inspect})", *args
61
+ end
62
+
63
+ # Creates a hyperlink that results in showing the route to the destination_id from the source_id.
64
+ # If source_id is not given, the source system is taken to be the system the user is currently in.
65
+ #
66
+ def link_to_route(text, destination_id, source_id = nil, *args)
67
+ function = "CCPEVE.showRouteTo(#{destination_id.inspect}"
68
+ function.concat ", #{source_id.inspect}" if source_id
69
+ function.concat ")"
70
+ link_to_function text, function, *args
71
+ end
72
+
73
+ # Creates a hyperlink that results in opening the map. If system_id is given, the map will focus on that system.
74
+ #
75
+ # system_id (Number)
76
+ # Optional ID of solar system to focus map on.
77
+ #
78
+ def link_to_map(text, system_id = nil, *args)
79
+ link_to_function text, "CCPEVE.showMap(#{system_id ? system_id.inspect : ''})", *args
80
+ end
81
+
82
+ # Creates a hyperlink that results in opening the fitting window and displays the fitting represented by fitting.
83
+ #
84
+ # fitting (String)
85
+ # A Ship DNA string.
86
+ #
87
+ # See http://wiki.eveonline.com/en/wiki/Ship_DNA for details
88
+ def link_to_fitting(text, ship_dna_string, *args)
89
+ link_to_function text, "CCPEVE.showFitting(#{ship_dna_string.inspect})", *args
90
+ end
91
+
92
+ # Creatse a hyperlink that results in opening the contract window and displaying the contract represented by the
93
+ # contract_id argument. Contracts are, however, assigned per-solar-system, and so a solar_system_id must also be
94
+ # provided.
95
+ #
96
+ # solar_system_id (Number)
97
+ # The ID number of the solar system in which the contract is located.
98
+ # contract_id (Number)
99
+ # The ID number of the contract to display.
100
+ def link_to_contract(text, solar_system_id, contract_id, *args)
101
+ link_to_function text, "CCPEVE.showContract(#{solar_system_id.inspect}, #{contract_id.inspect})", *args
102
+ end
103
+
104
+ # Creates a hyperlink which results in opening the market details window and displays the information about the
105
+ # item represented by type_id.
106
+ #
107
+ # typeID (Number)
108
+ # Type ID to display market details about
109
+ #
110
+ def link_to_market_details(text, type_id, *args)
111
+ link_to_function text, "CCPEVE.showMarketDetails(#{type_id.inspect})", *args
112
+ end
113
+
114
+ # Produces a hyperlink that will result in a pop-up a trust prompt in the client, allowing the user to either
115
+ # grant the trust request, ignore it, or always ignore trust requests from your site.
116
+ #
117
+ # trust_url (String)
118
+ # This is a fully-qualified domain name and path (e.g. http://wiki.eveonline.com/w/) to which your site would
119
+ # like the user to grant trust.
120
+ #
121
+ # The page will not be automatically refreshed if the user grants the trust request. Trust will take effect the
122
+ # next time the user refreshes the page, or navigates within the site.
123
+ #
124
+ # Note that trust_url is processed and only the protocol, domain and path will be used from it. If you supply a
125
+ # query string or anchor, they will be discarded. It is recommended that you primarily pass in only
126
+ # fully-qualified domain names without paths (e.g. http://wiki.eveonline.com instead of
127
+ # http://wiki.eveonline.com/w/index.php), as this avoids pestering the user for trust on every page.
128
+ #
129
+ def link_to_trust_request(text, trust_url = "http://#{request.host}/", *args)
130
+ trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
131
+ link_to_function text, "CCPEVE.requestTrust(#{trust_url.inspect})", *args
132
+ end
133
+
134
+ # This will generate a method call that produces a pop-up a trust prompt in the client, allowing the user to
135
+ # either grant the trust request, ignore it, or always ignore trust requests from your site.
136
+ #
137
+ # trust_url (String)
138
+ # This is a fully-qualified domain name and path (e.g. http://wiki.eveonline.com/w/) to which your site would
139
+ # like the user to grant trust.
140
+ #
141
+ # The page will not be automatically refreshed if the user grants the trust request. Trust will take effect the
142
+ # next time the user refreshes the page, or navigates within the site.
143
+ #
144
+ # Note that trust_url is processed and only the protocol, domain and path will be used from it. If you supply a
145
+ # query string or anchor, they will be discarded. It is recommended that you primarily pass in only
146
+ # fully-qualified domain names without paths (e.g. http://wiki.eveonline.com instead of
147
+ # http://wiki.eveonline.com/w/index.php), as this avoids pestering the user for trust on every page.
148
+ #
149
+ def request_trust(trust_url = "http://#{request.host}/", *args)
150
+ trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
151
+ javascript_tag "CCPEVE.requestTrust(#{trust_url.inspect});", *args
152
+ end
153
+
154
+ # Sets the client's autopilot destination to the specified solar system.
155
+ #
156
+ # solar_system_id (Number)
157
+ # The numerical identifier of the solar system to which you wish to set the client's autopilot destination.
158
+ #
159
+ # This method requires that the user grant Trust to the calling site.
160
+ def link_to_destination(text, solar_system_id, *args)
161
+ link_to_function text, "CCPEVE.setDestination(#{solar_system_id.inspect})", *args
162
+ end
163
+
164
+ # Adds the specified solar system to the end of the client's autopilot route. If the solar system is already in
165
+ # the route, no changes are made and the method fails silently.
166
+ #
167
+ # solar_system_id (Number)
168
+ # The numerical identifier of the solar system which you wish to append to the client's autopilot route.
169
+ #
170
+ # This method requires that the user grant Trust to the calling site.
171
+ def link_to_waypoint(text, solar_system_id, *args)
172
+ link_to_function text, "CCPEVE.addWaypoint(#{solar_system_id.inspect})", *args
173
+ end
174
+
175
+ # Causes the user to attempt to join the named channel. Normal channel access control rules apply. If the user is
176
+ # unable to join the channel, the method fails silently.
177
+ #
178
+ # channel_name (String)
179
+ # The name of the channel which the user will join.
180
+ #
181
+ # This method requires that the user grant Trust to the calling site.
182
+ def link_to_channel(text, channel_name, *args)
183
+ link_to_function text, "CCPEVE.joinChannel(#{channel_name.inspect})", *args
184
+ end
185
+
186
+ # Causes the user to subscribe to the named mailing list.
187
+ #
188
+ # mailing_list_name (String)
189
+ # The name of the mailing list which the user will join.
190
+ #
191
+ # This method requires that the user grant Trust to the calling site.
192
+ def link_to_mailing_list(text, mailing_list_name, *args)
193
+ link_to_function text, "CCPEVE.joinMailingList(#{mailing_list_name.inspect})", *args
194
+ end
195
+ end
196
+ end
@@ -1,11 +1,10 @@
1
- require 'eve/trust/mime_types'
2
1
  require 'eve/trust/controller_helpers'
3
2
  require 'eve/trust/igb_interface'
4
3
 
5
4
  module Eve
6
5
  # == Trust
7
6
  # 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
7
+ # to that View. In keeping with this paradigm, a few helper methods have been added that allow you to establish
9
8
  # trust with the In-Game Browser (IGB), which in turn provides access to more useful information such as the player's
10
9
  # current location. To establish trust with a compatible browser, simply add one line to your controller:
11
10
  #
@@ -1,83 +1,23 @@
1
1
  module Eve
2
2
  module Trust
3
3
  module ControllerHelpers
4
- # None of this exists unless ActionController exists first.
5
- if defined?(ActionController::Base)
6
- class ::ActionController::Base
4
+ def self.included(base)
5
+ base.instance_eval do
7
6
  hide_action :trust_message, :trust_message=, :detect_igb, :template_exists?,
8
7
  :set_igb_or_default, :default_template_exists?, :mock_methods_for_testing!,
9
8
  :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.")
9
+ class_attribute :trust_message
10
+ self.trust_message ||= "This web site is requesting your trust."
11
+
13
12
  delegate :igb?, :to => :igb
14
- attr_reader :igb
15
13
  before_filter :detect_igb
16
14
 
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
15
  class << self
76
16
  def requires_trust(message = trust_message)
77
17
  self.trust_message = message if message != trust_message
78
18
  before_filter :require_trust
79
19
  end
80
-
20
+
81
21
  def prefers_trust(message = trust_message)
82
22
  self.trust_message = message if message != trust_message
83
23
  before_filter :prefer_trust
@@ -85,6 +25,62 @@ module Eve
85
25
  end
86
26
  end
87
27
  end
28
+
29
+ def igb
30
+ @igb ||= Eve::Trust::IgbInterface.new(request)
31
+ end
32
+
33
+ def require_trust(trust_message = self.class.trust_message)
34
+ if igb? && !igb.trusted?
35
+ render :text => "<body onload=\"CCPEVE.requestTrust('http://#{request.host_with_port}')\">", :layout => false
36
+ end
37
+ true
38
+ end
39
+
40
+ def prefer_trust(trust_message = self.class.trust_message)
41
+ if igb? && !igb.trusted?
42
+ deliver_trust_message(trust_message)
43
+ end
44
+ true
45
+ end
46
+
47
+ def deliver_trust_message(trust_message = self.class.trust_message)
48
+ trust_uri = "http://#{request.host_with_port}/"
49
+ headers['Eve.trustme'] = "#{trust_uri}::#{trust_message}"
50
+ end
51
+
52
+ def detect_igb
53
+ if igb.igb?
54
+ set_igb_or_default
55
+ end
56
+ end
57
+
58
+ def set_igb_or_default
59
+ if default_template_exists? :igb
60
+ set_igb
61
+ end
62
+ end
63
+
64
+ def set_igb
65
+ request.format = :igb
66
+ igb
67
+ end
68
+
69
+ unless defined?(default_template_name)
70
+ def default_template_name
71
+ # FIXME: I didn't check how Rails3 actually decides which template to render --
72
+ # we should really follow the same rules so we don't break anything unintentionally.
73
+ action_name
74
+ end
75
+ end
76
+
77
+ def default_template_exists?(format = request.format)
78
+ formats = lookup_context.formats
79
+ lookup_context.formats = [format]
80
+ lookup_context.exists?(default_template_name, controller_path)
81
+ ensure
82
+ lookup_context.formats = formats
83
+ end
88
84
  end
89
85
  end
90
86
  end