Class: EVEApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/eveapi/client.rb

Overview

Client instance and HTTP method handling

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute character_id.



7
8
9
# File 'lib/eveapi/client.rb', line 7

def character_id
  @character_id
end

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/eveapi/client.rb', line 4

def connection
  @connection
end

#key_idObject

Returns the value of attribute key_id.



5
6
7
# File 'lib/eveapi/client.rb', line 5

def key_id
  @key_id
end

#row_countObject

Returns the value of attribute row_count.



8
9
10
# File 'lib/eveapi/client.rb', line 8

def row_count
  @row_count
end

#vcodeObject

Returns the value of attribute vcode.



6
7
8
# File 'lib/eveapi/client.rb', line 6

def vcode
  @vcode
end

Instance Method Details

#api_methodsObject



32
33
34
# File 'lib/eveapi/client.rb', line 32

def api_methods
  api_methods_hash.map { |m| m[:name] }
end

#api_methods_hashObject



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

#paramsObject



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_methodsObject



51
52
53
# File 'lib/eveapi/client.rb', line 51

def working_methods
  EVEApi::WORKING_METHODS
end