Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment