Class: Gw2::Api::Client
- Inherits:
-
Object
- Object
- Gw2::Api::Client
- Includes:
- Account, Achievements, Characters, Pvp
- Defined in:
- lib/gw2/api.rb
Overview
Used to create a client to talk to the Guild Wars 2 API Arguments Valid Arguments
-
api_key: [String] the api key to use for the client, defaults to ENV
Variables See modules for available methods See wiki.guildwars2.com/wiki/API:Main
Instance Method Summary collapse
-
#execute_request(endpoint) ⇒ Net::HTTP
Executes a request.
-
#execute_with_params(endpoint, parameters) ⇒ Object
Executes a request with parameters.
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
Methods included from Pvp
#pvp_games, #pvp_standings, #pvp_stats
Methods included from Characters
#character_active_buildtabs, #character_active_equipmenttabs, #character_backstory, #character_buildtabs, #character_core, #character_crafting, #character_equipment, #character_equipmenttabs, #character_hero_points, #character_inventory, #character_quests, #character_recipes, #character_sab, #character_skills, #character_specializations, #characters
Methods included from Account
#account, #account_achievements, #account_bank, #account_characters, #account_daily_crafting, #account_dungeons, #account_dyes, #account_finishers, #account_gliders, #account_home_cats, #account_home_nodes, #account_inventory, #account_jadebots, #account_legendary_armory, #account_luck, #account_mail_carriers, #account_masteries, #account_mastery_points, #account_materials, #account_minis, #account_mount_skins, #account_mount_types, #account_mounts_skins, #account_mounts_types, #account_novelties, #account_outfits, #account_progression, #account_pvp_heroes, #account_raids, #account_recipes, #account_shared_inventory, #account_skiffs, #account_skins, #account_titles, #account_wallet, #account_wizardsvault_daily, #account_wizardsvault_listings, #account_wizardsvault_weekly, #account_worldbosses, #commerce_transactions, #create_subtoken, #token_info
Methods included from Achievements
#achievements, #achievements_categories, #achievements_groups
Constructor Details
#initialize(args) ⇒ Client
Returns a new instance of Client.
28 29 30 31 |
# File 'lib/gw2/api.rb', line 28 def initialize(args) @api_key = args[:api_key] || ENV.fetch("GW2_API_KEY", nil) @base_url = "https://api.guildwars2.com/v2" end |
Instance Method Details
#execute_request(endpoint) ⇒ Net::HTTP
Executes a request
49 50 51 52 53 54 55 56 57 |
# File 'lib/gw2/api.rb', line 49 def execute_request(endpoint) uri = URI("#{@base_url}/#{endpoint}") request = Net::HTTP::Get.new(uri) request["Authorization"] = "Bearer #{@api_key}" Net::HTTP.start(request.uri.hostname, request.uri.port, use_ssl: true) do |http| http.request(request) end end |
#execute_with_params(endpoint, parameters) ⇒ Object
Executes a request with parameters
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gw2/api.rb', line 34 def execute_with_params(endpoint, parameters) output = endpoint return execute_request(output) if parameters.empty? output += "?" parameters.each do |key, value| output += "#{key}=#{value}&" end execute_request(output) end |