pattana 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/pattana/api/v1/base_controller.rb +12 -0
  3. data/app/controllers/pattana/api/v1/cities_controller.rb +62 -0
  4. data/app/controllers/pattana/api/v1/countries_controller.rb +18 -0
  5. data/app/controllers/pattana/api/v1/docs_base_controller.rb +21 -0
  6. data/app/controllers/pattana/api/v1/docs_controller.rb +105 -0
  7. data/app/controllers/pattana/api/v1/regions_controller.rb +27 -0
  8. data/app/models/city.rb +13 -0
  9. data/app/models/country.rb +13 -0
  10. data/app/models/region.rb +13 -0
  11. data/app/views/kuppayam/api/docs/_navigation.html.erb +31 -0
  12. data/app/views/pattana/api/v1/docs/cities_in_a_country/_neg_case_1.html.erb +27 -0
  13. data/app/views/pattana/api/v1/docs/cities_in_a_country/_pos_case_1.html.erb +63 -0
  14. data/app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_1.html.erb +27 -0
  15. data/app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_2.html.erb +27 -0
  16. data/app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_3.html.erb +27 -0
  17. data/app/views/pattana/api/v1/docs/cities_in_a_region/_pos_case_1.html.erb +63 -0
  18. data/app/views/pattana/api/v1/docs/cities_in_a_region/_pos_case_2.html.erb +63 -0
  19. data/app/views/pattana/api/v1/docs/countries/_pos_case_1.html.erb +90 -0
  20. data/app/views/pattana/api/v1/docs/regions/_neg_case_1.html.erb +27 -0
  21. data/app/views/pattana/api/v1/docs/regions/_pos_case_1.html.erb +54 -0
  22. data/config/locales/pattana/api.ar.yml +16 -0
  23. data/config/locales/pattana/api.en.yml +16 -0
  24. data/config/routes.rb +35 -0
  25. data/lib/pattana/version.rb +1 -1
  26. metadata +23 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d2b566f1a20f35368c5e99d93fdde8a3b3a9e18
4
- data.tar.gz: 688dbf20ca7c12c1af959a0dbf1965ef77ce1a6c
3
+ metadata.gz: 468d2c5b68afe569337545a39e80ec8d9d6f1160
4
+ data.tar.gz: 1ec9df908fd6cff6318c9d6306995621a1119dce
5
5
  SHA512:
