Guest User

Untitled

a guest
Jun 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. require 'faraday'
  2. require 'json'
  3. require 'uri'
  4.  
  5. data_api_url = ARGV[0]
  6. username = ARGV[1]
  7. password = ARGV[2]
  8.  
  9. if data_api_url.nil? or data_api_url.empty? or username.nil? or username.empty? or password.nil? or password.empty?
  10. puts '[usage]: ruby test.rb [data_api_base] [username] [password]'
  11. exit 1
  12. end
  13.  
  14. data_api_uri = URI.parse(data_api_url)
  15. data_api_host = "#{data_api_uri.scheme}://#{data_api_uri.host}"
  16.  
  17. conn = Faraday.new(url: data_api_host)
  18. res_authenticate = conn.post "#{data_api_uri.path}/v2/authentication", {
  19. username: username,
  20. password: password,
  21. clientId: 'faraday',
  22. }
  23.  
  24. json = JSON.parse(res_authenticate.body)
  25. access_token = json['accessToken']
  26.  
  27. count = 0
  28. while 1 do
  29. puts count
  30. count += 1
  31. res_create_entry = conn.post "#{data_api_uri.path}/v3/sites/1/entries", {
  32. entry: '{}',
  33. } do |req|
  34. req.headers['X-MT-Authorization'] = "MTAuth accessToken=\"#{access_token}\""
  35. end
  36. raise unless res_create_entry.success?
  37. puts res_create_entry.body
  38. end
Add Comment
Please, Sign In to add comment