diff --git a/app/api/repp/account_v1.rb b/app/api/repp/account_v1.rb new file mode 100644 index 000000000..fe3acd387 --- /dev/null +++ b/app/api/repp/account_v1.rb @@ -0,0 +1,16 @@ +module Repp + class AccountV1 < Grape::API + version 'v1', using: :path + + resource :accounts do + desc 'Return current cash account balance' + + get 'balance' do + @response = { + balance: current_user.registrar.cash_account.balance, + currency: current_user.registrar.cash_account.currency + } + end + end + end +end diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index 95f89f094..e467534f0 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -39,5 +39,6 @@ module Repp mount Repp::DomainV1 mount Repp::ContactV1 + mount Repp::AccountV1 end end diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index 6d8e6fa59..ee1a6459b 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -7,7 +7,7 @@ = link_to(t('add_deposit'), new_registrar_deposit_path, class: 'btn btn-default') %hr -= t('your_current_account_balance_is', balance: current_user.registrar.cash_account.balance) += t('your_current_account_balance_is', balance: current_user.registrar.cash_account.balance, currency: current_user.registrar.cash_account.currency) %h1= t('invoices') %hr diff --git a/config/locales/en.yml b/config/locales/en.yml index aa9952541..46fb51be0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -652,7 +652,7 @@ en: prepayment: 'Prepayment' vat: 'VAT (%{vat_prc}%)' unpaid: 'Unpaid' - your_current_account_balance_is: 'Your current account balance is %{balance} EUR' + your_current_account_balance_is: 'Your current account balance is %{balance} %{currency]' billing: 'Billing' your_account: 'Your account' pay_by_bank_link: 'Pay by bank link' diff --git a/db/migrate/20150416080828_add_currency_to_account.rb b/db/migrate/20150416080828_add_currency_to_account.rb new file mode 100644 index 000000000..5f67af359 --- /dev/null +++ b/db/migrate/20150416080828_add_currency_to_account.rb @@ -0,0 +1,7 @@ +class AddCurrencyToAccount < ActiveRecord::Migration + def change + add_column :accounts, :currency, :string + + Account.update_all(currency: 'EUR') + end +end diff --git a/db/schema.rb b/db/schema.rb index 2bf412209..5b91817ed 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150415075408) do +ActiveRecord::Schema.define(version: 20150416080828) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,6 +32,7 @@ ActiveRecord::Schema.define(version: 20150415075408) do t.decimal "balance", default: 0.0, null: false t.datetime "created_at" t.datetime "updated_at" + t.string "currency" end create_table "addresses", force: :cascade do |t| diff --git a/doc/repp-doc.md b/doc/repp-doc.md index 833d3522c..72644e960 100644 --- a/doc/repp-doc.md +++ b/doc/repp-doc.md @@ -9,4 +9,5 @@ Production API endpoint: https://repp.todo.ee/repp/v1 Main communication specification through Restful EPP (REPP): [Contact related functions](repp/v1/contact.md) -[Domain related functions](repp/v1/domain.md) +[Domain related functions](repp/v1/domain.md) +[Account related functions](repp/v1/account.md) diff --git a/doc/repp/v1/account.md b/doc/repp/v1/account.md new file mode 100644 index 000000000..a943f48e0 --- /dev/null +++ b/doc/repp/v1/account.md @@ -0,0 +1,25 @@ +## GET /repp/v1/accounts/balance +Returns domains of the current registrar. + + +#### Request +``` +GET /repp/v1/accounts/balance HTTP/1.1 +Accept: application/json +Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ== +Content-Length: 0 +Content-Type: application/json +``` + +#### Response +``` +HTTP/1.1 200 +Cache-Control: max-age=0, private, must-revalidate +Content-Length: 37 +Content-Type: application/json + +{ + "balance": "324.45", + "currency": "EUR" +} +``` diff --git a/doc/repp/v1/contact.md b/doc/repp/v1/contact.md index ca294722f..119889a7d 100644 --- a/doc/repp/v1/contact.md +++ b/doc/repp/v1/contact.md @@ -23,36 +23,34 @@ Content-Type: application/json ``` HTTP/1.1 200 Cache-Control: max-age=0, private, must-revalidate -Content-Length: 562 +Content-Length: 533 Content-Type: application/json { "contacts": [ { "id": 1, - "code": "sh995165920", - "reg_no": null, + "code": "sh135909910", "phone": "+372.12345678", - "email": "ronaldo@sauer.biz", + "email": "natasha.bechtelar@breitenberg.name", "fax": null, - "created_at": "2015-04-01T13:59:45.332Z", - "updated_at": "2015-04-01T13:59:45.332Z", + "created_at": "2015-04-16T08:44:33.041Z", + "updated_at": "2015-04-16T08:44:33.041Z", "ident": "37605030299", "ident_type": "priv", - "created_by_id": null, - "updated_by_id": null, "auth_info": "password", - "name": "Meagan Roob Jr.0", + "name": "Miss Sherwood Jacobi0", "org_name": null, "registrar_id": 1, - "creator_str": "autotest", - "updator_str": "autotest", + "creator_str": null, + "updator_str": null, "ident_country_code": "EE", "city": "Tallinn", "street": "Short street 11", "zip": "11111", "country_code": "EE", - "state": null + "state": null, + "legacy_id": null } ], "total_number_of_records": 2 @@ -81,7 +79,7 @@ Content-Type: application/json { "contacts": [ - "sh818918181" + "sh056866451" ], "total_number_of_records": 2 } diff --git a/doc/repp/v1/domain.md b/doc/repp/v1/domain.md index 6f9070aa4..467fd9c59 100644 --- a/doc/repp/v1/domain.md +++ b/doc/repp/v1/domain.md @@ -23,7 +23,7 @@ Content-Type: application/json ``` HTTP/1.1 200 Cache-Control: max-age=0, private, must-revalidate -Content-Length: 506 +Content-Length: 578 Content-Type: application/json { @@ -32,21 +32,24 @@ Content-Type: application/json "id": 1, "name": "domain0.ee", "registrar_id": 1, - "registered_at": "2015-04-01T13:59:45.874Z", + "registered_at": "2015-04-16T08:44:33.499Z", "status": null, - "valid_from": "2015-04-01T00:00:00.000Z", - "valid_to": "2016-04-01T00:00:00.000Z", + "valid_from": "2015-04-16T00:00:00.000Z", + "valid_to": "2016-04-16T00:00:00.000Z", "owner_contact_id": 1, - "auth_info": "78d0edcd105c8e1936457c1eef659611", - "created_at": "2015-04-01T13:59:45.871Z", - "updated_at": "2015-04-01T13:59:45.871Z", + "auth_info": "d081ba64515bc8ae9a512a98e6b1baa1", + "created_at": "2015-04-16T08:44:33.496Z", + "updated_at": "2015-04-16T08:44:33.496Z", "name_dirty": "domain0.ee", "name_puny": "domain0.ee", "period": 1, "period_unit": "y", "creator_str": null, "updator_str": null, - "whois_body": null + "whois_body": null, + "legacy_id": null, + "legacy_registrar_id": null, + "legacy_registrant_id": null } ], "total_number_of_records": 2 diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index d9558993d..9c33f1dff 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -101,7 +101,7 @@ namespace :import do Registrar.all.each do |x| next if x.cash_account - x.accounts.create(account_type: Account::CASH) + x.accounts.create(account_type: Account::CASH, currency: 'EUR') x.save(validate: false) end diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb index 8d93ccbd5..78e61bd5b 100644 --- a/spec/fabricators/account_fabricator.rb +++ b/spec/fabricators/account_fabricator.rb @@ -1,4 +1,5 @@ Fabricator(:account) do account_type { Account::CASH } balance 0.0 + currency 'EUR' end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 019f638cb..cd28b925b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -89,7 +89,7 @@ RSpec.configure do |config| c.syntax = [:should, :expect] end - Autodoc.configuration.path = 'doc/repp/v1' + Autodoc.configuration.path = 'doc/repp' Autodoc.configuration.suppressed_request_header = ['Host'] Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') diff --git a/spec/requests/v1/account_spec.rb b/spec/requests/v1/account_spec.rb new file mode 100644 index 000000000..8a586cea7 --- /dev/null +++ b/spec/requests/v1/account_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +describe Repp::AccountV1 do + before :all do + @registrar1 = Fabricate(:registrar1, accounts: + [Fabricate(:account, { balance: '324.45' })] + ) + @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) + end + + describe 'GET /repp/v1/accounts/balance' do + it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do + get_with_auth '/repp/v1/accounts/balance', {}, @api_user + response.status.should == 200 + + body = JSON.parse(response.body) + body['balance'].should == '324.45' + body['currency'].should == 'EUR' + + log = ApiLog::ReppLog.last + log[:request_path].should == '/repp/v1/accounts/balance' + log[:request_method].should == 'GET' + log[:request_params].should == '{}' + log[:response_code].should == '200' + log[:api_user_name].should == 'gitlab' + log[:api_user_registrar].should == 'registrar1' + log[:ip].should == '127.0.0.1' + end + end +end diff --git a/spec/requests/contact_spec.rb b/spec/requests/v1/contact_spec.rb similarity index 100% rename from spec/requests/contact_spec.rb rename to spec/requests/v1/contact_spec.rb diff --git a/spec/requests/domain_spec.rb b/spec/requests/v1/domain_spec.rb similarity index 100% rename from spec/requests/domain_spec.rb rename to spec/requests/v1/domain_spec.rb diff --git a/spec/support/request.rb b/spec/support/request.rb index 5c7315cfe..fedf1ae04 100644 --- a/spec/support/request.rb +++ b/spec/support/request.rb @@ -37,6 +37,7 @@ module Autodoc return unless example.metadata[:route_info_doc] route = request.env["rack.routing_args"][:route_info] return unless route.route_params.is_a?(Hash) + return if route.route_params.empty? rows = [ "| Field name | Required | Type | Allowed values | Description |",