EorzeaMarketNote Web API using Ruby example
Overview
Here is a example to display information on the Mandragora server's potion.
All sources
Please clone the example source from the following git repository.
The example for Ruby is contained in the ruby directory.
Premise
The example is based on the following tools and libraries.
How to run
The command to execute the example is as follow.
bundle install
bundle exec ruby example.rb
Main source(example.rb)
require 'bundler/setup'
Bundler.require
require 'active_support'
require 'json'
file_store = ActiveSupport::Cache.lookup_store(:file_store, [File.join(File.dirname(__FILE__), 'cache')])
url = 'https://ff14marketnoteapi.ownway.info/research/1/'
connection = Faraday::Connection.new(:url => url) do |builder|
# if you use Rails, you can Rails.cache instead of file_store
builder.use :http_cache, store: file_store
builder.use Faraday::Adapter::NetHttp
end
begin
response = connection.get('market_research', :dc => 'Mana')
if response.status == 200 then
aggregate_date = DateTime.parse(response.headers['Last-Modified'])
puts "Aggregate date:#{aggregate_date.iso8601}"
data = JSON.parse(response.body)
data_in_world = data['Mandragora']
latest_market_researches = data_in_world['l'] if data_in_world
optional_infos = data_in_world['o'] if data_in_world
# 7992765ec34: potion's item key
item_key = '7992765ec34'
potion_l = latest_market_researches[item_key] if latest_market_researches
potion_o = optional_infos[item_key] if optional_infos
if potion_l then
price_nq = potion_l[0]
price_hq = potion_l[1]
stock_nq = potion_l[2]
stock_hq = potion_l[3]
circulation1_nq = potion_l[4]
circulation1_hq = potion_l[5]
circulation2_nq = potion_l[6]
circulation2_hq = potion_l[7]
circulation_nq = (24 * circulation1_nq / circulation2_nq.to_f).round(2) if circulation1_nq && circulation2_nq
circulation_hq = (24 * circulation1_hq / circulation2_hq.to_f).round(2) if circulation1_hq && circulation2_hq
researched_time = Time.at(potion_l[8]) if potion_l[8]
puts "Potion's price(NQ):#{price_nq}"
puts "Potion's price(HQ):#{price_hq}"
puts "Potion's stock(NQ):#{stock_nq}"
puts "Potion's stock(HQ):#{stock_hq}"
puts "Potion's circulation pieces/day(NQ):#{circulation_nq}"
puts "Potion's circulation pieces/day(HQ):#{circulation_hq}"
puts "Potion's researched time:#{researched_time ? researched_time.iso8601 : ''}"
else
puts "No latest market research."
end
if potion_o then
material_cost_hq_first = potion_o[0]
material_cost_price_first = potion_o[1]
puts "Potion's material cost(HQ first):#{material_cost_hq_first}"
puts "Potion's material cost(Price first):#{material_cost_price_first}"
else
puts "No optional info."
end
else
puts "Error StatusCode:#{response.status}"
end
rescue => e
puts "Error Message:#{e.message}"
end