6
- metadata.gz: b9abfefaaff0c9ffc6809b62abc7fb9220394dbc6af6a574c6969df3086cfac245d58feef19e540358621407740483a4365ba38be88b3d49fb8850eef71d3566
7
- data.tar.gz: 109ee72c4ee3f9d0693b923a224ad82e21f484296a2d4771edcadbcdcae7554ec319293a58740a7121ac7c8918a23f3d34d3a5ffb33c94a97bb53295a442f0ba
6
+ metadata.gz: 07daba96fbfdd05189785d0579c0cf571e0888af8251f92d4bdc295db7536dccbc085b35c02115f33aee801b99e26b90edaf1d5d4a08f6f1be50951ef09d4c72
7
+ data.tar.gz: 9fc208a79e6d001d26da026cd262b9b52439148c4a67fab280a7fb685f79a05bf66285d28c2ade6772ad2f7dfd445fa7758c056e445734e21d6f0e08da62a669
@@ -0,0 +1,12 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class BaseController < ActionController::API
5
+
6
+ include ActionController::HttpAuthentication::Token::ControllerMethods
7
+ include RenderApiHelper
8
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class CitiesController < BaseController
5
+
6
+ def cities_in_a_country
7
+ proc_code = Proc.new do
8
+ @country = Country.find_by_id(params[:country_id])
9
+ if @country
10
+ @cities = @country.cities.where("show_in_api is true").order("name ASC").all
11
+ @success = true
12
+ @data = @cities
13
+ else
14
+ @success = false
15
+ @errors = {
16
+ heading: I18n.translate("api.cities.country_not_found.heading"),
17
+ message: I18n.translate("api.cities.country_not_found.message")
18
+ }
19
+ end
20
+ end
21
+ render_json_response(proc_code)
22
+ end
23
+
24
+ def cities_in_a_region
25
+ proc_code = Proc.new do
26
+ @region = Region.find_by_id(params[:region_id])
27
+ if @region
28
+ @country = Country.find_by_id(params[:country_id])
29
+ if @country
30
+ if @region.country_id == @country.id
31
+ @cities = @region.cities.where("show_in_api is true").order("name ASC").all
32
+ @success = true
33
+ @data = @cities
34
+ else
35
+ @success = false
36
+ @errors = {
37
+ heading: I18n.translate("api.cities.region_id_not_matching.heading"),
38
+ message: I18n.translate("api.cities.region_id_not_matching.message")
39
+ }
40
+ end
41
+ else
42
+ @success = false
43
+ @errors = {
44
+ heading: I18n.translate("api.cities.country_not_found.heading"),
45
+ message: I18n.translate("api.cities.country_not_found.message")
46
+ }
47
+ end
48
+ else
49
+ @success = false
50
+ @errors = {
51
+ heading: I18n.translate("api.cities.region_not_found.heading"),
52
+ message: I18n.translate("api.cities.region_not_found.message")
53
+ }
54
+ end
55
+ end
56
+ render_json_response(proc_code)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,18 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class CountriesController < BaseController
5
+
6
+ def index
7
+ proc_code = Proc.new do
8
+ @countries = Country.where("show_in_api is true").order("name ASC").all
9
+ @success = true
10
+ @data = @countries
11
+ end
12
+ render_json_response(proc_code)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,21 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class DocsBaseController < Kuppayam::BaseController
5
+
6
+ layout 'kuppayam/docs'
7
+
8
+ private
9
+
10
+ def breadcrumbs_configuration
11
+ {
12
+ heading: "Pattana - API Documentation",
13
+ description: "A brief documentation of all APIs implemented in the gem Pattana with input and output details and examples",
14
+ links: []
15
+ }
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,105 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class DocsController < Pattana::Api::V1::DocsBaseController
5
+
6
+ layout 'kuppayam/docs'
7
+
8
+ def countries
9
+ set_title("Countries API")
10
+ @request_type = "GET"
11
+ @end_point = "/api/v1/countries"
12
+ @description = "This API will return all the countries with other details like dialing prefix and ISO codes."
13
+
14
+ @info = "It will return only those countries who has show_in_api set true"
15
+
16
+ @input_headers = {
17
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
18
+ }
19
+
20
+ @example_path = "pattana/api/v1/docs/"
21
+ @examples = ["pos_case_1"]
22
+
23
+ set_nav("docs/countries")
24
+
25
+ render 'kuppayam/api/docs/show'
26
+ end
27
+
28
+ def regions
29
+ set_title("Regions API")
30
+ @request_type = "GET"
31
+ @end_point = "/api/v1/:country_id/regions"
32
+ @description = "This API will return all the regions in a particular country. The Country ID has to be passed."
33
+
34
+ @info = "It will return only those regions who has show_in_api set true"
35
+
36
+ @input_headers = {
37
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
38
+ }
39
+
40
+ @input_params = {
41
+ country_id: { mandatory: true, description: "The Country ID. You will get it from the Countries API", example: "for e.g: Country Id for U.A.E is 235 and that of India is 100", default: "" }
42
+ }
43
+
44
+ @example_path = "pattana/api/v1/docs/"
45
+ @examples = ["pos_case_1", "neg_case_1"]
46
+
47
+ set_nav("docs/regions")
48
+
49
+ render 'kuppayam/api/docs/show'
50
+ end
51
+
52
+ def cities_in_a_country
53
+ set_title("Cities API (in a country)")
54
+ @request_type = "GET"
55
+ @end_point = "/api/v1/:country_id/cities"
56
+ @description = "This API will return all the cities in a particular country. The Country ID has to be passed"
57
+
58
+ @info = "It will return only those cities who has show_in_api set true"
59
+
60
+ @input_headers = {
61
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
62
+ }
63
+
64
+ @input_params = {
65
+ country_id: { mandatory: true, description: "The Country ID. You will get it from the Countries API", example: "for e.g: Country Id for U.A.E is 235 and that of India is 100", default: "" }
66
+ }
67
+
68
+ @example_path = "pattana/api/v1/docs/"
69
+ @examples = ["pos_case_1", "neg_case_1"]
70
+
71
+ set_nav("docs/cities_in_a_country")
72
+
73
+ render 'kuppayam/api/docs/show'
74
+ end
75
+
76
+ def cities_in_a_region
77
+ set_title("Cities API (in a region)")
78
+ @request_type = "GET"
79
+ @end_point = "/api/v1/:country_id/:region_id/cities"
80
+ @description = "This API will return all the cities in a particular region. The Country ID & Region ID has to be passed"
81
+
82
+ @info = "It will return only those cities who has show_in_api set true"
83
+ @warning = "Make sure that the region (id) belongs to the country (id). Use the countries and regions API to get real id"
84
+
85
+ @input_headers = {
86
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
87
+ }
88
+
89
+ @input_params = {
90
+ country_id: { mandatory: true, description: "The Country ID. You will get it from the Countries API", example: "for e.g: Country Id for U.A.E is 235 and that of India is 100", default: "" },
91
+ region_id: { mandatory: true, description: "The Region ID. You will get it from the Regions API", example: "for e.g: Country Id for India is 100 and Region ID for Kerala is 1314", default: "" }
92
+ }
93
+
94
+ @example_path = "pattana/api/v1/docs/"
95
+ @examples = ["pos_case_1", "pos_case_2", "neg_case_1", "neg_case_2", "neg_case_3"]
96
+
97
+ set_nav("docs/cities_in_a_region")
98
+
99
+ render 'kuppayam/api/docs/show'
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,27 @@
1
+ module Pattana
2
+ module Api
3
+ module V1
4
+ class RegionsController < BaseController
5
+
6
+ def index
7
+ proc_code = Proc.new do
8
+ @country = Country.find_by_id(params[:country_id])
9
+ if @country
10
+ @regions = @country.regions.where("show_in_api is true").order("name ASC").all
11
+ @success = true
12
+ @data = @regions
13
+ else
14
+ @success = false
15
+ @errors = {
16
+ heading: I18n.translate("api.regions.country_not_found.heading"),
17
+ message: I18n.translate("api.regions.country_not_found.message")
18
+ }
19
+ end
20
+ end
21
+ render_json_response(proc_code)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -1,5 +1,8 @@
1
1
  class City < Pattana::ApplicationRecord
