rest_countries 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c859f16c16ef81060943f21b0d506cd239c1712c2a76420fa93f46ccef47f18d
4
- data.tar.gz: 1f691366dfb05e221b1efa18702998536cb7cbd394efb0e48b422f4a7fce584d
3
+ metadata.gz: 78db7eb6ecd1bf5a9f7f7a4d9af99f8f62f816b808a55e4dd286fc3f636f91d7
4
+ data.tar.gz: 3357dba340eb0e17580669feab416315305862b42b4e336f961bca926e13b039
5
5
  SHA512:
6
- metadata.gz: d5b87300db3674a74e170fc6c4a1c71a5094065e4f3196aa614859e26663b60b3c5c3644d3ad022a61ad6b693d9d3185cb67889d2416f04ea6c62abde2c5b8aa
7
- data.tar.gz: 4f82e38de329457884b8dab1c4baa73e3014dd791d231b6af27dc802878824686a92728391dc5de298cdcaacb965f61474901e577acb48a202c4e1590a5a924b
6
+ metadata.gz: bf7ed313c5b2c712ba09d9a4511742b41c6651304fb2a029d1b5421235c63cafb08db10a3fc814e6fa4c58691dee44d5f3552c50f4562eb92deeeef435b84a65
7
+ data.tar.gz: f434752dd23410ab5b37ff8ab0c768a2a30605d4a5a807be1be4050f8015dbc1374243f7bef67aa64120c4e25c6f63f317691175d3d6c063c8dbdda981c954e3
data/README.md CHANGED
@@ -58,6 +58,8 @@ The client then gives you access to the endpoints
58
58
 
59
59
  ### Region
60
60
 
61
+ Search by region: Africa, Americas, Asia, Europe, Oceania
62
+
61
63
  $ client.region(region)
62
64
 
63
65
  ### Subregions
@@ -1,5 +1,5 @@
1
1
  require "faraday"
2
- # require "faraday_middleware"
2
+ require "uri"
3
3
 
4
4
  module RestCountries
5
5
  class Client
@@ -7,14 +7,22 @@ module RestCountries
7
7
 
8
8
  attr_reader :adapter
9
9
 
10
- def initialize(adapter: Faraday.default_adapter)
10
+ def initialize(adapter: Faraday.default_adapter, max_retries: 3, retry_interval: 1, timeout: 10, open_timeout: 5)
11
11
  @adapter = adapter
12
+ @max_retries = max_retries
13
+ @retry_interval = retry_interval
14
+ @timeout = timeout
15
+ @open_timeout = open_timeout
12
16
  end
13
17
 
14
18
  def connection
15
19
  @connection ||= Faraday.new(BASE_URL) do |conn|
16
20
  conn.request :json
17
21
  conn.response :json, content_type: "application/json"
22
+ conn.request :retry, max: @max_retries, interval: @retry_interval,
23
+ exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError]
24
+ conn.options.timeout = @timeout
25
+ conn.options.open_timeout = @open_timeout
18
26
  conn.adapter adapter
19
27
  end
20
28
  end
@@ -32,7 +40,8 @@ module RestCountries
32
40
 
33
41
  # Search by country’s full name. It can be the common or official value
34
42
  def fullname(country_name)
35
- response = connection.get("name/#{country_name}?fullText=true")
43
+ encoded_name = URI.encode_www_form_component(country_name)
44
+ response = connection.get("name/#{encoded_name}?fullText=true")
36
45
  handle_response(response)
37
46
  end
38
47
 
@@ -68,19 +77,22 @@ module RestCountries
68
77
 
69
78
  # Search by capital city
70
79
  def capital(capital)
71
- response = connection.get("capital/#{capital}")
80
+ encoded_capital = URI.encode_www_form_component(capital)
81
+ response = connection.get("capital/#{encoded_capital}")
72
82
  handle_response(response)
73
83
  end
74
84
 
75
85
  # Search by region
76
86
  def region(region)
77
- response = connection.get("region/#{region}")
87
+ encoded_region = URI.encode_www_form_component(region)
88
+ response = connection.get("region/#{encoded_region}")
78
89
  handle_response(response)
79
90
  end
80
91
 
81
92
  # Search by subregions
82
93
  def subregion(subregion)
83
- response = connection.get("subregion/#{subregion}")
94
+ encoded_subregion = URI.encode_www_form_component(subregion)
95
+ response = connection.get("subregion/#{encoded_subregion}")
84
96
  handle_response(response)
85
97
  end
86
98
 
@@ -99,10 +111,17 @@ module RestCountries
99
111
  private
100
112
 
101
113
  def handle_response(response)
