Giter Site home page Giter Site logo

justinbeckwith / yelpsharp Goto Github PK

View Code? Open in Web Editor NEW
37.0 10.0 41.0 6.38 MB

YelpSharp is a .NET wrapper for the Yelp REST API. It lets you do all kinds of interesting things like searching for businesses, getting user comments and ratings, and handling common errors. The library is written in C#, and available on NuGet.

C# 94.60% HTML 3.77% Batchfile 1.63%

yelpsharp's Introduction

YelpSharp

YelpSharp is a .NET wrapper for the Yelp REST API. It lets you do all kinds of interesting things like searching for businesses, getting user comments and ratings, and handling common errors. The library is written C#, and is available on NuGet.

For more information, visit the Yelp REST API

Installing

In most cases, you're going to want to install the YelpSharp NuGet package. Open up the Package Manager Console in Visual Studio, and run this command:

PM> Install-Package YelpSharp

How to Use

The source includes a few examples that should help you get started with ASP.NET and Windows Phone 8. Before you get started, you need to register for a Yelp developer account, and register for an API key. If you are looking for something and having trouble, you can always check out the unit tests.

Handling Tokens

The Yelp constructor takes a set of options that includes all of the keys neccesary to use the V2 Yelp API. Keep these keys safe! There are a variety of ways to store them. You can put them in the applicationSettings portion of your web.config (recommended), or store them in an environment variable on your dev machine:

var options = new Options()
{
    AccessToken = Environment.GetEnvironmentVariable("YELP_ACCESS_TOKEN", EnvironmentVariableTarget.Machine),
    AccessTokenSecret = Environment.GetEnvironmentVariable("YELP_ACCESS_TOKEN_SECRET", EnvironmentVariableTarget.Machine),
    ConsumerKey = Environment.GetEnvironmentVariable("YELP_CONSUMER_KEY", EnvironmentVariableTarget.Machine),
    ConsumerSecret = Environment.GetEnvironmentVariable("YELP_CONSUMER_SECRET", EnvironmentVariableTarget.Machine)
};

For a full example of conviently storing your tokens, check out the MvcSample.

Using the Search API

YelpSharp uses the Task Parallel Library (TPL) to make managing asynchronous requests easier. The search API has two different ways of searching for results. The simplest way is to pass a city and a search term. This will search Yelp for all coffee places around Seattle, WA (there are a lot).

var task = y.Search("coffee", "seattle, wa").ContinueWith((searchResults) =>
{
    foreach (var business in searchResults.Result.businesses)
    {
        Console.WriteLine(business.name);
    }
});

There are a lot of other ways to search. For more info, the best place to look is the unit tests.

Building the Source

If you want to build the source, clone the repository, and open up YelpSharp.sln.

git clone https://github.com/JustinBeckwith/YelpSharp
explorer YelpSharp\YelpSharp.sln

Supported Platforms

YelpSharp targets .NET 4.0, and Windows Phone 8. If you would like support for other platforms, let me know.

License

MIT License

Questions?

Feel free to submit an issue on the repository, or find me at @JustinBeckwith

yelpsharp's People

Contributors

aladler avatar dlsteuer avatar haiderabbas avatar justinbeckwith avatar renovate-bot avatar swegner avatar thejoecode avatar tugberkugurlu avatar waywardmage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yelpsharp's Issues

YelpSharp C# Issue

Hi Justin,
Hi,
I am running the following Yelp c# call on my local machine and it works perfectly fine:-
var results = y.Search(searchOptions).Result;

However, when I host the code on the server, this very line returns the following exception:-
Message: One or more errors occurred.
Source: mscorlib
STackTrace: at 'System.Threading.Tasks.Task.ThrowIfExceptional(Boolean include TaskCancelledExceptions)\r\n at System.Threading.Tasks.Task 1.GetResultCore.......

I have also attached a screenshot of the same. Kindly help me in this as its driving me crazy.

yelperror

Reviews are not being returned on search api

While making a search call:

var yelp = new YelpSharp.Yelp(new Options()
{
AccessToken = _yelpContext.AccessToken,
AccessTokenSecret = _yelpContext.AccessTokenSecret,
ConsumerKey = _yelpContext.ConsumerKey,
ConsumerSecret = _yelpContext.ConsumerSecret
});

        var searchOptions = new SearchOptions
        {
            LocationOptions = new LocationOptions()
            {
                location = location
            },
            GeneralOptions = new GeneralOptions()
            {
                category_filter = categoryFilter,
                limit = take,
                offset = skip
            }
        };
        var search = yelp.Search(searchOptions);
        SearchResults searchResults = search.Result;

for all searchResults.businesses, reviews is always null.

Is this an API limitation or perhaps a bug?

