Last active
June 10, 2018 02:43
-
-
Save masiuchi/9c409fe3ddf8afa11e72cbed2570d43f to your computer and use it in GitHub Desktop.
Call MT create_entry endpoint many times.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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