Class: EveBadger::EveAPI
- Inherits:
-
Object
- Object
- EveBadger::EveAPI
- Defined in:
- lib/eve_badger/eve_api.rb
Instance Attribute Summary collapse
-
#character_id ⇒ Object
Returns the value of attribute character_id.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#key_id ⇒ Object
Returns the value of attribute key_id.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#vcode ⇒ Object
Returns the value of attribute vcode.
Instance Method Summary collapse
-
#access_mask ⇒ Object
access or retrieve access_mask, will also set key_type if an automatic fetch is triggered.
-
#access_mask=(mask) ⇒ Object
sets access_mask, coerces to integer.
-
#account(endpoint_name) ⇒ Object
takes an account endpoint name and returns a response object, raises an APIKeyError if the request would fail.
-
#character(endpoint_name) ⇒ Object
takes a character endpoint name and returns a response object, raises an APIKeyError if the request would fail.
-
#corporation(endpoint_name) ⇒ Object
takes a corporation endpoint name and returns a response object, raises an APIKeyError if the request would fail.
-
#details(endpoint_name, id_of_interest, fromid = nil, rowcount = nil) ⇒ Object
takes a detail endpoint name and id of interest then returns a response from the given endpoint name, raises an APIKeyError if the request would fail.
-
#initialize(args = {}) ⇒ EveAPI
constructor
A new instance of EveAPI.
-
#key_type ⇒ Object
access or retrieve key_type, will also set access_mask if an automatic fetch is triggered.
-
#key_type=(type) ⇒ Object
sets key_type, coerces to symbol.
Constructor Details
#initialize(args = {}) ⇒ EveAPI
Returns a new instance of EveAPI.
11 12 13 14 15 16 17 18 19 |
# File 'lib/eve_badger/eve_api.rb', line 11 def initialize(args={}) @domain = args[:sisi] ? EveBadger.default_sisi_domain : EveBadger.default_tq_domain @user_agent = EveBadger.default_user_agent @key_id = args[:key_id].to_s if args[:key_id] @vcode = args[:vcode].to_s if args[:vcode] @character_id = args[:character_id].to_s if args[:character_id] @access_mask = args[:access_mask].to_i if args[:access_mask] @key_type = args[:key_type].to_sym if args[:key_type] end |
Instance Attribute Details
#character_id ⇒ Object
Returns the value of attribute character_id.
9 10 11 |
# File 'lib/eve_badger/eve_api.rb', line 9 def character_id @character_id end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
9 10 11 |
# File 'lib/eve_badger/eve_api.rb', line 9 def domain @domain end |
#key_id ⇒ Object
Returns the value of attribute key_id.
9 10 11 |
# File 'lib/eve_badger/eve_api.rb', line 9 def key_id @key_id end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/eve_badger/eve_api.rb', line 8 def user_agent @user_agent end |
#vcode ⇒ Object
Returns the value of attribute vcode.
9 10 11 |
# File 'lib/eve_badger/eve_api.rb', line 9 def vcode @vcode end |
Instance Method Details
#access_mask ⇒ Object
access or retrieve access_mask, will also set key_type if an automatic fetch is triggered
47 48 49 |
# File 'lib/eve_badger/eve_api.rb', line 47 def access_mask @access_mask ||= get_access_mask end |
#access_mask=(mask) ⇒ Object
sets access_mask, coerces to integer
37 38 39 |
# File 'lib/eve_badger/eve_api.rb', line 37 def access_mask=(mask) @access_mask = mask ? mask.to_i : nil end |
#account(endpoint_name) ⇒ Object
takes an account endpoint name and returns a response object, raises an APIKeyError if the request would fail
57 58 59 60 61 |
# File 'lib/eve_badger/eve_api.rb', line 57 def account(endpoint_name) raise EveBadger::APIKeyError, 'missing required key_id or vcode' unless @key_id && @vcode endpoint = EveBadger::Endpoints.account(endpoint_name.to_sym) api_request(endpoint) end |
#character(endpoint_name) ⇒ Object
takes a character endpoint name and returns a response object, raises an APIKeyError if the request would fail
64 65 66 67 68 69 |
# File 'lib/eve_badger/eve_api.rb', line 64 def character(endpoint_name) raise EveBadger::APIKeyError, 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode raise EveBadger::APIKeyError, 'wrong key type' unless [:Character, :Account].include?(key_type) endpoint = EveBadger::Endpoints.character(endpoint_name.to_sym) api_request(endpoint) end |
#corporation(endpoint_name) ⇒ Object
takes a corporation endpoint name and returns a response object, raises an APIKeyError if the request would fail
72 73 74 75 76 77 |
# File 'lib/eve_badger/eve_api.rb', line 72 def corporation(endpoint_name) raise EveBadger::APIKeyError, 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode raise EveBadger::APIKeyError, 'wrong key type' unless key_type == :Corporation endpoint = EveBadger::Endpoints.corporation(endpoint_name.to_sym) api_request(endpoint) end |
#details(endpoint_name, id_of_interest, fromid = nil, rowcount = nil) ⇒ Object
takes a detail endpoint name and id of interest then returns a response from the given endpoint name, raises an APIKeyError if the request would fail
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/eve_badger/eve_api.rb', line 80 def details(endpoint_name, id_of_interest, fromid=nil, rowcount=nil) raise EveBadger::APIKeyError, 'wrong key type' unless [:Character, :Corporation, :Account].include?(key_type) endpoint = EveBadger::Endpoints.detail(endpoint_name.to_sym) if endpoint.permitted?(access_mask) uri = build_uri(endpoint) uri << "&#{endpoint.detail_id}=#{id_of_interest}" uri << "&fromID=#{fromid}" if fromid uri << "&rowCount=#{rowcount}" if rowcount get_response(uri) else raise EveBadger::APIKeyError, "#{endpoint.path} not permitted by access mask" end end |
#key_type ⇒ Object
access or retrieve key_type, will also set access_mask if an automatic fetch is triggered
52 53 54 |
# File 'lib/eve_badger/eve_api.rb', line 52 def key_type @key_type ||= get_key_type end |
#key_type=(type) ⇒ Object
sets key_type, coerces to symbol
42 43 44 |
# File 'lib/eve_badger/eve_api.rb', line 42 def key_type=(type) @key_type = type ? type.to_sym : nil end |