2
2
 
3
+ # Constants
4
+ EXCLUDED_JSON_ATTRIBUTES = [:created_at, :updated_at, :show_in_api]
5
+
3
6
  # Associations
4
7
  belongs_to :country
5
8
  belongs_to :region, optional: true
@@ -11,6 +14,16 @@ class City < Pattana::ApplicationRecord
11
14
  # Class Methods
12
15
  # ------------------
13
16
 
17
+ # Exclude some attributes info from json output.
18
+ def as_json(options={})
19
+ options[:except] ||= EXCLUDED_JSON_ATTRIBUTES
20
+ #options[:include] ||= []
21
+ #options[:methods] = []
22
+ #options[:methods] << :profile_image
23
+ json = super(options)
24
+ Hash[*json.map{|k, v| [k, v || ""]}.flatten]
25
+ end
26
+
14
27
  # Scopes Methods
15
28
 
16
29
  # return an active record relation object with the search query in its where clause
@@ -1,5 +1,8 @@
1
1
  class Country < Pattana::ApplicationRecord
2
2
 
3
+ # Constants
4
+ EXCLUDED_JSON_ATTRIBUTES = [:created_at, :updated_at, :show_in_api]
5
+
3
6
  # Associations
4
7
  has_many :regions
5
8
  has_many :cities
@@ -11,6 +14,16 @@ class Country < Pattana::ApplicationRecord
11
14
  # Class Methods
12
15
  # ------------------
13
16
 
17
+ # Exclude some attributes info from json output.
18
+ def as_json(options={})
19
+ options[:except] ||= EXCLUDED_JSON_ATTRIBUTES
20
+ #options[:include] ||= []
21
+ #options[:methods] = []
22
+ #options[:methods] << :profile_image
23
+ json = super(options)
24
+ Hash[*json.map{|k, v| [k, v || ""]}.flatten]
25
+ end
26
+
14
27
  # Scopes Methods
15
28
 
16
29
  # return an active record relation object with the search query in its where clause
@@ -1,5 +1,8 @@
1
1
  class Region < Pattana::ApplicationRecord
2
2
 
3
+ # Constants
4
+ EXCLUDED_JSON_ATTRIBUTES = [:created_at, :updated_at, :show_in_api]
5
+
3
6
  # Associations
4
7
  belongs_to :country
5
8
  has_many :cities
@@ -11,6 +14,16 @@ class Region < Pattana::ApplicationRecord
11
14
  # Class Methods
12
15
  # ------------------
13
16
 
17
+ # Exclude some attributes info from json output.
18
+ def as_json(options={})
19
+ options[:except] ||= EXCLUDED_JSON_ATTRIBUTES
20
+ #options[:include] ||= []
21
+ #options[:methods] = []
22
+ #options[:methods] << :profile_image
23
+ json = super(options)
24
+ Hash[*json.map{|k, v| [k, v || ""]}.flatten]
25
+ end
26
+
14
27
  # Scopes Methods