102
- if response.success?
114
+ case response.status
115
+ when 200...300
103
116
  response.body
117
+ when 404
118
+ raise NotFoundError, "Country not found"
119
+ when 400...500
120
+ raise ClientError, "Client error: #{response.status}"
121
+ when 500...600
122
+ raise ServerError, "Server error: #{response.status}"
104
123
  else
105
- raise "Error fetching data: #{response.status}"
124
+ raise "Unexpected response: #{response.status}"
106
125
  end
107
126
  end
108
127
  end
@@ -1,3 +1,9 @@
1
1
  module RestCountries
2
2
  class Error < StandardError; end
3
+
4
+ class NotFoundError < Error; end
5
+
6
+ class ClientError < Error; end
7
+
8
+ class ServerError < Error; end
3
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RestCountries
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.3"
5
5
  end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rest_countries/version"
4
+ require_relative "rest_countries/client"
5
+ require_relative "rest_countries/error"
4
6
 
5
- module RestCountries
6
- autoload :Client, "rest_countries/client"
7
- autoload :Error, "rest_countries/error"
8
- end
7
+ # module RestCountries
8
+ # autoload :Client, "rest_countries/client"
9
+ # autoload :Error, "rest_countries/error"
10
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mae Ann Sacedon Cimafranca
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -33,19 +33,12 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - ".rspec"
37
- - ".standard.yml"
38
- - CHANGELOG.md
39
- - CODE_OF_CONDUCT.md
40
36
  - LICENSE.txt
41
37
  - README.md
42
- - Rakefile
43
38
  - lib/rest_countries.rb
44
39
  - lib/rest_countries/client.rb
45
40
  - lib/rest_countries/error.rb
46
41
  - lib/rest_countries/version.rb
47
- - sig/rest_countries.rbs
48
- - ting API Requests
49
42
  homepage: https://github.com/cimafrancamae/rest_countries
50
43
  licenses:
