From fb01a743ee619388155b20163197487dacc045e9 Mon Sep 17 00:00:00 2001 From: Alex McLain Date: Sat, 19 Nov 2016 23:14:10 -0800 Subject: [PATCH] Implement Character::Locations endpoint --- lib/greeve.rb | 1 + lib/greeve/character/locations.rb | 36 +++++++++++++++++++++ spec/cassettes/character/locations.yml | 44 ++++++++++++++++++++++++++ spec/character/locations_spec.rb | 29 +++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 lib/greeve/character/locations.rb create mode 100644 spec/cassettes/character/locations.yml create mode 100644 spec/character/locations_spec.rb diff --git a/lib/greeve.rb b/lib/greeve.rb index e9b6e70..a5206cb 100644 --- a/lib/greeve.rb +++ b/lib/greeve.rb @@ -23,6 +23,7 @@ require_relative "greeve/character/calendar_event_attendees" require_relative "greeve/character/character_sheet" require_relative "greeve/character/clones" +require_relative "greeve/character/locations" require_relative "greeve/character/mail_bodies" require_relative "greeve/character/mail_messages" require_relative "greeve/character/mailing_lists" diff --git a/lib/greeve/character/locations.rb b/lib/greeve/character/locations.rb new file mode 100644 index 0000000..01d55e9 --- /dev/null +++ b/lib/greeve/character/locations.rb @@ -0,0 +1,36 @@ +require_relative "../base_item" + +module Greeve + module Character + # Location and name of specific items that belong to the character of the + # api key. This call can be used to retrieve the player-set name of + # containers and ships. + # + # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/character/char_locations.html + class Locations < Greeve::BaseItem + endpoint "char/Locations" + + rowset :locations, xpath: "eveapi/result/rowset[@name='locations']" do + attribute :item_id, xpath: "@itemID", type: :integer + attribute :item_name, xpath: "@itemName", type: :string + attribute :x, xpath: "@x", type: :numeric + attribute :y, xpath: "@y", type: :numeric + attribute :z, xpath: "@z", type: :numeric + end + + # @param character_id [Integer] EVE character ID + # + # @option opts [Array, Integer] :ids (nil) ID or array of IDs of + # items belonging to the character + def initialize(character_id, opts = {}) + ids = opts.delete(:ids) + ids = [ids] unless ids.nil? || ids.is_a?(Array) + + opts[:query_params] = { "characterID" => character_id } + opts[:query_params]["IDs"] = ids.join(",") if ids + + super(opts) + end + end + end +end diff --git a/spec/cassettes/character/locations.yml b/spec/cassettes/character/locations.yml new file mode 100644 index 0000000..822e90a --- /dev/null +++ b/spec/cassettes/character/locations.yml @@ -0,0 +1,44 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.eveonline.com/char/Locations.xml.aspx?characterID=462421468&keyID=1515664&vCode=QYYBHdsFMmdWjc9bkWhqqKx00NLqA1c3pNHlacqHUGpaTkrnyrzwZ0vFY9L6aei3 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Typhoeus - https://github.com/typhoeus/typhoeus + Expect: + - '' + response: + status: + code: 200 + message: OK + headers: + Transfer-Encoding: + - chunked + Content-Type: + - application/xml; charset=utf-8 + Access-Control-Allow-Origin: + - "*" + Date: + - Sun, 20 Nov 2016 06:03:11 GMT + body: + encoding: UTF-8 + string: > + + + 2016-11-20 06:03:11 + + + + + + 2016-11-20 07:03:11 + + http_version: '1.1' + adapter_metadata: + effective_url: https://api.eveonline.com/char/Locations.xml.aspx?characterID=462421468&keyID=1515664&vCode=QYYBHdsFMmdWjc9bkWhqqKx00NLqA1c3pNHlacqHUGpaTkrnyrzwZ0vFY9L6aei3 + recorded_at: Sun, 20 Nov 2016 06:03:11 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/character/locations_spec.rb b/spec/character/locations_spec.rb new file mode 100644 index 0000000..e2bcbba --- /dev/null +++ b/spec/character/locations_spec.rb @@ -0,0 +1,29 @@ +vcr_opts = { + cassette_name: "character/locations", +} + +describe Greeve::Character::Locations, vcr: vcr_opts do + let(:key) { "1515664" } + let(:vcode) { "QYYBHdsFMmdWjc9bkWhqqKx00NLqA1c3pNHlacqHUGpaTkrnyrzwZ0vFY9L6aei3" } + let(:character_id) { 462421468 } + + let(:resource) { + Greeve::Character::Locations.new(character_id, key: key, vcode: vcode) + } + + context "resource" do + subject { resource } + + its(:locations) { should be_a Greeve::Rowset } + end + + context "locations" do + subject { resource.locations.first } + + its(:item_id) { should eq 1010000493393 } + its(:item_name) { should eq "Zephyr Biscuit" } + its(:x) { should eq 0 } + its(:y) { should eq 0 } + its(:z) { should eq 0 } + end +end