15
28
 
16
29
  # return an active record relation object with the search query in its where clause
@@ -0,0 +1,31 @@
1
+ <ul class="nav tabs-vertical">
2
+ <li class="<%= nav_active?('docs/countries') ? 'active' : '' %>">
3
+ <a href="/docs/api/v1/countries">
4
+ <i class="fa-globe visible-xs"></i>
5
+ <span class="hidden-xs">Countries</span>
6
+ </a>
7
+ </li>
8
+ <li class="<%= nav_active?('docs/regions') ? 'active' : '' %>">
9
+ <a href="/docs/api/v1/regions">
10
+ <i class="fa-globe visible-xs"></i>
11
+ <span class="hidden-xs">Regions</span>
12
+ </a>
13
+ </li>
14
+ <li class="<%= nav_active?('docs/cities_in_a_country') ? 'active' : '' %>">
15
+ <a href="/docs/api/v1/cities_in_a_country">
16
+ <i class="fa-globe visible-xs"></i>
17
+ <span class="hidden-xs">Cities (in a Country)</span>
18
+ </a>
19
+ </li>
20
+ <li class="<%= nav_active?('docs/cities_in_a_region') ? 'active' : '' %>">
21
+ <a href="/docs/api/v1/cities_in_a_region">
22
+ <i class="fa-globe visible-xs"></i>
23
+ <span class="hidden-xs">Cities (in a Region)</span>
24
+ </a>
25
+ </li>
26
+ </ul>
27
+
28
+ <style type="text/css">
29
+ .panel-positive h4.panel-title a { color: #68b828 !important; }
30
+ .panel-negative h4.panel-title a { color: #cc3f44 !important; }
31
+ </style>
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 1 - should show errors if a valid country id is not passed"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Invalid Country ID",
14
+ "message": "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API."
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,63 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 1 - should return all the cities in a country"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": true,
12
+ "data": [
13
+ {
14
+ "id": 21,
15
+ "name": "Abu Dhabi",
16
+ "alternative_names": "A-pu-that-pi,AEbu Saby,AUH,Aboe Dhabi,Abou Dabi,Abu Dabi,Abu Dabis,Abu Daby,Abu Daibi,Abu Dhabi,Abu Dhabi emiraat,Abu Zabi,Abu Zaby,Abu Zabye,Abu Zabyo,Abu á¸\u008cabi,Abu á¸\u0090abi,Abu-Dabi,Abu-Dabi khot,Abu-Dabio,Abu-Dzabi,Abú DabÃ\u00ad,Abú DaibÃ\u00ad,Abú ZabÃ\u00ad,Abû ",
17
+ "iso_code": "",
18
+ "country_id": 235,
19
+ "region_id": 14,
20
+ "latitude": "24.46667",
21
+ "longitude": "54.36667",
22
+ "population": 603492,
23
+ "priority": 1000
24
+ },
25
+ {
26
+ "id": 20,
27
+ "name": "Adh Dhayd",
28
+ "alternative_names": "Adh Dhaid,Adh Dhayd,Al Daid,Al-Dhayd,Dayd,Dhaid,Dhayd,Duhayd,Ihaid,aldhyd,اÙ\u0084Ø°Ù\u008aد,á¸\u0090ayd",
29
+ "iso_code": "",
30
+ "country_id": 235,
31
+ "region_id": 11,
32
+ "latitude": "25.28812",
33
+ "longitude": "55.88157",
34
+ "population": 24716,
35
+ "priority": 1000
36
+ },
37
+ .
38
+ .
39
+ .
40
+ {
41
+ "id": 8,
42
+ "name": "Umm al Qaywayn",
43
+ "alternative_names": "Oumm al Qaiwain,Oumm al Qaïwaïn,Um al Kawain,Um al Quweim,Umm al Qaiwain,Umm al Qawain,Umm al Qaywayn,Umm al-Quwain,Umm-ehl'-Kajvajn,Yumul al Quwain,am alqywyn,Умм-Ñ\u008dлÑ\u008c-Ð\u009aайвайн,Ø£Ù\u0085 اÙ\u0084Ù\u0082Ù\u008aÙ\u0088Ù\u008aÙ\u0086",
44
+ "iso_code": "",
45
+ "country_id": 235,
46
+ "region_id": 8,
47
+ "latitude": "25.56473",
48
+ "longitude": "55.55517",
49
+ "population": 44411,
50
+ "priority": 1000
51
+ }]
52
+ }
53
+ eos
54
+
55
+ %>
56
+
57
+ <%= render partial: "kuppayam/api/docs/example", locals: {
58
+ negative_case: false,
59
+ example_id: "pos_case_1",
60
+ api_title: api_title,
61
+ api_input: api_input,
62
+ api_output: api_output
63
+ } %>
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 1 - should show errors if a valid country id is not passed"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Invalid Country ID",
14
+ "message": "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API."
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 2 - should show errors if a valid country id is not passed"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Invalid Region ID",
14
+ "message": "Pass a vaild Region ID to get the regions. Get Regions List along with their IDs from Regions API"
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 3 - should show errors if a valid country id is not passed"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Region ID and the Country ID doesn't match",
14
+ "message": "Make sure that you pass the region id which belongs the right country id. This error is likely to be encountered when the region id belongs to a different country id than the one you have passed"
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,63 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 1 - should return all the cities in a country"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": true,
12
+ "data": [
13
+ {
14
+ "id": 21,
15
+ "name": "Abu Dhabi",
16
+ "alternative_names": "A-pu-that-pi,AEbu Saby,AUH,Aboe Dhabi,Abou Dabi,Abu Dabi,Abu Dabis,Abu Daby,Abu Daibi,Abu Dhabi,Abu Dhabi emiraat,Abu Zabi,Abu Zaby,Abu Zabye,Abu Zabyo,Abu á¸\u008cabi,Abu á¸\u0090abi,Abu-Dabi,Abu-Dabi khot,Abu-Dabio,Abu-Dzabi,Abú DabÃ\u00ad,Abú DaibÃ\u00ad,Abú ZabÃ\u00ad,Abû ",
17
+ "iso_code": "",
18
+ "country_id": 235,
19
+ "region_id": 14,
20
+ "latitude": "24.46667",
21
+ "longitude": "54.36667",
22
+ "population": 603492,
23
+ "priority": 1000
24
+ },
25
+ {
26
+ "id": 20,
27
+ "name": "Adh Dhayd",
28
+ "alternative_names": "Adh Dhaid,Adh Dhayd,Al Daid,Al-Dhayd,Dayd,Dhaid,Dhayd,Duhayd,Ihaid,aldhyd,اÙ\u0084Ø°Ù\u008aد,á¸\u0090ayd",
29
+ "iso_code": "",
30
+ "country_id": 235,
31
+ "region_id": 11,
32
+ "latitude": "25.28812",
33
+ "longitude": "55.88157",
34
+ "population": 24716,
35
+ "priority": 1000
36
+ },
37
+ .
38
+ .
39
+ .
40
+ {
41
+ "id": 8,
42
+ "name": "Umm al Qaywayn",
43
+ "alternative_names": "Oumm al Qaiwain,Oumm al Qaïwaïn,Um al Kawain,Um al Quweim,Umm al Qaiwain,Umm al Qawain,Umm al Qaywayn,Umm al-Quwain,Umm-ehl'-Kajvajn,Yumul al Quwain,am alqywyn,Умм-Ñ\u008dлÑ\u008c-Ð\u009aайвайн,Ø£Ù\u0085 اÙ\u0084Ù\u0082Ù\u008aÙ\u0088Ù\u008aÙ\u0086",
44
+ "iso_code": "",
45
+ "country_id": 235,
46
+ "region_id": 8,
47
+ "latitude": "25.56473",
48
+ "longitude": "55.55517",
49
+ "population": 44411,
50
+ "priority": 1000
51
+ }]
52
+ }
53
+ eos
54
+
55
+ %>
56
+
57
+ <%= render partial: "kuppayam/api/docs/example", locals: {
58
+ negative_case: false,
59
+ example_id: "pos_case_1",
60
+ api_title: api_title,
61
+ api_input: api_input,
62
+ api_output: api_output
63
+ } %>
@@ -0,0 +1,63 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 2 - should return all the cities in a region"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": true,
12
+ "data": [
13
+ {
14
+ "id": 21,
15
+ "name": "Abu Dhabi",
16
+ "alternative_names": "A-pu-that-pi,AEbu Saby,AUH,Aboe Dhabi,Abou Dabi,Abu Dabi,Abu Dabis,Abu Daby,Abu Daibi,Abu Dhabi,Abu Dhabi emiraat,Abu Zabi,Abu Zaby,Abu Zabye,Abu Zabyo,Abu á¸\u008cabi,Abu á¸\u0090abi,Abu-Dabi,Abu-Dabi khot,Abu-Dabio,Abu-Dzabi,Abú DabÃ\u00ad,Abú DaibÃ\u00ad,Abú ZabÃ\u00ad,Abû ",
17
+ "iso_code": "",
18
+ "country_id": 235,
19
+ "region_id": 14,
20
+ "latitude": "24.46667",
21
+ "longitude": "54.36667",
22
+ "population": 603492,
23
+ "priority": 1000
24
+ },
25
+ {
26
+ "id": 20,
27
+ "name": "Adh Dhayd",
28
+ "alternative_names": "Adh Dhaid,Adh Dhayd,Al Daid,Al-Dhayd,Dayd,Dhaid,Dhayd,Duhayd,Ihaid,aldhyd,اÙ\u0084Ø°Ù\u008aد,á¸\u0090ayd",
29
+ "iso_code": "",
30
+ "country_id": 235,
31
+ "region_id": 11,
32
+ "latitude": "25.28812",
33
+ "longitude": "55.88157",
34
+ "population": 24716,
35
+ "priority": 1000
36
+ },
37
+ .
38
+ .
39
+ .
40
+ {
41
+ "id": 8,
42
+ "name": "Umm al Qaywayn",
43
+ "alternative_names": "Oumm al Qaiwain,Oumm al Qaïwaïn,Um al Kawain,Um al Quweim,Umm al Qaiwain,Umm al Qawain,Umm al Qaywayn,Umm al-Quwain,Umm-ehl'-Kajvajn,Yumul al Quwain,am alqywyn,Умм-Ñ\u008dлÑ\u008c-Ð\u009aайвайн,Ø£Ù\u0085 اÙ\u0084Ù\u0082Ù\u008aÙ\u0088Ù\u008aÙ\u0086",
44
+ "iso_code": "",
45
+ "country_id": 235,
46
+ "region_id": 8,
47
+ "latitude": "25.56473",
48
+ "longitude": "55.55517",
49
+ "population": 44411,
50
+ "priority": 1000
51
+ }]
52
+ }
53
+ eos
54
+
55
+ %>
56
+
57
+ <%= render partial: "kuppayam/api/docs/example", locals: {
58
+ negative_case: false,
59
+ example_id: "pos_case_1",
60
+ api_title: api_title,
61
+ api_input: api_input,
62
+ api_output: api_output
63
+ } %>
@@ -0,0 +1,90 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 1 - should return all the countries"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": true,
12
+ "data": [
13
+ {
14
+ "id": 1,
15
+ "name": "Afghanistan",
16
+ "official_name": "Afghanistan",
17
+ "iso_name": "AFGHANISTAN",
18
+ "fips": "AF",
19
+ "iso_alpha_2": "AF",
20
+ "iso_alpha_3": "AFG",
21
+ "itu_code": "AFG",
22
+ "dialing_prefix": "93",
23
+ "tld": ".af",
24
+ "latitude": "33.0",
25
+ "longitude": "65.0",
26
+ "capital": "Kabul",
27
+ "continent": "AS",
28
+ "currency_code": "AFN",
29
+ "currency_name": "Afghani",
30
+ "is_independent": "Yes",
31
+ "languages": "fa-AF,ps,uz-AF,tk",
32
+ "priority": 1000
33
+ },
34
+ {
35
+ "id": 2,
36
+ "name": "Albania",
37
+ "official_name": "Albania",
38
+ "iso_name": "ALBANIA",
39
+ "fips": "AL",
40
+ "iso_alpha_2": "AL",
41
+ "iso_alpha_3": "ALB",
42
+ "itu_code": "ALB",
43
+ "dialing_prefix": "355",
44
+ "tld": ".al",
45
+ "latitude": "41.0",
46
+ "longitude": "20.0",
47
+ "capital": "Tirana",
48
+ "continent": "EU",
49
+ "currency_code": "ALL",
50
+ "currency_name": "Lek",
51
+ "is_independent": "Yes",
52
+ "languages": "sq,el",
53
+ "priority": 1000
54
+ },
55
+ .
56
+ .
57
+ .
58
+ {
59
+ "id": 246,
60
+ "name": "Zimbabwe",
61
+ "official_name": "Zimbabwe",
62
+ "iso_name": "ZIMBABWE",
63
+ "fips": "ZI",
64
+ "iso_alpha_2": "ZW",
65
+ "iso_alpha_3": "ZWE",
66
+ "itu_code": "ZWE",
67
+ "dialing_prefix": "263",
68
+ "tld": ".zw",
69
+ "latitude": "-20.0",
70
+ "longitude": "30.0",
71
+ "capital": "Harare",
72
+ "continent": "AF",
73
+ "currency_code": "ZWL",
74
+ "currency_name": "Zimbabwe Dollar",
75
+ "is_independent": "Yes",
76
+ "languages": "en-ZW,sn,nr,nd",
77
+ "priority": 1000
78
+ }]
79
+ }
80
+ eos
81
+
82
+ %>
83
+
84
+ <%= render partial: "kuppayam/api/docs/example", locals: {
85
+ negative_case: false,
86
+ example_id: "pos_case_1",
87
+ api_title: api_title,
88
+ api_input: api_input,
89
+ api_output: api_output
90
+ } %>
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 1 - should show errors if a valid country id is not passed"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Invalid Country ID",
14
+ "message": "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API."
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,54 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 1 - should return all the regions in a country"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": true,
12
+ "data": [
13
+ {
14
+ "id": 8,
15
+ "name": "Umm Al Quwain",
16
+ "iso_code": "AE-07",
17
+ "country_id": 235,
18
+ "latitude": "",
19
+ "longitude": "",
20
+ "priority": 1000
21
+ },
22
+ {
23
+ "id": 9,
24
+ "name": "Ras Al Khaimah",
25
+ "iso_code": "AE-05",
26
+ "country_id": 235,
27
+ "latitude": "",
28
+ "longitude": "",
29
+ "priority": 1000
30
+ },
31
+ .
32
+ .
33
+ .
34
+ {
35
+ "id": 13,
36
+ "name": "Ajman",
37
+ "iso_code": "AE-02",
38
+ "country_id": 235,
39
+ "latitude": "25.41222",
40
+ "longitude": "55.434738",
41
+ "priority": 1000
42
+ }]
43
+ }
44
+ eos
45
+
46
+ %>
47
+
48
+ <%= render partial: "kuppayam/api/docs/example", locals: {
49
+ negative_case: false,
50
+ example_id: "pos_case_1",
51
+ api_title: api_title,
52
+ api_input: api_input,
53
+ api_output: api_output
54
+ } %>
@@ -0,0 +1,16 @@
1
+ en:
2
+ api:
3
+ regions:
4
+ country_not_found:
5
+ heading: "Invalid Country ID"
6
+ message: "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API"
7
+ cities:
8
+ country_not_found:
9
+ heading: "Invalid Country ID"
10
+ message: "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API"
11
+ region_not_found:
12
+ heading: "Invalid Region ID"
13
+ message: "Pass a vaild Region ID to get the regions. Get Regions List along with their IDs from Regions API"
14
+ region_id_not_matching:
15
+ heading: "Region ID and the Country ID doesn't match"
16
+ message: "Make sure that you pass the region id which belongs the right country id. This error is likely to be encountered when the region id belongs to a different country id than the one you have passed"
@@ -0,0 +1,16 @@
1
+ en:
2
+ api:
3
+ regions:
4
+ country_not_found:
5
+ heading: "Invalid Country ID"
6
+ message: "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API"
7
+ cities:
8
+ country_not_found:
9
+ heading: "Invalid Country ID"
10
+ message: "Pass a vaild Country ID to get the regions. Get Countries List along with their IDs from Countries API"
11
+ region_not_found:
12
+ heading: "Invalid Region ID"
13
+ message: "Pass a vaild Region ID to get the regions. Get Regions List along with their IDs from Regions API"
14
+ region_id_not_matching:
15
+ heading: "Region ID and the Country ID doesn't match"
16
+ message: "Make sure that you pass the region id which belongs the right country id. This error is likely to be encountered when the region id belongs to a different country id than the one you have passed"
@@ -11,4 +11,39 @@ Pattana::Engine.routes.draw do
11
11
  resources :regions, as: :regions
