Ruby on Rails アプリ内のユーザーが、外部のチケット管理システムである squishlist.com にチケットを送信できるようにしたいと考えています。次のような API と手順があります。認証してトークンを取得してから、トークンを使用してチケットを送信する必要があります。スキッシュリストより。
# get the token
https://api.squishlist.com/auth/?cfg=testcorp&user_key=privatekey&api_key=TEST-KEY-12345
=> {"token": "authtoken",
"expires": "2010-06-16 13:31:56"}
# and then the ticket with the token
https://api.squishlist.com/rest/?cfg=testcorp&token=authtoken&method=squish.issue.submit&prj=demo
POST data: {'issue_type': 1, 'subject': 'Hello, world.', 4: 'Open', 5: 10}
テスト目的で、テスト用のコントローラー、ルート、およびビュー (ページ) を作成しました。私のコントローラーには次のものがあります
require 'httparty'
require 'json'
class SubmitticketController < ApplicationController
def submit_a_ticket
@cfg = 'xxxsupport'
@user_key = '4787fsdbbfbfsdbhbfad5aba91129a3f1ed1b743321f7b'
@api_key = 'MrUser411'
@project = 'excelm-manoke'
@url_new_string = 'https://api.squishlist.com/auth/?cfg='+@cfg+'&user_key='+@user_key+'&api_key='+@api_key
# https://api.squishlist.com/auth/?cfg=xxxsupport&user_key=4787fsdbbfbfsdbhbfad5aba91129a3f1ed1b743321f7b&api_key=MrUser411 - this is what is created by @url_new_string
response = HTTParty.get(@url_new_string.to_str) #submit the string to get the token
@parsed_and_a_hash = JSON.parse(response)
@token = @parsed_and_a_hash["token"]
#make a new string with the token
@urlstring_to_post = 'https://api.squishlist.com/rest/?cfg='+@cfg+'&token='+@token+'&method=squish.issue.submit&prj='+@project
#submit and get a result
@result = HTTParty.post(@urlstring_to_post.to_str, :body => {:subject => 'This is the screen name', :issue_type => 'Application Problem', :status => 'Open', :priority => 'Normal', :description => 'This is the description for the problem'})
end
end
そして、コントローラーのアクションの結果を確認するためにアクセスするページがあり、次のコードが含まれています。
<p><%= @result %></p>
途中で受け取った応答のために、それが一般的に機能していることを知っています. squishlist で定義したフィールドのため、私の json は例とは異なります。誰でもこの問題について私を助けることができますか?
本当の問題は、jsonがどのように見えるか、そしてそれがほぼ一致しているかどうかを実際に見ることができないことだと思います。私は本当にjsonについてあまり知りません。私は簡単かもしれない何かを使用している必要があります。これを提出するためにajaxを使用する必要がありますか?どんな助けでも大歓迎です。ここのコミュニティが大好きです。