Skip to content

Commit

Permalink
Implement Character::Locations endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
amclain committed Nov 20, 2016
1 parent f34e33d commit fb01a74
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/greeve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions lib/greeve/character/locations.rb
Original file line number Diff line number Diff line change
@@ -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>, 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
44 changes: 44 additions & 0 deletions spec/cassettes/character/locations.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions spec/character/locations_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fb01a74

Please sign in to comment.