12
12
  resources :cities, as: :cities
13
13
 
14
+ # get '/api/v1/countries', :controller => "/api/v1/countries", action: :index, as: :api_v1_countries
15
+ # get '/api/v1/:country_id/regions', :controller => "/api/v1/regions", action: :index, as: :api_v1_regions
16
+ # get '/api/v1/:country_id/cities', :controller => "/api/v1/cities", action: :cities_in_a_country, as: :api_v1_cities_in_a_country
17
+ # get '/api/v1/:country_id/:region_id/cities', :controller => "/api/v1/cities", action: :cities_in_a_region, as: :api_v1_cities_in_a_region
18
+
19
+ # namespace :docs do
20
+ # namespace :api do
21
+ # namespace :v1 do
22
+ # get 'countries', to: "/api/v1/docs#countries"
23
+ # get 'regions', to: "/api/v1/docs#regions"
24
+ # get 'cities', to: "/api/v1/docs#cities"
25
+ # end
26
+ # end
27
+ # end
28
+
29
+ namespace :api do
30
+ namespace :v1 do
31
+ get 'countries', :controller => "countries", action: :index
32
+ get ':country_id/regions', :controller => "regions", action: :index
33
+ get ':country_id/cities', :controller => "cities", action: :cities_in_a_country
34
+ get ':country_id/:region_id/cities', :controller => "cities", action: :cities_in_a_region
35
+ end
36
+ end
37
+
38
+ scope :docs do
39
+ namespace :api do
40
+ namespace :v1 do
41
+ get 'countries', :controller => "docs"
42
+ get 'regions', :controller => "docs"
43
+ get 'cities_in_a_country', :controller => "docs"
44
+ get 'cities_in_a_region', :controller => "docs"
45
+ end
46
+ end
47
+ end
48
+
14
49
  end