51
44
  - MIT
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.standard.yml DELETED
@@ -1,3 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/standardrb/standard
3
- ruby_version: 3.0
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2024-05-06
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at cimafrancamae@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "standard/rake"
9
-
10
- task default: %i[spec standard]
@@ -1,4 +0,0 @@
1
- module RestCountries
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
data/ting API Requests DELETED
@@ -1,145 +0,0 @@
1
- =>
2
- [{"name"=>
3
- {"common"=>"Moldova",
4
- "official"=>"Republic of Moldova",
5
- "nativeName"=>{"ron"=>{"official"=>"Republica Moldova", "common"=>"Moldova"}}},
6
- "tld"=>[".md"],
7
- "cca2"=>"MD",
8
- "ccn3"=>"498",
9
- "cca3"=>"MDA",
10
- "cioc"=>"MDA",
11
- "independent"=>true,
12
- "status"=>"officially-assigned",
13
- "unMember"=>true,
14
- "currencies"=>{"MDL"=>{"name"=>"Moldovan leu", "symbol"=>"L"}},
15
- "idd"=>{"root"=>"+3", "suffixes"=>["73"]},
16
- "capital"=>["Chișinău"],
17
- "altSpellings"=>["MD", "Moldova, Republic of", "Republic of Moldova", "Republica Moldova"],
18
- "region"=>"Europe",
19
- "subregion"=>"Eastern Europe",
20
- "languages"=>{"ron"=>"Romanian"},
21
- "translations"=>
22
- {"ara"=>{"official"=>"جمهورية مولدوڤا", "common"=>"مولدوڤا"},
23
- "bre"=>{"official"=>"Republik Moldova", "common"=>"Moldova"},
24
- "ces"=>{"official"=>"Moldavská republika", "common"=>"Moldavsko"},
25
- "cym"=>{"official"=>"Republic of Moldova", "common"=>"Moldova"},
26
- "deu"=>{"official"=>"Republik Moldau", "common"=>"Moldawien"},
27
- "est"=>{"official"=>"Moldova Vabariik", "common"=>"Moldova"},
28
- "fin"=>{"official"=>"Moldovan tasavalta", "common"=>"Moldova"},
29
- "fra"=>{"official"=>"République de Moldavie", "common"=>"Moldavie"},
30
- "hrv"=>{"official"=>"Moldavija", "common"=>"Moldova"},
31
- "hun"=>{"official"=>"Moldovai Köztársaság", "common"=>"Moldova"},
32
- "ita"=>{"official"=>"Repubblica di Moldova", "common"=>"Moldavia"},
33
- "jpn"=>{"official"=>"モルドバ共和国", "common"=>"モルドバ共和国"},
34
- "kor"=>{"official"=>"몰도바 공화국", "common"=>"몰도바"},
35
- "nld"=>{"official"=>"Republiek Moldavië", "common"=>"Moldavië"},
36
- "per"=>{"official"=>"جمهوری مولداوی", "common"=>"مولداوی"},
37
- "pol"=>{"official"=>"Republika Mołdawii", "common"=>"Mołdawia"},
38
- "por"=>{"official"=>"República da Moldávia", "common"=>"Moldávia"},
39
- "rus"=>{"official"=>"Молдова", "common"=>"Молдавия"},
40
- "slk"=>{"official"=>"Moldavská republika", "common"=>"Moldavsko"},
41
- "spa"=>{"official"=>"República de Moldova", "common"=>"Moldavia"},
42
- "srp"=>{"official"=>"Република Молдавија", "common"=>"Молдавија"},
43
- "swe"=>{"official"=>"Republiken Moldavien", "common"=>"Moldavien"},
44
- "tur"=>{"official"=>"Moldova Cumhuriyeti", "common"=>"Moldova"},
45
- "urd"=>{"official"=>"جمہوریہ مالدووا", "common"=>"مالدووا"},
46
- "zho"=>{"official"=>"摩尔多瓦共和国", "common"=>"摩尔多瓦"}},
47
- "latlng"=>[47.0, 29.0],
48
- "landlocked"=>true,
49
- "borders"=>["ROU", "UKR"],
50
- "area"=>33846.0,
51
- "demonyms"=>{"eng"=>{"f"=>"Moldovan", "m"=>"Moldovan"}, "fra"=>{"f"=>"Moldave", "m"=>"Moldave"}},
52
- "flag"=>"🇲🇩",
53
- "maps"=>
54
- {"googleMaps"=>"https://goo.gl/maps/JjmyUuULujnDeFPf7",
55
- "openStreetMaps"=>"https://www.openstreetmap.org/relation/58974"},
56
- "population"=>2617820,
57
- "gini"=>{"2018"=>25.7},
58
- "fifa"=>"MDA",
59
- "car"=>{"signs"=>["MD"], "side"=>"right"},
60
- "timezones"=>["UTC+02:00"],
61
- "continents"=>["Europe"],
62
- "flags"=>
63
- {"png"=>"https://flagcdn.com/w320/md.png",
64
- "svg"=>"https://flagcdn.com/md.svg",
65
- "alt"=>
66
- "The flag of Moldova is composed of three equal vertical bands of blue, yellow and red, with the national coat of arms centered in the yellow band."},
67
- "coatOfArms"=>
68
- {"png"=>"https://mainfacts.com/media/images/coats_of_arms/md.png",
69
- "svg"=>"https://mainfacts.com/media/images/coats_of_arms/md.svg"},
70
- "startOfWeek"=>"monday",
71
- "capitalInfo"=>{"latlng"=>[47.01, 28.9]},
72
- "postalCode"=>{"format"=>"MD-####", "regex"=>"^(?:MD)*(\\d{4})$"}},
73
- {"name"=>
74
- {"common"=>"United States",
75
- "official"=>"United States of America",
76
- "nativeName"=>{"eng"=>{"official"=>"United States of America", "common"=>"United States"}}},
77
- "tld"=>[".us"],
78
- "cca2"=>"US",
79
- "ccn3"=>"840",
80
- "cca3"=>"USA",
81
- "cioc"=>"USA",
82
- "independent"=>true,
83
- "status"=>"officially-assigned",
84
- "unMember"=>true,
85
- "currencies"=>{"USD"=>{"name"=>"United States dollar", "symbol"=>"$"}},
86
- "idd"=>
87
- {"root"=>"+1",
88
- "suffixes"=>
89
- ["201",
90
- "202",
91
- "203",
92
- "205",
93
- "206",
94
- "207",
95
- "208",
96
- "209",
97
- "210",
98
- "212",
99
- "213",
100
- "214",
101
- "215",
102
- "216",
103
- "217",
104
- "218",
105
- "219",
106
- "220",
107
- "224",
108
- "225",
109
- "227",
110
- "228",
111
- "229",
112
- "231",
113
- "234",
114
- "239",
115
- "240",
116
- "248",
117
- "251",
118
- "252",
119
- "253",
120
- "254",
121
- "256",
122
- "260",
123
- "262",
124
- "267",
125
- "269",
126
- "270",
127
- "272",
128
- "274",
129
- "276",
130
- "281",
131
- "283",
132
- "301",
133
- "302",
134
- "303",
135
- "304",
136
- "305",
137
- "307",
138
- "308",
139
- "309",
140
- "310",
141
- "312",
142
- "313",
143
- "314",
144
- "315",
145
-