Skip to content

Commit

Permalink
Merge pull request #24 from guibranco/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
guibranco committed Mar 28, 2020
2 parents b8aed15 + 9d0971d commit 11f7dba
Show file tree
Hide file tree
Showing 13 changed files with 665 additions and 205 deletions.
145 changes: 131 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,107 @@

# Created by https://www.gitignore.io/api/rider,dotnetcore,visualstudio,visualstudiocode
# Edit at https://www.gitignore.io/?templates=rider,dotnetcore,visualstudio,visualstudiocode

### DotnetCore ###
# .NET Core build folders
/bin
/obj

# Common node modules locations
/node_modules
/wwwroot/node_modules


### Rider ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### VisualStudioCode ###
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
Expand All @@ -12,13 +110,18 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Mono auto generated files
mono_crash.*

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
Expand All @@ -36,9 +139,10 @@ Generated\ Files/
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml

# Build Results of an ATL Project
[Dd]ebugPS/
Expand All @@ -52,17 +156,15 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# StyleCop
StyleCopReport.xml

# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
Expand All @@ -77,6 +179,7 @@ StyleCopReport.xml
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
Expand Down Expand Up @@ -179,6 +282,8 @@ PublishScripts/

# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
Expand All @@ -203,12 +308,14 @@ BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
!?*.[Cc]ache/

# Others
ClientBin/
Expand All @@ -221,7 +328,7 @@ ClientBin/
*.publishsettings
orleans.codegen.cs

# Including strong name files can present a security risk
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

Expand Down Expand Up @@ -252,6 +359,9 @@ ServiceFabricBackup/
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl

# Microsoft Fakes
FakesAssemblies/
Expand Down Expand Up @@ -287,12 +397,8 @@ paket-files/
# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/
# CodeRush personal settings
.cr/personal

# Python Tools for Visual Studio (PTVS)
__pycache__/
Expand All @@ -317,7 +423,7 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
Expand All @@ -326,5 +432,16 @@ ASALocalRun/
# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder
# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Local History for Visual Studio
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# End of https://www.gitignore.io/api/rider,dotnetcore,visualstudio,visualstudiocode
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ Install-Package ViaCEP

The package has two classes:

- [ViaCEPClient](https://github.com/guibranco/ViaCEP/blob/master/ViaCEP/ViaCEPClient.cs) - The main class (methods)
- [ViaCEPResult](https://github.com/guibranco/ViaCEP/blob/master/ViaCEP/VIaCEPResult.cs) - The result class (data)
- [ViaCepClient](https://github.com/guibranco/ViaCEP/blob/master/ViaCEP/ViaCepClient.cs) - The main class (methods)
- [ViaCepResult](https://github.com/guibranco/ViaCEP/blob/master/ViaCEP/ViaCepResult.cs) - The result class (data)

This package is fully compatible with Dependency Injection. Use the interface *IViaCepClient* and the constructor with HttpClient parameter with a IHttpClientFactory instance.

```
//your DI container
services.AddHttpClient<IViaCepClient, ViaCepClient>(client =>{
client.BaseAddress = new Uri("https://viacep.com.br/");
})
```

You can search using the zip code/postal code (AKA CEP) or using the address data (state initials - UF, city name and location name - street, avenue, park, square). Both methods support async and sync!

## Querying by zip code / postal code (single result)

```cs
var result = ViaCEPClient.Search("01234567"); //searches for the postal code 01234-567
var result = new ViaCepClient().Search("01234567"); //searches for the postal code 01234-567
var address = result.Address;
var neighborhood = result.Neighborhood
//do what you need with 'result' instance of ViaCEPResult.
Expand All @@ -61,7 +71,7 @@ var neighborhood = result.Neighborhood
## Querying by address (list result)

```cs
var results = ViaCEPClient.Search("SP", "São Paulo", "Avenida Paulista"); //search for the Avenida Paulista in São Paulo / SP
var results = new ViaCepClient().Search("SP", "São Paulo", "Avenida Paulista"); //search for the Avenida Paulista in São Paulo / SP
foreach(var result in results){
var address = result.Address;
var neighborhood = result.Neighborhood;
Expand Down
48 changes: 48 additions & 0 deletions Src/ViaCEP/IViaCepClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace ViaCep
{
/// <summary>
/// The ViaCEP client interface.
/// </summary>
public interface IViaCepClient
{

/// <summary>
/// Searches the specified zip code.
/// </summary>
/// <param name="zipCode">The zip code.</param>
/// <returns></returns>
ViaCepResult Search(string zipCode);

/// <summary>
/// Searches the asynchronous.
/// </summary>
/// <param name="zipCode">The zip code.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<ViaCepResult> SearchAsync(string zipCode, CancellationToken cancellationToken);

/// <summary>
/// Searches the specified state initials.
/// </summary>
/// <param name="stateInitials">The state initials.</param>
/// <param name="city">The city.</param>
/// <param name="address">The address.</param>
/// <returns></returns>
IEnumerable<ViaCepResult> Search(string stateInitials, string city, string address);

/// <summary>
/// Searches the asynchronous.
/// </summary>
/// <param name="stateInitials">The state initials.</param>
/// <param name="city">The city.</param>
/// <param name="address">The address.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<IEnumerable<ViaCepResult>> SearchAsync(string stateInitials, string city, string address, CancellationToken cancellationToken);

}
}
4 changes: 2 additions & 2 deletions Src/ViaCEP/VIaCEPResult.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace ViaCEP
namespace ViaCep
{
using Newtonsoft.Json;

/// <summary>
/// The Via CEP result class.
/// </summary>
public sealed class ViaCEPResult
public sealed class ViaCepResult
{
/// <summary>
/// Gets or sets the zip code.
Expand Down
Loading

0 comments on commit 11f7dba

Please sign in to comment.