@@ -1,3 +1,3 @@
1
1
  module Pattana
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-24 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,14 +90,14 @@ dependencies:
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: 0.1.7
93
+ version: 0.1.8
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: 0.1.7
100
+ version: 0.1.8
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: bcrypt
103
103
  requirement: !ruby/object:Gem::Requirement
@@ -333,6 +333,12 @@ files:
333
333
  - app/assets/javascripts/pattana/application.js
334
334
  - app/assets/sketches/logo.sketch
335
335
  - app/assets/stylesheets/pattana/application.css
336
+ - app/controllers/pattana/api/v1/base_controller.rb
337
+ - app/controllers/pattana/api/v1/cities_controller.rb
338
+ - app/controllers/pattana/api/v1/countries_controller.rb
339
+ - app/controllers/pattana/api/v1/docs_base_controller.rb
340
+ - app/controllers/pattana/api/v1/docs_controller.rb
341
+ - app/controllers/pattana/api/v1/regions_controller.rb
336
342
  - app/controllers/pattana/application_controller.rb
337
343
  - app/controllers/pattana/cities_controller.rb
338
344
  - app/controllers/pattana/countries_controller.rb
@@ -346,11 +352,22 @@ files:
346
352
  - app/models/country.rb
347
353
  - app/models/pattana/application_record.rb
