Skip to content

Instantly share code, notes, and snippets.

@masiuchi
Last active June 10, 2018 02:43
Show Gist options
  • Save masiuchi/9c409fe3ddf8afa11e72cbed2570d43f to your computer and use it in GitHub Desktop.
Save masiuchi/9c409fe3ddf8afa11e72cbed2570d43f to your computer and use it in GitHub Desktop.
Call MT create_entry endpoint many times.
require 'faraday'
require 'json'
require 'uri'
data_api_url = ARGV[0]
username = ARGV[1]
password = ARGV[2]
if data_api_url.nil? or data_api_url.empty? or username.nil? or username.empty? or password.nil? or password.empty?
puts '[usage]: ruby test.rb [data_api_base] [username] [password]'
exit 1
end
data_api_uri = URI.parse(data_api_url)
data_api_host = "#{data_api_uri.scheme}://#{data_api_uri.host}"
conn = Faraday.new(url: data_api_host)
res_authenticate = conn.post "#{data_api_uri.path}/v2/authentication", {
username: username,
password: password,
clientId: 'faraday',
}
json = JSON.parse(res_authenticate.body)
access_token = json['accessToken']
count = 0
while 1 do
puts count
count += 1
res_create_entry = conn.post "#{data_api_uri.path}/v3/sites/1/entries", {
entry: '{}',
} do |req|
req.headers['X-MT-Authorization'] = "MTAuth accessToken=\"#{access_token}\""
end
raise unless res_create_entry.success?
puts res_create_entry.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment