2011-07-06 11 views
0

私は現在、サブスクリプションとペイメントのために、スプレーとチャージに基づいて構築されている既存のRuby on Railsアプリケーションを開発中です。以前にアプリケーションに取り組んでいた人はコメントを言及しておらず、ほとんどのものはRESTful Railsアプリケーションの真の表現ではありません。サブスクリプションのパラメータを

とにかく私は明確にしたい2つのことがあります。まず誰かがコードのこの部分が何をしているかを私に説明することができます:

https://[@subdomain].chargify.com/subscriptions/[@subscription.id].json 

が返されるJSONレスポンスがこれを可能としている:

couponJSON = `curl -u #{Chargify.api_key}:x https://#{Chargify.subdomain}.chargify.com/product_families/#{subscription_product_family_id}/coupons/find.json?code=#{params[:payment_form][:coupon_code]}` 

coupon_amount_in_cents = ActiveSupport::JSON.decode(couponJSON)['coupon']['amount_in_cents'] 

第二の事私はへのGETリクエストを行う必要があります。

> {"subscription":{ 
>   "id":[@subscription.id], 
>   "state":"active", 
>   "balance_in_cents":0, 
>   "current_period_started_at":`auto 
> generated`, 
>   "current_period_ends_at":`auto generated`, 
>   "activated_at":`auto generated`, 
>   "trial_ended_at":`auto generated`, 
>   "trial_started_at":`auto generated`, 
>   "expires_at":`auto generated`, 
>   "created_at":`auto generated`, 
>   "updated_at":`auto generated`, 
>   "cancellation_message":null, 
>   "customer":{ 
>   "id":`auto generated`, 
>   "first_name":`your value`, 
>   "last_name":`your value`, 
>   "email":`your value`, 
>   "organization":`your value`, 
>   "reference":`your value`, 
>   "updated_at":`auto generated`, 
>   "created_at":`auto generated` 
>   }, 
>   "product":{ 
>   "id":`auto generated`, 
>   "name":`your value`, 
>   "handle":`your value`, 
>   "price_in_cents":`your value`, 
>   "accounting_code":`your value`, 
>   "interval":`your value`, 
>   "interval_unit":`your value`, 
>   "product_family":{ 
>    "id":`auto generated`, 
>    "name":`your value`, 
>    "handle":`your value`, 
>    "accounting_code":`your value` 
>   } 
>   }, 
>   "credit_card":{ 
>   "first_name":`your value`, 
>   "last_name":`your value`, 
>   "masked_card_number":`your value`, 
>   "card_type":`auto generated`, 
>   "expiration_month":`your value`, 
>   "expiration_year":`your value` 
>   } 
>  }} 

私の質問は、上記のURLへのgetリクエストを行うのに最も時間のかかる方法でしょうか?もう一つは、 "information.html.erb"というタイトルのページに表示されたいくつかのパラメータを取得する必要があります。私はこのような何かをする最良の方法を仮定しています:

balance = params[_json][:balance_in_cents]. 

私はそれが正しいかどうかはわかりません。任意の提案をいただければ幸いです。

おかげ

答えて

0

HTTPartyとマルチJSONは私のために、これらの問題の両方を解決しました。

関連する問題