Class: EVEApi::Client
- Inherits:
-
Object
- Object
- EVEApi::Client
- Defined in:
- lib/eveapi/client.rb
Overview
Client instance and HTTP method handling
Instance Attribute Summary collapse
-
#character_id ⇒ Object
Returns the value of attribute character_id.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#key_id ⇒ Object
Returns the value of attribute key_id.
-
#row_count ⇒ Object
Returns the value of attribute row_count.
-
#vcode ⇒ Object
Returns the value of attribute vcode.
Instance Method Summary collapse
- #api_methods ⇒ Object
- #api_methods_hash ⇒ Object
- #check_path(name) ⇒ Object
-
#initialize(key_id = nil, vcode = nil, character_id = nil) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *_args, &_block) ⇒ Object
- #params ⇒ Object
- #ruby_method_name(m) ⇒ Object
- #working_methods ⇒ Object
Constructor Details
#initialize(key_id = nil, vcode = nil, character_id = nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/eveapi/client.rb', line 10 def initialize(key_id = nil, vcode = nil, character_id = nil) @connection ||= Excon.new(API_ENDPOINT) @key_id = key_id @character_id = character_id @vcode = vcode end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args, &_block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/eveapi/client.rb', line 44 def method_missing(name, *_args, &_block) fail 'Invalid Method Name' if check_path(name).empty? check_path(name) request = EVEApi::Request.new @connection.get(path: check_path(name), query: params) request.result end |
Instance Attribute Details
#character_id ⇒ Object
Returns the value of attribute character_id.
7 8 9 |
# File 'lib/eveapi/client.rb', line 7 def character_id @character_id end |
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/eveapi/client.rb', line 4 def connection @connection end |
#key_id ⇒ Object
Returns the value of attribute key_id.
5 6 7 |
# File 'lib/eveapi/client.rb', line 5 def key_id @key_id end |
#row_count ⇒ Object
Returns the value of attribute row_count.
8 9 10 |
# File 'lib/eveapi/client.rb', line 8 def row_count @row_count end |
#vcode ⇒ Object
Returns the value of attribute vcode.
6 7 8 |
# File 'lib/eveapi/client.rb', line 6 def vcode @vcode end |
Instance Method Details
#api_methods ⇒ Object
32 33 34 |
# File 'lib/eveapi/client.rb', line 32 def api_methods api_methods_hash.map { |m| m[:name] } end |
#api_methods_hash ⇒ Object
40 41 42 |
# File 'lib/eveapi/client.rb', line 40 def api_methods_hash api_call_list[:calls].map { |m| { name: ruby_method_name(m), desc: m[:description] } } end |
#check_path(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/eveapi/client.rb', line 17 def check_path(name) parts = name.to_s.split('_') return '' if parts.count < 2 "/#{parts[0]}/#{parts[1..-1].join('_').camelize}.xml.aspx" end |
#params ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/eveapi/client.rb', line 23 def params { 'rowCount' => row_count, 'keyID' => key_id, 'vCode' => vcode, 'characterID' => character_id }.select { |_k, v| v } end |
#ruby_method_name(m) ⇒ Object
36 37 38 |
# File 'lib/eveapi/client.rb', line 36 def ruby_method_name(m) (m[:type][0..3].downcase + '_' + m[:name].underscore).to_sym end |
#working_methods ⇒ Object
51 52 53 |
# File 'lib/eveapi/client.rb', line 51 def working_methods EVEApi::WORKING_METHODS end |