348
354
  - app/models/region.rb
355
+ - app/views/kuppayam/api/docs/_navigation.html.erb
349
356
  - app/views/layouts/kuppayam/_footer.html.erb
350
357
  - app/views/layouts/kuppayam/_header.html.erb
351
358
  - app/views/layouts/kuppayam/_navbar.html.erb
352
359
  - app/views/layouts/kuppayam/_sidebar.html.erb
353
360
  - app/views/layouts/pattana/application.html.erb
361
+ - app/views/pattana/api/v1/docs/cities_in_a_country/_neg_case_1.html.erb
362
+ - app/views/pattana/api/v1/docs/cities_in_a_country/_pos_case_1.html.erb
363
+ - app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_1.html.erb
364
+ - app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_2.html.erb
365
+ - app/views/pattana/api/v1/docs/cities_in_a_region/_neg_case_3.html.erb
366
+ - app/views/pattana/api/v1/docs/cities_in_a_region/_pos_case_1.html.erb
367
+ - app/views/pattana/api/v1/docs/cities_in_a_region/_pos_case_2.html.erb
368
+ - app/views/pattana/api/v1/docs/countries/_pos_case_1.html.erb
369
+ - app/views/pattana/api/v1/docs/regions/_neg_case_1.html.erb
370
+ - app/views/pattana/api/v1/docs/regions/_pos_case_1.html.erb
354
371
  - app/views/pattana/cities/_index.html.erb
355
372
  - app/views/pattana/cities/_row.html.erb
356
373
  - app/views/pattana/cities/_show.html.erb
@@ -368,6 +385,8 @@ files:
368
385
  - app/views/pattana/regions/_row.html.erb
369
386
  - app/views/pattana/regions/_show.html.erb
370
387
  - app/views/pattana/regions/index.html.erb
388
+ - config/locales/pattana/api.ar.yml
389
+ - config/locales/pattana/api.en.yml
371
390
  - config/routes.rb
372
391
  - db/master_data/cities.sql
373
392
  - db/master_data/countries.sql