coordinates in querystring (the ll=) are formatted incorrectly when thread is non-us culture

Yelp wants these to be formatted as 11.22222222, -33.4444444. The website I am using the library on is often run for a French audience so my thread culture is fr-FR so this gets formatted as ll=11,22222222, -33,4444444 (note commas instead of periods) so Yelp throws an error along the lines of INVALID LOCATION.

I have pulled the library down from github and I have written my own version of the CoordinateOptions class where I override the GetParameters to force a format of the lat/lng in US format. This works when I run some debug tests in a test console but only because I am rebuilding the YelpSharp.dll along with my tests.

I have tried adding just this override class to my project but it is ignored. I am not an expert with overrides but I believe this is because the original inside of the compiled YelpSharp DLL is not a virtual class therefor my change does not get picked up.

I am being told by others on my team that rebuilding my own version of YelpSharp and adding to the project is not an option because this change would "get lost" along the way and at some point someone would run a nuget package restore or something that would wipe out my version with the latest from nuget. I'm also being told that fooling around with the culture on the thread that runs this particular call to YelpSharp business search is not allowed either. To me that would solve the problem without question but various folks here say it is a no-no.

So I am kind of stuck. :( I am open to suggestions about how I might fix this. The library has worked splendidly before so I am not too keen on abandoning it. Is there an option I have missed? Certainly somebody else has to have encountered this same problem?

Thanks to anyone who can help with this.

  • Eve

Copy'n'paste bug in YelpSharp.Data.Options.GeneralOptions

It looks like there's a copy'n'paste bug in the YelpSharp.Data.Options.GeneralOptions class. In the GetParameters method, the code that assigns values to limit, offset, and source all check for a value on limit:

if (limit.HasValue) ps.Add("limit", this.limit.Value.ToString());
if (limit.HasValue) ps.Add("offset", this.offset.Value.ToString());
if (limit.HasValue) ps.Add("sort", this.sort.Value.ToString());

NuGet not working for Windows Phone 8 Project

I am developing a Windows Phone 8 App in C# and want to use Yelp API v2. I tried adding the NuGet YelpSharp in my project but it didn't add any library into my project references. Is it not compatible with Windows Phone 8 projects.

UNAVAILABLE_FOR_LOCATION error when using coordinates search

Hi,

Each time I try to search using coordinates, I get a UNAVAILABLE_FOR_LOCATION error.

No matter which coordinates I use, even those provided in the UnitTest sample.

When I search using term or location, everything works fine.

Here is a sample of what's not working for me, taken from de UnitTest page.

What am I missing ?

Thanks for your help


var yelp = new Yelp(Config.Options);
var searchOptions = new YelpSharp.Data.Options.SearchOptions()
{
GeneralOptions = new GeneralOptions() { radius_filter = 5 },
LocationOptions = new CoordinateOptions()
{
latitude = 37.788022,
longitude = -122.399797
}
};
var results = yelp.Search(searchOptions).Result;

RestSharp Dependency

Trying to use YelpSharp on project that also involves Twilio. Twiliio requires latest version of RestSharp but YelpSharp fails with authentication error using newest version of RestSharp. Hope you can update or suggest work around. Love the library and hope you can help me out. Thanks.

Radius_filter and General Options Errors

I am using the following for the search options:

            var searchOptions = new YelpSharp.Data.Options.SearchOptions()
            {
                GeneralOptions = new GeneralOptions() { term = keyword, radius_filter=20 },
                LocationOptions = new LocationOptions()
                {
                    location = "new york, ny",
                    coordinates = new CoordinateOptions()
                    {
                        latitude = Convert.ToDouble(latitude),
                        longitude = Convert.ToDouble(longitude)
                    }
                }
            };

If I take out radius_filter it works fine but if I include it, I get an error I am I doing something wrong?

NuGet package out of date

Hi Justin,

it seems, that the NuGet-package for YelpSharp is out of date. The package still has the c'n'p error fixed for issue #8.

Thank You in advance
Mike

The api 'freezes' on .GetBusiness(yelpID).Result

Hello,

I've tested with a couple of restaurants for the GetBusiness method and it worked fine up until it began to just 'freeze' when I called .GetBusiness().Result. Nothing happens and it doesn't return a value, when I debug with VS I go to the .Result call and it just stays like that in the execution of the method.

Do you have any idea what might be wrong? Why it does not return a value or throw an exception?

Unable to get windows phone yelpsharp project running via test project

I downloaded the complete YelpSharp zip file from Github and placed it on my computer. I am running visual studio 2013 professional. I navigated to the downloaded files and opened the YelpSharp.sln file in the YelpSharp Samples folder. I entered all my key information and was able to run some test and return the desired results.

I copied the test case code to my windows phone 8 project and attempted to make the same calls. It did not work and no exception appeared to be thrown. I went back to the samples project and removed the basic yelp sharp project and instead loaded the Windows Phone yelp project and referenced that in the project with the unit test cases. I also ensured all my NuGet packages were updated to up to date.

When I attempted to run the same test the previously worked with the base yelpsharp library, the test failed. The code is crashing in the Yelp.cs file in the following function:

    /// <summary>
    /// advanced search based on search options object
    /// </summary>
    /// <param name="options"></param>
    /// <returns></returns>
    public Task<SearchResults> Search(SearchOptions options)
    {
        var result = makeRequest<SearchResults>("search", null, options.GetParameters());
        return result;
    }

The error that is being returned is below:
{"Could not load file or assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"}

I know what the error means. It is just that I cannot find the place were this specific version of the System.Net DLL is being referenced in order to resolve the challenge. I fear it may be in one of the other dependent packages like RestSharp. Any assistance in resolving this would be greatly appreciated.

I am a little confused as what exactly i need to get YelpSharp to work for me.

Hi. I am building a universal windows 10 app, and I am hoping to implement YelpSharp. When I add the files I want to my project I get tons of errors, usually regarding assembly references. My question is can I just take the files I need or do I need to import them using the package manager? Any help on the matter would greatly appreciated.

Search business with term containing '&' character

Hi,

I found an issue when trying to search a term and location

term = "Frimark Keller & Associates"

location = "60173"

Here is my C# source code which return 0 business

        var options = new Options
            {
                AccessToken = "<AccessToken>",
                AccessTokenSecret = "<AccessTokenSecret>",
                ConsumerKey = "<ConsumerKey>",
                ConsumerSecret = "<ConsumerSecret>"
            };
        var y = new Yelp(options);
        var searchOptions = new SearchOptions
            {
                GeneralOptions = new GeneralOptions
                    {
                        term = "Frimark Keller & Associates"
                    },
                LocationOptions = new LocationOptions
                    {
                        location = "60173"
                    }
            };
        var results = y.Search(searchOptions).Result;

Then, I went to Yelp page to search via browser, it returned one business

http://www.yelp.com/search?find_desc=Frimark%20Keller%20%26%20Associates&find_loc=60173&ns=1

I also used the JavaScript page to do the test, and it returned one result too.

Then, I download the YelpSharp source code to debug. I found this line of code

protected Task makeRequest(string area, string id, Dictionary<string, string> parameters)
{
// build the url with parameters
var url = area;
if (!String.IsNullOrEmpty(id)) url += "/" + Uri.EscapeDataString(id);
// restsharp FTW!
var client = new RestClient(rootUri)
{
Authenticator =
OAuth1Authenticator.ForProtectedResource(options.ConsumerKey, options.ConsumerSecret, options.AccessToken, options.AccessTokenSecret)
};
var request = new RestRequest(url, Method.GET);
if (parameters != null)
{
string[] keys = parameters.Keys.ToArray();
foreach (string k in keys)
{
request.AddParameter(k, parameters[k].Replace("&", "%26"));
}
}
var tcs = new TaskCompletionSource();
var handle = client.ExecuteAsync(request, response =>
{
var results = JsonConvert.DeserializeObject(response.Content);
tcs.SetResult(results);
});
return tcs.Task;
}

I am wondering why we need to encode '&' character because I think it will be encoded by RestClient automatically.

request.AddParameter(k, parameters[k].Replace("&", "%26"))

This line of code cause the '&' be encoded twice and no business returned.

Can you guy correct the code? Just simple remove .Replace("&", "%26") will get it working correctly. Or any purpose for this code?

Thanks & best regards,

HUNG T NGUYEN

No lat,long in results under Location.Coodinate object !!!

Any idea why there is never any latitude or longitude returned for a Business object under location.coodinate ?

The 'Location' object is always null for any results. I've tried the same query with another Yelp library and it returns the lat/long

Example code:

        foreach (Business business in results.businesses)
        {
            if (business.location.coordinate == null) 
                 Console.WriteLine( "Got a NULL business  LOCATION obj from YELP");
        }

Status=WaitingForActivation, Method="{null}", Result = "{Not yet computed}"

Hello,

When I am trying to "Search" with the Yelp api in a c# webservice, it runs ok and I get results fine. But when I try to run the same configuration with same access keys in C# UnitTest project, I get the following result.

Status=WaitingForActivation, Method="{null}", Result = "{Not yet computed}"
Exception=null
AsyncState = null

There is no error but the result set is empty. Does the not work in a library project?

Please advice. Let me know if you have further questions or need more info

Thank you in advance.

-Vishal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.