class GW2API::Endpoint
Public Class Methods
new()
click to toggle source
# File lib/endpoint.rb, line 7 def initialize # The URL of the API endpoint @url = GW2API::BASE_URL # Does this endpoint support ?id= and ?ids=? @bulk_expandable = false # Does this endpoint support ?ids=all? @bulk_expandable_all = false # Does this endpoint support ?page= and ?page_size=? @paginated = false # Does this endpoint support ?language=? @localized = false # Does this endpoint require an API key? @authenticated = false # Does this endpoint optionally allow an API key? @authenticated_optional = false end
Public Instance Methods
all()
click to toggle source
# File lib/endpoint.rb, line 38 def all return nil unless @bulk_expandable_all api_call("#{@url}?ids=all") end
api_call(url)
click to toggle source
# File lib/endpoint.rb, line 43 def api_call(url) request = Typhoeus::Request.new(url) request.on_complete do |resp| if resp.success? return JSON.parse(resp.body, object_class: OpenStruct) else return nil end end request.run end
get(id = nil)
click to toggle source
# File lib/endpoint.rb, line 29 def get(id = nil) return nil if id.nil? && @bulk_expandable if id.kind_of?(Array) api_call("#{@url}?ids=#{id.join(',')}") else api_call("#{@url}/#{id}") end end
ids()
click to toggle source
# File lib/endpoint.rb, line 24 def ids return nil unless @bulk_expandable api_call "#{@url}?ids=all" end